diff --git a/.ipynb_checkpoints/helper-checkpoint.ipynb b/.ipynb_checkpoints/helper-checkpoint.ipynb index 18ccf57..420b07f 100644 --- a/.ipynb_checkpoints/helper-checkpoint.ipynb +++ b/.ipynb_checkpoints/helper-checkpoint.ipynb @@ -57,26 +57,26 @@ "name": "stdout", "output_type": "stream", "text": [ - "call json%add(p,\"TopDriveTdsPowerState\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveTdsPowerState)\n", - "call json%add(p,\"TopDriveTorqueWrench\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveTorqueWrench)\n", - "call json%add(p,\"TopDriveDrillTorqueState\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveDrillTorqueState)\n", - "call json%add(p,\"TopDriveLinkTiltState\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveLinkTiltState)\n", - "call json%add(p,\"TopDriveIbop\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveIbop)\n", - "call json%add(p,\"TopDriveTorqueLimitKnob\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveTorqueLimitKnob)\n", - "call json%add(p,\"RpmKnob\",data%EquipmentControl%ControlPanel%CTopDrive%RpmKnob)\n", - "call json%add(p,\"TopDriveOperationFaultLed\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveOperationFaultLed)\n", - "call json%add(p,\"TopDriveTdsPowerLed\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveTdsPowerLed)\n", - "call json%add(p,\"TopDriveTorqueWrenchLed\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveTorqueWrenchLed)\n", - "call json%add(p,\"TopDriveLinkTiltLed\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveLinkTiltLed)\n", - "call json%add(p,\"TopDriveIbopLed\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveIbopLed)\n", - "call json%add(p,\"TopDriveTorqueLimitGauge\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveTorqueLimitGauge)\n", - "call json%add(p,\"TopDriveTorqueGauge\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveTorqueGauge)\n", - "call json%add(p,\"TopDriveRpmGauge\",data%EquipmentControl%ControlPanel%CTopDrive%TopDriveRpmGauge)\n" + "call json%add(p,\"TopDriveTdsPowerState\",data%Equipments%ControlPanel%CTopDrive%TopDriveTdsPowerState)\n", + "call json%add(p,\"TopDriveTorqueWrench\",data%Equipments%ControlPanel%CTopDrive%TopDriveTorqueWrench)\n", + "call json%add(p,\"TopDriveDrillTorqueState\",data%Equipments%ControlPanel%CTopDrive%TopDriveDrillTorqueState)\n", + "call json%add(p,\"TopDriveLinkTiltState\",data%Equipments%ControlPanel%CTopDrive%TopDriveLinkTiltState)\n", + "call json%add(p,\"TopDriveIbop\",data%Equipments%ControlPanel%CTopDrive%TopDriveIbop)\n", + "call json%add(p,\"TopDriveTorqueLimitKnob\",data%Equipments%ControlPanel%CTopDrive%TopDriveTorqueLimitKnob)\n", + "call json%add(p,\"RpmKnob\",data%Equipments%ControlPanel%CTopDrive%RpmKnob)\n", + "call json%add(p,\"TopDriveOperationFaultLed\",data%Equipments%ControlPanel%CTopDrive%TopDriveOperationFaultLed)\n", + "call json%add(p,\"TopDriveTdsPowerLed\",data%Equipments%ControlPanel%CTopDrive%TopDriveTdsPowerLed)\n", + "call json%add(p,\"TopDriveTorqueWrenchLed\",data%Equipments%ControlPanel%CTopDrive%TopDriveTorqueWrenchLed)\n", + "call json%add(p,\"TopDriveLinkTiltLed\",data%Equipments%ControlPanel%CTopDrive%TopDriveLinkTiltLed)\n", + "call json%add(p,\"TopDriveIbopLed\",data%Equipments%ControlPanel%CTopDrive%TopDriveIbopLed)\n", + "call json%add(p,\"TopDriveTorqueLimitGauge\",data%Equipments%ControlPanel%CTopDrive%TopDriveTorqueLimitGauge)\n", + "call json%add(p,\"TopDriveTorqueGauge\",data%Equipments%ControlPanel%CTopDrive%TopDriveTorqueGauge)\n", + "call json%add(p,\"TopDriveRpmGauge\",data%Equipments%ControlPanel%CTopDrive%TopDriveRpmGauge)\n" ] } ], "source": [ - "precode = \"\"\"call json%add(pform,\"\",data%EquipmentControl%ControlPanel%CTopDrive%\"\"\"\n", + "precode = \"\"\"call json%add(pform,\"\",data%Equipments%ControlPanel%CTopDrive%\"\"\"\n", "input = open(\"Text1.txt\")\n", "lines = input.readlines()\n", "for line in lines:\n", diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b78e7b4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,30 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug SimulationCore2", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/SimulationCore2_DEBUG", + "args": ["Config-debug.json"], + "stopAtEntry": false, + "cwd": "${workspaceRoot}", + "externalConsole": false, + "MIMode": "gdb", + // "preLaunchTask": "make debug", + }, + { + "name": "Debug write_vars", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceRoot}/write_vars", + "args": ["Config-debug.json"], + "stopAtEntry": false, + "cwd": "${workspaceRoot}", + "externalConsole": false, + "MIMode": "gdb", + // "preLaunchTask": "make debug", + } + + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..2925973 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,25 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "make", + "type": "shell", + "command": "make", + "options": { + "cwd": "${workspaceRoot}" + } + }, + { + "label": "make debug", + "type": "shell", + "command": "make", + "args": [ + "debug" + ], + "options": { + "cwd": "${workspaceRoot}" + } + }, + + ] +} \ No newline at end of file diff --git a/CSharp/BasicInputs/Bha/CStringConfiguration.f90 b/CSharp/BasicInputs/Bha/CStringConfiguration.f90 index a4f9955..fdbbecb 100644 --- a/CSharp/BasicInputs/Bha/CStringConfiguration.f90 +++ b/CSharp/BasicInputs/Bha/CStringConfiguration.f90 @@ -76,14 +76,15 @@ module CStringConfiguration type(json_value),pointer :: parent type(json_core) :: json type(json_value),pointer :: pitems,pitem,pbit,p - integer:: i + integer:: i,n ! 1. create new node call json%create_object(p,'StringConfiguration') call json%create_array(pitems,'StringConfigurationItems') ! 2. add member of data type to new node - do i=1,data%Configuration%StringConfiguration%StringConfigurationCount - call json%create_object(pitem,'StringConfigurationItem') + n = data%Configuration%StringConfiguration%StringConfigurationCount + do i=1,n + call json%create_object(pitem,'') call json%add(pitem,"ComponentLength",data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentLength) call json%add(pitem,"ComponentType",data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentType) call json%add(pitem,"Grade",data%Configuration%StringConfiguration%StringConfigurations(i)%Grade) @@ -95,6 +96,7 @@ module CStringConfiguration call json%add(pitem,"WeightPerLength",data%Configuration%StringConfiguration%StringConfigurations(i)%WeightPerLength) call json%add(pitems,pitem) end do + call json%create_object(pbit,"BitDefenition") call json%add(pbit,"BitCodeHundreds",data%Configuration%StringConfiguration%BitDefinition%BitCodeHundreds) call json%add(pbit,"BitCodeOnes",data%Configuration%StringConfiguration%BitDefinition%BitCodeOnes) @@ -113,5 +115,4 @@ module CStringConfiguration call json%add(p,pbit) call json%add(parent,p) end subroutine - end module CStringConfiguration \ No newline at end of file diff --git a/CSharp/BasicInputs/Bha/CStringConfiguration.i90 b/CSharp/BasicInputs/Bha/CStringConfiguration.i90 new file mode 100644 index 0000000..d855690 --- /dev/null +++ b/CSharp/BasicInputs/Bha/CStringConfiguration.i90 @@ -0,0 +1,119 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/Bha/CStringConfiguration.f90" +module CStringConfiguration + use CStringConfigurationVariables + use SimulationVariables + use json_module + + implicit none + public + contains + + subroutine StringConfigurationFromJson(parent) + use json_module,IK =>json_ik + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pitems,pitem,pval,pbit + logical::is_found + type(CStringItem) :: item + integer::i,n_children + CHARACTER(KIND=JSON_CK, LEN=:), ALLOCATABLE :: val + + + call json%get(parent,'StringConfiguration',p) + + call json%get(p,'StringConfigurationItems',pitems) + call json%info(pitems, n_children=n_children) + if (.not. allocated(data%Configuration%StringConfiguration%StringConfigurations) .or. size(data%Configuration%StringConfiguration%StringConfigurations)/=n_children) then + ALLOCATE(data%Configuration%StringConfiguration%StringConfigurations(n_children)) + endif + do i=1,n_children + call json%get_child(pitems, i, pitem, found=is_found) + + call json%get(pitem,"ComponentType",pval) + call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentType) + call json%get(pitem,"NumberOfJoint",pval) + call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint) + call json%get(pitem,"LengthPerJoint",pval) + call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%LengthPerJoint) + call json%get(pitem,"NominalOd",pval) + call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalOd) + call json%get(pitem,"NominalId",pval) + call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalId) + call json%get(pitem,"WeightPerLength",pval) + call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%WeightPerLength) + call json%get(pitem,"ComponentLength",pval) + call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentLength) + call json%get(pitem,"NominalToolJointOd",pval) + call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalToolJointOd) + call json%get(pitem,"Grade",pval) + call json%get(pval,val) + data%Configuration%StringConfiguration%StringConfigurations(i)%Grade = val + end do + call json%get(p,'BitDefenition',pbit) + call json%get(pbit,'BitType',pval) + call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitType) + call json%get(pbit,'BitSize',pval) + call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitSize) + call json%get(pbit,'BitCodeHundreds',pval) + call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeHundreds) + call json%get(pbit,'BitCodeTens',pval) + call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeTens) + call json%get(pbit,'BitCodeOnes',pval) + call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeOnes) + call json%get(pbit,'BitNozzleSize',pval) + call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitNozzleSize) + call json%get(pbit,'BitLength',pval) + call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitLength) + call json%get(pbit,'BitWeightPerLength',pval) + call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitWeightPerLength) + call json%get(pbit,'BitNozzleNo',pval) + call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitNozzleNo) + call json%get(pbit,'FloatValve',pval) + call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%FloatValve) + end subroutine + + subroutine StringConfigurationToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: pitems,pitem,pbit,p + integer:: i,n +! 1. create new node + call json%create_object(p,'StringConfiguration') + call json%create_array(pitems,'StringConfigurationItems') + +! 2. add member of data type to new node + n = data%Configuration%StringConfiguration%StringConfigurationCount + do i=1,n + call json%create_object(pitem,'') + call json%add(pitem,"ComponentLength",data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentLength) + call json%add(pitem,"ComponentType",data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentType) + call json%add(pitem,"Grade",data%Configuration%StringConfiguration%StringConfigurations(i)%Grade) + call json%add(pitem,"LengthPerJoint",data%Configuration%StringConfiguration%StringConfigurations(i)%LengthPerJoint) + call json%add(pitem,"NominalId",data%Configuration%StringConfiguration%StringConfigurations(i)%NominalId) + call json%add(pitem,"NominalOd",data%Configuration%StringConfiguration%StringConfigurations(i)%NominalOd) + call json%add(pitem,"NominalToolJointOd",data%Configuration%StringConfiguration%StringConfigurations(i)%NominalToolJointOd) + call json%add(pitem,"NumberOfJoint",data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint) + call json%add(pitem,"WeightPerLength",data%Configuration%StringConfiguration%StringConfigurations(i)%WeightPerLength) + call json%add(pitems,pitem) + end do + + call json%create_object(pbit,"BitDefenition") + call json%add(pbit,"BitCodeHundreds",data%Configuration%StringConfiguration%BitDefinition%BitCodeHundreds) + call json%add(pbit,"BitCodeOnes",data%Configuration%StringConfiguration%BitDefinition%BitCodeOnes) + call json%add(pbit,"BitCodeTens",data%Configuration%StringConfiguration%BitDefinition%BitCodeTens) + call json%add(pbit,"BitLength",data%Configuration%StringConfiguration%BitDefinition%BitLength) + call json%add(pbit,"BitNozzleNo",data%Configuration%StringConfiguration%BitDefinition%BitNozzleNo) + call json%add(pbit,"BitNozzleSize",data%Configuration%StringConfiguration%BitDefinition%BitNozzleSize) + call json%add(pbit,"BitSize",data%Configuration%StringConfiguration%BitDefinition%BitSize) + call json%add(pbit,"BitType",data%Configuration%StringConfiguration%BitDefinition%BitType) + call json%add(pbit,"BitWeightPerLength",data%Configuration%StringConfiguration%BitDefinition%BitWeightPerLength) + call json%add(pbit,"FloatValve",data%Configuration%StringConfiguration%BitDefinition%FloatValve) + +! call json%add(p,"StringConfigurationCount",dat%Configuration%StringConfiguration%StringConfigurationCount) +! 3. add new node to parent + call json%add(p,pitems) + call json%add(p,pbit) + call json%add(parent,p) + end subroutine +end module CStringConfiguration diff --git a/CSharp/BasicInputs/Bha/CStringConfigurationVariables.f90 b/CSharp/BasicInputs/Bha/CStringConfigurationVariables.f90 index ca1a946..0f03f62 100644 --- a/CSharp/BasicInputs/Bha/CStringConfigurationVariables.f90 +++ b/CSharp/BasicInputs/Bha/CStringConfigurationVariables.f90 @@ -38,7 +38,7 @@ module CStringConfigurationVariables end type CBitInfo Type :: StringConfigurationType - integer :: StringConfigurationCount = 0 + integer :: StringConfigurationCount type(CStringItem), allocatable :: StringConfigurations(:) type(CBitInfo) :: BitDefinition End type StringConfigurationType diff --git a/CSharp/BasicInputs/Bha/CStringConfigurationVariables.i90 b/CSharp/BasicInputs/Bha/CStringConfigurationVariables.i90 new file mode 100644 index 0000000..ad3b7ca --- /dev/null +++ b/CSharp/BasicInputs/Bha/CStringConfigurationVariables.i90 @@ -0,0 +1,47 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/Bha/CStringConfigurationVariables.f90" +module CStringConfigurationVariables + implicit none + public +!constants + integer :: Bit_ComponentType = 0 + integer :: Stabilizer_ComponentType = 1 + integer :: Collar_ComponentType = 2 + integer :: DrillPipe_ComponentType = 3 + integer :: Heavyweight_ComponentType = 4 + + integer :: Cone_BitType = 0 + integer :: PDC_BitType = 1 + integer :: Rock_BitType = 2 + + type, bind(c), public :: CStringItem + integer :: ComponentType + real(8) :: NumberOfJoint + real(8) :: LengthPerJoint + real(8) :: NominalOd + real(8) :: NominalId + real(8) :: WeightPerLength + real(8) :: ComponentLength + real(8) :: NominalToolJointOd + character(1) :: Grade + end type CStringItem + + type, bind(c), public :: CBitInfo + integer :: BitType + real(8) :: BitSize + integer :: BitCodeHundreds + integer :: BitCodeTens + integer :: BitCodeOnes + real(8) :: BitNozzleSize + real(8) :: BitLength + real(8) :: BitWeightPerLength + integer :: BitNozzleNo + logical :: FloatValve + end type CBitInfo + + Type :: StringConfigurationType + integer :: StringConfigurationCount + type(CStringItem), allocatable :: StringConfigurations(:) + type(CBitInfo) :: BitDefinition + End type StringConfigurationType + contains +end module CStringConfigurationVariables diff --git a/CSharp/BasicInputs/CMudPropertiesVariables.i90 b/CSharp/BasicInputs/CMudPropertiesVariables.i90 new file mode 100644 index 0000000..7f9874a --- /dev/null +++ b/CSharp/BasicInputs/CMudPropertiesVariables.i90 @@ -0,0 +1,83 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/CMudPropertiesVariables.f90" +module CMudPropertiesVariables + use CIActionReference +!**use CDoubleEventHandlerCollection + implicit none + public +!constants + integer, parameter :: WaterBase_MudType = 0 + integer, parameter :: OilBase_MudType = 1 + integer, parameter :: PowerLaw_RheologyModel = 0 + integer, parameter :: Bingham_RheologyModel = 1 + integer, parameter :: Newtonian_RheologyModel = 2 + INTEGER, PARAMETER :: Herschel_Bulkley_RheologyModel = 3 + +! variables + Type::MudPropertiesType + integer :: ActiveMudType + integer :: ActiveRheologyModel + real(8) :: ActiveMudVolume + real(8) :: ActiveMudVolumeGal + real(8) :: ActiveDensity + real(8) :: ActivePlasticViscosity + real(8) :: ActiveYieldPoint + real(8) :: ActiveThetaThreeHundred + real(8) :: ActiveThetaSixHundred + + integer :: ReserveMudType + real(8) :: ReserveMudVolume + real(8) :: ReserveMudVolumeGal + real(8) :: ReserveDensity + real(8) :: ReservePlasticViscosity + real(8) :: ReserveYieldPoint + real(8) :: ReserveThetaThreeHundred + real(8) :: ReserveThetaSixHundred + + real(8) :: ActiveTotalTankCapacity + real(8) :: ActiveTotalTankCapacityGal + real(8) :: ActiveSettledContents + real(8) :: ActiveSettledContentsGal + real(8) :: ActiveTotalContents + real(8) :: ActiveTotalContentsGal + logical :: ActiveAutoDensity + real(8) :: InitialTripTankMudVolume + real(8) :: InitialTripTankMudVolumeGal + real(8) :: PedalFlowMeter + End type MudPropertiesType +! Type(MudPropertiesType)::MudProperties + + + +! subroutine SubscribeActiveMudVolume(a) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeActiveMudVolume +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeActiveMudVolume' :: SubscribeActiveMudVolume +! implicit none +! procedure (ActionDouble) :: a +! ActiveMudVolumePtr => a +! end subroutine + +! subroutine SubscribeActiveDensity(a) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeActiveDensity +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeActiveDensity' :: SubscribeActiveDensity +! implicit none +! procedure (ActionDouble) :: a +! ActiveDensityPtr => a +! end subroutine + +! subroutine SubscribeReserveMudVolume(a) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeReserveMudVolume +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeReserveMudVolume' :: SubscribeReserveMudVolume +! implicit none +! procedure (ActionDouble) :: a +! ReserveMudVolumePtr => a +! end subroutine + +! subroutine SubscribeReserveDensity(a) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeReserveDensity +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeReserveDensity' :: SubscribeReserveDensity +! implicit none +! procedure (ActionDouble) :: a +! ReserveDensityPtr => a +! end subroutine + +end module CMudPropertiesVariables diff --git a/CSharp/BasicInputs/Geology/CFormation.f90 b/CSharp/BasicInputs/Geology/CFormation.f90 index 538b879..16bf2d8 100644 --- a/CSharp/BasicInputs/Geology/CFormation.f90 +++ b/CSharp/BasicInputs/Geology/CFormation.f90 @@ -46,12 +46,12 @@ module CFormation type(json_value),pointer :: parent type(json_core) :: json type(json_value),pointer :: p,pform - integer :: i + integer :: i,n ! 1. create new node call json%create_array(p,'Formations') - - do i=1,data%Configuration%Formation%Count + n= data%Configuration%Formation%Count + do i=1,n call json%create_object(pform,'') call json%add(pform,"Abrasiveness",data%Configuration%Formation%Formations(i)%Abrasiveness) call json%add(pform,"Drillablity",data%Configuration%Formation%Formations(i)%Drillablity) diff --git a/CSharp/BasicInputs/Geology/CFormation.i90 b/CSharp/BasicInputs/Geology/CFormation.i90 new file mode 100644 index 0000000..edf9157 --- /dev/null +++ b/CSharp/BasicInputs/Geology/CFormation.i90 @@ -0,0 +1,69 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/Geology/CFormation.f90" +module CFormation + use CFormationVariables + use SimulationVariables + use json_module + implicit none + + contains + + subroutine FormationFromJson(parent) + use json_module,IK =>json_ik + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pitem,pval + logical::is_found + integer::i,n_children + CHARACTER(KIND=JSON_CK, LEN=:), ALLOCATABLE :: val + + + call json%get(parent,'Formation',p) + + call json%info(p, n_children=n_children) + data%Configuration%Formation%Count = n_children + if (.not. allocated(data%Configuration%Formation%Formations) .or. size(data%Configuration%Formation%Formations)/=n_children) then + ALLOCATE(data%Configuration%Formation%Formations(n_children)) + endif + do i=1,n_children + call json%get_child(p, i, pitem, found=is_found) + + call json%get(pitem,'Top',pval) + call json%get(pval,data%Configuration%Formation%Formations(i)%Top) + call json%get(pitem,'Thickness',pval) + call json%get(pval,data%Configuration%Formation%Formations(i)%Thickness) + call json%get(pitem,'Drillablity',pval) + call json%get(pval,data%Configuration%Formation%Formations(i)%Drillablity) + call json%get(pitem,'Abrasiveness',pval) + call json%get(pval,data%Configuration%Formation%Formations(i)%Abrasiveness) + call json%get(pitem,'ThresholdWeight',pval) + call json%get(pval,data%Configuration%Formation%Formations(i)%ThresholdWeight) + call json%get(pitem,'PorePressureGradient',pval) + call json%get(pval,data%Configuration%Formation%Formations(i)%PorePressureGradient) + end do + end subroutine + + subroutine FormationToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pform + integer :: i,n + +! 1. create new node + call json%create_array(p,'Formations') + n= data%Configuration%Formation%Count + do i=1,n + call json%create_object(pform,'') + call json%add(pform,"Abrasiveness",data%Configuration%Formation%Formations(i)%Abrasiveness) + call json%add(pform,"Drillablity",data%Configuration%Formation%Formations(i)%Drillablity) + call json%add(pform,"PorePressureGradient",data%Configuration%Formation%Formations(i)%PorePressureGradient) + call json%add(pform,"Thickness",data%Configuration%Formation%Formations(i)%Thickness) + call json%add(pform,"ThresholdWeight",data%Configuration%Formation%Formations(i)%ThresholdWeight) + call json%add(pform,"Top",data%Configuration%Formation%Formations(i)%Top) + call json%add(p,pform) + end do + + call json%add(parent,p) + end subroutine + +end module CFormation diff --git a/CSharp/BasicInputs/Geology/CFormationVariables.i90 b/CSharp/BasicInputs/Geology/CFormationVariables.i90 new file mode 100644 index 0000000..d633fe1 --- /dev/null +++ b/CSharp/BasicInputs/Geology/CFormationVariables.i90 @@ -0,0 +1,22 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/Geology/CFormationVariables.f90" +module CFormationVariables +! !@use ConfigurationVariables, only: Configuration + implicit none + public + +! types +! Pipe Items in String Array + type, bind(c), public :: CFormationItem + real(8) :: Top + real(8) :: Thickness + real(8) :: Drillablity + real(8) :: Abrasiveness + real(8) :: ThresholdWeight + real(8) :: PorePressureGradient + end type CFormationItem + + Type::FormationType + integer :: Count = 0 + type(CFormationItem), allocatable :: Formations(:) + End type FormationType +end module CFormationVariables diff --git a/CSharp/BasicInputs/Geology/CReservoir.f90 b/CSharp/BasicInputs/Geology/CReservoir.f90 index 478713b..62c4b11 100644 --- a/CSharp/BasicInputs/Geology/CReservoir.f90 +++ b/CSharp/BasicInputs/Geology/CReservoir.f90 @@ -6,13 +6,9 @@ module CReservoir contains subroutine ReservoirFromJson(parent) - use json_module,IK =>json_ik type(json_value),pointer :: parent type(json_core) :: json - type(json_value),pointer :: p,pitem,pval - logical::is_found - integer::i,n_children - CHARACTER(KIND=JSON_CK, LEN=:), ALLOCATABLE :: val + type(json_value),pointer :: p,pval call json%get(parent,'Reservoir',p) diff --git a/CSharp/BasicInputs/Geology/CReservoir.i90 b/CSharp/BasicInputs/Geology/CReservoir.i90 new file mode 100644 index 0000000..7da502e --- /dev/null +++ b/CSharp/BasicInputs/Geology/CReservoir.i90 @@ -0,0 +1,71 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/Geology/CReservoir.f90" +module CReservoir + use SimulationVariables + use json_module + implicit none + + contains + + subroutine ReservoirFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + + call json%get(parent,'Reservoir',p) + + call json%get(p,'FormationNo',pval) + call json%get(pval,data%Configuration%Reservoir%FormationNo) + call json%get(p,'FormationTop',pval) + call json%get(pval,data%Configuration%Reservoir%FormationTop) + call json%get(p,'PressureGradient',pval) + call json%get(pval,data%Configuration%Reservoir%PressureGradient) + call json%get(p,'FormationPermeability',pval) + call json%get(pval,data%Configuration%Reservoir%FormationPermeability) + call json%get(p,'GeothermalGradient',pval) + call json%get(pval,data%Configuration%Reservoir%GeothermalGradient) + call json%get(p,'FluidType',pval) + call json%get(pval,data%Configuration%Reservoir%FluidType) + call json%get(p,'FluidGradient',pval) + call json%get(pval,data%Configuration%Reservoir%FluidGradient) + call json%get(p,'FluidViscosity',pval) + call json%get(pval,data%Configuration%Reservoir%FluidViscosity) + call json%get(p,'InactiveInflux',pval) + call json%get(pval,data%Configuration%Reservoir%InactiveInflux) + call json%get(p,'IsAutoMigrationRateSelected',pval) + call json%get(pval,data%Configuration%Reservoir%IsAutoMigrationRateSelected) + call json%get(p,'AutoMigrationRate',pval) + call json%get(pval,data%Configuration%Reservoir%AutoMigrationRate) + call json%get(p,'MakeKickSinglePacket',pval) + call json%get(pval,data%Configuration%Reservoir%MakeKickSinglePacket) + end subroutine + + subroutine ReservoirToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Reservoir') + +! 2. add member of data type to new node +! call StringConfigurationToJson(p) +! call FormationToJson(p) + call json%add(p,"AutoMigrationRate",data%Configuration%Reservoir%AutoMigrationRate) + call json%add(p,"FluidGradient",data%Configuration%Reservoir%FluidGradient) + call json%add(p,"FluidType",data%Configuration%Reservoir%FluidType) + call json%add(p,"FluidViscosity",data%Configuration%Reservoir%FluidViscosity) + call json%add(p,"FormationNo",data%Configuration%Reservoir%FormationNo) + call json%add(p,"FormationPermeability",data%Configuration%Reservoir%FormationPermeability) + call json%add(p,"FormationTop",data%Configuration%Reservoir%FormationTop) + call json%add(p,"GeothermalGradient",data%Configuration%Reservoir%GeothermalGradient) + call json%add(p,"InactiveInflux",data%Configuration%Reservoir%InactiveInflux) + call json%add(p,"IsAutoMigrationRateSelected",data%Configuration%Reservoir%IsAutoMigrationRateSelected) + call json%add(p,"MakeKickSinglePacket",data%Configuration%Reservoir%MakeKickSinglePacket) + call json%add(p,"PressureGradient",data%Configuration%Reservoir%PressureGradient) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine +end module CReservoir diff --git a/CSharp/BasicInputs/Geology/CShoe.i90 b/CSharp/BasicInputs/Geology/CShoe.i90 new file mode 100644 index 0000000..971df2b --- /dev/null +++ b/CSharp/BasicInputs/Geology/CShoe.i90 @@ -0,0 +1,57 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/Geology/CShoe.f90" +module CShoe + use SimulationVariables + use json_module + + implicit none + public + contains + + subroutine ShoeFromJson(parent) + use json_module,IK =>json_ik + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pitem,pval + logical::is_found + integer::i,n_children + CHARACTER(KIND=JSON_CK, LEN=:), ALLOCATABLE :: val + + + call json%get(parent,'Shoe',p) + + call json%get(p,'FormationNo',pval) + call json%get(pval,data%Configuration%Shoe%FormationNo) + call json%get(p,'ShoeDepth',pval) + call json%get(pval,data%Configuration%Shoe%ShoeDepth) + call json%get(p,'LeakOff',pval) + call json%get(pval,data%Configuration%Shoe%LeakOff) + call json%get(p,'Breakdown',pval) + call json%get(pval,data%Configuration%Shoe%Breakdown) + call json%get(p,'FracturePropagation',pval) + call json%get(pval,data%Configuration%Shoe%FracturePropagation) + call json%get(p,'InactiveFracture',pval) + call json%get(pval,data%Configuration%Shoe%InactiveFracture) + end subroutine + + subroutine ShoeToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Shoe') + +! 2. add member of data type to new node + call json%add(p,"Breakdown",data%Configuration%Shoe%Breakdown) + call json%add(p,"FormationNo",data%Configuration%Shoe%FormationNo) + call json%add(p,"FracturePropagation",data%Configuration%Shoe%FracturePropagation) + call json%add(p,"InactiveFracture",data%Configuration%Shoe%InactiveFracture) + call json%add(p,"LeakOff",data%Configuration%Shoe%LeakOff) + call json%add(p,"ShoeDepth",data%Configuration%Shoe%ShoeDepth) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + +end module CShoe diff --git a/CSharp/BasicInputs/Geology/CShoeVariables.f90 b/CSharp/BasicInputs/Geology/CShoeVariables.f90 index c075aef..309a2b0 100644 --- a/CSharp/BasicInputs/Geology/CShoeVariables.f90 +++ b/CSharp/BasicInputs/Geology/CShoeVariables.f90 @@ -10,5 +10,5 @@ module CShoeVariables real(8) :: FracturePropagation logical :: InactiveFracture End type ShoeType - Type(ShoeType)::Shoe + ! Type(ShoeType)::Shoe end module CShoeVariables \ No newline at end of file diff --git a/CSharp/BasicInputs/Geology/CShoeVariables.i90 b/CSharp/BasicInputs/Geology/CShoeVariables.i90 new file mode 100644 index 0000000..2608829 --- /dev/null +++ b/CSharp/BasicInputs/Geology/CShoeVariables.i90 @@ -0,0 +1,15 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/Geology/CShoeVariables.f90" +module CShoeVariables + implicit none + public +! variables + Type::ShoeType + integer :: FormationNo + real(8) :: ShoeDepth + real(8) :: LeakOff + real(8) :: Breakdown + real(8) :: FracturePropagation + logical :: InactiveFracture + End type ShoeType +! Type(ShoeType)::Shoe +end module CShoeVariables diff --git a/CSharp/BasicInputs/MudProperties.i90 b/CSharp/BasicInputs/MudProperties.i90 new file mode 100644 index 0000000..bbbff9a --- /dev/null +++ b/CSharp/BasicInputs/MudProperties.i90 @@ -0,0 +1,156 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/MudProperties.f90" +module MudPropertiesModule + use SimulationVariables + use json_module + implicit none + + contains + + subroutine MudPropertiesToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Mud') + +! 2. add member of data type to new node + call json%add(p,"ActiveMudType",data%Configuration%Mud%ActiveMudType) + call json%add(p,"ActiveRheologyModel",data%Configuration%Mud%ActiveRheologyModel) + call json%add(p,"ActiveMudVolume",data%Configuration%Mud%ActiveMudVolume) + call json%add(p,"ActiveMudVolumeGal",data%Configuration%Mud%ActiveMudVolumeGal) + call json%add(p,"ActiveDensity",data%Configuration%Mud%ActiveDensity) + call json%add(p,"ActivePlasticViscosity",data%Configuration%Mud%ActivePlasticViscosity) + call json%add(p,"ActiveYieldPoint",data%Configuration%Mud%ActiveYieldPoint) + call json%add(p,"ActiveThetaThreeHundred",data%Configuration%Mud%ActiveThetaThreeHundred) + call json%add(p,"ActiveThetaSixHundred",data%Configuration%Mud%ActiveThetaSixHundred) + call json%add(p,"ReserveMudType",data%Configuration%Mud%ReserveMudType) + call json%add(p,"ReserveMudVolume",data%Configuration%Mud%ReserveMudVolume) + call json%add(p,"ReserveMudVolumeGal",data%Configuration%Mud%ReserveMudVolumeGal) + call json%add(p,"ReserveDensity",data%Configuration%Mud%ReserveDensity) + call json%add(p,"ReservePlasticViscosity",data%Configuration%Mud%ReservePlasticViscosity) + call json%add(p,"ReserveYieldPoint",data%Configuration%Mud%ReserveYieldPoint) + call json%add(p,"ReserveThetaThreeHundred",data%Configuration%Mud%ReserveThetaThreeHundred) + call json%add(p,"ReserveThetaSixHundred",data%Configuration%Mud%ReserveThetaSixHundred) + call json%add(p,"ActiveTotalTankCapacity",data%Configuration%Mud%ActiveTotalTankCapacity) + call json%add(p,"ActiveTotalTankCapacityGal",data%Configuration%Mud%ActiveTotalTankCapacityGal) + call json%add(p,"ActiveSettledContents",data%Configuration%Mud%ActiveSettledContents) + call json%add(p,"ActiveSettledContentsGal",data%Configuration%Mud%ActiveSettledContentsGal) + call json%add(p,"ActiveTotalContents",data%Configuration%Mud%ActiveTotalContents) + call json%add(p,"ActiveTotalContentsGal",data%Configuration%Mud%ActiveTotalContentsGal) + call json%add(p,"ActiveAutoDensity",data%Configuration%Mud%ActiveAutoDensity) + call json%add(p,"InitialTripTankMudVolume",data%Configuration%Mud%InitialTripTankMudVolume) + call json%add(p,"InitialTripTankMudVolumeGal",data%Configuration%Mud%InitialTripTankMudVolumeGal) + call json%add(p,"PedalFlowMeter",data%Configuration%Mud%PedalFlowMeter) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine MudPropertiesFromJson(parent) + use json_module,IK =>json_ik + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pitems,pitem,pval,pbit + + call json%get(parent,'Mud',p) + + call json%get(p,"ActiveMudType",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveMudType) + call json%get(p,"ActiveRheologyModel",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveRheologyModel) + call json%get(p,"ActiveMudVolume",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveMudVolume) + call json%get(p,"ActiveMudVolumeGal",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveMudVolumeGal) + call json%get(p,"ActiveDensity",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveDensity) + call json%get(p,"ActivePlasticViscosity",pitem) + call json%get(pitem,data%Configuration%Mud%ActivePlasticViscosity) + call json%get(p,"ActiveYieldPoint",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveYieldPoint) + call json%get(p,"ActiveThetaThreeHundred",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveThetaThreeHundred) + call json%get(p,"ActiveThetaSixHundred",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveThetaSixHundred) + call json%get(p,"ReserveMudType",pitem) + call json%get(pitem,data%Configuration%Mud%ReserveMudType) + call json%get(p,"ReserveMudVolume",pitem) + call json%get(pitem,data%Configuration%Mud%ReserveMudVolume) + call json%get(p,"ReserveMudVolumeGal",pitem) + call json%get(pitem,data%Configuration%Mud%ReserveMudVolumeGal) + call json%get(p,"ReserveDensity",pitem) + call json%get(pitem,data%Configuration%Mud%ReserveDensity) + call json%get(p,"ReservePlasticViscosity",pitem) + call json%get(pitem,data%Configuration%Mud%ReservePlasticViscosity) + call json%get(p,"ReserveYieldPoint",pitem) + call json%get(pitem,data%Configuration%Mud%ReserveYieldPoint) + call json%get(p,"ReserveThetaThreeHundred",pitem) + call json%get(pitem,data%Configuration%Mud%ReserveThetaThreeHundred) + call json%get(p,"ReserveThetaSixHundred",pitem) + call json%get(pitem,data%Configuration%Mud%ReserveThetaSixHundred) + call json%get(p,"ActiveTotalTankCapacity",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveTotalTankCapacity) + call json%get(p,"ActiveTotalTankCapacityGal",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveTotalTankCapacityGal) + call json%get(p,"ActiveSettledContents",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveSettledContents) + call json%get(p,"ActiveSettledContentsGal",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveSettledContentsGal) + call json%get(p,"ActiveTotalContents",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveTotalContents) + call json%get(p,"ActiveTotalContentsGal",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveTotalContentsGal) + call json%get(p,"ActiveAutoDensity",pitem) + call json%get(pitem,data%Configuration%Mud%ActiveAutoDensity) + call json%get(p,"InitialTripTankMudVolume",pitem) + call json%get(pitem,data%Configuration%Mud%InitialTripTankMudVolume) + call json%get(p,"InitialTripTankMudVolumeGal",pitem) + call json%get(pitem,data%Configuration%Mud%InitialTripTankMudVolumeGal) + call json%get(p,"PedalFlowMeter",pitem) + call json%get(pitem,data%Configuration%Mud%PedalFlowMeter) + + end subroutine + + subroutine Set_ActiveMudVolume_StudentStation(v) + implicit none + real*8, intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%Configuration%Mud%ActiveMudVolume == v) return + #endif + data%Configuration%Mud%ActiveMudVolume = v +! if(associated(ActiveMudVolumePtr)) call ActiveMudVolumePtr(data%Configuration%Mud%ActiveMudVolume) + end subroutine + + subroutine Set_ActiveDensity_StudentStation(v) + implicit none + real*8, intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%Configuration%Mud%ActiveDensity == v) return + #endif + data%Configuration%Mud%ActiveDensity = v +! if(associated(ActiveDensityPtr)) call ActiveDensityPtr(data%Configuration%Mud%ActiveDensity) + end subroutine + + subroutine Set_ReserveMudVolume_StudentStation(v) + implicit none + real*8, intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%Configuration%Mud%ReserveMudVolume == v) return + #endif + data%Configuration%Mud%ReserveMudVolume = v +! if(associated(ReserveMudVolumePtr)) call ReserveMudVolumePtr(data%Configuration%Mud%ReserveMudVolume) + end subroutine + + subroutine Set_ReserveDensity_StudentStation(v) + implicit none + real*8, intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%Configuration%Mud%ReserveDensity == v) return + #endif + data%Configuration%Mud%ReserveDensity = v +! if(associated(ReserveDensityPtr)) call ReserveDensityPtr(data%Configuration%Mud%ReserveDensity) + end subroutine + +end module MudPropertiesModule diff --git a/CSharp/BasicInputs/RigSpecifications/CAccumulator.i90 b/CSharp/BasicInputs/RigSpecifications/CAccumulator.i90 new file mode 100644 index 0000000..9fb6e70 --- /dev/null +++ b/CSharp/BasicInputs/RigSpecifications/CAccumulator.i90 @@ -0,0 +1,69 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/RigSpecifications/CAccumulator.f90" +module CAccumulator + use SimulationVariables +! use CAccumulatorVariables + use json_module + implicit none + public + contains + + subroutine AccumulatorFromJson(parent) + + use json_module,IK =>json_ik + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pitem,pval + logical::is_found + integer::i,n_children + CHARACTER(KIND=JSON_CK, LEN=:), ALLOCATABLE :: val + + + call json%get(parent,'Accumulator',p) + + call json%get(p,'NumberOfBottels',pval) + call json%get(pval,data%Configuration%Accumulator%NumberOfBottels) + call json%get(p,'AccumulatorSystemSize',pval) + call json%get(pval,data%Configuration%Accumulator%AccumulatorSystemSize) + call json%get(p,'OilTankVolume',pval) + call json%get(pval,data%Configuration%Accumulator%OilTankVolume) + call json%get(p,'PrechargePressure',pval) + call json%get(pval,data%Configuration%Accumulator%PrechargePressure) + call json%get(p,'AccumulatorMinimumOperatingPressure',pval) + call json%get(pval,data%Configuration%Accumulator%AccumulatorMinimumOperatingPressure) + call json%get(p,'ElectricPumpOutput',pval) + call json%get(pval,data%Configuration%Accumulator%ElectricPumpOutput) + call json%get(p,'StartPressure',pval) + call json%get(pval,data%Configuration%Accumulator%StartPressure) + call json%get(p,'StopPressure',pval) + call json%get(pval,data%Configuration%Accumulator%StopPressure) + call json%get(p,'AirPlungerPumpOutput',pval) + call json%get(pval,data%Configuration%Accumulator%AirPlungerPumpOutput) + call json%get(p,'StartPressure2',pval) + call json%get(pval,data%Configuration%Accumulator%StartPressure2) + call json%get(p,'StopPressure2',pval) + call json%get(pval,data%Configuration%Accumulator%StopPressure2) + end subroutine + + subroutine AccumulatorToJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%create_object(p,'Accumulator') + + call json%add(p,'AccumulatorMinimumOperatingPressure',data%Configuration%Accumulator%AccumulatorMinimumOperatingPressure) + call json%add(p,'AccumulatorSystemSize',data%Configuration%Accumulator%AccumulatorSystemSize) + call json%add(p,'AirPlungerPumpOutput',data%Configuration%Accumulator%AirPlungerPumpOutput) + call json%add(p,'ElectricPumpOutput',data%Configuration%Accumulator%ElectricPumpOutput) + call json%add(p,'NumberOfBottels',data%Configuration%Accumulator%NumberOfBottels) + call json%add(p,'OilTankVolume',data%Configuration%Accumulator%OilTankVolume) + call json%add(p,'PrechargePressure',data%Configuration%Accumulator%PrechargePressure) + call json%add(p,'StartPressure',data%Configuration%Accumulator%StartPressure) + call json%add(p,'StartPressure2',data%Configuration%Accumulator%StartPressure2) + call json%add(p,'StopPressure',data%Configuration%Accumulator%StopPressure) + call json%add(p,'StopPressure2',data%Configuration%Accumulator%StopPressure2) + + call json%add(parent,p) + end subroutine + +end module CAccumulator diff --git a/CSharp/BasicInputs/RigSpecifications/CBopStack.i90 b/CSharp/BasicInputs/RigSpecifications/CBopStack.i90 new file mode 100644 index 0000000..911f3bb --- /dev/null +++ b/CSharp/BasicInputs/RigSpecifications/CBopStack.i90 @@ -0,0 +1,107 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/RigSpecifications/CBopStack.f90" +module CBopStack + use SimulationVariables + use json_module + implicit none + public + contains + + + subroutine BopStackFromJson(parent) + + use json_module,IK =>json_ik + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pitem,pval + logical::is_found + integer::i,n_children + CHARACTER(KIND=JSON_CK, LEN=:), ALLOCATABLE :: val + + + call json%get(parent,'BopStack',p) + call json%get(p,'AboveAnnularHeight',pval) + call json%get(pval,data%Configuration%BopStack%AboveAnnularHeight) + call json%get(p,'AnnularPreventerHeight',pval) + call json%get(pval,data%Configuration%BopStack%AnnularPreventerHeight) + call json%get(p,'UpperRamHeight',pval) + call json%get(pval,data%Configuration%BopStack%UpperRamHeight) + call json%get(p,'LowerRamHeight',pval) + call json%get(pval,data%Configuration%BopStack%LowerRamHeight) + call json%get(p,'BlindRamHeight',pval) + call json%get(pval,data%Configuration%BopStack%BlindRamHeight) + call json%get(p,'KillHeight',pval) + call json%get(pval,data%Configuration%BopStack%KillHeight) + call json%get(p,'KillOpen',pval) + call json%get(pval,data%Configuration%BopStack%KillOpen) + call json%get(p,'KillClose',pval) + call json%get(pval,data%Configuration%BopStack%KillClose) + call json%get(p,'GroundLevel',pval) + call json%get(pval,data%Configuration%BopStack%GroundLevel) + call json%get(p,'LowerRamOpen',pval) + call json%get(pval,data%Configuration%BopStack%LowerRamOpen) + call json%get(p,'LowerRamClose',pval) + call json%get(pval,data%Configuration%BopStack%LowerRamClose) + call json%get(p,'ChokeOpen',pval) + call json%get(pval,data%Configuration%BopStack%ChokeOpen) + call json%get(p,'ChokeClose',pval) + call json%get(pval,data%Configuration%BopStack%ChokeClose) + call json%get(p,'BlindRamOpen',pval) + call json%get(pval,data%Configuration%BopStack%BlindRamOpen) + call json%get(p,'BlindRamClose',pval) + call json%get(pval,data%Configuration%BopStack%BlindRamClose) + call json%get(p,'UpperRamOpen',pval) + call json%get(pval,data%Configuration%BopStack%UpperRamOpen) + call json%get(p,'UpperRamClose',pval) + call json%get(pval,data%Configuration%BopStack%UpperRamClose) + call json%get(p,'AnnularPreventerOpen',pval) + call json%get(pval,data%Configuration%BopStack%AnnularPreventerOpen) + call json%get(p,'AnnularPreventerClose',pval) + call json%get(pval,data%Configuration%BopStack%AnnularPreventerClose) + call json%get(p,'RamStringDrag',pval) + call json%get(pval,data%Configuration%BopStack%RamStringDrag) + call json%get(p,'AnnularStringDrag',pval) + call json%get(pval,data%Configuration%BopStack%AnnularStringDrag) + call json%get(p,'ChokeLineLength',pval) + call json%get(pval,data%Configuration%BopStack%ChokeLineLength) + call json%get(p,'ChokeLineId',pval) + call json%get(pval,data%Configuration%BopStack%ChokeLineId) + +end subroutine + subroutine BopStackToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'BopStack') + +! 2. add member of data type to new node + call json%add(p,"AboveAnnularHeight",data%Configuration%BopStack%AboveAnnularHeight) + call json%add(p,"AnnularPreventerClose",data%Configuration%BopStack%AnnularPreventerClose) + call json%add(p,"AnnularPreventerHeight",data%Configuration%BopStack%AnnularPreventerHeight) + call json%add(p,"AnnularPreventerOpen",data%Configuration%BopStack%AnnularPreventerOpen) + call json%add(p,"AnnularStringDrag",data%Configuration%BopStack%AnnularStringDrag) + call json%add(p,"BlindRamClose",data%Configuration%BopStack%BlindRamClose) + call json%add(p,"BlindRamHeight",data%Configuration%BopStack%BlindRamHeight) + call json%add(p,"BlindRamOpen",data%Configuration%BopStack%BlindRamOpen) + call json%add(p,"ChokeClose",data%Configuration%BopStack%ChokeClose) + call json%add(p,"ChokeLineId",data%Configuration%BopStack%ChokeLineId) + call json%add(p,"ChokeLineLength",data%Configuration%BopStack%ChokeLineLength) + call json%add(p,"ChokeOpen",data%Configuration%BopStack%ChokeOpen) + call json%add(p,"GroundLevel",data%Configuration%BopStack%GroundLevel) + call json%add(p,"KillClose",data%Configuration%BopStack%KillClose) + call json%add(p,"KillHeight",data%Configuration%BopStack%KillHeight) + call json%add(p,"KillOpen",data%Configuration%BopStack%KillOpen) + call json%add(p,"LowerRamClose",data%Configuration%BopStack%LowerRamClose) + call json%add(p,"LowerRamHeight",data%Configuration%BopStack%LowerRamHeight) + call json%add(p,"LowerRamOpen",data%Configuration%BopStack%LowerRamOpen) + call json%add(p,"RamStringDrag",data%Configuration%BopStack%RamStringDrag) + call json%add(p,"UpperRamClose",data%Configuration%BopStack%UpperRamClose) + call json%add(p,"UpperRamHeight",data%Configuration%BopStack%UpperRamHeight) + call json%add(p,"UpperRamOpen",data%Configuration%BopStack%UpperRamOpen) +! 3. add new node to parent + call json%add(parent,p) + end subroutine + +end module CBopStack diff --git a/CSharp/BasicInputs/RigSpecifications/CBopStackVariables.i90 b/CSharp/BasicInputs/RigSpecifications/CBopStackVariables.i90 new file mode 100644 index 0000000..3b1a6f9 --- /dev/null +++ b/CSharp/BasicInputs/RigSpecifications/CBopStackVariables.i90 @@ -0,0 +1,31 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/RigSpecifications/CBopStackVariables.f90" +module CBopStackVariables + implicit none + public + Type::BopStackSpecificationType + real(8) :: AboveAnnularHeight = 10.0d0 + real(8) :: AnnularPreventerHeight = 10.2d0 + real(8) :: UpperRamHeight = 14.632d0 + real(8) :: LowerRamHeight = 21.35d0 + real(8) :: BlindRamHeight = 16.24d0 + real(8) :: KillHeight = 18.8d0 + real(8) :: KillOpen = 1.5d0 + real(8) :: KillClose = 1.5d0 + real(8) :: GroundLevel = 30.0d0 + real(8) :: LowerRamOpen + real(8) :: LowerRamClose + real(8) :: ChokeOpen + real(8) :: ChokeClose + real(8) :: BlindRamOpen + real(8) :: BlindRamClose + real(8) :: UpperRamOpen + real(8) :: UpperRamClose + real(8) :: AnnularPreventerOpen + real(8) :: AnnularPreventerClose + real(8) :: RamStringDrag + real(8) :: AnnularStringDrag + real(8) :: ChokeLineLength + real(8) :: ChokeLineId + End Type BopStackSpecificationType + +end module CBopStackVariables diff --git a/CSharp/BasicInputs/RigSpecifications/CHoisting.f90 b/CSharp/BasicInputs/RigSpecifications/CHoisting.f90 index 25e242f..33f64c7 100644 --- a/CSharp/BasicInputs/RigSpecifications/CHoisting.f90 +++ b/CSharp/BasicInputs/RigSpecifications/CHoisting.f90 @@ -41,12 +41,12 @@ module CHoisting ! 2. add member of data type to new node ! call StringConfigurationToJson(p) ! call FormationToJson(p) - call json%add(p,"DrillingLineBreakingLoadAbrasiveness",data%Configuration%Hoisting%DrillingLineBreakingLoad) - call json%add(p,"DriveTypeAbrasiveness",data%Configuration%Hoisting%DriveType) - call json%add(p,"KellyWeightAbrasiveness",data%Configuration%Hoisting%KellyWeight) - call json%add(p,"NumberOfLineAbrasiveness",data%Configuration%Hoisting%NumberOfLine) - call json%add(p,"TopDriveWeightAbrasiveness",data%Configuration%Hoisting%TopDriveWeight) - call json%add(p,"TravelingBlockWeightAbrasiveness",data%Configuration%Hoisting%TravelingBlockWeight) + call json%add(p,"DrillingLineBreakingLoad",data%Configuration%Hoisting%DrillingLineBreakingLoad) + call json%add(p,"DriveType",data%Configuration%Hoisting%DriveType) + call json%add(p,"KellyWeight",data%Configuration%Hoisting%KellyWeight) + call json%add(p,"NumberOfLine",data%Configuration%Hoisting%NumberOfLine) + call json%add(p,"TopDriveWeight",data%Configuration%Hoisting%TopDriveWeight) + call json%add(p,"TravelingBlockWeight",data%Configuration%Hoisting%TravelingBlockWeight) ! 3. add new node to parent call json%add(parent,p) end subroutine diff --git a/CSharp/BasicInputs/RigSpecifications/CPumps.i90 b/CSharp/BasicInputs/RigSpecifications/CPumps.i90 new file mode 100644 index 0000000..5432c6e --- /dev/null +++ b/CSharp/BasicInputs/RigSpecifications/CPumps.i90 @@ -0,0 +1,277 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/RigSpecifications/CPumps.f90" +module CPumps + use SimulationVariables + use json_module + implicit none + public + contains + + subroutine PumpsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Pumps') + +! 2. add member of data type to new node +! call StringConfigurationToJson(p) +! call FormationToJson(p) + call json%add(p,"MudPump1LinerDiameter",data%Configuration%Pumps%MudPump1LinerDiameter) + call json%add(p,"MudPump1Stroke",data%Configuration%Pumps%MudPump1Stroke) + call json%add(p,"MudPump1MechanicalEfficiency",data%Configuration%Pumps%MudPump1MechanicalEfficiency) + call json%add(p,"MudPump1VolumetricEfficiency",data%Configuration%Pumps%MudPump1VolumetricEfficiency) + call json%add(p,"MudPump1Output",data%Configuration%Pumps%MudPump1Output) + call json%add(p,"MudPump1OutputBblStroke",data%Configuration%Pumps%MudPump1OutputBblStroke) + call json%add(p,"MudPump1Maximum",data%Configuration%Pumps%MudPump1Maximum) + call json%add(p,"MudPump1ReliefValvePressure",data%Configuration%Pumps%MudPump1ReliefValvePressure) + call json%add(p,"MudPump2LinerDiameter",data%Configuration%Pumps%MudPump2LinerDiameter) + call json%add(p,"MudPump2Stroke",data%Configuration%Pumps%MudPump2Stroke) + call json%add(p,"MudPump2MechanicalEfficiency",data%Configuration%Pumps%MudPump2MechanicalEfficiency) + call json%add(p,"MudPump2VolumetricEfficiency",data%Configuration%Pumps%MudPump2VolumetricEfficiency) + call json%add(p,"MudPump2Output",data%Configuration%Pumps%MudPump2Output) + call json%add(p,"MudPump2OutputBblStroke",data%Configuration%Pumps%MudPump2OutputBblStroke) + call json%add(p,"MudPump2Maximum",data%Configuration%Pumps%MudPump2Maximum) + call json%add(p,"MudPump2ReliefValvePressure",data%Configuration%Pumps%MudPump2ReliefValvePressure) + call json%add(p,"CementPumpLinerDiameter",data%Configuration%Pumps%CementPumpLinerDiameter) + call json%add(p,"CementPumpStroke",data%Configuration%Pumps%CementPumpStroke) + call json%add(p,"CementPumpMechanicalEfficiency",data%Configuration%Pumps%CementPumpMechanicalEfficiency) + call json%add(p,"CementPumpVolumetricEfficiency",data%Configuration%Pumps%CementPumpVolumetricEfficiency) + call json%add(p,"CementPumpOutput",data%Configuration%Pumps%CementPumpOutput) + call json%add(p,"CementPumpOutputBblStroke",data%Configuration%Pumps%CementPumpOutputBblStroke) + call json%add(p,"CementPumpMaximum",data%Configuration%Pumps%CementPumpMaximum) + call json%add(p,"CementPumpReliefValvePressure ",data%Configuration%Pumps%CementPumpReliefValvePressure ) + call json%add(p,"MudPump1ReliefValveIsSet",data%Configuration%Pumps%MudPump1ReliefValveIsSet) + call json%add(p,"MudPump2ReliefValveIsSet",data%Configuration%Pumps%MudPump2ReliefValveIsSet) + call json%add(p,"CementPumpReliefValveIsSet",data%Configuration%Pumps%CementPumpReliefValveIsSet) + call json%add(p,"ManualPumpPower",data%Configuration%Pumps%ManualPumpPower) + call json%add(p,"Valve1",data%Configuration%Pumps%Valve1) + call json%add(p,"Valve2",data%Configuration%Pumps%Valve2) + call json%add(p,"Valve3",data%Configuration%Pumps%Valve3) + call json%add(p,"Valve4",data%Configuration%Pumps%Valve4) + call json%add(p,"Valve5",data%Configuration%Pumps%Valve5) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine PumpsFromJson(parent) + use json_module,IK =>json_ik + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pitems,pitem,pval,pbit + + call json%get(parent,'Pumps',p) + + call json%get(p,"MudPump1LinerDiameter",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump1LinerDiameter) + call json%get(p,"MudPump1Stroke",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump1Stroke) + call json%get(p,"MudPump1MechanicalEfficiency",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump1MechanicalEfficiency) + call json%get(p,"MudPump1VolumetricEfficiency",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump1VolumetricEfficiency) + call json%get(p,"MudPump1Output",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump1Output) + call json%get(p,"MudPump1OutputBblStroke",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump1OutputBblStroke) + call json%get(p,"MudPump1Maximum",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump1Maximum) + call json%get(p,"MudPump1ReliefValvePressure",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump1ReliefValvePressure) + call json%get(p,"MudPump2LinerDiameter",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump2LinerDiameter) + call json%get(p,"MudPump2Stroke",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump2Stroke) + call json%get(p,"MudPump2MechanicalEfficiency",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump2MechanicalEfficiency) + call json%get(p,"MudPump2VolumetricEfficiency",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump2VolumetricEfficiency) + call json%get(p,"MudPump2Output",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump2Output) + call json%get(p,"MudPump2OutputBblStroke",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump2OutputBblStroke) + call json%get(p,"MudPump2Maximum",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump2Maximum) + call json%get(p,"MudPump2ReliefValvePressure",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump2ReliefValvePressure) + call json%get(p,"CementPumpLinerDiameter",pitem) + call json%get(pitem,data%Configuration%Pumps%CementPumpLinerDiameter) + call json%get(p,"CementPumpStroke",pitem) + call json%get(pitem,data%Configuration%Pumps%CementPumpStroke) + call json%get(p,"CementPumpMechanicalEfficiency",pitem) + call json%get(pitem,data%Configuration%Pumps%CementPumpMechanicalEfficiency) + call json%get(p,"CementPumpVolumetricEfficiency",pitem) + call json%get(pitem,data%Configuration%Pumps%CementPumpVolumetricEfficiency) + call json%get(p,"CementPumpOutput",pitem) + call json%get(pitem,data%Configuration%Pumps%CementPumpOutput) + call json%get(p,"CementPumpOutputBblStroke",pitem) + call json%get(pitem,data%Configuration%Pumps%CementPumpOutputBblStroke) + call json%get(p,"CementPumpMaximum",pitem) + call json%get(pitem,data%Configuration%Pumps%CementPumpMaximum) + call json%get(p,"CementPumpReliefValvePressure",pitem) + call json%get(pitem,data%Configuration%Pumps%CementPumpReliefValvePressure) + call json%get(p,"MudPump1ReliefValveIsSet",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump1ReliefValveIsSet) + call json%get(p,"MudPump2ReliefValveIsSet",pitem) + call json%get(pitem,data%Configuration%Pumps%MudPump2ReliefValveIsSet) + call json%get(p,"CementPumpReliefValveIsSet",pitem) + call json%get(pitem,data%Configuration%Pumps%CementPumpReliefValveIsSet) + call json%get(p,"ManualPumpPower",pitem) + call json%get(pitem,data%Configuration%Pumps%ManualPumpPower) + call json%get(p,"Valve1",pitem) + call json%get(pitem,data%Configuration%Pumps%Valve1) + call json%get(p,"Valve2",pitem) + call json%get(pitem,data%Configuration%Pumps%Valve2) + call json%get(p,"Valve3",pitem) + call json%get(pitem,data%Configuration%Pumps%Valve3) + call json%get(p,"Valve4",pitem) + call json%get(pitem,data%Configuration%Pumps%Valve4) + call json%get(p,"Valve5",pitem) + call json%get(pitem,data%Configuration%Pumps%Valve5) + + end subroutine + + + subroutine OpenPump1() + use CManifolds + implicit none + call ChangeValve(16, .true.) + end subroutine + + subroutine ClosePump1() + use CManifolds + implicit none + call ChangeValve(16, .false.) + end subroutine + + subroutine OpenPump2() + use CManifolds + implicit none + call ChangeValve(17, .true.) + end subroutine + + subroutine ClosePump2() + use CManifolds + implicit none + call ChangeValve(17, .false.) + end subroutine + + + subroutine OpenCementPump() + use CManifolds + implicit none + call ChangeValve(18, .true.) + end subroutine + + subroutine CloseCementPump() + use CManifolds + implicit none + call ChangeValve(18, .false.) + end subroutine + +! subroutine SetMudPump1LinerDiameterN(a) +! implicit none +! real(8) :: a +! if(associated(MudPump1LinerDiameterPtr)) call MudPump1LinerDiameterPtr(a) +! end subroutine + +! subroutine SetMudPump2LinerDiameterN(a) +! implicit none +! real(8) :: a +! if(associated(MudPump2LinerDiameterPtr)) call MudPump2LinerDiameterPtr(a) +! end subroutine + +! subroutine SetMudPump3LinerDiameterN(a) +! implicit none +! real(8) :: a +! if(associated(MudPump3LinerDiameterPtr)) call MudPump3LinerDiameterPtr(a) +! end subroutine + + + +! subroutine SetMudPump1OutputBblStrokeN(a) +! implicit none +! real(8) :: a +! if(associated(MudPump1OutputBblStrokePtr)) call MudPump1OutputBblStrokePtr(a) +! end subroutine + +! subroutine SetMudPump2OutputBblStrokeN(a) +! implicit none +! real(8) :: a +! if(associated(MudPump2OutputBblStrokePtr)) call MudPump2OutputBblStrokePtr(a) +! end subroutine + +! subroutine SetMudPump3OutputBblStrokeN(a) +! implicit none +! real(8) :: a +! if(associated(MudPump3OutputBblStrokePtr)) call MudPump3OutputBblStrokePtr(a) +! end subroutine + + + + +! subroutine CalcMudPump1LinerDiameter() +! use, intrinsic :: IEEE_ARITHMETIC +! implicit none +! real(8) :: a +! a = (MathPI / 4.d0) * data%Configuration%Pumps%MudPump1Stroke * 3.0d0 * data%Configuration%Pumps%MudPump1VolumetricEfficiency / 9702.03d0 +! a = dsqrt(data%Configuration%Pumps%MudPump1OutputBblStroke / a) +! if (.not.IEEE_IS_FINITE(a) .or. IEEE_IS_NAN(a)) then +! data%Configuration%Pumps%MudPump1LinerDiameter = 0.0 +! else +! data%Configuration%Pumps%MudPump1LinerDiameter = a +! endif +! call SetMudPump1LinerDiameterN(data%Configuration%Pumps%MudPump1LinerDiameter) +! end subroutine + +! subroutine CalcMudPump2LinerDiameter() +! use, intrinsic :: IEEE_ARITHMETIC +! implicit none +! real(8) :: a +! a = (MathPI / 4.d0) * data%Configuration%Pumps%MudPump2Stroke * 3.0d0 * data%Configuration%Pumps%MudPump2VolumetricEfficiency / 9702.03d0 +! a = dsqrt(data%Configuration%Pumps%MudPump2OutputBblStroke / a) +! if (.not.IEEE_IS_FINITE(a) .or. IEEE_IS_NAN(a)) then +! data%Configuration%Pumps%MudPump2LinerDiameter = 0.0 +! else +! data%Configuration%Pumps%MudPump2LinerDiameter = a +! endif +! call SetMudPump2LinerDiameterN(data%Configuration%Pumps%MudPump2LinerDiameter) +! end subroutine + +! subroutine CalcMudPump3LinerDiameter() +! use, intrinsic :: IEEE_ARITHMETIC +! implicit none +! real(8) :: a +! a = (MathPI / 4.d0) * data%Configuration%Pumps%CementPumpStroke * 3.0d0 * data%Configuration%Pumps%CementPumpVolumetricEfficiency / 9702.03d0 +! a = dsqrt(data%Configuration%Pumps%CementPumpOutputBblStroke / a) +! if (.not.IEEE_IS_FINITE(a) .or. IEEE_IS_NAN(a)) then +! data%Configuration%Pumps%CementPumpLinerDiameter = 0.0 +! else +! data%Configuration%Pumps%CementPumpLinerDiameter = a +! endif +! call SetMudPump3LinerDiameterN(data%Configuration%Pumps%CementPumpLinerDiameter) +! end subroutine + + + +! subroutine CalcPump1OutputBblStroke() +! implicit none +! data%Configuration%Pumps%MudPump1OutputBblStroke = (MathPI / 4.d0) * (data%Configuration%Pumps%MudPump1LinerDiameter**2) * data%Configuration%Pumps%MudPump1Stroke * 3.0d0 * data%Configuration%Pumps%MudPump1VolumetricEfficiency / 9702.03d0 +! call SetMudPump1OutputBblStrokeN(data%Configuration%Pumps%MudPump1OutputBblStroke) +! end subroutine + +! subroutine CalcPump2OutputBblStroke() +! implicit none +! data%Configuration%Pumps%MudPump2OutputBblStroke = (MathPI / 4.d0) * (data%Configuration%Pumps%MudPump2LinerDiameter**2) * data%Configuration%Pumps%MudPump2Stroke * 3.0d0 * data%Configuration%Pumps%MudPump2VolumetricEfficiency / 9702.03d0 +! call SetMudPump2OutputBblStrokeN(data%Configuration%Pumps%MudPump2OutputBblStroke) +! end subroutine + +! subroutine CalcPump3OutputBblStroke() +! implicit none +! data%Configuration%Pumps%CementPumpOutputBblStroke = (MathPI / 4.d0) * (data%Configuration%Pumps%CementPumpLinerDiameter**2) * data%Configuration%Pumps%CementPumpStroke * 3.0d0 * data%Configuration%Pumps%CementPumpVolumetricEfficiency / 9702.03d0 +! call SetMudPump3OutputBblStrokeN(data%Configuration%Pumps%CementPumpOutputBblStroke) +! end subroutine + +end module CPumps diff --git a/CSharp/BasicInputs/RigSpecifications/CPumpsVariables.i90 b/CSharp/BasicInputs/RigSpecifications/CPumpsVariables.i90 new file mode 100644 index 0000000..3f2565f --- /dev/null +++ b/CSharp/BasicInputs/RigSpecifications/CPumpsVariables.i90 @@ -0,0 +1,61 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/RigSpecifications/CPumpsVariables.f90" +module CPumpsVariables + use CIActionReference + implicit none + public + + +! Pumps Specifications + Type::PumpSpecificationType + real(8) :: MudPump1LinerDiameter + real(8) :: MudPump1Stroke + real(8) :: MudPump1MechanicalEfficiency + real(8) :: MudPump1VolumetricEfficiency + real(8) :: MudPump1Output + real(8) :: MudPump1OutputBblStroke + real(8) :: MudPump1Maximum + real(8) :: MudPump1ReliefValvePressure + + real(8) :: MudPump2LinerDiameter + real(8) :: MudPump2Stroke + real(8) :: MudPump2MechanicalEfficiency + real(8) :: MudPump2VolumetricEfficiency + real(8) :: MudPump2Output + real(8) :: MudPump2OutputBblStroke + real(8) :: MudPump2Maximum + real(8) :: MudPump2ReliefValvePressure + + real(8) :: CementPumpLinerDiameter + real(8) :: CementPumpStroke + real(8) :: CementPumpMechanicalEfficiency + real(8) :: CementPumpVolumetricEfficiency + real(8) :: CementPumpOutput + real(8) :: CementPumpOutputBblStroke + real(8) :: CementPumpMaximum + real(8) :: CementPumpReliefValvePressure + + logical :: MudPump1ReliefValveIsSet + logical :: MudPump2ReliefValveIsSet + logical :: CementPumpReliefValveIsSet + + logical :: ManualPumpPower + logical :: Valve1 + logical :: Valve2 + logical :: Valve3 + logical :: Valve4 + logical :: Valve5 + End type PumpSpecificationType +! Type(PumpSpecificationType)::PumpsSpecification + +! procedure (ActionDouble), pointer :: MudPump1LinerDiameterPtr +! procedure (ActionDouble), pointer :: MudPump2LinerDiameterPtr +! procedure (ActionDouble), pointer :: MudPump3LinerDiameterPtr +! procedure (ActionDouble), pointer :: MudPump1OutputBblStrokePtr +! procedure (ActionDouble), pointer :: MudPump2OutputBblStrokePtr +! procedure (ActionDouble), pointer :: MudPump3OutputBblStrokePtr + + + real(8) :: MathPI = 3.14159265358979d0 + + contains +end module CPumpsVariables diff --git a/CSharp/BasicInputs/RigSpecifications/cbopstackvariables.mod b/CSharp/BasicInputs/RigSpecifications/cbopstackvariables.mod new file mode 100644 index 0000000..ec717a9 Binary files /dev/null and b/CSharp/BasicInputs/RigSpecifications/cbopstackvariables.mod differ diff --git a/CSharp/BasicInputs/WellProfile/CCasingLinerChokeVariables.i90 b/CSharp/BasicInputs/WellProfile/CCasingLinerChokeVariables.i90 new file mode 100644 index 0000000..d10b618 --- /dev/null +++ b/CSharp/BasicInputs/WellProfile/CCasingLinerChokeVariables.i90 @@ -0,0 +1,27 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/WellProfile/CCasingLinerChokeVariables.f90" +module CCasingLinerChokeVariables + implicit none + public +! variables + Type::CasingLinerChokeType + real(8) :: CasingDepth + real(8) :: CasingId + real(8) :: CasingOd + real(8) :: CasingWeight + real(8) :: CasingCollapsePressure + real(8) :: CasingTensileStrength + + real(8) :: LinerTopDepth + real(8) :: LinerLength + real(8) :: LinerId + real(8) :: LinerOd + real(8) :: LinerWeight + real(8) :: LinerCollapsePressure + real(8) :: LinerTensileStrength + + real(8) :: OpenHoleId + real(8) :: OpenHoleLength + End Type CasingLinerChokeType +! Type(CasingLinerChokeType)::CasingLinerChoke + contains +end module CCasingLinerChokeVariables diff --git a/CSharp/BasicInputs/WellProfile/CPathGeneration.f90 b/CSharp/BasicInputs/WellProfile/CPathGeneration.f90 index 152e09a..d4932b0 100644 --- a/CSharp/BasicInputs/WellProfile/CPathGeneration.f90 +++ b/CSharp/BasicInputs/WellProfile/CPathGeneration.f90 @@ -10,13 +10,14 @@ module CPathGeneration type(json_value),pointer :: parent type(json_core) :: json type(json_value),pointer :: ppath,pitems,pdp,p - integer::i + integer::i,n ! 1. create new node call json%create_object(ppath,'Path') call json%create_array(pitems,'Items') - do i=1,data%Configuration%Path%ItemCount + n = data%Configuration%Path%ItemCount + do i=1,n call json%create_object(p,'') call json%add(p,"HoleType",data%Configuration%Path%items(i)%HoleType) call json%add(p,"Angle",data%Configuration%Path%items(i)%Angle) @@ -28,17 +29,17 @@ module CPathGeneration call json%add(pitems,p) end do - call json%create_array(pdp,'DataPoints') - do i=1,data%Configuration%Path%DataPointsCount - call json%create_object(p,'') - call json%add(p,"X",data%Configuration%Path%DataPoints(i)%X) - call json%add(p,"Y",data%Configuration%Path%DataPoints(i)%Y) - call json%add(pdp,p) - end do + ! call json%create_array(pdp,'DataPoints') + ! do i=1,data%Configuration%Path%DataPointsCount + ! call json%create_object(p,'') + ! call json%add(p,"X",data%Configuration%Path%DataPoints(i)%X) + ! call json%add(p,"Y",data%Configuration%Path%DataPoints(i)%Y) + ! call json%add(pdp,p) + ! end do ! 3. add new node to parent call json%add(ppath,pitems) - call json%add(ppath,pdp) + ! call json%add(ppath,pdp) call json%add(parent,ppath) end subroutine @@ -77,19 +78,19 @@ module CPathGeneration call json%get(pval,data%Configuration%Path%Items(i)%TotalVerticalDepth) end do - call json%get(p,'DataPoints',dpoints) - call json%info(dpoints, n_children=n_children) + ! call json%get(p,'DataPoints',dpoints) + ! call json%info(dpoints, n_children=n_children) - if (.not. allocated(data%Configuration%Path%DataPoints) .or. size(data%Configuration%Path%DataPoints)/=n_children) then - ALLOCATE(data%Configuration%Path%DataPoints(n_children)) - endif - do i=1,n_children - call json%get_child(dpoints, i, dpoint, found=is_found) - call json%get(dpoint,"X",pval) - call json%get(pval,data%Configuration%Path%DataPoints(i)%X) - call json%get(dpoint,"Y",pval) - call json%get(pval,data%Configuration%Path%DataPoints(i)%Y) - end do + ! if (.not. allocated(data%Configuration%Path%DataPoints) .or. size(data%Configuration%Path%DataPoints)/=n_children) then + ! ALLOCATE(data%Configuration%Path%DataPoints(n_children)) + ! endif + ! do i=1,n_children + ! call json%get_child(dpoints, i, dpoint, found=is_found) + ! call json%get(dpoint,"X",pval) + ! call json%get(pval,data%Configuration%Path%DataPoints(i)%X) + ! call json%get(dpoint,"Y",pval) + ! call json%get(pval,data%Configuration%Path%DataPoints(i)%Y) + ! end do end subroutine diff --git a/CSharp/BasicInputs/WellProfile/CPathGeneration.i90 b/CSharp/BasicInputs/WellProfile/CPathGeneration.i90 new file mode 100644 index 0000000..eeab784 --- /dev/null +++ b/CSharp/BasicInputs/WellProfile/CPathGeneration.i90 @@ -0,0 +1,98 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/WellProfile/CPathGeneration.f90" +module CPathGeneration + use SimulationVariables !@ + use json_module + implicit none + public + contains + + subroutine PathGenerationToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: ppath,pitems,pdp,p + integer::i,n + +! 1. create new node + call json%create_object(ppath,'Path') + + call json%create_array(pitems,'Items') + n = data%Configuration%Path%ItemCount + do i=1,n + call json%create_object(p,'') + call json%add(p,"HoleType",data%Configuration%Path%items(i)%HoleType) + call json%add(p,"Angle",data%Configuration%Path%items(i)%Angle) + call json%add(p,"Length",data%Configuration%Path%items(i)%Length) + call json%add(p,"FinalAngle",data%Configuration%Path%items(i)%FinalAngle) + call json%add(p,"TotalLength",data%Configuration%Path%items(i)%TotalLength) + call json%add(p,"MeasuredDepth",data%Configuration%Path%items(i)%MeasuredDepth) + call json%add(p,"TotalVerticalDepth",data%Configuration%Path%items(i)%TotalVerticalDepth) + call json%add(pitems,p) + end do + +! call json%create_array(pdp,'DataPoints') +! do i=1,data%Configuration%Path%DataPointsCount +! call json%create_object(p,'') +! call json%add(p,"X",data%Configuration%Path%DataPoints(i)%X) +! call json%add(p,"Y",data%Configuration%Path%DataPoints(i)%Y) +! call json%add(pdp,p) +! end do + +! 3. add new node to parent + call json%add(ppath,pitems) +! call json%add(ppath,pdp) + call json%add(parent,ppath) + end subroutine + + subroutine PathGenerationFromJson(parent) + use json_module,IK =>json_ik + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pitems,pitem,pval,pbit,dpoints,dpoint + logical::is_found + type(CStringItem) :: item + integer::i,n_children + CHARACTER(KIND=JSON_CK, LEN=:), ALLOCATABLE :: val + + call json%get(parent,'Path',p) + call json%get(p,'Items',pitems) + call json%info(pitems, n_children=n_children) + + if (.not. allocated(data%Configuration%Path%Items) .or. size(data%Configuration%Path%Items)/=n_children) then + ALLOCATE(data%Configuration%Path%Items(n_children)) + endif + do i=1,n_children + call json%get_child(pitems, i, pitem, found=is_found) + call json%get(pitem,"HoleType",pval) + call json%get(pval,data%Configuration%Path%Items(i)%HoleType) + call json%get(pitem,"Angle",pval) + call json%get(pval,data%Configuration%Path%Items(i)%Angle) + call json%get(pitem,"Length",pval) + call json%get(pval,data%Configuration%Path%Items(i)%Length) + call json%get(pitem,"FinalAngle",pval) + call json%get(pval,data%Configuration%Path%Items(i)%FinalAngle) + call json%get(pitem,"TotalLength",pval) + call json%get(pval,data%Configuration%Path%Items(i)%TotalLength) + call json%get(pitem,"MeasuredDepth",pval) + call json%get(pval,data%Configuration%Path%Items(i)%MeasuredDepth) + call json%get(pitem,"TotalVerticalDepth",pval) + call json%get(pval,data%Configuration%Path%Items(i)%TotalVerticalDepth) + end do + +! call json%get(p,'DataPoints',dpoints) +! call json%info(dpoints, n_children=n_children) + +! if (.not. allocated(data%Configuration%Path%DataPoints) .or. size(data%Configuration%Path%DataPoints)/=n_children) then +! ALLOCATE(data%Configuration%Path%DataPoints(n_children)) +! endif +! do i=1,n_children +! call json%get_child(dpoints, i, dpoint, found=is_found) +! call json%get(dpoint,"X",pval) +! call json%get(pval,data%Configuration%Path%DataPoints(i)%X) +! call json%get(dpoint,"Y",pval) +! call json%get(pval,data%Configuration%Path%DataPoints(i)%Y) +! end do + + + end subroutine +end module CPathGeneration diff --git a/CSharp/BasicInputs/WellProfile/CPathGenerationVariables.f90 b/CSharp/BasicInputs/WellProfile/CPathGenerationVariables.f90 index f962c7c..cbaf418 100644 --- a/CSharp/BasicInputs/WellProfile/CPathGenerationVariables.f90 +++ b/CSharp/BasicInputs/WellProfile/CPathGenerationVariables.f90 @@ -21,8 +21,8 @@ module CPathGenerationVariables Type :: PathGenerationType integer :: ItemCount = 0 type(CPathGenerationItem), allocatable :: Items(:) - integer :: DataPointsCount = 0 - type(CDataPointItem), allocatable :: DataPoints(:) + ! integer :: DataPointsCount = 0 + ! type(CDataPointItem), allocatable :: DataPoints(:) End type PathGenerationType ! Type(PathGenerationType)::PathGeneration diff --git a/CSharp/BasicInputs/WellProfile/CPathGenerationVariables.i90 b/CSharp/BasicInputs/WellProfile/CPathGenerationVariables.i90 new file mode 100644 index 0000000..a4dd47e --- /dev/null +++ b/CSharp/BasicInputs/WellProfile/CPathGenerationVariables.i90 @@ -0,0 +1,31 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/WellProfile/CPathGenerationVariables.f90" +module CPathGenerationVariables + implicit none + public + +! types + type, bind(c), public :: CPathGenerationItem + integer :: HoleType + real(8) :: Angle + real(8) :: Length + real(8) :: FinalAngle + real(8) :: TotalLength + real(8) :: MeasuredDepth + real(8) :: TotalVerticalDepth + end type CPathGenerationItem + + type, bind(c), public :: CDataPointItem + real(8) :: X + real(8) :: Y + end type CDataPointItem + + Type :: PathGenerationType + integer :: ItemCount = 0 + type(CPathGenerationItem), allocatable :: Items(:) +! integer :: DataPointsCount = 0 +! type(CDataPointItem), allocatable :: DataPoints(:) + End type PathGenerationType + +! Type(PathGenerationType)::PathGeneration + +end module CPathGenerationVariables diff --git a/CSharp/DownHole/CDownHoleTypes.i90 b/CSharp/DownHole/CDownHoleTypes.i90 new file mode 100644 index 0000000..5103c89 --- /dev/null +++ b/CSharp/DownHole/CDownHoleTypes.i90 @@ -0,0 +1,53 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/DownHole/CDownHoleTypes.f90" +module CDownHoleTypes + implicit none + public + +!enums + enum, bind(c) + enumerator STRING_BIT !0 + enumerator STRING_STABILIZER !1 + enumerator STRING_COLLAR !2 + enumerator STRING_DRILLPIPE !3 + enumerator STRING_HEAVYWEIGHT !4 + end enum + + enum, bind(c) + enumerator FLUID_NORMAL_MUD !0 + enumerator FLUID_GAS_KICK !1 + enumerator FLUID_WATER_KICK !2 + enumerator FLUID_OIL_KICK !3 + enumerator FLUID_NO_MUD !4 + end enum + +! new types + type, bind(c), public :: CFluid + real(8) :: StartMd + real(8) :: EndMd + real(8) :: Density + integer :: MudType + end type CFluid + + type, bind(c), public :: CStringComponents + real(8) :: Length + real(8) :: TopDepth + real(8) :: DownDepth + real(8) :: Od + real(8) :: Id + integer :: ComponentType + end type CStringComponents + + type, bind(c), public :: CStringComponent + real(8) :: StartMd + real(8) :: EndMd + integer :: ComponentType + end type CStringComponent + + type, bind(c), public :: CBopElement + integer :: ElementType + real :: ElementStart + real :: ElementEnd + end type CBopElement + + contains +end module CDownHoleTypes diff --git a/CSharp/DownHole/CDownHoleVariables.f90 b/CSharp/DownHole/CDownHoleVariables.f90 index 060819f..6598c50 100644 --- a/CSharp/DownHole/CDownHoleVariables.f90 +++ b/CSharp/DownHole/CDownHoleVariables.f90 @@ -9,19 +9,18 @@ module CDownHoleVariables ! Outputs to user interface !!!!!!!!!!!!!!!!!!!!! type :: DownHoleType + ! Input logical :: AnnDrillMud logical :: AnnCirculateMud + ! Output integer :: AnnalusFluidsCount = 0 integer :: StringFluidsCount = 0 type(CFluid), allocatable :: AnnalusFluids(:) !, target type(CFluid), allocatable :: StringFluids(:) - integer :: StringCount = 0 type(CStringComponent), allocatable :: String(:) - type(CBopElement), allocatable :: BopElements(:) - real(8) :: DrillPipePressure real(8) :: CasingPressure real(8) :: ShoePressure @@ -32,12 +31,12 @@ module CDownHoleVariables real :: SecondKickVolume real :: PermeabilityExposedHeight - real(8) :: Density - real(8) :: Pressure - real(8) :: Temperature - real(8) :: Height - real(8) :: Volume + ! Not used (only density printed) + ! real(8) :: Density + ! real(8) :: Pressure + ! real(8) :: Temperature + ! real(8) :: Height + ! real(8) :: Volume end type DownHoleType - type(DownHoleType):: DownHole contains end module CDownHoleVariables \ No newline at end of file diff --git a/CSharp/DownHole/CDownHoleVariables.i90 b/CSharp/DownHole/CDownHoleVariables.i90 new file mode 100644 index 0000000..eebb229 --- /dev/null +++ b/CSharp/DownHole/CDownHoleVariables.i90 @@ -0,0 +1,43 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/DownHole/CDownHoleVariables.f90" +module CDownHoleVariables + use CDownHoleTypes +! use CStringConfigurationVariables +! use CDownHoleActions + use CLog4 + implicit none + public +!!!!!!!!!!!!!!!!!!!!! +! Outputs to user interface +!!!!!!!!!!!!!!!!!!!!! + type :: DownHoleType +! Input + logical :: AnnDrillMud + logical :: AnnCirculateMud + +! Output + integer :: AnnalusFluidsCount = 0 + integer :: StringFluidsCount = 0 + type(CFluid), allocatable :: AnnalusFluids(:) !, target + type(CFluid), allocatable :: StringFluids(:) + integer :: StringCount = 0 + type(CStringComponent), allocatable :: String(:) + type(CBopElement), allocatable :: BopElements(:) + real(8) :: DrillPipePressure + real(8) :: CasingPressure + real(8) :: ShoePressure + real(8) :: BottomHolePressure + real(8) :: FormationPressure + real :: InfluxRate + real :: KickVolume + real :: SecondKickVolume + real :: PermeabilityExposedHeight + +! Not used (only density printed) +! real(8) :: Density +! real(8) :: Pressure +! real(8) :: Temperature +! real(8) :: Height +! real(8) :: Volume + end type DownHoleType + contains +end module CDownHoleVariables diff --git a/CSharp/DownHole/DownHole.f90 b/CSharp/DownHole/DownHole.f90 index cb9b7da..74662a9 100644 --- a/CSharp/DownHole/DownHole.f90 +++ b/CSharp/DownHole/DownHole.f90 @@ -1,46 +1,90 @@ module DownHoleModule use SimulationVariables contains + + subroutine MudPropertiesToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + ! 1. create new node + call json%create_object(p,'DownHole') + + ! 2. add member of data type to new node + ! call json%add(p,"AnnalusFluidsCount",data%Equipments%DownHole%AnnalusFluidsCount) + ! call json%add(p,"StringFluidsCount",data%Equipments%DownHole%StringFluidsCount) + ! call json%add(p,"AnnalusFluids(:)",data%Equipments%DownHole%AnnalusFluids(:)) + ! call json%add(p,"StringFluids(:)",data%Equipments%DownHole%StringFluids(:)) + ! call json%add(p,"StringCount",data%Equipments%DownHole%StringCount) + ! call json%add(p,"String(:)",data%Equipments%DownHole%String(:)) + ! call json%add(p,"BopElements(:)",data%Equipments%DownHole%BopElements(:)) + call json%add(p,"DrillPipePressure",data%Equipments%DownHole%DrillPipePressure) + call json%add(p,"CasingPressure",data%Equipments%DownHole%CasingPressure) + call json%add(p,"ShoePressure",data%Equipments%DownHole%ShoePressure) + call json%add(p,"BottomHolePressure",data%Equipments%DownHole%BottomHolePressure) + call json%add(p,"FormationPressure",data%Equipments%DownHole%FormationPressure) + call json%add(p,"InfluxRate",data%Equipments%DownHole%InfluxRate) + call json%add(p,"KickVolume",data%Equipments%DownHole%KickVolume) + call json%add(p,"SecondKickVolume",data%Equipments%DownHole%SecondKickVolume) + call json%add(p,"PermeabilityExposedHeight",data%Equipments%DownHole%PermeabilityExposedHeight) + ! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine DownHoleFromJson(parent) + use json_module,IK =>json_ik + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pitems,pitem,pval,pbit + + call json%get(parent,'DownHole',p) + call json%get(p,'AnnDrillMud',pval) + call json%get(pval,data%Equipments%DownHole%AnnDrillMud) + call json%get(p,'AnnCirculateMud',pval) + call json%get(pval,data%Equipments%DownHole%AnnCirculateMud) + end subroutine + subroutine SetAnnalusFluids(count, array) implicit none integer, intent(in) :: count integer :: i, offset type(CFluid), intent(inout), target :: array(count) type(CFluid), pointer :: item - DownHole%AnnalusFluidsCount = count + data%Equipments%DownHole%AnnalusFluidsCount = count print*, 'AnnalusFluidsCount = ', count - if(size(DownHole%AnnalusFluids) > 0) then - deallocate(DownHole%AnnalusFluids) + if(size(data%Equipments%DownHole%AnnalusFluids) > 0) then + deallocate(data%Equipments%DownHole%AnnalusFluids) end if if(count > 0) then offset = 0; item => array(1) if(item%StartMd > 0) then - DownHole%AnnalusFluidsCount = DownHole%AnnalusFluidsCount + 1 + data%Equipments%DownHole%AnnalusFluidsCount = data%Equipments%DownHole%AnnalusFluidsCount + 1 offset = 1; - allocate(DownHole%AnnalusFluids(DownHole%AnnalusFluidsCount)) - DownHole%AnnalusFluids(1)%StartMd = 0 - DownHole%AnnalusFluids(1)%EndMd = item%StartMd - DownHole%AnnalusFluids(1)%Density = 0 - DownHole%AnnalusFluids(1)%MudType = FLUID_NO_MUD + allocate(data%Equipments%DownHole%AnnalusFluids(data%Equipments%DownHole%AnnalusFluidsCount)) + data%Equipments%DownHole%AnnalusFluids(1)%StartMd = 0 + data%Equipments%DownHole%AnnalusFluids(1)%EndMd = item%StartMd + data%Equipments%DownHole%AnnalusFluids(1)%Density = 0 + data%Equipments%DownHole%AnnalusFluids(1)%MudType = FLUID_NO_MUD endif !if(associated(AnnalusMudCountPtr)) then ! call AnnalusMudCountPtr(AnnalusFluidsCount) !end if - if(.not.allocated(DownHole%AnnalusFluids))allocate(DownHole%AnnalusFluids(DownHole%AnnalusFluidsCount)) + if(.not.allocated(data%Equipments%DownHole%AnnalusFluids))allocate(data%Equipments%DownHole%AnnalusFluids(data%Equipments%DownHole%AnnalusFluidsCount)) !print*, '============START-AN============' - if(item%StartMd < 0) DownHole%AnnalusFluids(1)%StartMd = 0 + if(item%StartMd < 0) data%Equipments%DownHole%AnnalusFluids(1)%StartMd = 0 do i = 1, count item => array(i) - DownHole%AnnalusFluids(i + offset)%StartMd = item%StartMd - if(i==1) DownHole%AnnalusFluids(i)%StartMd = 0 + data%Equipments%DownHole%AnnalusFluids(i + offset)%StartMd = item%StartMd + if(i==1) data%Equipments%DownHole%AnnalusFluids(i)%StartMd = 0 !print*, 'AnnalusFluids(',i,')%StartMd=', AnnalusFluids(i)%StartMd - DownHole%AnnalusFluids(i + offset)%EndMd = item%EndMd + data%Equipments%DownHole%AnnalusFluids(i + offset)%EndMd = item%EndMd !print*, 'AnnalusFluids(',i,')%EndMd=', AnnalusFluids(i)%EndMd - DownHole%AnnalusFluids(i + offset)%Density = item%Density + data%Equipments%DownHole%AnnalusFluids(i + offset)%Density = item%Density !print*, 'AnnalusFluids(',i,')%Density=', AnnalusFluids(i)%Density - DownHole%AnnalusFluids(i + offset)%MudType = item%MudType + data%Equipments%DownHole%AnnalusFluids(i + offset)%MudType = item%MudType !print*, 'AnnalusFluids(',i,')%MudType=', AnnalusFluids(i)%MudType !print*, '----------------------------' end do @@ -58,10 +102,10 @@ module DownHoleModule integer :: i, offset !, startArr type(CFluid), intent(inout), target :: array(count) type(CFluid), pointer :: item - DownHole%StringFluidsCount = count + data%Equipments%DownHole%StringFluidsCount = count print*, 'StringFluidsCount = ', count - if(size(DownHole%StringFluids) > 0) then - deallocate(DownHole%StringFluids) + if(size(data%Equipments%DownHole%StringFluids) > 0) then + deallocate(data%Equipments%DownHole%StringFluids) end if !startArr = 1 @@ -80,30 +124,30 @@ module DownHoleModule !if(count <= 0) return if(item%StartMd > 0) then - DownHole%StringFluidsCount = DownHole%StringFluidsCount + 1 + data%Equipments%DownHole%StringFluidsCount = data%Equipments%DownHole%StringFluidsCount + 1 offset = offset + 1 - allocate(DownHole%StringFluids(DownHole%StringFluidsCount)) - DownHole%StringFluids(1)%StartMd = 0 - DownHole%StringFluids(1)%EndMd = item%StartMd - DownHole%StringFluids(1)%Density = 0 - DownHole%StringFluids(1)%MudType = FLUID_NO_MUD + allocate(data%Equipments%DownHole%StringFluids(data%Equipments%DownHole%StringFluidsCount)) + data%Equipments%DownHole%StringFluids(1)%StartMd = 0 + data%Equipments%DownHole%StringFluids(1)%EndMd = item%StartMd + data%Equipments%DownHole%StringFluids(1)%Density = 0 + data%Equipments%DownHole%StringFluids(1)%MudType = FLUID_NO_MUD endif !if(associated(StringMudCountPtr)) then ! call StringMudCountPtr(count) !end if - if(.not.allocated(DownHole%StringFluids))allocate(DownHole%StringFluids(DownHole%StringFluidsCount)) + if(.not.allocated(data%Equipments%DownHole%StringFluids))allocate(data%Equipments%DownHole%StringFluids(data%Equipments%DownHole%StringFluidsCount)) !print*, '============START-ST============' !print*, 'count=', count do i = 1, count item => array(i) - DownHole%StringFluids(i + offset)%StartMd = item%StartMd - if(i==1) DownHole%StringFluids(i)%StartMd = 0 + data%Equipments%DownHole%StringFluids(i + offset)%StartMd = item%StartMd + if(i==1) data%Equipments%DownHole%StringFluids(i)%StartMd = 0 !print*, 'StringFluids(i)%StartMd=', StringFluids(i)%StartMd - DownHole%StringFluids(i + offset)%EndMd = item%EndMd + data%Equipments%DownHole%StringFluids(i + offset)%EndMd = item%EndMd !print*, 'StringFluids(i)%EndMd=', StringFluids(i)%EndMd - DownHole%StringFluids(i + offset)%Density = item%Density - DownHole%StringFluids(i + offset)%MudType = item%MudType + data%Equipments%DownHole%StringFluids(i + offset)%Density = item%Density + data%Equipments%DownHole%StringFluids(i + offset)%MudType = item%MudType !print*, '----------------------------' end do !!if(item%StartMd < 0) StringFluids(1)%StartMd = 0 @@ -121,15 +165,15 @@ module DownHoleModule integer :: i !, j type(CStringComponents), intent(inout), target :: array(count) type(CStringComponents), pointer :: item - DownHole%StringCount = count - if(size(DownHole%String) > 0) then - deallocate(DownHole%String) + data%Equipments%DownHole%StringCount = count + if(size(data%Equipments%DownHole%String) > 0) then + deallocate(data%Equipments%DownHole%String) end if if(count > 0) then !if(associated(StringComponentCountPtr)) then ! call StringComponentCountPtr(count) !end if - allocate(DownHole%String(count)) + allocate(data%Equipments%DownHole%String(count)) !j = 0 !print*, '============CMP-ST============' !call Log_3( '============CMP-ST============') @@ -141,20 +185,20 @@ module DownHoleModule !String(i)%DownDepth = item%DownDepth !String(i)%Od = item%Od !String(i)%Id = item%Id - DownHole%String(i)%ComponentType= item%ComponentType + data%Equipments%DownHole%String(i)%ComponentType= item%ComponentType !j = j + 1 - DownHole%String(i)%StartMd = item%TopDepth - DownHole%String(i)%EndMd = item%DownDepth + data%Equipments%DownHole%String(i)%StartMd = item%TopDepth + data%Equipments%DownHole%String(i)%EndMd = item%DownDepth - DownHole%String(i)%ComponentType=0 + data%Equipments%DownHole%String(i)%ComponentType=0 !if(item%ComponentType > 4 ) then ! String(i)%ComponentType=0 ! String(i)%StartMd = 0 !endif - if(item%ComponentType == 3) DownHole%String(i)%ComponentType=0 - if(item%ComponentType == 4) DownHole%String(i)%ComponentType=1 - if(item%ComponentType == 2) DownHole%String(i)%ComponentType=2 - if(item%ComponentType == 1) DownHole%String(i)%ComponentType=3 + if(item%ComponentType == 3) data%Equipments%DownHole%String(i)%ComponentType=0 + if(item%ComponentType == 4) data%Equipments%DownHole%String(i)%ComponentType=1 + if(item%ComponentType == 2) data%Equipments%DownHole%String(i)%ComponentType=2 + if(item%ComponentType == 1) data%Equipments%DownHole%String(i)%ComponentType=3 !print*, 'item%ComponentType=', item%ComponentType !print*, 'String(i)%ComponentType=', String(i)%ComponentType !print*, 'String(i)%StartMd=', String(i)%StartMd @@ -183,8 +227,8 @@ module DownHoleModule integer :: i = 1 !, j type(CBopElement), intent(inout), target :: array(count) type(CBopElement), pointer :: item - if(size(DownHole%BopElements) > 0) deallocate(DownHole%BopElements) - allocate(DownHole%BopElements(count)) + if(size(data%Equipments%DownHole%BopElements) > 0) deallocate(data%Equipments%DownHole%BopElements) + allocate(data%Equipments%DownHole%BopElements(count)) do i = 1, count item => array(i) @@ -193,9 +237,9 @@ module DownHoleModule !call Log_4('item%ElementType', item%ElementType) !call Log_4('=====================================================') - DownHole%BopElements(i)%ElementStart = item%ElementStart - DownHole%BopElements(i)%ElementEnd = item%ElementEnd - DownHole%BopElements(i)%ElementType = item%ElementType + data%Equipments%DownHole%BopElements(i)%ElementStart = item%ElementStart + data%Equipments%DownHole%BopElements(i)%ElementEnd = item%ElementEnd + data%Equipments%DownHole%BopElements(i)%ElementType = item%ElementType end do !if(associated(BopElementsPtr)) call BopElementsPtr(BopElements) diff --git a/CSharp/DownHole/DownHole.i90 b/CSharp/DownHole/DownHole.i90 new file mode 100644 index 0000000..bd8f8d3 --- /dev/null +++ b/CSharp/DownHole/DownHole.i90 @@ -0,0 +1,249 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/DownHole/DownHole.f90" +module DownHoleModule + use SimulationVariables + contains + + subroutine MudPropertiesToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'DownHole') + +! 2. add member of data type to new node +! call json%add(p,"AnnalusFluidsCount",data%Equipments%DownHole%AnnalusFluidsCount) +! call json%add(p,"StringFluidsCount",data%Equipments%DownHole%StringFluidsCount) +! call json%add(p,"AnnalusFluids(:)",data%Equipments%DownHole%AnnalusFluids(:)) +! call json%add(p,"StringFluids(:)",data%Equipments%DownHole%StringFluids(:)) +! call json%add(p,"StringCount",data%Equipments%DownHole%StringCount) +! call json%add(p,"String(:)",data%Equipments%DownHole%String(:)) +! call json%add(p,"BopElements(:)",data%Equipments%DownHole%BopElements(:)) + call json%add(p,"DrillPipePressure",data%Equipments%DownHole%DrillPipePressure) + call json%add(p,"CasingPressure",data%Equipments%DownHole%CasingPressure) + call json%add(p,"ShoePressure",data%Equipments%DownHole%ShoePressure) + call json%add(p,"BottomHolePressure",data%Equipments%DownHole%BottomHolePressure) + call json%add(p,"FormationPressure",data%Equipments%DownHole%FormationPressure) + call json%add(p,"InfluxRate",data%Equipments%DownHole%InfluxRate) + call json%add(p,"KickVolume",data%Equipments%DownHole%KickVolume) + call json%add(p,"SecondKickVolume",data%Equipments%DownHole%SecondKickVolume) + call json%add(p,"PermeabilityExposedHeight",data%Equipments%DownHole%PermeabilityExposedHeight) +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine DownHoleFromJson(parent) + use json_module,IK =>json_ik + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pitems,pitem,pval,pbit + + call json%get(parent,'DownHole',p) + call json%get(p,'AnnDrillMud',pval) + call json%get(pval,data%Equipments%DownHole%AnnDrillMud) + call json%get(p,'AnnCirculateMud',pval) + call json%get(pval,data%Equipments%DownHole%AnnCirculateMud) + end subroutine + + subroutine SetAnnalusFluids(count, array) + implicit none + integer, intent(in) :: count + integer :: i, offset + type(CFluid), intent(inout), target :: array(count) + type(CFluid), pointer :: item + data%Equipments%DownHole%AnnalusFluidsCount = count + print*, 'AnnalusFluidsCount = ', count + if(size(data%Equipments%DownHole%AnnalusFluids) > 0) then + deallocate(data%Equipments%DownHole%AnnalusFluids) + end if + if(count > 0) then + offset = 0; + item => array(1) + if(item%StartMd > 0) then + data%Equipments%DownHole%AnnalusFluidsCount = data%Equipments%DownHole%AnnalusFluidsCount + 1 + offset = 1; + allocate(data%Equipments%DownHole%AnnalusFluids(data%Equipments%DownHole%AnnalusFluidsCount)) + data%Equipments%DownHole%AnnalusFluids(1)%StartMd = 0 + data%Equipments%DownHole%AnnalusFluids(1)%EndMd = item%StartMd + data%Equipments%DownHole%AnnalusFluids(1)%Density = 0 + data%Equipments%DownHole%AnnalusFluids(1)%MudType = FLUID_NO_MUD + endif + +!if(associated(AnnalusMudCountPtr)) then +! call AnnalusMudCountPtr(AnnalusFluidsCount) +!end if + if(.not.allocated(data%Equipments%DownHole%AnnalusFluids))allocate(data%Equipments%DownHole%AnnalusFluids(data%Equipments%DownHole%AnnalusFluidsCount)) +!print*, '============START-AN============' + if(item%StartMd < 0) data%Equipments%DownHole%AnnalusFluids(1)%StartMd = 0 + do i = 1, count + item => array(i) + data%Equipments%DownHole%AnnalusFluids(i + offset)%StartMd = item%StartMd + if(i==1) data%Equipments%DownHole%AnnalusFluids(i)%StartMd = 0 +!print*, 'AnnalusFluids(',i,')%StartMd=', AnnalusFluids(i)%StartMd + data%Equipments%DownHole%AnnalusFluids(i + offset)%EndMd = item%EndMd +!print*, 'AnnalusFluids(',i,')%EndMd=', AnnalusFluids(i)%EndMd + data%Equipments%DownHole%AnnalusFluids(i + offset)%Density = item%Density +!print*, 'AnnalusFluids(',i,')%Density=', AnnalusFluids(i)%Density + data%Equipments%DownHole%AnnalusFluids(i + offset)%MudType = item%MudType +!print*, 'AnnalusFluids(',i,')%MudType=', AnnalusFluids(i)%MudType +!print*, '----------------------------' + end do +!print*, '============END-AN============' +!if(associated(AnnalusMudArrayPtr)) then +! !AnnalusFluidsPtr => AnnalusFluids +! call AnnalusMudArrayPtr(AnnalusFluids) +!end if + end if + end subroutine SetAnnalusFluids + + subroutine SetStringFluids(count, array) + implicit none + integer, intent(in) :: count + integer :: i, offset !, startArr + type(CFluid), intent(inout), target :: array(count) + type(CFluid), pointer :: item + data%Equipments%DownHole%StringFluidsCount = count + print*, 'StringFluidsCount = ', count + if(size(data%Equipments%DownHole%StringFluids) > 0) then + deallocate(data%Equipments%DownHole%StringFluids) + end if + +!startArr = 1 + + if(count > 0) then + offset = 0; + item => array(1) +! +!if(item%StartMd <= 0 .and. item%EndMd <= 0) then +! StringFluidsCount = StringFluidsCount - 1 +! count = count - 1 +! offset = offset + 1 +! startArr = startArr + 1 +!endif +! +!if(count <= 0) return + + if(item%StartMd > 0) then + data%Equipments%DownHole%StringFluidsCount = data%Equipments%DownHole%StringFluidsCount + 1 + offset = offset + 1 + allocate(data%Equipments%DownHole%StringFluids(data%Equipments%DownHole%StringFluidsCount)) + data%Equipments%DownHole%StringFluids(1)%StartMd = 0 + data%Equipments%DownHole%StringFluids(1)%EndMd = item%StartMd + data%Equipments%DownHole%StringFluids(1)%Density = 0 + data%Equipments%DownHole%StringFluids(1)%MudType = FLUID_NO_MUD + endif + +!if(associated(StringMudCountPtr)) then +! call StringMudCountPtr(count) +!end if + if(.not.allocated(data%Equipments%DownHole%StringFluids))allocate(data%Equipments%DownHole%StringFluids(data%Equipments%DownHole%StringFluidsCount)) +!print*, '============START-ST============' +!print*, 'count=', count + do i = 1, count + item => array(i) + data%Equipments%DownHole%StringFluids(i + offset)%StartMd = item%StartMd + if(i==1) data%Equipments%DownHole%StringFluids(i)%StartMd = 0 +!print*, 'StringFluids(i)%StartMd=', StringFluids(i)%StartMd + data%Equipments%DownHole%StringFluids(i + offset)%EndMd = item%EndMd +!print*, 'StringFluids(i)%EndMd=', StringFluids(i)%EndMd + data%Equipments%DownHole%StringFluids(i + offset)%Density = item%Density + data%Equipments%DownHole%StringFluids(i + offset)%MudType = item%MudType +!print*, '----------------------------' + end do +!!if(item%StartMd < 0) StringFluids(1)%StartMd = 0 +!!print*, '============END-ST============' +!if(associated(StringMudArrayPtr)) then +! call StringMudArrayPtr(StringFluids) +!end if + end if + end subroutine SetStringFluids + + subroutine SetString(count, array) + use CLog3 + implicit none + integer, intent(in) :: count + integer :: i !, j + type(CStringComponents), intent(inout), target :: array(count) + type(CStringComponents), pointer :: item + data%Equipments%DownHole%StringCount = count + if(size(data%Equipments%DownHole%String) > 0) then + deallocate(data%Equipments%DownHole%String) + end if + if(count > 0) then +!if(associated(StringComponentCountPtr)) then +! call StringComponentCountPtr(count) +!end if + allocate(data%Equipments%DownHole%String(count)) +!j = 0 +!print*, '============CMP-ST============' +!call Log_3( '============CMP-ST============') +!do i = count, 1, -1 + do i = 1, count + item => array(i) +!String(i)%Length = item%Length +!String(i)%TopDepth = item%TopDepth +!String(i)%DownDepth = item%DownDepth +!String(i)%Od = item%Od +!String(i)%Id = item%Id + data%Equipments%DownHole%String(i)%ComponentType= item%ComponentType +!j = j + 1 + data%Equipments%DownHole%String(i)%StartMd = item%TopDepth + data%Equipments%DownHole%String(i)%EndMd = item%DownDepth + + data%Equipments%DownHole%String(i)%ComponentType=0 +!if(item%ComponentType > 4 ) then +! String(i)%ComponentType=0 +! String(i)%StartMd = 0 +!endif + if(item%ComponentType == 3) data%Equipments%DownHole%String(i)%ComponentType=0 + if(item%ComponentType == 4) data%Equipments%DownHole%String(i)%ComponentType=1 + if(item%ComponentType == 2) data%Equipments%DownHole%String(i)%ComponentType=2 + if(item%ComponentType == 1) data%Equipments%DownHole%String(i)%ComponentType=3 +!print*, 'item%ComponentType=', item%ComponentType +!print*, 'String(i)%ComponentType=', String(i)%ComponentType +!print*, 'String(i)%StartMd=', String(i)%StartMd +!print*, 'String(i)%EndMd=', String(i)%EndMd +!print*, '----------------------------' + +!call Log_3( 'item%ComponentType=', item%ComponentType) +!call Log_3( 'String(i)%ComponentType=', String(i)%ComponentType) +!call Log_3( 'String(i)%StartMd=', String(i)%StartMd) +!call Log_3( 'String(i)%EndMd=', String(i)%EndMd) +!call Log_3( '----------------------------') + + end do +!!print*, '============CMP-ST============' +!!call Log_3( '============CMP-ST============') +!if(associated(StringComponentArrayPtr)) then +! call StringComponentArrayPtr(String) +!end if + end if + end subroutine SetString + + subroutine SetBopElements(array) + use CLog4 + implicit none + integer, parameter :: count = 4 + integer :: i = 1 !, j + type(CBopElement), intent(inout), target :: array(count) + type(CBopElement), pointer :: item + if(size(data%Equipments%DownHole%BopElements) > 0) deallocate(data%Equipments%DownHole%BopElements) + allocate(data%Equipments%DownHole%BopElements(count)) + + do i = 1, count + item => array(i) +!call Log_4('item%ElementStart', item%ElementStart) +!call Log_4('item%ElementEnd', item%ElementEnd) +!call Log_4('item%ElementType', item%ElementType) +!call Log_4('=====================================================') + + data%Equipments%DownHole%BopElements(i)%ElementStart = item%ElementStart + data%Equipments%DownHole%BopElements(i)%ElementEnd = item%ElementEnd + data%Equipments%DownHole%BopElements(i)%ElementType = item%ElementType + end do + +!if(associated(BopElementsPtr)) call BopElementsPtr(BopElements) + end subroutine SetBopElements + +end module DownHoleModule diff --git a/CSharp/DownHole/cdownholetypes.mod b/CSharp/DownHole/cdownholetypes.mod new file mode 100644 index 0000000..5f5f501 Binary files /dev/null and b/CSharp/DownHole/cdownholetypes.mod differ diff --git a/CSharp/Equipments/ControlPanels/CBopControlPanel.f90 b/CSharp/Equipments/ControlPanels/CBopControlPanel.f90 index 18db3ef..fbf07f6 100644 --- a/CSharp/Equipments/ControlPanels/CBopControlPanel.f90 +++ b/CSharp/Equipments/ControlPanels/CBopControlPanel.f90 @@ -5,6 +5,75 @@ module CBopControlPanel public contains + subroutine BopControlPanelFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + ! 1. get related root + call json%get(parent,'BopControl',p) + call json%get(p,'AnnularRegulatorSetControl',pval) + call json%get(pval,data%Equipments%BopControlPanel%AnnularRegulatorSetControl) + call json%get(p,'AirMasterValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%AirMasterValve) + call json%get(p,'ByePassValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%ByePassValve) + call json%get(p,'AnnularValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%AnnularValve) + call json%get(p,'UpperRamsValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%UpperRamsValve) + call json%get(p,'MiddleRamsValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%MiddleRamsValve) + call json%get(p,'KillLineValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%KillLineValve) + call json%get(p,'ChokeLineValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%ChokeLineValve) + call json%get(p,'LowerRamsValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%LowerRamsValve) + ! call json%get(p,'ManifoldPressureGauge',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%ManifoldPressureGauge) + ! call json%get(p,'AirSupplyPressureGauge',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%AirSupplyPressureGauge) + ! call json%get(p,'AccumulatorPressureGauge',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%AccumulatorPressureGauge) + ! call json%get(p,'AnnularPressureGauge',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%AnnularPressureGauge) + ! call json%get(p,'AnnularOpenLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%AnnularOpenLED) + ! call json%get(p,'AnnularCloseLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%AnnularCloseLED) + ! call json%get(p,'UpperRamsOpenLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%UpperRamsOpenLED) + ! call json%get(p,'UpperRamsCloseLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%UpperRamsCloseLED) + ! call json%get(p,'MiddleRamsOpenLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%MiddleRamsOpenLED) + ! call json%get(p,'MiddleRamsCloseLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%MiddleRamsCloseLED) + ! call json%get(p,'KillLineOpenLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%KillLineOpenLED) + ! call json%get(p,'KillLineCloseLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%KillLineCloseLED) + ! call json%get(p,'ChokeLineOpenLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%ChokeLineOpenLED) + ! call json%get(p,'ChokeLineCloseLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%ChokeLineCloseLED) + ! call json%get(p,'LowerRamsOpenLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%LowerRamsOpenLED) + ! call json%get(p,'LowerRamsCloseLED',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%LowerRamsCloseLED) + ! call json%get(p,'AnnularStatus',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%AnnularStatus) + ! call json%get(p,'UpperRamsStatus',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%UpperRamsStatus) + ! call json%get(p,'MiddleRamsStatus',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%MiddleRamsStatus) + ! call json%get(p,'LowerRamsStatus',pval) + ! call json%get(pval,data%Equipments%BopControlPanel%LowerRamsStatus) + + ! 2. get member of data type from node + end subroutine + subroutine BopControlPanelToJson(parent) type(json_value),pointer :: parent @@ -14,36 +83,35 @@ module CBopControlPanel ! 1. create new node call json%create_object(p,'BopControl') - call json%add(p,"AnnularRegulatorSetControl",data%EquipmentControl%BopControlPanel%AnnularRegulatorSetControl) - call json%add(p,"AirMasterValve",data%EquipmentControl%BopControlPanel%AirMasterValve) - call json%add(p,"ByePassValve",data%EquipmentControl%BopControlPanel%ByePassValve) - call json%add(p,"AnnularValve",data%EquipmentControl%BopControlPanel%AnnularValve) - call json%add(p,"UpperRamsValve",data%EquipmentControl%BopControlPanel%UpperRamsValve) - call json%add(p,"MiddleRamsValve",data%EquipmentControl%BopControlPanel%MiddleRamsValve) - call json%add(p,"KillLineValve",data%EquipmentControl%BopControlPanel%KillLineValve) - call json%add(p,"ChokeLineValve",data%EquipmentControl%BopControlPanel%ChokeLineValve) - call json%add(p,"LowerRamsValve",data%EquipmentControl%BopControlPanel%LowerRamsValve) - call json%add(p,"ManifoldPressureGauge",data%EquipmentControl%BopControlPanel%ManifoldPressureGauge) - call json%add(p,"AirSupplyPressureGauge",data%EquipmentControl%BopControlPanel%AirSupplyPressureGauge) - call json%add(p,"AccumulatorPressureGauge",data%EquipmentControl%BopControlPanel%AccumulatorPressureGauge) - call json%add(p,"AnnularPressureGauge",data%EquipmentControl%BopControlPanel%AnnularPressureGauge) - call json%add(p,"AnnularOpenLED",data%EquipmentControl%BopControlPanel%AnnularOpenLED) - call json%add(p,"AnnularCloseLED",data%EquipmentControl%BopControlPanel%AnnularCloseLED) - call json%add(p,"UpperRamsOpenLED",data%EquipmentControl%BopControlPanel%UpperRamsOpenLED) - call json%add(p,"UpperRamsCloseLED",data%EquipmentControl%BopControlPanel%UpperRamsCloseLED) - call json%add(p,"MiddleRamsOpenLED",data%EquipmentControl%BopControlPanel%MiddleRamsOpenLED) - call json%add(p,"MiddleRamsCloseLED",data%EquipmentControl%BopControlPanel%MiddleRamsCloseLED) - call json%add(p,"KillLineOpenLED",data%EquipmentControl%BopControlPanel%KillLineOpenLED) - call json%add(p,"KillLineCloseLED",data%EquipmentControl%BopControlPanel%KillLineCloseLED) - call json%add(p,"ChokeLineOpenLED",data%EquipmentControl%BopControlPanel%ChokeLineOpenLED) - call json%add(p,"ChokeLineCloseLED",data%EquipmentControl%BopControlPanel%ChokeLineCloseLED) - call json%add(p,"LowerRamsOpenLED",data%EquipmentControl%BopControlPanel%LowerRamsOpenLED) - call json%add(p,"LowerRamsCloseLED",data%EquipmentControl%BopControlPanel%LowerRamsCloseLED) - call json%add(p,"AnnularStatus",data%EquipmentControl%BopControlPanel%AnnularStatus) - call json%add(p,"UpperRamsStatus",data%EquipmentControl%BopControlPanel%UpperRamsStatus) - call json%add(p,"MiddleRamsStatus",data%EquipmentControl%BopControlPanel%MiddleRamsStatus) - call json%add(p,"LowerRamsStatus",data%EquipmentControl%BopControlPanel%LowerRamsStatus) - + ! call json%add(p,"AnnularRegulatorSetControl",data%Equipments%BopControlPanel%AnnularRegulatorSetControl) + ! call json%add(p,"AirMasterValve",data%Equipments%BopControlPanel%AirMasterValve) + ! call json%add(p,"ByePassValve",data%Equipments%BopControlPanel%ByePassValve) + ! call json%add(p,"AnnularValve",data%Equipments%BopControlPanel%AnnularValve) + ! call json%add(p,"UpperRamsValve",data%Equipments%BopControlPanel%UpperRamsValve) + ! call json%add(p,"MiddleRamsValve",data%Equipments%BopControlPanel%MiddleRamsValve) + ! call json%add(p,"KillLineValve",data%Equipments%BopControlPanel%KillLineValve) + ! call json%add(p,"ChokeLineValve",data%Equipments%BopControlPanel%ChokeLineValve) + ! call json%add(p,"LowerRamsValve",data%Equipments%BopControlPanel%LowerRamsValve) + call json%add(p,"ManifoldPressureGauge",data%Equipments%BopControlPanel%ManifoldPressureGauge) + call json%add(p,"AirSupplyPressureGauge",data%Equipments%BopControlPanel%AirSupplyPressureGauge) + call json%add(p,"AccumulatorPressureGauge",data%Equipments%BopControlPanel%AccumulatorPressureGauge) + call json%add(p,"AnnularPressureGauge",data%Equipments%BopControlPanel%AnnularPressureGauge) + call json%add(p,"AnnularOpenLED",data%Equipments%BopControlPanel%AnnularOpenLED) + call json%add(p,"AnnularCloseLED",data%Equipments%BopControlPanel%AnnularCloseLED) + call json%add(p,"UpperRamsOpenLED",data%Equipments%BopControlPanel%UpperRamsOpenLED) + call json%add(p,"UpperRamsCloseLED",data%Equipments%BopControlPanel%UpperRamsCloseLED) + call json%add(p,"MiddleRamsOpenLED",data%Equipments%BopControlPanel%MiddleRamsOpenLED) + call json%add(p,"MiddleRamsCloseLED",data%Equipments%BopControlPanel%MiddleRamsCloseLED) + call json%add(p,"KillLineOpenLED",data%Equipments%BopControlPanel%KillLineOpenLED) + call json%add(p,"KillLineCloseLED",data%Equipments%BopControlPanel%KillLineCloseLED) + call json%add(p,"ChokeLineOpenLED",data%Equipments%BopControlPanel%ChokeLineOpenLED) + call json%add(p,"ChokeLineCloseLED",data%Equipments%BopControlPanel%ChokeLineCloseLED) + call json%add(p,"LowerRamsOpenLED",data%Equipments%BopControlPanel%LowerRamsOpenLED) + call json%add(p,"LowerRamsCloseLED",data%Equipments%BopControlPanel%LowerRamsCloseLED) + call json%add(p,"AnnularStatus",data%Equipments%BopControlPanel%AnnularStatus) + call json%add(p,"UpperRamsStatus",data%Equipments%BopControlPanel%UpperRamsStatus) + call json%add(p,"MiddleRamsStatus",data%Equipments%BopControlPanel%MiddleRamsStatus) + call json%add(p,"LowerRamsStatus",data%Equipments%BopControlPanel%LowerRamsStatus) call json%add(parent,p) end subroutine diff --git a/CSharp/Equipments/ControlPanels/CBopControlPanel.i90 b/CSharp/Equipments/ControlPanels/CBopControlPanel.i90 new file mode 100644 index 0000000..d263584 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CBopControlPanel.i90 @@ -0,0 +1,198 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CBopControlPanel.f90" +module CBopControlPanel +! use CBopControlPanel + use SimulationVariables + implicit none + public + contains + + subroutine BopControlPanelFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + +! 1. get related root + call json%get(parent,'BopControl',p) + call json%get(p,'AnnularRegulatorSetControl',pval) + call json%get(pval,data%Equipments%BopControlPanel%AnnularRegulatorSetControl) + call json%get(p,'AirMasterValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%AirMasterValve) + call json%get(p,'ByePassValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%ByePassValve) + call json%get(p,'AnnularValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%AnnularValve) + call json%get(p,'UpperRamsValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%UpperRamsValve) + call json%get(p,'MiddleRamsValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%MiddleRamsValve) + call json%get(p,'KillLineValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%KillLineValve) + call json%get(p,'ChokeLineValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%ChokeLineValve) + call json%get(p,'LowerRamsValve',pval) + call json%get(pval,data%Equipments%BopControlPanel%LowerRamsValve) +! call json%get(p,'ManifoldPressureGauge',pval) +! call json%get(pval,data%Equipments%BopControlPanel%ManifoldPressureGauge) +! call json%get(p,'AirSupplyPressureGauge',pval) +! call json%get(pval,data%Equipments%BopControlPanel%AirSupplyPressureGauge) +! call json%get(p,'AccumulatorPressureGauge',pval) +! call json%get(pval,data%Equipments%BopControlPanel%AccumulatorPressureGauge) +! call json%get(p,'AnnularPressureGauge',pval) +! call json%get(pval,data%Equipments%BopControlPanel%AnnularPressureGauge) +! call json%get(p,'AnnularOpenLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%AnnularOpenLED) +! call json%get(p,'AnnularCloseLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%AnnularCloseLED) +! call json%get(p,'UpperRamsOpenLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%UpperRamsOpenLED) +! call json%get(p,'UpperRamsCloseLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%UpperRamsCloseLED) +! call json%get(p,'MiddleRamsOpenLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%MiddleRamsOpenLED) +! call json%get(p,'MiddleRamsCloseLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%MiddleRamsCloseLED) +! call json%get(p,'KillLineOpenLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%KillLineOpenLED) +! call json%get(p,'KillLineCloseLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%KillLineCloseLED) +! call json%get(p,'ChokeLineOpenLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%ChokeLineOpenLED) +! call json%get(p,'ChokeLineCloseLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%ChokeLineCloseLED) +! call json%get(p,'LowerRamsOpenLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%LowerRamsOpenLED) +! call json%get(p,'LowerRamsCloseLED',pval) +! call json%get(pval,data%Equipments%BopControlPanel%LowerRamsCloseLED) +! call json%get(p,'AnnularStatus',pval) +! call json%get(pval,data%Equipments%BopControlPanel%AnnularStatus) +! call json%get(p,'UpperRamsStatus',pval) +! call json%get(pval,data%Equipments%BopControlPanel%UpperRamsStatus) +! call json%get(p,'MiddleRamsStatus',pval) +! call json%get(pval,data%Equipments%BopControlPanel%MiddleRamsStatus) +! call json%get(p,'LowerRamsStatus',pval) +! call json%get(pval,data%Equipments%BopControlPanel%LowerRamsStatus) + +! 2. get member of data type from node + end subroutine + + subroutine BopControlPanelToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'BopControl') + +! call json%add(p,"AnnularRegulatorSetControl",data%Equipments%BopControlPanel%AnnularRegulatorSetControl) +! call json%add(p,"AirMasterValve",data%Equipments%BopControlPanel%AirMasterValve) +! call json%add(p,"ByePassValve",data%Equipments%BopControlPanel%ByePassValve) +! call json%add(p,"AnnularValve",data%Equipments%BopControlPanel%AnnularValve) +! call json%add(p,"UpperRamsValve",data%Equipments%BopControlPanel%UpperRamsValve) +! call json%add(p,"MiddleRamsValve",data%Equipments%BopControlPanel%MiddleRamsValve) +! call json%add(p,"KillLineValve",data%Equipments%BopControlPanel%KillLineValve) +! call json%add(p,"ChokeLineValve",data%Equipments%BopControlPanel%ChokeLineValve) +! call json%add(p,"LowerRamsValve",data%Equipments%BopControlPanel%LowerRamsValve) + call json%add(p,"ManifoldPressureGauge",data%Equipments%BopControlPanel%ManifoldPressureGauge) + call json%add(p,"AirSupplyPressureGauge",data%Equipments%BopControlPanel%AirSupplyPressureGauge) + call json%add(p,"AccumulatorPressureGauge",data%Equipments%BopControlPanel%AccumulatorPressureGauge) + call json%add(p,"AnnularPressureGauge",data%Equipments%BopControlPanel%AnnularPressureGauge) + call json%add(p,"AnnularOpenLED",data%Equipments%BopControlPanel%AnnularOpenLED) + call json%add(p,"AnnularCloseLED",data%Equipments%BopControlPanel%AnnularCloseLED) + call json%add(p,"UpperRamsOpenLED",data%Equipments%BopControlPanel%UpperRamsOpenLED) + call json%add(p,"UpperRamsCloseLED",data%Equipments%BopControlPanel%UpperRamsCloseLED) + call json%add(p,"MiddleRamsOpenLED",data%Equipments%BopControlPanel%MiddleRamsOpenLED) + call json%add(p,"MiddleRamsCloseLED",data%Equipments%BopControlPanel%MiddleRamsCloseLED) + call json%add(p,"KillLineOpenLED",data%Equipments%BopControlPanel%KillLineOpenLED) + call json%add(p,"KillLineCloseLED",data%Equipments%BopControlPanel%KillLineCloseLED) + call json%add(p,"ChokeLineOpenLED",data%Equipments%BopControlPanel%ChokeLineOpenLED) + call json%add(p,"ChokeLineCloseLED",data%Equipments%BopControlPanel%ChokeLineCloseLED) + call json%add(p,"LowerRamsOpenLED",data%Equipments%BopControlPanel%LowerRamsOpenLED) + call json%add(p,"LowerRamsCloseLED",data%Equipments%BopControlPanel%LowerRamsCloseLED) + call json%add(p,"AnnularStatus",data%Equipments%BopControlPanel%AnnularStatus) + call json%add(p,"UpperRamsStatus",data%Equipments%BopControlPanel%UpperRamsStatus) + call json%add(p,"MiddleRamsStatus",data%Equipments%BopControlPanel%MiddleRamsStatus) + call json%add(p,"LowerRamsStatus",data%Equipments%BopControlPanel%LowerRamsStatus) + + call json%add(parent,p) + end subroutine + + + + subroutine OpenAnnular() + use CManifolds + implicit none + call ChangeValve(52, .true.) + end subroutine + + subroutine CloseAnnular() + use CManifolds + implicit none + call ChangeValve(52, .false.) + end subroutine + + subroutine OpenUpperRams() + use CManifolds + implicit none + call ChangeValve(51, .true.) + end subroutine + + subroutine CloseUpperRams() + use CManifolds + implicit none + call ChangeValve(51, .false.) + end subroutine + + subroutine OpenMiddleRams() + use CManifolds + implicit none + call ToggleMiddleRams(.true.) + end subroutine + + subroutine CloseMiddleRams() + use CManifolds + implicit none + call ToggleMiddleRams(.false.) + end subroutine + + subroutine OpenKillLine() + use CManifolds + implicit none + call ChangeValve(46, .true.) + end subroutine + + subroutine CloseKillLine() + use CManifolds + implicit none + call ChangeValve(46, .false.) + end subroutine + + subroutine OpenChokeLine() + use CManifolds + implicit none + call ChangeValve(47, .true.) +!WRITE (*,*) ' valve 47 true ' + end subroutine + + subroutine CloseChokeLine() + use CManifolds + implicit none + call ChangeValve(47, .false.) +!WRITE (*,*) ' valve 47 false ' + end subroutine + + subroutine OpenLowerRams() + use CManifolds + implicit none + call ChangeValve(49, .true.) +!WRITE (*,*) ' valve 49 true ' + end subroutine + + subroutine CloseLowerRams() + use CManifolds + implicit none + call ChangeValve(49, .false.) +!WRITE (*,*) ' valve 49 false ' + end subroutine + + end module CBopControlPanel diff --git a/CSharp/Equipments/ControlPanels/CBopControlPanelVariables.i90 b/CSharp/Equipments/ControlPanels/CBopControlPanelVariables.i90 new file mode 100644 index 0000000..fc115f4 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CBopControlPanelVariables.i90 @@ -0,0 +1,41 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CBopControlPanelVariables.f90" +module CBopControlPanelVariables + implicit none + public + Type, Public:: BopControlPanelType +! Input vars + real(8) :: AnnularRegulatorSetControl + real(8) :: AirMasterValve + real(8) :: ByePassValve + real(8) :: AnnularValve + real(8) :: UpperRamsValve + real(8) :: MiddleRamsValve + real(8) :: KillLineValve + real(8) :: ChokeLineValve + real(8) :: LowerRamsValve + +! Output vars + real(8) :: ManifoldPressureGauge + real(8) :: AirSupplyPressureGauge + real(8) :: AccumulatorPressureGauge + real(8) :: AnnularPressureGauge + integer :: AnnularOpenLED + integer :: AnnularCloseLED + integer :: UpperRamsOpenLED + integer :: UpperRamsCloseLED + integer :: MiddleRamsOpenLED + integer :: MiddleRamsCloseLED + integer :: KillLineOpenLED + integer :: KillLineCloseLED + integer :: ChokeLineOpenLED + integer :: ChokeLineCloseLED + integer :: LowerRamsOpenLED + integer :: LowerRamsCloseLED + real(8) :: AnnularStatus + real(8) :: UpperRamsStatus + real(8) :: MiddleRamsStatus + real(8) :: LowerRamsStatus + end type + contains + +end module CBopControlPanelVariables diff --git a/CSharp/Equipments/ControlPanels/CChokeControlPanel.f90 b/CSharp/Equipments/ControlPanels/CChokeControlPanel.f90 index 20fd64b..a556923 100644 --- a/CSharp/Equipments/ControlPanels/CChokeControlPanel.f90 +++ b/CSharp/Equipments/ControlPanels/CChokeControlPanel.f90 @@ -3,7 +3,45 @@ module CChokeControlPanel use SimulationVariables implicit none public - contains + contains + + subroutine ChokeControlPanelFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + ! 1. get related root + call json%get(parent,'ChokeControl',p) + + ! 2. get member of data type from node + call json%get(p,'ChokePanelPumpSelectorSwitch',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch) + call json%get(p,'ChokePanelStrokeResetSwitch',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch) + call json%get(p,'ChokeSelectorSwitch',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokeSelectorSwitch) + call json%get(p,'ChokeRateControlKnob',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokeRateControlKnob) + call json%get(p,'ChokeControlLever',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokeControlLever) + call json%get(p,'ChokePanelRigAirSwitch',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch) + ! call json%get(p,'EnableAutoChoke',pval) + ! call json%get(pval,data%Equipments%ChokeControlPanel%EnableAutoChoke) + ! call json%get(p,'StandPipePressure',pval) + ! call json%get(pval,data%Equipments%ChokeControlPanel%StandPipePressure) + ! call json%get(p,'CasingPressure',pval) + ! call json%get(pval,data%Equipments%ChokeControlPanel%CasingPressure) + ! call json%get(p,'ChokePosition',pval) + ! call json%get(pval,data%Equipments%ChokeControlPanel%ChokePosition) + ! call json%get(p,'ChokePanelSPMCounter',pval) + ! call json%get(pval,data%Equipments%ChokeControlPanel%ChokePanelSPMCounter) + ! call json%get(p,'ChokePanelTotalStrokeCounter',pval) + ! call json%get(pval,data%Equipments%ChokeControlPanel%ChokePanelTotalStrokeCounter) + ! call json%get(p,'Choke1LED',pval) + ! call json%get(pval,data%Equipments%ChokeControlPanel%Choke1LED) + ! call json%get(p,'Choke2LED',pval) + ! call json%get(pval,data%Equipments%ChokeControlPanel%Choke2LED) + end subroutine subroutine ChokeControlPanelToJson(parent) @@ -13,20 +51,20 @@ module CChokeControlPanel ! 1. create new node call json%create_object(p,'ChokeControl') - call json%add(p,"ChokePanelPumpSelectorSwitch",data%EquipmentControl%ChokeControlPanel%ChokePanelPumpSelectorSwitch) - call json%add(p,"ChokePanelStrokeResetSwitch",data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch) - call json%add(p,"ChokeSelectorSwitch",data%EquipmentControl%ChokeControlPanel%ChokeSelectorSwitch) - call json%add(p,"ChokeRateControlKnob",data%EquipmentControl%ChokeControlPanel%ChokeRateControlKnob) - call json%add(p,"ChokeControlLever",data%EquipmentControl%ChokeControlPanel%ChokeControlLever) - call json%add(p,"ChokePanelRigAirSwitch",data%EquipmentControl%ChokeControlPanel%ChokePanelRigAirSwitch) - call json%add(p,"EnableAutoChoke",data%EquipmentControl%ChokeControlPanel%EnableAutoChoke) - call json%add(p,"StandPipePressure",data%EquipmentControl%ChokeControlPanel%StandPipePressure) - call json%add(p,"CasingPressure",data%EquipmentControl%ChokeControlPanel%CasingPressure) - call json%add(p,"ChokePosition",data%EquipmentControl%ChokeControlPanel%ChokePosition) - call json%add(p,"ChokePanelSPMCounter",data%EquipmentControl%ChokeControlPanel%ChokePanelSPMCounter) - call json%add(p,"ChokePanelTotalStrokeCounter",data%EquipmentControl%ChokeControlPanel%ChokePanelTotalStrokeCounter) - call json%add(p,"Choke1LED",data%EquipmentControl%ChokeControlPanel%Choke1LED) - call json%add(p,"Choke2LED",data%EquipmentControl%ChokeControlPanel%Choke2LED) + ! call json%add(p,"ChokePanelPumpSelectorSwitch",data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch) + ! call json%add(p,"ChokePanelStrokeResetSwitch",data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch) + ! call json%add(p,"ChokeSelectorSwitch",data%Equipments%ChokeControlPanel%ChokeSelectorSwitch) + ! call json%add(p,"ChokeRateControlKnob",data%Equipments%ChokeControlPanel%ChokeRateControlKnob) + ! call json%add(p,"ChokeControlLever",data%Equipments%ChokeControlPanel%ChokeControlLever) + ! call json%add(p,"ChokePanelRigAirSwitch",data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch) + ! call json%add(p,"EnableAutoChoke",data%Equipments%ChokeControlPanel%EnableAutoChoke) + call json%add(p,"StandPipePressure",data%Equipments%ChokeControlPanel%StandPipePressure) + call json%add(p,"CasingPressure",data%Equipments%ChokeControlPanel%CasingPressure) + call json%add(p,"ChokePosition",data%Equipments%ChokeControlPanel%ChokePosition) + call json%add(p,"ChokePanelSPMCounter",data%Equipments%ChokeControlPanel%ChokePanelSPMCounter) + call json%add(p,"ChokePanelTotalStrokeCounter",data%Equipments%ChokeControlPanel%ChokePanelTotalStrokeCounter) + call json%add(p,"Choke1LED",data%Equipments%ChokeControlPanel%Choke1LED) + call json%add(p,"Choke2LED",data%Equipments%ChokeControlPanel%Choke2LED) call json%add(parent,p) diff --git a/CSharp/Equipments/ControlPanels/CChokeControlPanel.i90 b/CSharp/Equipments/ControlPanels/CChokeControlPanel.i90 new file mode 100644 index 0000000..fd4c809 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CChokeControlPanel.i90 @@ -0,0 +1,74 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CChokeControlPanel.f90" +module CChokeControlPanel + use CChokeControlPanelVariables + use SimulationVariables + implicit none + public + contains + + subroutine ChokeControlPanelFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval +! 1. get related root + call json%get(parent,'ChokeControl',p) + +! 2. get member of data type from node + call json%get(p,'ChokePanelPumpSelectorSwitch',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch) + call json%get(p,'ChokePanelStrokeResetSwitch',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch) + call json%get(p,'ChokeSelectorSwitch',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokeSelectorSwitch) + call json%get(p,'ChokeRateControlKnob',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokeRateControlKnob) + call json%get(p,'ChokeControlLever',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokeControlLever) + call json%get(p,'ChokePanelRigAirSwitch',pval) + call json%get(pval,data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch) +! call json%get(p,'EnableAutoChoke',pval) +! call json%get(pval,data%Equipments%ChokeControlPanel%EnableAutoChoke) +! call json%get(p,'StandPipePressure',pval) +! call json%get(pval,data%Equipments%ChokeControlPanel%StandPipePressure) +! call json%get(p,'CasingPressure',pval) +! call json%get(pval,data%Equipments%ChokeControlPanel%CasingPressure) +! call json%get(p,'ChokePosition',pval) +! call json%get(pval,data%Equipments%ChokeControlPanel%ChokePosition) +! call json%get(p,'ChokePanelSPMCounter',pval) +! call json%get(pval,data%Equipments%ChokeControlPanel%ChokePanelSPMCounter) +! call json%get(p,'ChokePanelTotalStrokeCounter',pval) +! call json%get(pval,data%Equipments%ChokeControlPanel%ChokePanelTotalStrokeCounter) +! call json%get(p,'Choke1LED',pval) +! call json%get(pval,data%Equipments%ChokeControlPanel%Choke1LED) +! call json%get(p,'Choke2LED',pval) +! call json%get(pval,data%Equipments%ChokeControlPanel%Choke2LED) + end subroutine + + subroutine ChokeControlPanelToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'ChokeControl') +! call json%add(p,"ChokePanelPumpSelectorSwitch",data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch) +! call json%add(p,"ChokePanelStrokeResetSwitch",data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch) +! call json%add(p,"ChokeSelectorSwitch",data%Equipments%ChokeControlPanel%ChokeSelectorSwitch) +! call json%add(p,"ChokeRateControlKnob",data%Equipments%ChokeControlPanel%ChokeRateControlKnob) +! call json%add(p,"ChokeControlLever",data%Equipments%ChokeControlPanel%ChokeControlLever) +! call json%add(p,"ChokePanelRigAirSwitch",data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch) +! call json%add(p,"EnableAutoChoke",data%Equipments%ChokeControlPanel%EnableAutoChoke) + call json%add(p,"StandPipePressure",data%Equipments%ChokeControlPanel%StandPipePressure) + call json%add(p,"CasingPressure",data%Equipments%ChokeControlPanel%CasingPressure) + call json%add(p,"ChokePosition",data%Equipments%ChokeControlPanel%ChokePosition) + call json%add(p,"ChokePanelSPMCounter",data%Equipments%ChokeControlPanel%ChokePanelSPMCounter) + call json%add(p,"ChokePanelTotalStrokeCounter",data%Equipments%ChokeControlPanel%ChokePanelTotalStrokeCounter) + call json%add(p,"Choke1LED",data%Equipments%ChokeControlPanel%Choke1LED) + call json%add(p,"Choke2LED",data%Equipments%ChokeControlPanel%Choke2LED) + + + call json%add(parent,p) + end subroutine + +end module CChokeControlPanel diff --git a/CSharp/Equipments/ControlPanels/CChokeControlPanelVariables.f90 b/CSharp/Equipments/ControlPanels/CChokeControlPanelVariables.f90 index b931a87..d4819e8 100644 --- a/CSharp/Equipments/ControlPanels/CChokeControlPanelVariables.f90 +++ b/CSharp/Equipments/ControlPanels/CChokeControlPanelVariables.f90 @@ -9,7 +9,7 @@ module CChokeControlPanelVariables real(8) :: ChokeControlLever logical :: ChokePanelRigAirSwitch - logical :: EnableAutoChoke + ! logical :: EnableAutoChoke ! Output vars real(8) :: StandPipePressure diff --git a/CSharp/Equipments/ControlPanels/CChokeControlPanelVariables.i90 b/CSharp/Equipments/ControlPanels/CChokeControlPanelVariables.i90 new file mode 100644 index 0000000..94b172b --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CChokeControlPanelVariables.i90 @@ -0,0 +1,24 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CChokeControlPanelVariables.f90" +module CChokeControlPanelVariables + implicit none + type, public :: ChokeControlPanelType +! Input vars + integer :: ChokePanelPumpSelectorSwitch + logical :: ChokePanelStrokeResetSwitch + logical :: ChokeSelectorSwitch + real(8) :: ChokeRateControlKnob + real(8) :: ChokeControlLever + logical :: ChokePanelRigAirSwitch + +! logical :: EnableAutoChoke + +! Output vars + real(8) :: StandPipePressure + real(8) :: CasingPressure + real(8) :: ChokePosition + real(8) :: ChokePanelSPMCounter + real(8) :: ChokePanelTotalStrokeCounter + integer :: Choke1LED + integer :: Choke2LED + End Type ChokeControlPanelType +end module CChokeControlPanelVariables diff --git a/CSharp/Equipments/ControlPanels/CChokeManifold.f90 b/CSharp/Equipments/ControlPanels/CChokeManifold.f90 index a18440a..4c9ff5d 100644 --- a/CSharp/Equipments/ControlPanels/CChokeManifold.f90 +++ b/CSharp/Equipments/ControlPanels/CChokeManifold.f90 @@ -7,6 +7,55 @@ module CChokeManifold public contains + subroutine ChokeManifoldFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + ! 1. get related root + call json%get(parent,'ChokeManifold',p) + + ! 2. get member of data type from node + call json%get(p,'ChokeManifoldValve1',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve1) + call json%get(p,'ChokeManifoldValve2',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve2) + call json%get(p,'LeftManualChoke',pval) + call json%get(pval,data%Equipments%ChokeManifold%LeftManualChoke) + call json%get(p,'ChokeManifoldValve4',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve4) + call json%get(p,'ChokeManifoldValve5',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve5) + call json%get(p,'RightManualChoke',pval) + call json%get(pval,data%Equipments%ChokeManifold%RightManualChoke) + call json%get(p,'ChokeManifoldValve7',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve7) + call json%get(p,'ChokeManifoldValve8',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve8) + call json%get(p,'ChokeManifoldValve9',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve9) + call json%get(p,'ChokeManifoldValve10',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve10) + call json%get(p,'ChokeManifoldValve11',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve11) + call json%get(p,'ChokeManifoldValve12',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve12) + call json%get(p,'ChokeManifoldValve13',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve13) + ! call json%get(p,'HydraulicChock1',pval) + ! call json%get(pval,data%Equipments%ChokeManifold%HydraulicChock1) + ! call json%get(p,'HydraulicChock2',pval) + ! call json%get(pval,data%Equipments%ChokeManifold%HydraulicChock2) + call json%get(p,'HyChock1OnProblem',pval) + call json%get(pval,data%Equipments%ChokeManifold%HyChock1OnProblem) + call json%get(p,'HyChock2OnProblem',pval) + call json%get(pval,data%Equipments%ChokeManifold%HyChock2OnProblem) + call json%get(p,'LeftManChokeOnProblem',pval) + call json%get(pval,data%Equipments%ChokeManifold%LeftManChokeOnProblem) + call json%get(p,'RightManChokeOnProblem',pval) + call json%get(pval,data%Equipments%ChokeManifold%RightManChokeOnProblem) + end subroutine + subroutine ChokeManifoldToJson(parent) type(json_value),pointer :: parent @@ -15,25 +64,26 @@ module CChokeManifold ! 1. create new node call json%create_object(p,'ChokeManifold') - call json%add(p,"ChokeManifoldValve1",data%EquipmentControl%ChokeManifold%ChokeManifoldValve1) - call json%add(p,"ChokeManifoldValve2",data%EquipmentControl%ChokeManifold%ChokeManifoldValve2) - call json%add(p,"LeftManualChoke",data%EquipmentControl%ChokeManifold%LeftManualChoke) - call json%add(p,"ChokeManifoldValve4",data%EquipmentControl%ChokeManifold%ChokeManifoldValve4) - call json%add(p,"ChokeManifoldValve5",data%EquipmentControl%ChokeManifold%ChokeManifoldValve5) - call json%add(p,"RightManualChoke",data%EquipmentControl%ChokeManifold%RightManualChoke) - call json%add(p,"ChokeManifoldValve7",data%EquipmentControl%ChokeManifold%ChokeManifoldValve7) - call json%add(p,"ChokeManifoldValve8",data%EquipmentControl%ChokeManifold%ChokeManifoldValve8) - call json%add(p,"ChokeManifoldValve9",data%EquipmentControl%ChokeManifold%ChokeManifoldValve9) - call json%add(p,"ChokeManifoldValve10",data%EquipmentControl%ChokeManifold%ChokeManifoldValve10) - call json%add(p,"ChokeManifoldValve11",data%EquipmentControl%ChokeManifold%ChokeManifoldValve11) - call json%add(p,"ChokeManifoldValve12",data%EquipmentControl%ChokeManifold%ChokeManifoldValve12) - call json%add(p,"ChokeManifoldValve13",data%EquipmentControl%ChokeManifold%ChokeManifoldValve13) - call json%add(p,"HydraulicChock1",data%EquipmentControl%ChokeManifold%HydraulicChock1) - call json%add(p,"HydraulicChock2",data%EquipmentControl%ChokeManifold%HydraulicChock2) - call json%add(p,"HyChock1OnProblem",data%EquipmentControl%ChokeManifold%HyChock1OnProblem) - call json%add(p,"HyChock2OnProblem",data%EquipmentControl%ChokeManifold%HyChock2OnProblem) - call json%add(p,"LeftManChokeOnProblem",data%EquipmentControl%ChokeManifold%LeftManChokeOnProblem) - call json%add(p,"RightManChokeOnProblem",data%EquipmentControl%ChokeManifold%RightManChokeOnProblem) + ! call json%add(p,"ChokeManifoldValve1",data%Equipments%ChokeManifold%ChokeManifoldValve1) + ! call json%add(p,"ChokeManifoldValve2",data%Equipments%ChokeManifold%ChokeManifoldValve2) + ! call json%add(p,"LeftManualChoke",data%Equipments%ChokeManifold%LeftManualChoke) + ! call json%add(p,"ChokeManifoldValve4",data%Equipments%ChokeManifold%ChokeManifoldValve4) + ! call json%add(p,"ChokeManifoldValve5",data%Equipments%ChokeManifold%ChokeManifoldValve5) + ! call json%add(p,"RightManualChoke",data%Equipments%ChokeManifold%RightManualChoke) + ! call json%add(p,"ChokeManifoldValve7",data%Equipments%ChokeManifold%ChokeManifoldValve7) + ! call json%add(p,"ChokeManifoldValve8",data%Equipments%ChokeManifold%ChokeManifoldValve8) + ! call json%add(p,"ChokeManifoldValve9",data%Equipments%ChokeManifold%ChokeManifoldValve9) + ! call json%add(p,"ChokeManifoldValve10",data%Equipments%ChokeManifold%ChokeManifoldValve10) + ! call json%add(p,"ChokeManifoldValve11",data%Equipments%ChokeManifold%ChokeManifoldValve11) + ! call json%add(p,"ChokeManifoldValve12",data%Equipments%ChokeManifold%ChokeManifoldValve12) + ! call json%add(p,"ChokeManifoldValve13",data%Equipments%ChokeManifold%ChokeManifoldValve13) + call json%add(p,"HydraulicChock1",data%Equipments%ChokeManifold%HydraulicChock1) + call json%add(p,"HydraulicChock2",data%Equipments%ChokeManifold%HydraulicChock2) + + call json%add(p,"HyChock1OnProblem",data%Equipments%ChokeManifold%HyChock1OnProblem) + call json%add(p,"HyChock2OnProblem",data%Equipments%ChokeManifold%HyChock2OnProblem) + call json%add(p,"LeftManChokeOnProblem",data%Equipments%ChokeManifold%LeftManChokeOnProblem) + call json%add(p,"RightManChokeOnProblem",data%Equipments%ChokeManifold%RightManChokeOnProblem) call json%add(parent,p) end subroutine @@ -41,8 +91,8 @@ module CChokeManifold subroutine SetHydraulicChock1(v) implicit none integer, intent(in) :: v - data%EquipmentControl%ChokeManifold%HydraulicChock1 = v - if(data%EquipmentControl%ChokeManifold%HyChock1OnProblem) then + data%Equipments%ChokeManifold%HydraulicChock1 = v + if(data%Equipments%ChokeManifold%HyChock1OnProblem) then call ChangeValve(33, .true.) else if(v == 100) then @@ -57,8 +107,8 @@ end subroutine subroutine SetHydraulicChock2(v) implicit none integer, intent(in) :: v - data%EquipmentControl%ChokeManifold%HydraulicChock2 = v - if(data%EquipmentControl%ChokeManifold%HyChock2OnProblem) then + data%Equipments%ChokeManifold%HydraulicChock2 = v + if(data%Equipments%ChokeManifold%HyChock2OnProblem) then call ChangeValve(34, .true.) else if(v==100) then diff --git a/CSharp/Equipments/ControlPanels/CChokeManifold.i90 b/CSharp/Equipments/ControlPanels/CChokeManifold.i90 new file mode 100644 index 0000000..1d0e9d2 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CChokeManifold.i90 @@ -0,0 +1,124 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CChokeManifold.f90" +module CChokeManifold +! use CChokeManifoldVariables + use SimulationVariables + use CManifolds + use CLog2 + implicit none + public + contains + + subroutine ChokeManifoldFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + +! 1. get related root + call json%get(parent,'ChokeManifold',p) + +! 2. get member of data type from node + call json%get(p,'ChokeManifoldValve1',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve1) + call json%get(p,'ChokeManifoldValve2',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve2) + call json%get(p,'LeftManualChoke',pval) + call json%get(pval,data%Equipments%ChokeManifold%LeftManualChoke) + call json%get(p,'ChokeManifoldValve4',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve4) + call json%get(p,'ChokeManifoldValve5',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve5) + call json%get(p,'RightManualChoke',pval) + call json%get(pval,data%Equipments%ChokeManifold%RightManualChoke) + call json%get(p,'ChokeManifoldValve7',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve7) + call json%get(p,'ChokeManifoldValve8',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve8) + call json%get(p,'ChokeManifoldValve9',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve9) + call json%get(p,'ChokeManifoldValve10',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve10) + call json%get(p,'ChokeManifoldValve11',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve11) + call json%get(p,'ChokeManifoldValve12',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve12) + call json%get(p,'ChokeManifoldValve13',pval) + call json%get(pval,data%Equipments%ChokeManifold%ChokeManifoldValve13) +! call json%get(p,'HydraulicChock1',pval) +! call json%get(pval,data%Equipments%ChokeManifold%HydraulicChock1) +! call json%get(p,'HydraulicChock2',pval) +! call json%get(pval,data%Equipments%ChokeManifold%HydraulicChock2) + call json%get(p,'HyChock1OnProblem',pval) + call json%get(pval,data%Equipments%ChokeManifold%HyChock1OnProblem) + call json%get(p,'HyChock2OnProblem',pval) + call json%get(pval,data%Equipments%ChokeManifold%HyChock2OnProblem) + call json%get(p,'LeftManChokeOnProblem',pval) + call json%get(pval,data%Equipments%ChokeManifold%LeftManChokeOnProblem) + call json%get(p,'RightManChokeOnProblem',pval) + call json%get(pval,data%Equipments%ChokeManifold%RightManChokeOnProblem) + end subroutine + + subroutine ChokeManifoldToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'ChokeManifold') +! call json%add(p,"ChokeManifoldValve1",data%Equipments%ChokeManifold%ChokeManifoldValve1) +! call json%add(p,"ChokeManifoldValve2",data%Equipments%ChokeManifold%ChokeManifoldValve2) +! call json%add(p,"LeftManualChoke",data%Equipments%ChokeManifold%LeftManualChoke) +! call json%add(p,"ChokeManifoldValve4",data%Equipments%ChokeManifold%ChokeManifoldValve4) +! call json%add(p,"ChokeManifoldValve5",data%Equipments%ChokeManifold%ChokeManifoldValve5) +! call json%add(p,"RightManualChoke",data%Equipments%ChokeManifold%RightManualChoke) +! call json%add(p,"ChokeManifoldValve7",data%Equipments%ChokeManifold%ChokeManifoldValve7) +! call json%add(p,"ChokeManifoldValve8",data%Equipments%ChokeManifold%ChokeManifoldValve8) +! call json%add(p,"ChokeManifoldValve9",data%Equipments%ChokeManifold%ChokeManifoldValve9) +! call json%add(p,"ChokeManifoldValve10",data%Equipments%ChokeManifold%ChokeManifoldValve10) +! call json%add(p,"ChokeManifoldValve11",data%Equipments%ChokeManifold%ChokeManifoldValve11) +! call json%add(p,"ChokeManifoldValve12",data%Equipments%ChokeManifold%ChokeManifoldValve12) +! call json%add(p,"ChokeManifoldValve13",data%Equipments%ChokeManifold%ChokeManifoldValve13) + call json%add(p,"HydraulicChock1",data%Equipments%ChokeManifold%HydraulicChock1) + call json%add(p,"HydraulicChock2",data%Equipments%ChokeManifold%HydraulicChock2) + + call json%add(p,"HyChock1OnProblem",data%Equipments%ChokeManifold%HyChock1OnProblem) + call json%add(p,"HyChock2OnProblem",data%Equipments%ChokeManifold%HyChock2OnProblem) + call json%add(p,"LeftManChokeOnProblem",data%Equipments%ChokeManifold%LeftManChokeOnProblem) + call json%add(p,"RightManChokeOnProblem",data%Equipments%ChokeManifold%RightManChokeOnProblem) + + call json%add(parent,p) + end subroutine + + subroutine SetHydraulicChock1(v) + implicit none + integer, intent(in) :: v + data%Equipments%ChokeManifold%HydraulicChock1 = v + if(data%Equipments%ChokeManifold%HyChock1OnProblem) then + call ChangeValve(33, .true.) + else + if(v == 100) then + if(Manifold%Valve(33)%Status) call ChangeValve(33, .false.) + else + if(.not.Manifold%Valve(33)%Status) call ChangeValve(33, .true.) + endif + endif +!WRITE (*,*) ' valve 33 ', Valve(33)%Status, ' arg ', v +end subroutine + +subroutine SetHydraulicChock2(v) + implicit none + integer, intent(in) :: v + data%Equipments%ChokeManifold%HydraulicChock2 = v + if(data%Equipments%ChokeManifold%HyChock2OnProblem) then + call ChangeValve(34, .true.) + else + if(v==100) then + if(Manifold%Valve(34)%Status) call ChangeValve(34, .false.) + else + if(.not.Manifold%Valve(34)%Status) call ChangeValve(34, .true.) + endif + endif +!WRITE (*,*) ' valve 34 ', Valve(34)%Status, ' arg ', v +end subroutine + +end module CChokeManifold diff --git a/CSharp/Equipments/ControlPanels/CChokeManifoldVariables.i90 b/CSharp/Equipments/ControlPanels/CChokeManifoldVariables.i90 new file mode 100644 index 0000000..9dfe622 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CChokeManifoldVariables.i90 @@ -0,0 +1,37 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CChokeManifoldVariables.f90" +module CChokeManifoldVariables + implicit none + public + Type :: ChokeManifoldType +! Input vars + logical :: ChokeManifoldValve1 + logical :: ChokeManifoldValve2 + real(8) :: LeftManualChoke + logical :: ChokeManifoldValve4 + logical :: ChokeManifoldValve5 + real(8) :: RightManualChoke + logical :: ChokeManifoldValve7 + logical :: ChokeManifoldValve8 + logical :: ChokeManifoldValve9 + logical :: ChokeManifoldValve10 + logical :: ChokeManifoldValve11 + logical :: ChokeManifoldValve12 + logical :: ChokeManifoldValve13 + +! Output vars + integer :: HydraulicChock1 + integer :: HydraulicChock2 + +! Control vars + logical :: HyChock1OnProblem = .false. + logical :: HyChock2OnProblem = .false. + logical :: LeftManChokeOnProblem = .false. + logical :: RightManChokeOnProblem = .false. + End Type ChokeManifoldType + + + + contains + + +endmodule CChokeManifoldVariables diff --git a/CSharp/Equipments/ControlPanels/CDataDisplayConsole.f90 b/CSharp/Equipments/ControlPanels/CDataDisplayConsole.f90 index 3dec0af..9839764 100644 --- a/CSharp/Equipments/ControlPanels/CDataDisplayConsole.f90 +++ b/CSharp/Equipments/ControlPanels/CDataDisplayConsole.f90 @@ -5,6 +5,179 @@ module CDataDisplayConsole public contains + subroutine DataDisplayConsoleFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + ! 1. get related root + call json%get(parent,'DataDisplay',p) + + ! 2. get member of data type from node + ! call json%get(p,'TripAlarmLow',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%TripAlarmLow) + ! call json%get(p,'TripAlarmHigh',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%TripAlarmHigh) + ! call json%get(p,'RetFlowAlarmLow',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%RetFlowAlarmLow) + ! call json%get(p,'RetFlowAlarmHigh',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%RetFlowAlarmHigh) + ! call json%get(p,'PitAlarmLow',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%PitAlarmLow) + ! call json%get(p,'PitAlarmHigh',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%PitAlarmHigh) + ! call json%get(p,'PortWeightOnBit',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%PortWeightOnBit) + ! call json%get(p,'PortHookLoad',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%PortHookLoad) + ! call json%get(p,'PortCasingPressure',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%PortCasingPressure) + ! call json%get(p,'PortPumpPressure',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%PortPumpPressure) + call json%get(p,'TripTankSetAlarmLow',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankSetAlarmLow) + call json%get(p,'TripTankSetAlarmHigh',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankSetAlarmHigh) + call json%get(p,'TripTankSetAlarmSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankSetAlarmSwitch) + call json%get(p,'TripTankPowerSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankPowerSwitch) + call json%get(p,'TripTankPumpSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankPumpSwitch) + call json%get(p,'TripTankHornSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankHornSwitch) + call json%get(p,'AcidGasDetectionHornSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%AcidGasDetectionHornSwitch) + call json%get(p,'TotalStrokeCounterResetSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TotalStrokeCounterResetSwitch) + call json%get(p,'DrillingTrippingSelectorSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%DrillingTrippingSelectorSwitch) + call json%get(p,'MVTSetAlarmLowKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTSetAlarmLowKnob) + call json%get(p,'MVTSetAlarmHighKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTSetAlarmHighKnob) + call json%get(p,'MVTSetAlarmSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTSetAlarmSwitch) + call json%get(p,'MudTank1Switch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MudTank1Switch) + call json%get(p,'MudTank2Switch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MudTank2Switch) + call json%get(p,'MudTank3Switch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MudTank3Switch) + call json%get(p,'MudTank4Switch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MudTank4Switch) + call json%get(p,'MVTFineKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTFineKnob) + call json%get(p,'MVTCoarseKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTCoarseKnob) + call json%get(p,'MVTHornSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTHornSwitch) + call json%get(p,'MVTDeviationTripSelectionSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTDeviationTripSelectionSwitch) + call json%get(p,'MVTPowerSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTPowerSwitch) + call json%get(p,'MFFIResetTotalStrokes',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIResetTotalStrokes) + call json%get(p,'MFFIResetFillCounter',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIResetFillCounter) + call json%get(p,'MFFIPumpSelectorSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch) + call json%get(p,'MFFIFillSPMSelectorSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIFillSPMSelectorSwitch) + call json%get(p,'MFFISetAlarmLowKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFISetAlarmLowKnob) + call json%get(p,'MFFISetAlarmHighKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFISetAlarmHighKnob) + call json%get(p,'MFFISetAlarmSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFISetAlarmSwitch) + call json%get(p,'MFFIPowerSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIPowerSwitch) + call json%get(p,'MFFIHornSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIHornSwitch) + call json%get(p,'ResetWob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%ResetWob) + call json%get(p,'Clutch',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%Clutch) + ! call json%get(p,'WOBPointer',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%WOBPointer) + ! call json%get(p,'HookLoadPointer',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%HookLoadPointer) + ! call json%get(p,'TripTankGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%TripTankGauge) + ! call json%get(p,'TripTankAlarmLED',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%TripTankAlarmLED) + ! call json%get(p,'TripTankPumpLED',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%TripTankPumpLED) + ! call json%get(p,'StandPipePressureGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%StandPipePressureGauge) + ! call json%get(p,'CasingPressureGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%CasingPressureGauge) + ! call json%get(p,'MP1SPMGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MP1SPMGauge) + ! call json%get(p,'MP2SPMGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MP2SPMGauge) + ! call json%get(p,'ReturnLineTempGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%ReturnLineTempGauge) + ! call json%get(p,'RotaryTorqueGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%RotaryTorqueGauge) + ! call json%get(p,'RotaryRPMGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%RotaryRPMGauge) + ! call json%get(p,'AcidGasDetectionLED',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%AcidGasDetectionLED) + ! call json%get(p,'TotalStrokeCounter',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%TotalStrokeCounter) + ! call json%get(p,'PitGainLossGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%PitGainLossGauge) + ! call json%get(p,'MudTanksVolumeGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MudTanksVolumeGauge) + ! call json%get(p,'MVTAlarmLED',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MVTAlarmLED) + ! call json%get(p,'ReturnMudFlowGauge',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%ReturnMudFlowGauge) + ! call json%get(p,'FillStrokeCounter',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%FillStrokeCounter) + ! call json%get(p,'MFFITotalStrokeCounter',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter) + ! call json%get(p,'MFFIAlarmLED',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MFFIAlarmLED) + ! call json%get(p,'MFFIPumpLED',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MFFIPumpLED) + ! call json%get(p,'TotalWellDepth',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%TotalWellDepth) + ! call json%get(p,'BitDepth',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%BitDepth) + ! call json%get(p,'HookLoad',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%HookLoad) + ! call json%get(p,'StandPipePressure',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%StandPipePressure) + ! call json%get(p,'CasingPressure',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%CasingPressure) + ! call json%get(p,'MP1SPM',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MP1SPM) + ! call json%get(p,'MP2SPM',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MP2SPM) + ! call json%get(p,'RTTorque',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%RTTorque) + ! call json%get(p,'RTRPM',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%RTRPM) + ! call json%get(p,'WOP',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%WOP) + ! call json%get(p,'ROP',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%ROP) + ! call json%get(p,'MudWeightIn',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MudWeightIn) + ! call json%get(p,'MudWeightOut',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%MudWeightOut) + ! call json%get(p,'Buzzer1',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%Buzzer1) + ! call json%get(p,'Buzzer2',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%Buzzer2) + ! call json%get(p,'Buzzer3',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%Buzzer3) + ! call json%get(p,'Buzzer4',pval) + ! call json%get(pval,data%Equipments%DataDisplayConsole%Buzzer4) + end subroutine + subroutine DataDisplayConsoleToJson(parent) type(json_value),pointer :: parent @@ -13,87 +186,89 @@ module CDataDisplayConsole ! 1. create new node call json%create_object(p,'DataDisplay') - call json%add(p,"TripAlarmLow",data%EquipmentControl%DataDisplayConsole%TripAlarmLow) - call json%add(p,"TripAlarmHigh",data%EquipmentControl%DataDisplayConsole%TripAlarmHigh) - call json%add(p,"RetFlowAlarmLow",data%EquipmentControl%DataDisplayConsole%RetFlowAlarmLow) - call json%add(p,"RetFlowAlarmHigh",data%EquipmentControl%DataDisplayConsole%RetFlowAlarmHigh) - call json%add(p,"PitAlarmLow",data%EquipmentControl%DataDisplayConsole%PitAlarmLow) - call json%add(p,"PitAlarmHigh",data%EquipmentControl%DataDisplayConsole%PitAlarmHigh) - call json%add(p,"PortWeightOnBit",data%EquipmentControl%DataDisplayConsole%PortWeightOnBit) - call json%add(p,"PortHookLoad",data%EquipmentControl%DataDisplayConsole%PortHookLoad) - call json%add(p,"PortCasingPressure",data%EquipmentControl%DataDisplayConsole%PortCasingPressure) - call json%add(p,"PortPumpPressure",data%EquipmentControl%DataDisplayConsole%PortPumpPressure) - call json%add(p,"TripTankSetAlarmLow",data%EquipmentControl%DataDisplayConsole%TripTankSetAlarmLow) - call json%add(p,"TripTankSetAlarmHigh",data%EquipmentControl%DataDisplayConsole%TripTankSetAlarmHigh) - call json%add(p,"TripTankSetAlarmSwitch",data%EquipmentControl%DataDisplayConsole%TripTankSetAlarmSwitch) - call json%add(p,"TripTankPowerSwitch",data%EquipmentControl%DataDisplayConsole%TripTankPowerSwitch) - call json%add(p,"TripTankPumpSwitch",data%EquipmentControl%DataDisplayConsole%TripTankPumpSwitch) - call json%add(p,"TripTankHornSwitch",data%EquipmentControl%DataDisplayConsole%TripTankHornSwitch) - call json%add(p,"AcidGasDetectionHornSwitch",data%EquipmentControl%DataDisplayConsole%AcidGasDetectionHornSwitch) - call json%add(p,"TotalStrokeCounterResetSwitch",data%EquipmentControl%DataDisplayConsole%TotalStrokeCounterResetSwitch) - call json%add(p,"DrillingTrippingSelectorSwitch",data%EquipmentControl%DataDisplayConsole%DrillingTrippingSelectorSwitch) - call json%add(p,"MVTSetAlarmLowKnob",data%EquipmentControl%DataDisplayConsole%MVTSetAlarmLowKnob) - call json%add(p,"MVTSetAlarmHighKnob",data%EquipmentControl%DataDisplayConsole%MVTSetAlarmHighKnob) - call json%add(p,"MVTSetAlarmSwitch",data%EquipmentControl%DataDisplayConsole%MVTSetAlarmSwitch) - call json%add(p,"MudTank1Switch",data%EquipmentControl%DataDisplayConsole%MudTank1Switch) - call json%add(p,"MudTank2Switch",data%EquipmentControl%DataDisplayConsole%MudTank2Switch) - call json%add(p,"MudTank3Switch",data%EquipmentControl%DataDisplayConsole%MudTank3Switch) - call json%add(p,"MudTank4Switch",data%EquipmentControl%DataDisplayConsole%MudTank4Switch) - call json%add(p,"MVTFineKnob",data%EquipmentControl%DataDisplayConsole%MVTFineKnob) - call json%add(p,"MVTCoarseKnob",data%EquipmentControl%DataDisplayConsole%MVTCoarseKnob) - call json%add(p,"MVTHornSwitch",data%EquipmentControl%DataDisplayConsole%MVTHornSwitch) - call json%add(p,"MVTDeviationTripSelectionSwitch",data%EquipmentControl%DataDisplayConsole%MVTDeviationTripSelectionSwitch) - call json%add(p,"MVTPowerSwitch",data%EquipmentControl%DataDisplayConsole%MVTPowerSwitch) - call json%add(p,"MFFIResetTotalStrokes",data%EquipmentControl%DataDisplayConsole%MFFIResetTotalStrokes) - call json%add(p,"MFFIResetFillCounter",data%EquipmentControl%DataDisplayConsole%MFFIResetFillCounter) - call json%add(p,"MFFIPumpSelectorSwitch",data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch) - call json%add(p,"MFFIFillSPMSelectorSwitch",data%EquipmentControl%DataDisplayConsole%MFFIFillSPMSelectorSwitch) - call json%add(p,"MFFISetAlarmLowKnob",data%EquipmentControl%DataDisplayConsole%MFFISetAlarmLowKnob) - call json%add(p,"MFFISetAlarmHighKnob",data%EquipmentControl%DataDisplayConsole%MFFISetAlarmHighKnob) - call json%add(p,"MFFISetAlarmSwitch",data%EquipmentControl%DataDisplayConsole%MFFISetAlarmSwitch) - call json%add(p,"MFFIPowerSwitch",data%EquipmentControl%DataDisplayConsole%MFFIPowerSwitch) - call json%add(p,"MFFIHornSwitch",data%EquipmentControl%DataDisplayConsole%MFFIHornSwitch) - call json%add(p,"ResetWob",data%EquipmentControl%DataDisplayConsole%ResetWob) - call json%add(p,"Clutch",data%EquipmentControl%DataDisplayConsole%Clutch) - call json%add(p,"WOBPointer",data%EquipmentControl%DataDisplayConsole%WOBPointer) - call json%add(p,"HookLoadPointer",data%EquipmentControl%DataDisplayConsole%HookLoadPointer) - call json%add(p,"TripTankGauge",data%EquipmentControl%DataDisplayConsole%TripTankGauge) - call json%add(p,"TripTankAlarmLED",data%EquipmentControl%DataDisplayConsole%TripTankAlarmLED) - call json%add(p,"TripTankPumpLED",data%EquipmentControl%DataDisplayConsole%TripTankPumpLED) - call json%add(p,"StandPipePressureGauge",data%EquipmentControl%DataDisplayConsole%StandPipePressureGauge) - call json%add(p,"CasingPressureGauge",data%EquipmentControl%DataDisplayConsole%CasingPressureGauge) - call json%add(p,"MP1SPMGauge",data%EquipmentControl%DataDisplayConsole%MP1SPMGauge) - call json%add(p,"MP2SPMGauge",data%EquipmentControl%DataDisplayConsole%MP2SPMGauge) - call json%add(p,"ReturnLineTempGauge",data%EquipmentControl%DataDisplayConsole%ReturnLineTempGauge) - call json%add(p,"RotaryTorqueGauge",data%EquipmentControl%DataDisplayConsole%RotaryTorqueGauge) - call json%add(p,"RotaryRPMGauge",data%EquipmentControl%DataDisplayConsole%RotaryRPMGauge) - call json%add(p,"AcidGasDetectionLED",data%EquipmentControl%DataDisplayConsole%AcidGasDetectionLED) - call json%add(p,"TotalStrokeCounter",data%EquipmentControl%DataDisplayConsole%TotalStrokeCounter) - call json%add(p,"PitGainLossGauge",data%EquipmentControl%DataDisplayConsole%PitGainLossGauge) - call json%add(p,"MudTanksVolumeGauge",data%EquipmentControl%DataDisplayConsole%MudTanksVolumeGauge) - call json%add(p,"MVTAlarmLED",data%EquipmentControl%DataDisplayConsole%MVTAlarmLED) - call json%add(p,"ReturnMudFlowGauge",data%EquipmentControl%DataDisplayConsole%ReturnMudFlowGauge) - call json%add(p,"FillStrokeCounter",data%EquipmentControl%DataDisplayConsole%FillStrokeCounter) - call json%add(p,"MFFITotalStrokeCounter",data%EquipmentControl%DataDisplayConsole%MFFITotalStrokeCounter) - call json%add(p,"MFFIAlarmLED",data%EquipmentControl%DataDisplayConsole%MFFIAlarmLED) - call json%add(p,"MFFIPumpLED",data%EquipmentControl%DataDisplayConsole%MFFIPumpLED) - call json%add(p,"TotalWellDepth",data%EquipmentControl%DataDisplayConsole%TotalWellDepth) - call json%add(p,"BitDepth",data%EquipmentControl%DataDisplayConsole%BitDepth) - call json%add(p,"HookLoad",data%EquipmentControl%DataDisplayConsole%HookLoad) - call json%add(p,"StandPipePressure",data%EquipmentControl%DataDisplayConsole%StandPipePressure) - call json%add(p,"CasingPressure",data%EquipmentControl%DataDisplayConsole%CasingPressure) - call json%add(p,"MP1SPM",data%EquipmentControl%DataDisplayConsole%MP1SPM) - call json%add(p,"MP2SPM",data%EquipmentControl%DataDisplayConsole%MP2SPM) - call json%add(p,"RTTorque",data%EquipmentControl%DataDisplayConsole%RTTorque) - call json%add(p,"RTRPM",data%EquipmentControl%DataDisplayConsole%RTRPM) - call json%add(p,"WOP",data%EquipmentControl%DataDisplayConsole%WOP) - call json%add(p,"ROP",data%EquipmentControl%DataDisplayConsole%ROP) - call json%add(p,"MudWeightIn",data%EquipmentControl%DataDisplayConsole%MudWeightIn) - call json%add(p,"MudWeightOut",data%EquipmentControl%DataDisplayConsole%MudWeightOut) - call json%add(p,"Buzzer1",data%EquipmentControl%DataDisplayConsole%Buzzer1) - call json%add(p,"Buzzer2",data%EquipmentControl%DataDisplayConsole%Buzzer2) - call json%add(p,"Buzzer3",data%EquipmentControl%DataDisplayConsole%Buzzer3) - call json%add(p,"Buzzer4",data%EquipmentControl%DataDisplayConsole%Buzzer4) + ! call json%add(p,"TripAlarmLow",data%Equipments%DataDisplayConsole%TripAlarmLow) + ! call json%add(p,"TripAlarmHigh",data%Equipments%DataDisplayConsole%TripAlarmHigh) + ! call json%add(p,"RetFlowAlarmLow",data%Equipments%DataDisplayConsole%RetFlowAlarmLow) + ! call json%add(p,"RetFlowAlarmHigh",data%Equipments%DataDisplayConsole%RetFlowAlarmHigh) + ! call json%add(p,"PitAlarmLow",data%Equipments%DataDisplayConsole%PitAlarmLow) + ! call json%add(p,"PitAlarmHigh",data%Equipments%DataDisplayConsole%PitAlarmHigh) + ! call json%add(p,"PortWeightOnBit",data%Equipments%DataDisplayConsole%PortWeightOnBit) + ! call json%add(p,"PortHookLoad",data%Equipments%DataDisplayConsole%PortHookLoad) + ! call json%add(p,"PortCasingPressure",data%Equipments%DataDisplayConsole%PortCasingPressure) + ! call json%add(p,"PortPumpPressure",data%Equipments%DataDisplayConsole%PortPumpPressure) + + ! call json%add(p,"TripTankSetAlarmLow",data%Equipments%DataDisplayConsole%TripTankSetAlarmLow) + ! call json%add(p,"TripTankSetAlarmHigh",data%Equipments%DataDisplayConsole%TripTankSetAlarmHigh) + ! call json%add(p,"TripTankSetAlarmSwitch",data%Equipments%DataDisplayConsole%TripTankSetAlarmSwitch) + ! call json%add(p,"TripTankPowerSwitch",data%Equipments%DataDisplayConsole%TripTankPowerSwitch) + ! call json%add(p,"TripTankPumpSwitch",data%Equipments%DataDisplayConsole%TripTankPumpSwitch) + ! call json%add(p,"TripTankHornSwitch",data%Equipments%DataDisplayConsole%TripTankHornSwitch) + ! call json%add(p,"AcidGasDetectionHornSwitch",data%Equipments%DataDisplayConsole%AcidGasDetectionHornSwitch) + ! call json%add(p,"TotalStrokeCounterResetSwitch",data%Equipments%DataDisplayConsole%TotalStrokeCounterResetSwitch) + ! call json%add(p,"DrillingTrippingSelectorSwitch",data%Equipments%DataDisplayConsole%DrillingTrippingSelectorSwitch) + ! call json%add(p,"MVTSetAlarmLowKnob",data%Equipments%DataDisplayConsole%MVTSetAlarmLowKnob) + ! call json%add(p,"MVTSetAlarmHighKnob",data%Equipments%DataDisplayConsole%MVTSetAlarmHighKnob) + ! call json%add(p,"MVTSetAlarmSwitch",data%Equipments%DataDisplayConsole%MVTSetAlarmSwitch) + ! call json%add(p,"MudTank1Switch",data%Equipments%DataDisplayConsole%MudTank1Switch) + ! call json%add(p,"MudTank2Switch",data%Equipments%DataDisplayConsole%MudTank2Switch) + ! call json%add(p,"MudTank3Switch",data%Equipments%DataDisplayConsole%MudTank3Switch) + ! call json%add(p,"MudTank4Switch",data%Equipments%DataDisplayConsole%MudTank4Switch) + ! call json%add(p,"MVTFineKnob",data%Equipments%DataDisplayConsole%MVTFineKnob) + ! call json%add(p,"MVTCoarseKnob",data%Equipments%DataDisplayConsole%MVTCoarseKnob) + ! call json%add(p,"MVTHornSwitch",data%Equipments%DataDisplayConsole%MVTHornSwitch) + ! call json%add(p,"MVTDeviationTripSelectionSwitch",data%Equipments%DataDisplayConsole%MVTDeviationTripSelectionSwitch) + ! call json%add(p,"MVTPowerSwitch",data%Equipments%DataDisplayConsole%MVTPowerSwitch) + ! call json%add(p,"MFFIResetTotalStrokes",data%Equipments%DataDisplayConsole%MFFIResetTotalStrokes) + ! call json%add(p,"MFFIResetFillCounter",data%Equipments%DataDisplayConsole%MFFIResetFillCounter) + ! call json%add(p,"MFFIPumpSelectorSwitch",data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch) + ! call json%add(p,"MFFIFillSPMSelectorSwitch",data%Equipments%DataDisplayConsole%MFFIFillSPMSelectorSwitch) + ! call json%add(p,"MFFISetAlarmLowKnob",data%Equipments%DataDisplayConsole%MFFISetAlarmLowKnob) + ! call json%add(p,"MFFISetAlarmHighKnob",data%Equipments%DataDisplayConsole%MFFISetAlarmHighKnob) + ! call json%add(p,"MFFISetAlarmSwitch",data%Equipments%DataDisplayConsole%MFFISetAlarmSwitch) + ! call json%add(p,"MFFIPowerSwitch",data%Equipments%DataDisplayConsole%MFFIPowerSwitch) + ! call json%add(p,"MFFIHornSwitch",data%Equipments%DataDisplayConsole%MFFIHornSwitch) + ! call json%add(p,"ResetWob",data%Equipments%DataDisplayConsole%ResetWob) + ! call json%add(p,"Clutch",data%Equipments%DataDisplayConsole%Clutch) + + call json%add(p,"WOBPointer",data%Equipments%DataDisplayConsole%WOBPointer) + call json%add(p,"HookLoadPointer",data%Equipments%DataDisplayConsole%HookLoadPointer) + call json%add(p,"TripTankGauge",data%Equipments%DataDisplayConsole%TripTankGauge) + call json%add(p,"TripTankAlarmLED",data%Equipments%DataDisplayConsole%TripTankAlarmLED) + call json%add(p,"TripTankPumpLED",data%Equipments%DataDisplayConsole%TripTankPumpLED) + call json%add(p,"StandPipePressureGauge",data%Equipments%DataDisplayConsole%StandPipePressureGauge) + call json%add(p,"CasingPressureGauge",data%Equipments%DataDisplayConsole%CasingPressureGauge) + call json%add(p,"MP1SPMGauge",data%Equipments%DataDisplayConsole%MP1SPMGauge) + call json%add(p,"MP2SPMGauge",data%Equipments%DataDisplayConsole%MP2SPMGauge) + call json%add(p,"ReturnLineTempGauge",data%Equipments%DataDisplayConsole%ReturnLineTempGauge) + call json%add(p,"RotaryTorqueGauge",data%Equipments%DataDisplayConsole%RotaryTorqueGauge) + call json%add(p,"RotaryRPMGauge",data%Equipments%DataDisplayConsole%RotaryRPMGauge) + call json%add(p,"AcidGasDetectionLED",data%Equipments%DataDisplayConsole%AcidGasDetectionLED) + call json%add(p,"TotalStrokeCounter",data%Equipments%DataDisplayConsole%TotalStrokeCounter) + call json%add(p,"PitGainLossGauge",data%Equipments%DataDisplayConsole%PitGainLossGauge) + call json%add(p,"MudTanksVolumeGauge",data%Equipments%DataDisplayConsole%MudTanksVolumeGauge) + call json%add(p,"MVTAlarmLED",data%Equipments%DataDisplayConsole%MVTAlarmLED) + call json%add(p,"ReturnMudFlowGauge",data%Equipments%DataDisplayConsole%ReturnMudFlowGauge) + call json%add(p,"FillStrokeCounter",data%Equipments%DataDisplayConsole%FillStrokeCounter) + call json%add(p,"MFFITotalStrokeCounter",data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter) + call json%add(p,"MFFIAlarmLED",data%Equipments%DataDisplayConsole%MFFIAlarmLED) + call json%add(p,"MFFIPumpLED",data%Equipments%DataDisplayConsole%MFFIPumpLED) + call json%add(p,"TotalWellDepth",data%Equipments%DataDisplayConsole%TotalWellDepth) + call json%add(p,"BitDepth",data%Equipments%DataDisplayConsole%BitDepth) + call json%add(p,"HookLoad",data%Equipments%DataDisplayConsole%HookLoad) + call json%add(p,"StandPipePressure",data%Equipments%DataDisplayConsole%StandPipePressure) + call json%add(p,"CasingPressure",data%Equipments%DataDisplayConsole%CasingPressure) + call json%add(p,"MP1SPM",data%Equipments%DataDisplayConsole%MP1SPM) + call json%add(p,"MP2SPM",data%Equipments%DataDisplayConsole%MP2SPM) + call json%add(p,"RTTorque",data%Equipments%DataDisplayConsole%RTTorque) + call json%add(p,"RTRPM",data%Equipments%DataDisplayConsole%RTRPM) + call json%add(p,"WOP",data%Equipments%DataDisplayConsole%WOP) + call json%add(p,"ROP",data%Equipments%DataDisplayConsole%ROP) + call json%add(p,"MudWeightIn",data%Equipments%DataDisplayConsole%MudWeightIn) + call json%add(p,"MudWeightOut",data%Equipments%DataDisplayConsole%MudWeightOut) + call json%add(p,"Buzzer1",data%Equipments%DataDisplayConsole%Buzzer1) + call json%add(p,"Buzzer2",data%Equipments%DataDisplayConsole%Buzzer2) + call json%add(p,"Buzzer3",data%Equipments%DataDisplayConsole%Buzzer3) + call json%add(p,"Buzzer4",data%Equipments%DataDisplayConsole%Buzzer4) call json%add(parent,p) @@ -101,87 +276,87 @@ module CDataDisplayConsole subroutine Set_TotalDepth(v) - use SimulationVariables !@!!, only: data%EquipmentControl%DrillingWatch%Depth + use SimulationVariables !@!!, only: data%Equipments%DrillingWatch%Depth ! use CSimulationVariables, only: SetDistanceDrilled implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%TotalWellDepth = v - data%EquipmentControl%DrillingWatch%Depth = v + data%Equipments%DataDisplayConsole%TotalWellDepth = v + data%Equipments%DrillingWatch%Depth = v ! call SetDistanceDrilled(v) end subroutine subroutine Set_BitPosition(v) - use SimulationVariables !@!!, only: data%EquipmentControl%DrillingWatch%BitPosition + use SimulationVariables !@!!, only: data%Equipments%DrillingWatch%BitPosition implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%BitDepth = v - data%EquipmentControl%DrillingWatch%BitPosition = v + data%Equipments%DataDisplayConsole%BitDepth = v + data%Equipments%DrillingWatch%BitPosition = v end subroutine subroutine Set_RotaryTorque(v) - use SimulationVariables !@!!, only: data%EquipmentControl%DrillingWatch%Torque + use SimulationVariables !@!!, only: data%Equipments%DrillingWatch%Torque implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%RotaryTorqueGauge = v - data%EquipmentControl%DrillingWatch%Torque = v - data%EquipmentControl%DataDisplayConsole%RTTorque = v + data%Equipments%DataDisplayConsole%RotaryTorqueGauge = v + data%Equipments%DrillingWatch%Torque = v + data%Equipments%DataDisplayConsole%RTTorque = v end subroutine subroutine Set_MudWeightIn(v) - use SimulationVariables !@!, only: MudWeightInDw => data%EquipmentControl%DataDisplayConsole%MudWeightIn + use SimulationVariables !@!, only: MudWeightInDw => data%Equipments%DataDisplayConsole%MudWeightIn implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%MudWeightIn = v - data%EquipmentControl%DrillingWatch%MudWeightIn = v + data%Equipments%DataDisplayConsole%MudWeightIn = v + data%Equipments%DrillingWatch%MudWeightIn = v end subroutine subroutine Set_MudWeightOut(v) - use SimulationVariables !@!, only: MudWeightOutDw => data%EquipmentControl%DataDisplayConsole%MudWeightOut + use SimulationVariables !@!, only: MudWeightOutDw => data%Equipments%DataDisplayConsole%MudWeightOut implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%MudWeightOut = v - data%EquipmentControl%DrillingWatch%MudWeightOut = v + data%Equipments%DataDisplayConsole%MudWeightOut = v + data%Equipments%DrillingWatch%MudWeightOut = v end subroutine subroutine Set_TripTankVolume(v) - use SimulationVariables !@!, only: data%EquipmentControl%DrillingWatch%TripTankVolume + use SimulationVariables !@!, only: data%Equipments%DrillingWatch%TripTankVolume implicit none real(8), intent(in) :: v - data%EquipmentControl%DrillingWatch%TripTankVolume = v + data%Equipments%DrillingWatch%TripTankVolume = v end subroutine subroutine Set_FillVolume(v) - use SimulationVariables !@!, only: data%EquipmentControl%DrillingWatch%FillVolume + use SimulationVariables !@!, only: data%Equipments%DrillingWatch%FillVolume implicit none real(8), intent(in) :: v - data%EquipmentControl%DrillingWatch%FillVolume = v + data%Equipments%DrillingWatch%FillVolume = v end subroutine subroutine Set_HookLoad(v) - use SimulationVariables !@!, only: HookLoadDw => data%EquipmentControl%DataDisplayConsole%HookLoad + use SimulationVariables !@!, only: HookLoadDw => data%Equipments%DataDisplayConsole%HookLoad implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%HookLoadPointer = v - data%EquipmentControl%DrillingWatch%HookLoad = v * 1000 - data%EquipmentControl%DataDisplayConsole%HookLoad = v + data%Equipments%DataDisplayConsole%HookLoadPointer = v + data%Equipments%DrillingWatch%HookLoad = v * 1000 + data%Equipments%DataDisplayConsole%HookLoad = v end subroutine subroutine Set_WeightOnBit(v) - use SimulationVariables !@!, only: data%EquipmentControl%DrillingWatch%WeightOnBit + use SimulationVariables !@!, only: data%Equipments%DrillingWatch%WeightOnBit implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%WOBPointer = v - data%EquipmentControl%DrillingWatch%WeightOnBit = v - data%EquipmentControl%DataDisplayConsole%WOP = v + data%Equipments%DataDisplayConsole%WOBPointer = v + data%Equipments%DrillingWatch%WeightOnBit = v + data%Equipments%DataDisplayConsole%WOP = v end subroutine subroutine Set_ROP(v) - use SimulationVariables !@!, only: ROPDw => data%EquipmentControl%DataDisplayConsole%ROP + use SimulationVariables !@!, only: ROPDw => data%Equipments%DataDisplayConsole%ROP implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%ROP = v - data%EquipmentControl%DrillingWatch%ROP = v + data%Equipments%DataDisplayConsole%ROP = v + data%Equipments%DrillingWatch%ROP = v end subroutine subroutine Set_CasingPressure(v) @@ -190,22 +365,22 @@ module CDataDisplayConsole use SimulationVariables!, only: CasingPressureChoke => CasingPressure implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%CasingPressureGauge = v - data%EquipmentControl%DrillingWatch%CasingPressure = v - data%EquipmentControl%ChokeControlPanel%CasingPressure = v - data%EquipmentControl%DataDisplayConsole%CasingPressure = v + data%Equipments%DataDisplayConsole%CasingPressureGauge = v + data%Equipments%DrillingWatch%CasingPressure = v + data%Equipments%ChokeControlPanel%CasingPressure = v + data%Equipments%DataDisplayConsole%CasingPressure = v end subroutine subroutine Set_StandPipePressure(v) - use SimulationVariables !@!, only: data%EquipmentControl%DrillingWatch%PumpPressure + use SimulationVariables !@!, only: data%Equipments%DrillingWatch%PumpPressure use CChokeControlPanelVariables - use SimulationVariables!, only: StandPipePressureChoke => data%EquipmentControl%DataDisplayConsole%StandPipePressure + use SimulationVariables!, only: StandPipePressureChoke => data%Equipments%DataDisplayConsole%StandPipePressure implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%StandPipePressureGauge = v - data%EquipmentControl%DrillingWatch%PumpPressure = v - data%EquipmentControl%ChokeControlPanel%StandPipePressure = v - data%EquipmentControl%DataDisplayConsole%StandPipePressure = v + data%Equipments%DataDisplayConsole%StandPipePressureGauge = v + data%Equipments%DrillingWatch%PumpPressure = v + data%Equipments%ChokeControlPanel%StandPipePressure = v + data%Equipments%DataDisplayConsole%StandPipePressure = v @@ -213,13 +388,13 @@ module CDataDisplayConsole subroutine Set_RotaryRPMGauge(v) - use SimulationVariables !@!, only: data%EquipmentControl%DrillingWatch%RPM + use SimulationVariables !@!, only: data%Equipments%DrillingWatch%RPM implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%RotaryRPMGauge = v - data%EquipmentControl%DrillingWatch%RPM = v - data%EquipmentControl%DataDisplayConsole%RTRPM = v - ! call data%EquipmentControl%DataDisplayConsole%OnRotaryRpmChange%RunAll(v) + data%Equipments%DataDisplayConsole%RotaryRPMGauge = v + data%Equipments%DrillingWatch%RPM = v + data%Equipments%DataDisplayConsole%RTRPM = v + ! call data%Equipments%DataDisplayConsole%OnRotaryRpmChange%RunAll(v) end subroutine @@ -228,22 +403,22 @@ module CDataDisplayConsole subroutine Set_MP1SPMGauge(v) implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%MP1SPMGauge = v - data%EquipmentControl%DataDisplayConsole%MP1SPM = v - !@data%State%unitySignals%(PumpsSpmChanges)) call PumpsSpmChanges(data%EquipmentControl%DataDisplayConsole%MP1SPMGauge, data%EquipmentControl%DataDisplayConsole%MP2SPMGauge) + data%Equipments%DataDisplayConsole%MP1SPMGauge = v + data%Equipments%DataDisplayConsole%MP1SPM = v + !@data%State%unitySignals%(PumpsSpmChanges)) call PumpsSpmChanges(data%Equipments%DataDisplayConsole%MP1SPMGauge, data%Equipments%DataDisplayConsole%MP2SPMGauge) #ifdef deb - print*, 'MP1SPMGauge=', data%EquipmentControl%DataDisplayConsole%MP1SPMGauge + print*, 'MP1SPMGauge=', data%Equipments%DataDisplayConsole%MP1SPMGauge #endif end subroutine subroutine Set_MP2SPMGauge(v) implicit none real(8), intent(in) :: v - data%EquipmentControl%DataDisplayConsole%MP2SPMGauge = v - data%EquipmentControl%DataDisplayConsole%MP2SPM = v - !@data%State%unitySignals%(PumpsSpmChanges)) call PumpsSpmChanges(data%EquipmentControl%DataDisplayConsole%MP1SPMGauge, data%EquipmentControl%DataDisplayConsole%MP2SPMGauge) + data%Equipments%DataDisplayConsole%MP2SPMGauge = v + data%Equipments%DataDisplayConsole%MP2SPM = v + !@data%State%unitySignals%(PumpsSpmChanges)) call PumpsSpmChanges(data%Equipments%DataDisplayConsole%MP1SPMGauge, data%Equipments%DataDisplayConsole%MP2SPMGauge) #ifdef deb - print*, 'MP2SPMGauge=', data%EquipmentControl%DataDisplayConsole%MP2SPMGauge + print*, 'MP2SPMGauge=', data%Equipments%DataDisplayConsole%MP2SPMGauge #endif end subroutine end module CDataDisplayConsole \ No newline at end of file diff --git a/CSharp/Equipments/ControlPanels/CDataDisplayConsole.i90 b/CSharp/Equipments/ControlPanels/CDataDisplayConsole.i90 new file mode 100644 index 0000000..f3e4959 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CDataDisplayConsole.i90 @@ -0,0 +1,423 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CDataDisplayConsole.f90" +module CDataDisplayConsole +! use CDataDisplayConsole + use SimulationVariables + implicit none + public + contains + + subroutine DataDisplayConsoleFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + +! 1. get related root + call json%get(parent,'DataDisplay',p) + +! 2. get member of data type from node +! call json%get(p,'TripAlarmLow',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%TripAlarmLow) +! call json%get(p,'TripAlarmHigh',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%TripAlarmHigh) +! call json%get(p,'RetFlowAlarmLow',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%RetFlowAlarmLow) +! call json%get(p,'RetFlowAlarmHigh',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%RetFlowAlarmHigh) +! call json%get(p,'PitAlarmLow',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%PitAlarmLow) +! call json%get(p,'PitAlarmHigh',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%PitAlarmHigh) +! call json%get(p,'PortWeightOnBit',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%PortWeightOnBit) +! call json%get(p,'PortHookLoad',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%PortHookLoad) +! call json%get(p,'PortCasingPressure',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%PortCasingPressure) +! call json%get(p,'PortPumpPressure',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%PortPumpPressure) + call json%get(p,'TripTankSetAlarmLow',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankSetAlarmLow) + call json%get(p,'TripTankSetAlarmHigh',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankSetAlarmHigh) + call json%get(p,'TripTankSetAlarmSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankSetAlarmSwitch) + call json%get(p,'TripTankPowerSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankPowerSwitch) + call json%get(p,'TripTankPumpSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankPumpSwitch) + call json%get(p,'TripTankHornSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TripTankHornSwitch) + call json%get(p,'AcidGasDetectionHornSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%AcidGasDetectionHornSwitch) + call json%get(p,'TotalStrokeCounterResetSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%TotalStrokeCounterResetSwitch) + call json%get(p,'DrillingTrippingSelectorSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%DrillingTrippingSelectorSwitch) + call json%get(p,'MVTSetAlarmLowKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTSetAlarmLowKnob) + call json%get(p,'MVTSetAlarmHighKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTSetAlarmHighKnob) + call json%get(p,'MVTSetAlarmSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTSetAlarmSwitch) + call json%get(p,'MudTank1Switch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MudTank1Switch) + call json%get(p,'MudTank2Switch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MudTank2Switch) + call json%get(p,'MudTank3Switch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MudTank3Switch) + call json%get(p,'MudTank4Switch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MudTank4Switch) + call json%get(p,'MVTFineKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTFineKnob) + call json%get(p,'MVTCoarseKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTCoarseKnob) + call json%get(p,'MVTHornSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTHornSwitch) + call json%get(p,'MVTDeviationTripSelectionSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTDeviationTripSelectionSwitch) + call json%get(p,'MVTPowerSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MVTPowerSwitch) + call json%get(p,'MFFIResetTotalStrokes',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIResetTotalStrokes) + call json%get(p,'MFFIResetFillCounter',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIResetFillCounter) + call json%get(p,'MFFIPumpSelectorSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch) + call json%get(p,'MFFIFillSPMSelectorSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIFillSPMSelectorSwitch) + call json%get(p,'MFFISetAlarmLowKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFISetAlarmLowKnob) + call json%get(p,'MFFISetAlarmHighKnob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFISetAlarmHighKnob) + call json%get(p,'MFFISetAlarmSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFISetAlarmSwitch) + call json%get(p,'MFFIPowerSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIPowerSwitch) + call json%get(p,'MFFIHornSwitch',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%MFFIHornSwitch) + call json%get(p,'ResetWob',pval) + call json%get(pval,data%Equipments%DataDisplayConsole%ResetWob) + call json%get(p,'Clutch',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%Clutch) +! call json%get(p,'WOBPointer',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%WOBPointer) +! call json%get(p,'HookLoadPointer',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%HookLoadPointer) +! call json%get(p,'TripTankGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%TripTankGauge) +! call json%get(p,'TripTankAlarmLED',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%TripTankAlarmLED) +! call json%get(p,'TripTankPumpLED',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%TripTankPumpLED) +! call json%get(p,'StandPipePressureGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%StandPipePressureGauge) +! call json%get(p,'CasingPressureGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%CasingPressureGauge) +! call json%get(p,'MP1SPMGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MP1SPMGauge) +! call json%get(p,'MP2SPMGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MP2SPMGauge) +! call json%get(p,'ReturnLineTempGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%ReturnLineTempGauge) +! call json%get(p,'RotaryTorqueGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%RotaryTorqueGauge) +! call json%get(p,'RotaryRPMGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%RotaryRPMGauge) +! call json%get(p,'AcidGasDetectionLED',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%AcidGasDetectionLED) +! call json%get(p,'TotalStrokeCounter',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%TotalStrokeCounter) +! call json%get(p,'PitGainLossGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%PitGainLossGauge) +! call json%get(p,'MudTanksVolumeGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MudTanksVolumeGauge) +! call json%get(p,'MVTAlarmLED',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MVTAlarmLED) +! call json%get(p,'ReturnMudFlowGauge',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%ReturnMudFlowGauge) +! call json%get(p,'FillStrokeCounter',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%FillStrokeCounter) +! call json%get(p,'MFFITotalStrokeCounter',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter) +! call json%get(p,'MFFIAlarmLED',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MFFIAlarmLED) +! call json%get(p,'MFFIPumpLED',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MFFIPumpLED) +! call json%get(p,'TotalWellDepth',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%TotalWellDepth) +! call json%get(p,'BitDepth',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%BitDepth) +! call json%get(p,'HookLoad',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%HookLoad) +! call json%get(p,'StandPipePressure',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%StandPipePressure) +! call json%get(p,'CasingPressure',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%CasingPressure) +! call json%get(p,'MP1SPM',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MP1SPM) +! call json%get(p,'MP2SPM',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MP2SPM) +! call json%get(p,'RTTorque',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%RTTorque) +! call json%get(p,'RTRPM',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%RTRPM) +! call json%get(p,'WOP',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%WOP) +! call json%get(p,'ROP',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%ROP) +! call json%get(p,'MudWeightIn',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MudWeightIn) +! call json%get(p,'MudWeightOut',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%MudWeightOut) +! call json%get(p,'Buzzer1',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%Buzzer1) +! call json%get(p,'Buzzer2',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%Buzzer2) +! call json%get(p,'Buzzer3',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%Buzzer3) +! call json%get(p,'Buzzer4',pval) +! call json%get(pval,data%Equipments%DataDisplayConsole%Buzzer4) + end subroutine + + subroutine DataDisplayConsoleToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'DataDisplay') +! call json%add(p,"TripAlarmLow",data%Equipments%DataDisplayConsole%TripAlarmLow) +! call json%add(p,"TripAlarmHigh",data%Equipments%DataDisplayConsole%TripAlarmHigh) +! call json%add(p,"RetFlowAlarmLow",data%Equipments%DataDisplayConsole%RetFlowAlarmLow) +! call json%add(p,"RetFlowAlarmHigh",data%Equipments%DataDisplayConsole%RetFlowAlarmHigh) +! call json%add(p,"PitAlarmLow",data%Equipments%DataDisplayConsole%PitAlarmLow) +! call json%add(p,"PitAlarmHigh",data%Equipments%DataDisplayConsole%PitAlarmHigh) +! call json%add(p,"PortWeightOnBit",data%Equipments%DataDisplayConsole%PortWeightOnBit) +! call json%add(p,"PortHookLoad",data%Equipments%DataDisplayConsole%PortHookLoad) +! call json%add(p,"PortCasingPressure",data%Equipments%DataDisplayConsole%PortCasingPressure) +! call json%add(p,"PortPumpPressure",data%Equipments%DataDisplayConsole%PortPumpPressure) + +! call json%add(p,"TripTankSetAlarmLow",data%Equipments%DataDisplayConsole%TripTankSetAlarmLow) +! call json%add(p,"TripTankSetAlarmHigh",data%Equipments%DataDisplayConsole%TripTankSetAlarmHigh) +! call json%add(p,"TripTankSetAlarmSwitch",data%Equipments%DataDisplayConsole%TripTankSetAlarmSwitch) +! call json%add(p,"TripTankPowerSwitch",data%Equipments%DataDisplayConsole%TripTankPowerSwitch) +! call json%add(p,"TripTankPumpSwitch",data%Equipments%DataDisplayConsole%TripTankPumpSwitch) +! call json%add(p,"TripTankHornSwitch",data%Equipments%DataDisplayConsole%TripTankHornSwitch) +! call json%add(p,"AcidGasDetectionHornSwitch",data%Equipments%DataDisplayConsole%AcidGasDetectionHornSwitch) +! call json%add(p,"TotalStrokeCounterResetSwitch",data%Equipments%DataDisplayConsole%TotalStrokeCounterResetSwitch) +! call json%add(p,"DrillingTrippingSelectorSwitch",data%Equipments%DataDisplayConsole%DrillingTrippingSelectorSwitch) +! call json%add(p,"MVTSetAlarmLowKnob",data%Equipments%DataDisplayConsole%MVTSetAlarmLowKnob) +! call json%add(p,"MVTSetAlarmHighKnob",data%Equipments%DataDisplayConsole%MVTSetAlarmHighKnob) +! call json%add(p,"MVTSetAlarmSwitch",data%Equipments%DataDisplayConsole%MVTSetAlarmSwitch) +! call json%add(p,"MudTank1Switch",data%Equipments%DataDisplayConsole%MudTank1Switch) +! call json%add(p,"MudTank2Switch",data%Equipments%DataDisplayConsole%MudTank2Switch) +! call json%add(p,"MudTank3Switch",data%Equipments%DataDisplayConsole%MudTank3Switch) +! call json%add(p,"MudTank4Switch",data%Equipments%DataDisplayConsole%MudTank4Switch) +! call json%add(p,"MVTFineKnob",data%Equipments%DataDisplayConsole%MVTFineKnob) +! call json%add(p,"MVTCoarseKnob",data%Equipments%DataDisplayConsole%MVTCoarseKnob) +! call json%add(p,"MVTHornSwitch",data%Equipments%DataDisplayConsole%MVTHornSwitch) +! call json%add(p,"MVTDeviationTripSelectionSwitch",data%Equipments%DataDisplayConsole%MVTDeviationTripSelectionSwitch) +! call json%add(p,"MVTPowerSwitch",data%Equipments%DataDisplayConsole%MVTPowerSwitch) +! call json%add(p,"MFFIResetTotalStrokes",data%Equipments%DataDisplayConsole%MFFIResetTotalStrokes) +! call json%add(p,"MFFIResetFillCounter",data%Equipments%DataDisplayConsole%MFFIResetFillCounter) +! call json%add(p,"MFFIPumpSelectorSwitch",data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch) +! call json%add(p,"MFFIFillSPMSelectorSwitch",data%Equipments%DataDisplayConsole%MFFIFillSPMSelectorSwitch) +! call json%add(p,"MFFISetAlarmLowKnob",data%Equipments%DataDisplayConsole%MFFISetAlarmLowKnob) +! call json%add(p,"MFFISetAlarmHighKnob",data%Equipments%DataDisplayConsole%MFFISetAlarmHighKnob) +! call json%add(p,"MFFISetAlarmSwitch",data%Equipments%DataDisplayConsole%MFFISetAlarmSwitch) +! call json%add(p,"MFFIPowerSwitch",data%Equipments%DataDisplayConsole%MFFIPowerSwitch) +! call json%add(p,"MFFIHornSwitch",data%Equipments%DataDisplayConsole%MFFIHornSwitch) +! call json%add(p,"ResetWob",data%Equipments%DataDisplayConsole%ResetWob) +! call json%add(p,"Clutch",data%Equipments%DataDisplayConsole%Clutch) + + call json%add(p,"WOBPointer",data%Equipments%DataDisplayConsole%WOBPointer) + call json%add(p,"HookLoadPointer",data%Equipments%DataDisplayConsole%HookLoadPointer) + call json%add(p,"TripTankGauge",data%Equipments%DataDisplayConsole%TripTankGauge) + call json%add(p,"TripTankAlarmLED",data%Equipments%DataDisplayConsole%TripTankAlarmLED) + call json%add(p,"TripTankPumpLED",data%Equipments%DataDisplayConsole%TripTankPumpLED) + call json%add(p,"StandPipePressureGauge",data%Equipments%DataDisplayConsole%StandPipePressureGauge) + call json%add(p,"CasingPressureGauge",data%Equipments%DataDisplayConsole%CasingPressureGauge) + call json%add(p,"MP1SPMGauge",data%Equipments%DataDisplayConsole%MP1SPMGauge) + call json%add(p,"MP2SPMGauge",data%Equipments%DataDisplayConsole%MP2SPMGauge) + call json%add(p,"ReturnLineTempGauge",data%Equipments%DataDisplayConsole%ReturnLineTempGauge) + call json%add(p,"RotaryTorqueGauge",data%Equipments%DataDisplayConsole%RotaryTorqueGauge) + call json%add(p,"RotaryRPMGauge",data%Equipments%DataDisplayConsole%RotaryRPMGauge) + call json%add(p,"AcidGasDetectionLED",data%Equipments%DataDisplayConsole%AcidGasDetectionLED) + call json%add(p,"TotalStrokeCounter",data%Equipments%DataDisplayConsole%TotalStrokeCounter) + call json%add(p,"PitGainLossGauge",data%Equipments%DataDisplayConsole%PitGainLossGauge) + call json%add(p,"MudTanksVolumeGauge",data%Equipments%DataDisplayConsole%MudTanksVolumeGauge) + call json%add(p,"MVTAlarmLED",data%Equipments%DataDisplayConsole%MVTAlarmLED) + call json%add(p,"ReturnMudFlowGauge",data%Equipments%DataDisplayConsole%ReturnMudFlowGauge) + call json%add(p,"FillStrokeCounter",data%Equipments%DataDisplayConsole%FillStrokeCounter) + call json%add(p,"MFFITotalStrokeCounter",data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter) + call json%add(p,"MFFIAlarmLED",data%Equipments%DataDisplayConsole%MFFIAlarmLED) + call json%add(p,"MFFIPumpLED",data%Equipments%DataDisplayConsole%MFFIPumpLED) + call json%add(p,"TotalWellDepth",data%Equipments%DataDisplayConsole%TotalWellDepth) + call json%add(p,"BitDepth",data%Equipments%DataDisplayConsole%BitDepth) + call json%add(p,"HookLoad",data%Equipments%DataDisplayConsole%HookLoad) + call json%add(p,"StandPipePressure",data%Equipments%DataDisplayConsole%StandPipePressure) + call json%add(p,"CasingPressure",data%Equipments%DataDisplayConsole%CasingPressure) + call json%add(p,"MP1SPM",data%Equipments%DataDisplayConsole%MP1SPM) + call json%add(p,"MP2SPM",data%Equipments%DataDisplayConsole%MP2SPM) + call json%add(p,"RTTorque",data%Equipments%DataDisplayConsole%RTTorque) + call json%add(p,"RTRPM",data%Equipments%DataDisplayConsole%RTRPM) + call json%add(p,"WOP",data%Equipments%DataDisplayConsole%WOP) + call json%add(p,"ROP",data%Equipments%DataDisplayConsole%ROP) + call json%add(p,"MudWeightIn",data%Equipments%DataDisplayConsole%MudWeightIn) + call json%add(p,"MudWeightOut",data%Equipments%DataDisplayConsole%MudWeightOut) + call json%add(p,"Buzzer1",data%Equipments%DataDisplayConsole%Buzzer1) + call json%add(p,"Buzzer2",data%Equipments%DataDisplayConsole%Buzzer2) + call json%add(p,"Buzzer3",data%Equipments%DataDisplayConsole%Buzzer3) + call json%add(p,"Buzzer4",data%Equipments%DataDisplayConsole%Buzzer4) + + + call json%add(parent,p) + end subroutine + + + subroutine Set_TotalDepth(v) + use SimulationVariables !@!!, only: data%Equipments%DrillingWatch%Depth +! use CSimulationVariables, only: SetDistanceDrilled + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%TotalWellDepth = v + data%Equipments%DrillingWatch%Depth = v +! call SetDistanceDrilled(v) + end subroutine + + subroutine Set_BitPosition(v) + use SimulationVariables !@!!, only: data%Equipments%DrillingWatch%BitPosition + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%BitDepth = v + data%Equipments%DrillingWatch%BitPosition = v + end subroutine + + subroutine Set_RotaryTorque(v) + use SimulationVariables !@!!, only: data%Equipments%DrillingWatch%Torque + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%RotaryTorqueGauge = v + data%Equipments%DrillingWatch%Torque = v + data%Equipments%DataDisplayConsole%RTTorque = v + end subroutine + + + subroutine Set_MudWeightIn(v) + use SimulationVariables !@!, only: MudWeightInDw => data%Equipments%DataDisplayConsole%MudWeightIn + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%MudWeightIn = v + data%Equipments%DrillingWatch%MudWeightIn = v + end subroutine + + subroutine Set_MudWeightOut(v) + use SimulationVariables !@!, only: MudWeightOutDw => data%Equipments%DataDisplayConsole%MudWeightOut + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%MudWeightOut = v + data%Equipments%DrillingWatch%MudWeightOut = v + end subroutine + + subroutine Set_TripTankVolume(v) + use SimulationVariables !@!, only: data%Equipments%DrillingWatch%TripTankVolume + implicit none + real(8), intent(in) :: v + data%Equipments%DrillingWatch%TripTankVolume = v + end subroutine + + subroutine Set_FillVolume(v) + use SimulationVariables !@!, only: data%Equipments%DrillingWatch%FillVolume + implicit none + real(8), intent(in) :: v + data%Equipments%DrillingWatch%FillVolume = v + end subroutine + + subroutine Set_HookLoad(v) + use SimulationVariables !@!, only: HookLoadDw => data%Equipments%DataDisplayConsole%HookLoad + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%HookLoadPointer = v + data%Equipments%DrillingWatch%HookLoad = v * 1000 + data%Equipments%DataDisplayConsole%HookLoad = v + end subroutine + + subroutine Set_WeightOnBit(v) + use SimulationVariables !@!, only: data%Equipments%DrillingWatch%WeightOnBit + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%WOBPointer = v + data%Equipments%DrillingWatch%WeightOnBit = v + data%Equipments%DataDisplayConsole%WOP = v + end subroutine + + subroutine Set_ROP(v) + use SimulationVariables !@!, only: ROPDw => data%Equipments%DataDisplayConsole%ROP + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%ROP = v + data%Equipments%DrillingWatch%ROP = v + end subroutine + + subroutine Set_CasingPressure(v) + use SimulationVariables !@!, only: CasingPressureDw => CasingPressure + use CChokeControlPanelVariables + use SimulationVariables!, only: CasingPressureChoke => CasingPressure + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%CasingPressureGauge = v + data%Equipments%DrillingWatch%CasingPressure = v + data%Equipments%ChokeControlPanel%CasingPressure = v + data%Equipments%DataDisplayConsole%CasingPressure = v + end subroutine + + subroutine Set_StandPipePressure(v) + use SimulationVariables !@!, only: data%Equipments%DrillingWatch%PumpPressure + use CChokeControlPanelVariables + use SimulationVariables!, only: StandPipePressureChoke => data%Equipments%DataDisplayConsole%StandPipePressure + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%StandPipePressureGauge = v + data%Equipments%DrillingWatch%PumpPressure = v + data%Equipments%ChokeControlPanel%StandPipePressure = v + data%Equipments%DataDisplayConsole%StandPipePressure = v + + + + end subroutine + + + subroutine Set_RotaryRPMGauge(v) + use SimulationVariables !@!, only: data%Equipments%DrillingWatch%RPM + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%RotaryRPMGauge = v + data%Equipments%DrillingWatch%RPM = v + data%Equipments%DataDisplayConsole%RTRPM = v +! call data%Equipments%DataDisplayConsole%OnRotaryRpmChange%RunAll(v) + end subroutine + + + + + subroutine Set_MP1SPMGauge(v) + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%MP1SPMGauge = v + data%Equipments%DataDisplayConsole%MP1SPM = v +!@data%State%unitySignals%(PumpsSpmChanges)) call PumpsSpmChanges(data%Equipments%DataDisplayConsole%MP1SPMGauge, data%Equipments%DataDisplayConsole%MP2SPMGauge) +# 411 + + end subroutine + + subroutine Set_MP2SPMGauge(v) + implicit none + real(8), intent(in) :: v + data%Equipments%DataDisplayConsole%MP2SPMGauge = v + data%Equipments%DataDisplayConsole%MP2SPM = v +!@data%State%unitySignals%(PumpsSpmChanges)) call PumpsSpmChanges(data%Equipments%DataDisplayConsole%MP1SPMGauge, data%Equipments%DataDisplayConsole%MP2SPMGauge) +# 422 + + end subroutine +end module CDataDisplayConsole diff --git a/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.f90 b/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.f90 index 9f93201..6b3ce09 100644 --- a/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.f90 +++ b/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.f90 @@ -6,12 +6,12 @@ module CDataDisplayConsoleVariables Type :: DataDisplayConsoleType !portable - real(8) :: TripAlarmLow - real(8) :: TripAlarmHigh - real(8) :: RetFlowAlarmLow - real(8) :: RetFlowAlarmHigh - real(8) :: PitAlarmLow - real(8) :: PitAlarmHigh + ! real(8) :: TripAlarmLow + ! real(8) :: TripAlarmHigh + ! real(8) :: RetFlowAlarmLow + ! real(8) :: RetFlowAlarmHigh + ! real(8) :: PitAlarmLow + ! real(8) :: PitAlarmHigh real(8) :: PortWeightOnBit real(8) :: PortHookLoad @@ -97,10 +97,6 @@ module CDataDisplayConsoleVariables logical :: Buzzer4 End Type DataDisplayConsoleType - - ! events - ! procedure (ActionDualDouble), pointer :: PumpsSpmChanges => null() - contains end module CDataDisplayConsoleVariables \ No newline at end of file diff --git a/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.i90 b/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.i90 new file mode 100644 index 0000000..1d4fb69 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.i90 @@ -0,0 +1,103 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CDataDisplayConsoleVariables.f90" +module CDataDisplayConsoleVariables + use CIActionReference +! !**use CDoubleEventHandlerCollection + implicit none + public + + Type :: DataDisplayConsoleType +!portable +! real(8) :: TripAlarmLow +! real(8) :: TripAlarmHigh +! real(8) :: RetFlowAlarmLow +! real(8) :: RetFlowAlarmHigh +! real(8) :: PitAlarmLow +! real(8) :: PitAlarmHigh + + real(8) :: PortWeightOnBit + real(8) :: PortHookLoad + real(8) :: PortCasingPressure + real(8) :: PortPumpPressure + +! Input vars + real(8) :: TripTankSetAlarmLow + real(8) :: TripTankSetAlarmHigh + integer :: TripTankSetAlarmSwitch + logical :: TripTankPowerSwitch + logical :: TripTankPumpSwitch + logical :: TripTankHornSwitch + logical :: AcidGasDetectionHornSwitch + logical :: TotalStrokeCounterResetSwitch + logical :: DrillingTrippingSelectorSwitch + real(8) :: MVTSetAlarmLowKnob + real(8) :: MVTSetAlarmHighKnob + integer :: MVTSetAlarmSwitch + logical :: MudTank1Switch + logical :: MudTank2Switch + logical :: MudTank3Switch + logical :: MudTank4Switch + real(8) :: MVTFineKnob + real(8) :: MVTCoarseKnob + logical :: MVTHornSwitch + logical :: MVTDeviationTripSelectionSwitch + logical :: MVTPowerSwitch + logical :: MFFIResetTotalStrokes + logical :: MFFIResetFillCounter + integer :: MFFIPumpSelectorSwitch + logical :: MFFIFillSPMSelectorSwitch + real(8) :: MFFISetAlarmLowKnob + real(8) :: MFFISetAlarmHighKnob + integer :: MFFISetAlarmSwitch + logical :: MFFIPowerSwitch + logical :: MFFIHornSwitch + + logical :: ResetWob + logical :: Clutch + +! Output vars + real(8) :: WOBPointer + real(8) :: HookLoadPointer + real(8) :: TripTankGauge + integer :: TripTankAlarmLED + integer :: TripTankPumpLED + real(8) :: StandPipePressureGauge + real(8) :: CasingPressureGauge + real(8) :: MP1SPMGauge + real(8) :: MP2SPMGauge + real(8) :: ReturnLineTempGauge + real(8) :: RotaryTorqueGauge + real(8) :: RotaryRPMGauge +! !**type(DoubleEventHandlerCollection) :: OnRotaryRpmChange + integer :: AcidGasDetectionLED + real(8) :: TotalStrokeCounter +!real(8) :: TotalStrokeCounter_temp + real(8) :: PitGainLossGauge + real(8) :: MudTanksVolumeGauge + integer :: MVTAlarmLED + real(8) :: ReturnMudFlowGauge + real(8) :: FillStrokeCounter + real(8) :: MFFITotalStrokeCounter + integer :: MFFIAlarmLED + integer :: MFFIPumpLED + real(8) :: TotalWellDepth + real(8) :: BitDepth + real(8) :: HookLoad + real(8) :: StandPipePressure + real(8) :: CasingPressure + real(8) :: MP1SPM + real(8) :: MP2SPM + real(8) :: RTTorque + real(8) :: RTRPM + real(8) :: WOP + real(8) :: ROP + real(8) :: MudWeightIn + real(8) :: MudWeightOut + logical :: Buzzer1 + logical :: Buzzer2 + logical :: Buzzer3 + logical :: Buzzer4 + End Type DataDisplayConsoleType + + contains + +end module CDataDisplayConsoleVariables diff --git a/CSharp/Equipments/ControlPanels/CDrillingConsole.f90 b/CSharp/Equipments/ControlPanels/CDrillingConsole.f90 index 63339cf..25baf65 100644 --- a/CSharp/Equipments/ControlPanels/CDrillingConsole.f90 +++ b/CSharp/Equipments/ControlPanels/CDrillingConsole.f90 @@ -10,6 +10,184 @@ module CDrillingConsole contains + subroutine DrillingConsoleFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + ! 1. get related root + call json%get(parent,'Drilling',p) + + ! 2. get member of data type from node + call json%get(p,'AssignmentSwitch',pval) + call json%get(pval,data%Equipments%DrillingConsole%AssignmentSwitch) + call json%get(p,'EmergencySwitch',pval) + call json%get(pval,data%Equipments%DrillingConsole%EmergencySwitch) + call json%get(p,'RTTorqueLimitKnob',pval) + call json%get(pval,data%Equipments%DrillingConsole%RTTorqueLimitKnob) + call json%get(p,'MP1CPSwitchI',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP1CPSwitchI) + call json%get(p,'MP1CPSwitchT',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP1CPSwitchT) + call json%get(p,'MP1CPSwitch',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP1CPSwitch) + call json%get(p,'MP1ThrottleUpdate',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP1ThrottleUpdate) + call json%get(p,'MP1Throttle',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP1Throttle) + call json%get(p,'MP2SwitchI',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP2SwitchI) + call json%get(p,'MP2SwitchT',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP2SwitchT) + call json%get(p,'MP2Switch',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP2Switch) + call json%get(p,'MP2ThrottleUpdate',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP2ThrottleUpdate) + call json%get(p,'MP2Throttle',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP2Throttle) + call json%get(p,'DWSwitch',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWSwitch) + call json%get(p,'DWThrottle',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWThrottle) + call json%get(p,'RTSwitch',pval) + call json%get(pval,data%Equipments%DrillingConsole%RTSwitch) + call json%get(p,'RTThrottle',pval) + call json%get(pval,data%Equipments%DrillingConsole%RTThrottle) + call json%get(p,'DWBreak',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWBreak) + call json%get(p,'PreviousDWBreak',pval) + call json%get(pval,data%Equipments%DrillingConsole%PreviousDWBreak) + call json%get(p,'ForceBreak',pval) + call json%get(pval,data%Equipments%DrillingConsole%ForceBreak) + call json%get(p,'DWAcceleretor',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWAcceleretor) + call json%get(p,'DWTransmisionLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWTransmisionLever) + call json%get(p,'DWPowerLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWPowerLever) + call json%get(p,'TongLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%TongLever) + call json%get(p,'RTTransmissionLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%RTTransmissionLever) + call json%get(p,'DWClutchLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWClutchLever) + call json%get(p,'EddyBreakLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%EddyBreakLever) + call json%get(p,'AutoDW',pval) + call json%get(pval,data%Equipments%DrillingConsole%AutoDW) + call json%get(p,'GEN1',pval) + call json%get(pval,data%Equipments%DrillingConsole%GEN1) + call json%get(p,'GEN2',pval) + call json%get(pval,data%Equipments%DrillingConsole%GEN2) + call json%get(p,'GEN3',pval) + call json%get(pval,data%Equipments%DrillingConsole%GEN3) + call json%get(p,'GEN4',pval) + call json%get(pval,data%Equipments%DrillingConsole%GEN4) + call json%get(p,'Permission_OpenKellyCock',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_OpenKellyCock) + call json%get(p,'OpenKellyCock',pval) + call json%get(pval,data%Equipments%DrillingConsole%OpenKellyCock) + call json%get(p,'Permission_CloseKellyCock',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_CloseKellyCock) + call json%get(p,'CloseKellyCock',pval) + call json%get(pval,data%Equipments%DrillingConsole%CloseKellyCock) + call json%get(p,'Permission_OpenSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_OpenSafetyValve) + call json%get(p,'OpenSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%OpenSafetyValve) + call json%get(p,'Permission_CloseSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_CloseSafetyValve) + call json%get(p,'CloseSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%CloseSafetyValve) + call json%get(p,'Permission_IRSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_IRSafetyValve) + call json%get(p,'IRSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%IRSafetyValve) + call json%get(p,'Permission_IRIBop',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_IRIBop) + call json%get(p,'IRIBop',pval) + call json%get(pval,data%Equipments%DrillingConsole%IRIBop) + call json%get(p,'LatchPipe',pval) + call json%get(pval,data%Equipments%DrillingConsole%LatchPipe) + call json%get(p,'UnlatchPipe',pval) + call json%get(pval,data%Equipments%DrillingConsole%UnlatchPipe) + call json%get(p,'Swing',pval) + call json%get(pval,data%Equipments%DrillingConsole%Swing) + call json%get(p,'FillMouseHole',pval) + call json%get(pval,data%Equipments%DrillingConsole%FillMouseHole) + call json%get(p,'Slips',pval) + call json%get(pval,data%Equipments%DrillingConsole%Slips) + call json%get(p,'BrakeLeverCoefficient',pval) + call json%get(pval,data%Equipments%DrillingConsole%BrakeLeverCoefficient) + call json%get(p,'HideDrillingBrake',pval) + call json%get(pval,data%Equipments%DrillingConsole%HideDrillingBrake) + call json%get(p,'ParkingBrakeBtn',pval) + call json%get(pval,data%Equipments%DrillingConsole%ParkingBrakeBtn) + + ! call json%get(p,'ParkingBrakeLed',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%ParkingBrakeLed) + ! call json%get(p,'GEN1LED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%GEN1LED) + ! call json%get(p,'GEN2LED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%GEN2LED) + ! call json%get(p,'GEN3LED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%GEN3LED) + ! call json%get(p,'GEN4LED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%GEN4LED) + ! call json%get(p,'SCR1LED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%SCR1LED) + ! call json%get(p,'SCR2LED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%SCR2LED) + ! call json%get(p,'SCR3LED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%SCR3LED) + ! call json%get(p,'SCR4LED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%SCR4LED) + ! call json%get(p,'MP1BLWR',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%MP1BLWR) + ! call json%get(p,'MP2BLWR',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%MP2BLWR) + ! call json%get(p,'DWBLWR',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%DWBLWR) + ! call json%get(p,'RTBLWR',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%RTBLWR) + ! call json%get(p,'PWRLIM',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%PWRLIM) + ! call json%get(p,'PWRLIMMTR',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%PWRLIMMTR) + ! call json%get(p,'RTTorqueLimitGauge',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%RTTorqueLimitGauge) + ! call json%get(p,'AutoDWLED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%AutoDWLED) + ! call json%get(p,'GEN1BTNLED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%GEN1BTNLED) + ! call json%get(p,'GEN2BTNLED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%GEN2BTNLED) + ! call json%get(p,'GEN3BTNLED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%GEN3BTNLED) + ! call json%get(p,'GEN4BTNLED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%GEN4BTNLED) + ! call json%get(p,'OpenKellyCockLed',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%OpenKellyCockLed) + ! call json%get(p,'CloseKellyCockLed',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%CloseKellyCockLed) + ! call json%get(p,'OpenSafetyValveLed',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%OpenSafetyValveLed) + ! call json%get(p,'CloseSafetyValveLed',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%CloseSafetyValveLed) + ! call json%get(p,'IRSafetyValveLed',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%IRSafetyValveLed) + ! call json%get(p,'IRIBopLed',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%IRIBopLed) + ! call json%get(p,'LatchPipeLED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%LatchPipeLED) + ! call json%get(p,'UnlatchPipeLED',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%UnlatchPipeLED) + ! call json%get(p,'SwingLed',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%SwingLed) + ! call json%get(p,'FillMouseHoleLed',pval) + ! call json%get(pval,data%Equipments%DrillingConsole%FillMouseHoleLed) + end subroutine + subroutine DrillingConsoleToJson(parent) type(json_value),pointer :: parent @@ -18,89 +196,92 @@ module CDrillingConsole ! 1. create new node call json%create_object(p,'Drilling') - call json%add(p,"AssignmentSwitch",data%EquipmentControl%DrillingConsole%AssignmentSwitch) - call json%add(p,"EmergencySwitch",data%EquipmentControl%DrillingConsole%EmergencySwitch) - call json%add(p,"RTTorqueLimitKnob",data%EquipmentControl%DrillingConsole%RTTorqueLimitKnob) - call json%add(p,"MP1CPSwitchI",data%EquipmentControl%DrillingConsole%MP1CPSwitchI) - call json%add(p,"MP1CPSwitchT",data%EquipmentControl%DrillingConsole%MP1CPSwitchT) - call json%add(p,"MP1CPSwitch",data%EquipmentControl%DrillingConsole%MP1CPSwitch) - call json%add(p,"MP1ThrottleUpdate",data%EquipmentControl%DrillingConsole%MP1ThrottleUpdate) - call json%add(p,"MP1Throttle",data%EquipmentControl%DrillingConsole%MP1Throttle) - call json%add(p,"MP2SwitchI",data%EquipmentControl%DrillingConsole%MP2SwitchI) - call json%add(p,"MP2SwitchT",data%EquipmentControl%DrillingConsole%MP2SwitchT) - call json%add(p,"MP2Switch",data%EquipmentControl%DrillingConsole%MP2Switch) - call json%add(p,"MP2ThrottleUpdate",data%EquipmentControl%DrillingConsole%MP2ThrottleUpdate) - call json%add(p,"MP2Throttle",data%EquipmentControl%DrillingConsole%MP2Throttle) - call json%add(p,"DWSwitch",data%EquipmentControl%DrillingConsole%DWSwitch) - call json%add(p,"DWThrottle",data%EquipmentControl%DrillingConsole%DWThrottle) - call json%add(p,"RTSwitch",data%EquipmentControl%DrillingConsole%RTSwitch) - call json%add(p,"RTThrottle",data%EquipmentControl%DrillingConsole%RTThrottle) - call json%add(p,"DWBreak",data%EquipmentControl%DrillingConsole%DWBreak) - call json%add(p,"PreviousDWBreak",data%EquipmentControl%DrillingConsole%PreviousDWBreak) - call json%add(p,"ForceBreak",data%EquipmentControl%DrillingConsole%ForceBreak) - call json%add(p,"DWAcceleretor",data%EquipmentControl%DrillingConsole%DWAcceleretor) - call json%add(p,"DWTransmisionLever",data%EquipmentControl%DrillingConsole%DWTransmisionLever) - call json%add(p,"DWPowerLever",data%EquipmentControl%DrillingConsole%DWPowerLever) - call json%add(p,"TongLever",data%EquipmentControl%DrillingConsole%TongLever) - call json%add(p,"RTTransmissionLever",data%EquipmentControl%DrillingConsole%RTTransmissionLever) - call json%add(p,"DWClutchLever",data%EquipmentControl%DrillingConsole%DWClutchLever) - call json%add(p,"EddyBreakLever",data%EquipmentControl%DrillingConsole%EddyBreakLever) - call json%add(p,"AutoDW",data%EquipmentControl%DrillingConsole%AutoDW) - call json%add(p,"GEN1",data%EquipmentControl%DrillingConsole%GEN1) - call json%add(p,"GEN2",data%EquipmentControl%DrillingConsole%GEN2) - call json%add(p,"GEN3",data%EquipmentControl%DrillingConsole%GEN3) - call json%add(p,"GEN4",data%EquipmentControl%DrillingConsole%GEN4) - call json%add(p,"Permission_OpenKellyCock",data%EquipmentControl%DrillingConsole%Permission_OpenKellyCock) - call json%add(p,"OpenKellyCock",data%EquipmentControl%DrillingConsole%OpenKellyCock) - call json%add(p,"Permission_CloseKellyCock",data%EquipmentControl%DrillingConsole%Permission_CloseKellyCock) - call json%add(p,"CloseKellyCock",data%EquipmentControl%DrillingConsole%CloseKellyCock) - call json%add(p,"Permission_OpenSafetyValve",data%EquipmentControl%DrillingConsole%Permission_OpenSafetyValve) - call json%add(p,"OpenSafetyValve",data%EquipmentControl%DrillingConsole%OpenSafetyValve) - call json%add(p,"Permission_CloseSafetyValve",data%EquipmentControl%DrillingConsole%Permission_CloseSafetyValve) - call json%add(p,"CloseSafetyValve",data%EquipmentControl%DrillingConsole%CloseSafetyValve) - call json%add(p,"Permission_IRSafetyValve",data%EquipmentControl%DrillingConsole%Permission_IRSafetyValve) - call json%add(p,"IRSafetyValve",data%EquipmentControl%DrillingConsole%IRSafetyValve) - call json%add(p,"Permission_IRIBop",data%EquipmentControl%DrillingConsole%Permission_IRIBop) - call json%add(p,"IRIBop",data%EquipmentControl%DrillingConsole%IRIBop) - call json%add(p,"LatchPipe",data%EquipmentControl%DrillingConsole%LatchPipe) - call json%add(p,"UnlatchPipe",data%EquipmentControl%DrillingConsole%UnlatchPipe) - call json%add(p,"Swing",data%EquipmentControl%DrillingConsole%Swing) - call json%add(p,"FillMouseHole",data%EquipmentControl%DrillingConsole%FillMouseHole) - call json%add(p,"Slips",data%EquipmentControl%DrillingConsole%Slips) - call json%add(p,"BrakeLeverCoefficient",data%EquipmentControl%DrillingConsole%BrakeLeverCoefficient) - call json%add(p,"HideDrillingBrake",data%EquipmentControl%DrillingConsole%HideDrillingBrake) - call json%add(p,"ParkingBrakeBtn",data%EquipmentControl%DrillingConsole%ParkingBrakeBtn) - call json%add(p,"ParkingBrakeLed",data%EquipmentControl%DrillingConsole%ParkingBrakeLed) - call json%add(p,"GEN1LED",data%EquipmentControl%DrillingConsole%GEN1LED) - call json%add(p,"GEN2LED",data%EquipmentControl%DrillingConsole%GEN2LED) - call json%add(p,"GEN3LED",data%EquipmentControl%DrillingConsole%GEN3LED) - call json%add(p,"GEN4LED",data%EquipmentControl%DrillingConsole%GEN4LED) - call json%add(p,"SCR1LED",data%EquipmentControl%DrillingConsole%SCR1LED) - call json%add(p,"SCR2LED",data%EquipmentControl%DrillingConsole%SCR2LED) - call json%add(p,"SCR3LED",data%EquipmentControl%DrillingConsole%SCR3LED) - call json%add(p,"SCR4LED",data%EquipmentControl%DrillingConsole%SCR4LED) - call json%add(p,"MP1BLWR",data%EquipmentControl%DrillingConsole%MP1BLWR) - call json%add(p,"MP2BLWR",data%EquipmentControl%DrillingConsole%MP2BLWR) - call json%add(p,"DWBLWR",data%EquipmentControl%DrillingConsole%DWBLWR) - call json%add(p,"RTBLWR",data%EquipmentControl%DrillingConsole%RTBLWR) - call json%add(p,"PWRLIM",data%EquipmentControl%DrillingConsole%PWRLIM) - call json%add(p,"PWRLIMMTR",data%EquipmentControl%DrillingConsole%PWRLIMMTR) - call json%add(p,"RTTorqueLimitGauge",data%EquipmentControl%DrillingConsole%RTTorqueLimitGauge) - call json%add(p,"AutoDWLED",data%EquipmentControl%DrillingConsole%AutoDWLED) - call json%add(p,"GEN1BTNLED",data%EquipmentControl%DrillingConsole%GEN1BTNLED) - call json%add(p,"GEN2BTNLED",data%EquipmentControl%DrillingConsole%GEN2BTNLED) - call json%add(p,"GEN3BTNLED",data%EquipmentControl%DrillingConsole%GEN3BTNLED) - call json%add(p,"GEN4BTNLED",data%EquipmentControl%DrillingConsole%GEN4BTNLED) - call json%add(p,"OpenKellyCockLed",data%EquipmentControl%DrillingConsole%OpenKellyCockLed) - call json%add(p,"CloseKellyCockLed",data%EquipmentControl%DrillingConsole%CloseKellyCockLed) - call json%add(p,"OpenSafetyValveLed",data%EquipmentControl%DrillingConsole%OpenSafetyValveLed) - call json%add(p,"CloseSafetyValveLed",data%EquipmentControl%DrillingConsole%CloseSafetyValveLed) - call json%add(p,"IRSafetyValveLed",data%EquipmentControl%DrillingConsole%IRSafetyValveLed) - call json%add(p,"IRIBopLed",data%EquipmentControl%DrillingConsole%IRIBopLed) - call json%add(p,"LatchPipeLED",data%EquipmentControl%DrillingConsole%LatchPipeLED) - call json%add(p,"UnlatchPipeLED",data%EquipmentControl%DrillingConsole%UnlatchPipeLED) - call json%add(p,"SwingLed",data%EquipmentControl%DrillingConsole%SwingLed) - call json%add(p,"FillMouseHoleLed",data%EquipmentControl%DrillingConsole%FillMouseHoleLed) + ! call json%add(p,"AssignmentSwitch",data%Equipments%DrillingConsole%AssignmentSwitch) + ! call json%add(p,"EmergencySwitch",data%Equipments%DrillingConsole%EmergencySwitch) + ! call json%add(p,"RTTorqueLimitKnob",data%Equipments%DrillingConsole%RTTorqueLimitKnob) + ! call json%add(p,"MP1CPSwitchI",data%Equipments%DrillingConsole%MP1CPSwitchI) + ! call json%add(p,"MP1CPSwitchT",data%Equipments%DrillingConsole%MP1CPSwitchT) + ! call json%add(p,"MP1CPSwitch",data%Equipments%DrillingConsole%MP1CPSwitch) + ! call json%add(p,"MP1ThrottleUpdate",data%Equipments%DrillingConsole%MP1ThrottleUpdate) + ! call json%add(p,"MP1Throttle",data%Equipments%DrillingConsole%MP1Throttle) + ! call json%add(p,"MP2SwitchI",data%Equipments%DrillingConsole%MP2SwitchI) + ! call json%add(p,"MP2SwitchT",data%Equipments%DrillingConsole%MP2SwitchT) + ! call json%add(p,"MP2Switch",data%Equipments%DrillingConsole%MP2Switch) + ! call json%add(p,"MP2ThrottleUpdate",data%Equipments%DrillingConsole%MP2ThrottleUpdate) + ! call json%add(p,"MP2Throttle",data%Equipments%DrillingConsole%MP2Throttle) + ! call json%add(p,"DWSwitch",data%Equipments%DrillingConsole%DWSwitch) + ! call json%add(p,"DWThrottle",data%Equipments%DrillingConsole%DWThrottle) + ! call json%add(p,"RTSwitch",data%Equipments%DrillingConsole%RTSwitch) + ! call json%add(p,"RTThrottle",data%Equipments%DrillingConsole%RTThrottle) + ! call json%add(p,"DWBreak",data%Equipments%DrillingConsole%DWBreak) + ! call json%add(p,"PreviousDWBreak",data%Equipments%DrillingConsole%PreviousDWBreak) + ! call json%add(p,"ForceBreak",data%Equipments%DrillingConsole%ForceBreak) + ! call json%add(p,"DWAcceleretor",data%Equipments%DrillingConsole%DWAcceleretor) + ! call json%add(p,"DWTransmisionLever",data%Equipments%DrillingConsole%DWTransmisionLever) + ! call json%add(p,"DWPowerLever",data%Equipments%DrillingConsole%DWPowerLever) + ! call json%add(p,"TongLever",data%Equipments%DrillingConsole%TongLever) + ! call json%add(p,"RTTransmissionLever",data%Equipments%DrillingConsole%RTTransmissionLever) + ! call json%add(p,"DWClutchLever",data%Equipments%DrillingConsole%DWClutchLever) + ! call json%add(p,"EddyBreakLever",data%Equipments%DrillingConsole%EddyBreakLever) + ! call json%add(p,"AutoDW",data%Equipments%DrillingConsole%AutoDW) + ! call json%add(p,"GEN1",data%Equipments%DrillingConsole%GEN1) + ! call json%add(p,"GEN2",data%Equipments%DrillingConsole%GEN2) + ! call json%add(p,"GEN3",data%Equipments%DrillingConsole%GEN3) + ! call json%add(p,"GEN4",data%Equipments%DrillingConsole%GEN4) + ! call json%add(p,"Permission_OpenKellyCock",data%Equipments%DrillingConsole%Permission_OpenKellyCock) + ! call json%add(p,"OpenKellyCock",data%Equipments%DrillingConsole%OpenKellyCock) + ! call json%add(p,"Permission_CloseKellyCock",data%Equipments%DrillingConsole%Permission_CloseKellyCock) + ! call json%add(p,"CloseKellyCock",data%Equipments%DrillingConsole%CloseKellyCock) + ! call json%add(p,"Permission_OpenSafetyValve",data%Equipments%DrillingConsole%Permission_OpenSafetyValve) + ! call json%add(p,"OpenSafetyValve",data%Equipments%DrillingConsole%OpenSafetyValve) + ! call json%add(p,"Permission_CloseSafetyValve",data%Equipments%DrillingConsole%Permission_CloseSafetyValve) + ! call json%add(p,"CloseSafetyValve",data%Equipments%DrillingConsole%CloseSafetyValve) + ! call json%add(p,"Permission_IRSafetyValve",data%Equipments%DrillingConsole%Permission_IRSafetyValve) + ! call json%add(p,"IRSafetyValve",data%Equipments%DrillingConsole%IRSafetyValve) + ! call json%add(p,"Permission_IRIBop",data%Equipments%DrillingConsole%Permission_IRIBop) + ! call json%add(p,"IRIBop",data%Equipments%DrillingConsole%IRIBop) + ! call json%add(p,"LatchPipe",data%Equipments%DrillingConsole%LatchPipe) + ! call json%add(p,"UnlatchPipe",data%Equipments%DrillingConsole%UnlatchPipe) + ! call json%add(p,"Swing",data%Equipments%DrillingConsole%Swing) + ! call json%add(p,"FillMouseHole",data%Equipments%DrillingConsole%FillMouseHole) + ! call json%add(p,"Slips",data%Equipments%DrillingConsole%Slips) + ! call json%add(p,"BrakeLeverCoefficient",data%Equipments%DrillingConsole%BrakeLeverCoefficient) + ! call json%add(p,"HideDrillingBrake",data%Equipments%DrillingConsole%HideDrillingBrake) + ! call json%add(p,"ParkingBrakeBtn",data%Equipments%DrillingConsole%ParkingBrakeBtn) + + + + call json%add(p,"ParkingBrakeLed",data%Equipments%DrillingConsole%ParkingBrakeLed) + call json%add(p,"GEN1LED",data%Equipments%DrillingConsole%GEN1LED) + call json%add(p,"GEN2LED",data%Equipments%DrillingConsole%GEN2LED) + call json%add(p,"GEN3LED",data%Equipments%DrillingConsole%GEN3LED) + call json%add(p,"GEN4LED",data%Equipments%DrillingConsole%GEN4LED) + call json%add(p,"SCR1LED",data%Equipments%DrillingConsole%SCR1LED) + call json%add(p,"SCR2LED",data%Equipments%DrillingConsole%SCR2LED) + call json%add(p,"SCR3LED",data%Equipments%DrillingConsole%SCR3LED) + call json%add(p,"SCR4LED",data%Equipments%DrillingConsole%SCR4LED) + call json%add(p,"MP1BLWR",data%Equipments%DrillingConsole%MP1BLWR) + call json%add(p,"MP2BLWR",data%Equipments%DrillingConsole%MP2BLWR) + call json%add(p,"DWBLWR",data%Equipments%DrillingConsole%DWBLWR) + call json%add(p,"RTBLWR",data%Equipments%DrillingConsole%RTBLWR) + call json%add(p,"PWRLIM",data%Equipments%DrillingConsole%PWRLIM) + call json%add(p,"PWRLIMMTR",data%Equipments%DrillingConsole%PWRLIMMTR) + call json%add(p,"RTTorqueLimitGauge",data%Equipments%DrillingConsole%RTTorqueLimitGauge) + call json%add(p,"AutoDWLED",data%Equipments%DrillingConsole%AutoDWLED) + call json%add(p,"GEN1BTNLED",data%Equipments%DrillingConsole%GEN1BTNLED) + call json%add(p,"GEN2BTNLED",data%Equipments%DrillingConsole%GEN2BTNLED) + call json%add(p,"GEN3BTNLED",data%Equipments%DrillingConsole%GEN3BTNLED) + call json%add(p,"GEN4BTNLED",data%Equipments%DrillingConsole%GEN4BTNLED) + call json%add(p,"OpenKellyCockLed",data%Equipments%DrillingConsole%OpenKellyCockLed) + call json%add(p,"CloseKellyCockLed",data%Equipments%DrillingConsole%CloseKellyCockLed) + call json%add(p,"OpenSafetyValveLed",data%Equipments%DrillingConsole%OpenSafetyValveLed) + call json%add(p,"CloseSafetyValveLed",data%Equipments%DrillingConsole%CloseSafetyValveLed) + call json%add(p,"IRSafetyValveLed",data%Equipments%DrillingConsole%IRSafetyValveLed) + call json%add(p,"IRIBopLed",data%Equipments%DrillingConsole%IRIBopLed) + call json%add(p,"LatchPipeLED",data%Equipments%DrillingConsole%LatchPipeLED) + call json%add(p,"UnlatchPipeLED",data%Equipments%DrillingConsole%UnlatchPipeLED) + call json%add(p,"SwingLed",data%Equipments%DrillingConsole%SwingLed) + call json%add(p,"FillMouseHoleLed",data%Equipments%DrillingConsole%FillMouseHoleLed) call json%add(parent,p) end subroutine diff --git a/CSharp/Equipments/ControlPanels/CDrillingConsole.i90 b/CSharp/Equipments/ControlPanels/CDrillingConsole.i90 new file mode 100644 index 0000000..41ff42b --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CDrillingConsole.i90 @@ -0,0 +1,290 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CDrillingConsole.f90" +module CDrillingConsole + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables +! use CSimulationVariables + use CLog4 + use CLog3 + implicit none + public + contains + + + subroutine DrillingConsoleFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + +! 1. get related root + call json%get(parent,'Drilling',p) + +! 2. get member of data type from node + call json%get(p,'AssignmentSwitch',pval) + call json%get(pval,data%Equipments%DrillingConsole%AssignmentSwitch) + call json%get(p,'EmergencySwitch',pval) + call json%get(pval,data%Equipments%DrillingConsole%EmergencySwitch) + call json%get(p,'RTTorqueLimitKnob',pval) + call json%get(pval,data%Equipments%DrillingConsole%RTTorqueLimitKnob) + call json%get(p,'MP1CPSwitchI',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP1CPSwitchI) + call json%get(p,'MP1CPSwitchT',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP1CPSwitchT) + call json%get(p,'MP1CPSwitch',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP1CPSwitch) + call json%get(p,'MP1ThrottleUpdate',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP1ThrottleUpdate) + call json%get(p,'MP1Throttle',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP1Throttle) + call json%get(p,'MP2SwitchI',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP2SwitchI) + call json%get(p,'MP2SwitchT',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP2SwitchT) + call json%get(p,'MP2Switch',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP2Switch) + call json%get(p,'MP2ThrottleUpdate',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP2ThrottleUpdate) + call json%get(p,'MP2Throttle',pval) + call json%get(pval,data%Equipments%DrillingConsole%MP2Throttle) + call json%get(p,'DWSwitch',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWSwitch) + call json%get(p,'DWThrottle',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWThrottle) + call json%get(p,'RTSwitch',pval) + call json%get(pval,data%Equipments%DrillingConsole%RTSwitch) + call json%get(p,'RTThrottle',pval) + call json%get(pval,data%Equipments%DrillingConsole%RTThrottle) + call json%get(p,'DWBreak',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWBreak) + call json%get(p,'PreviousDWBreak',pval) + call json%get(pval,data%Equipments%DrillingConsole%PreviousDWBreak) + call json%get(p,'ForceBreak',pval) + call json%get(pval,data%Equipments%DrillingConsole%ForceBreak) + call json%get(p,'DWAcceleretor',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWAcceleretor) + call json%get(p,'DWTransmisionLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWTransmisionLever) + call json%get(p,'DWPowerLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWPowerLever) + call json%get(p,'TongLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%TongLever) + call json%get(p,'RTTransmissionLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%RTTransmissionLever) + call json%get(p,'DWClutchLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%DWClutchLever) + call json%get(p,'EddyBreakLever',pval) + call json%get(pval,data%Equipments%DrillingConsole%EddyBreakLever) + call json%get(p,'AutoDW',pval) + call json%get(pval,data%Equipments%DrillingConsole%AutoDW) + call json%get(p,'GEN1',pval) + call json%get(pval,data%Equipments%DrillingConsole%GEN1) + call json%get(p,'GEN2',pval) + call json%get(pval,data%Equipments%DrillingConsole%GEN2) + call json%get(p,'GEN3',pval) + call json%get(pval,data%Equipments%DrillingConsole%GEN3) + call json%get(p,'GEN4',pval) + call json%get(pval,data%Equipments%DrillingConsole%GEN4) + call json%get(p,'Permission_OpenKellyCock',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_OpenKellyCock) + call json%get(p,'OpenKellyCock',pval) + call json%get(pval,data%Equipments%DrillingConsole%OpenKellyCock) + call json%get(p,'Permission_CloseKellyCock',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_CloseKellyCock) + call json%get(p,'CloseKellyCock',pval) + call json%get(pval,data%Equipments%DrillingConsole%CloseKellyCock) + call json%get(p,'Permission_OpenSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_OpenSafetyValve) + call json%get(p,'OpenSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%OpenSafetyValve) + call json%get(p,'Permission_CloseSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_CloseSafetyValve) + call json%get(p,'CloseSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%CloseSafetyValve) + call json%get(p,'Permission_IRSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_IRSafetyValve) + call json%get(p,'IRSafetyValve',pval) + call json%get(pval,data%Equipments%DrillingConsole%IRSafetyValve) + call json%get(p,'Permission_IRIBop',pval) + call json%get(pval,data%Equipments%DrillingConsole%Permission_IRIBop) + call json%get(p,'IRIBop',pval) + call json%get(pval,data%Equipments%DrillingConsole%IRIBop) + call json%get(p,'LatchPipe',pval) + call json%get(pval,data%Equipments%DrillingConsole%LatchPipe) + call json%get(p,'UnlatchPipe',pval) + call json%get(pval,data%Equipments%DrillingConsole%UnlatchPipe) + call json%get(p,'Swing',pval) + call json%get(pval,data%Equipments%DrillingConsole%Swing) + call json%get(p,'FillMouseHole',pval) + call json%get(pval,data%Equipments%DrillingConsole%FillMouseHole) + call json%get(p,'Slips',pval) + call json%get(pval,data%Equipments%DrillingConsole%Slips) + call json%get(p,'BrakeLeverCoefficient',pval) + call json%get(pval,data%Equipments%DrillingConsole%BrakeLeverCoefficient) + call json%get(p,'HideDrillingBrake',pval) + call json%get(pval,data%Equipments%DrillingConsole%HideDrillingBrake) + call json%get(p,'ParkingBrakeBtn',pval) + call json%get(pval,data%Equipments%DrillingConsole%ParkingBrakeBtn) + +! call json%get(p,'ParkingBrakeLed',pval) +! call json%get(pval,data%Equipments%DrillingConsole%ParkingBrakeLed) +! call json%get(p,'GEN1LED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%GEN1LED) +! call json%get(p,'GEN2LED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%GEN2LED) +! call json%get(p,'GEN3LED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%GEN3LED) +! call json%get(p,'GEN4LED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%GEN4LED) +! call json%get(p,'SCR1LED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%SCR1LED) +! call json%get(p,'SCR2LED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%SCR2LED) +! call json%get(p,'SCR3LED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%SCR3LED) +! call json%get(p,'SCR4LED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%SCR4LED) +! call json%get(p,'MP1BLWR',pval) +! call json%get(pval,data%Equipments%DrillingConsole%MP1BLWR) +! call json%get(p,'MP2BLWR',pval) +! call json%get(pval,data%Equipments%DrillingConsole%MP2BLWR) +! call json%get(p,'DWBLWR',pval) +! call json%get(pval,data%Equipments%DrillingConsole%DWBLWR) +! call json%get(p,'RTBLWR',pval) +! call json%get(pval,data%Equipments%DrillingConsole%RTBLWR) +! call json%get(p,'PWRLIM',pval) +! call json%get(pval,data%Equipments%DrillingConsole%PWRLIM) +! call json%get(p,'PWRLIMMTR',pval) +! call json%get(pval,data%Equipments%DrillingConsole%PWRLIMMTR) +! call json%get(p,'RTTorqueLimitGauge',pval) +! call json%get(pval,data%Equipments%DrillingConsole%RTTorqueLimitGauge) +! call json%get(p,'AutoDWLED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%AutoDWLED) +! call json%get(p,'GEN1BTNLED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%GEN1BTNLED) +! call json%get(p,'GEN2BTNLED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%GEN2BTNLED) +! call json%get(p,'GEN3BTNLED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%GEN3BTNLED) +! call json%get(p,'GEN4BTNLED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%GEN4BTNLED) +! call json%get(p,'OpenKellyCockLed',pval) +! call json%get(pval,data%Equipments%DrillingConsole%OpenKellyCockLed) +! call json%get(p,'CloseKellyCockLed',pval) +! call json%get(pval,data%Equipments%DrillingConsole%CloseKellyCockLed) +! call json%get(p,'OpenSafetyValveLed',pval) +! call json%get(pval,data%Equipments%DrillingConsole%OpenSafetyValveLed) +! call json%get(p,'CloseSafetyValveLed',pval) +! call json%get(pval,data%Equipments%DrillingConsole%CloseSafetyValveLed) +! call json%get(p,'IRSafetyValveLed',pval) +! call json%get(pval,data%Equipments%DrillingConsole%IRSafetyValveLed) +! call json%get(p,'IRIBopLed',pval) +! call json%get(pval,data%Equipments%DrillingConsole%IRIBopLed) +! call json%get(p,'LatchPipeLED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%LatchPipeLED) +! call json%get(p,'UnlatchPipeLED',pval) +! call json%get(pval,data%Equipments%DrillingConsole%UnlatchPipeLED) +! call json%get(p,'SwingLed',pval) +! call json%get(pval,data%Equipments%DrillingConsole%SwingLed) +! call json%get(p,'FillMouseHoleLed',pval) +! call json%get(pval,data%Equipments%DrillingConsole%FillMouseHoleLed) + end subroutine + + subroutine DrillingConsoleToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Drilling') +! call json%add(p,"AssignmentSwitch",data%Equipments%DrillingConsole%AssignmentSwitch) +! call json%add(p,"EmergencySwitch",data%Equipments%DrillingConsole%EmergencySwitch) +! call json%add(p,"RTTorqueLimitKnob",data%Equipments%DrillingConsole%RTTorqueLimitKnob) +! call json%add(p,"MP1CPSwitchI",data%Equipments%DrillingConsole%MP1CPSwitchI) +! call json%add(p,"MP1CPSwitchT",data%Equipments%DrillingConsole%MP1CPSwitchT) +! call json%add(p,"MP1CPSwitch",data%Equipments%DrillingConsole%MP1CPSwitch) +! call json%add(p,"MP1ThrottleUpdate",data%Equipments%DrillingConsole%MP1ThrottleUpdate) +! call json%add(p,"MP1Throttle",data%Equipments%DrillingConsole%MP1Throttle) +! call json%add(p,"MP2SwitchI",data%Equipments%DrillingConsole%MP2SwitchI) +! call json%add(p,"MP2SwitchT",data%Equipments%DrillingConsole%MP2SwitchT) +! call json%add(p,"MP2Switch",data%Equipments%DrillingConsole%MP2Switch) +! call json%add(p,"MP2ThrottleUpdate",data%Equipments%DrillingConsole%MP2ThrottleUpdate) +! call json%add(p,"MP2Throttle",data%Equipments%DrillingConsole%MP2Throttle) +! call json%add(p,"DWSwitch",data%Equipments%DrillingConsole%DWSwitch) +! call json%add(p,"DWThrottle",data%Equipments%DrillingConsole%DWThrottle) +! call json%add(p,"RTSwitch",data%Equipments%DrillingConsole%RTSwitch) +! call json%add(p,"RTThrottle",data%Equipments%DrillingConsole%RTThrottle) +! call json%add(p,"DWBreak",data%Equipments%DrillingConsole%DWBreak) +! call json%add(p,"PreviousDWBreak",data%Equipments%DrillingConsole%PreviousDWBreak) +! call json%add(p,"ForceBreak",data%Equipments%DrillingConsole%ForceBreak) +! call json%add(p,"DWAcceleretor",data%Equipments%DrillingConsole%DWAcceleretor) +! call json%add(p,"DWTransmisionLever",data%Equipments%DrillingConsole%DWTransmisionLever) +! call json%add(p,"DWPowerLever",data%Equipments%DrillingConsole%DWPowerLever) +! call json%add(p,"TongLever",data%Equipments%DrillingConsole%TongLever) +! call json%add(p,"RTTransmissionLever",data%Equipments%DrillingConsole%RTTransmissionLever) +! call json%add(p,"DWClutchLever",data%Equipments%DrillingConsole%DWClutchLever) +! call json%add(p,"EddyBreakLever",data%Equipments%DrillingConsole%EddyBreakLever) +! call json%add(p,"AutoDW",data%Equipments%DrillingConsole%AutoDW) +! call json%add(p,"GEN1",data%Equipments%DrillingConsole%GEN1) +! call json%add(p,"GEN2",data%Equipments%DrillingConsole%GEN2) +! call json%add(p,"GEN3",data%Equipments%DrillingConsole%GEN3) +! call json%add(p,"GEN4",data%Equipments%DrillingConsole%GEN4) +! call json%add(p,"Permission_OpenKellyCock",data%Equipments%DrillingConsole%Permission_OpenKellyCock) +! call json%add(p,"OpenKellyCock",data%Equipments%DrillingConsole%OpenKellyCock) +! call json%add(p,"Permission_CloseKellyCock",data%Equipments%DrillingConsole%Permission_CloseKellyCock) +! call json%add(p,"CloseKellyCock",data%Equipments%DrillingConsole%CloseKellyCock) +! call json%add(p,"Permission_OpenSafetyValve",data%Equipments%DrillingConsole%Permission_OpenSafetyValve) +! call json%add(p,"OpenSafetyValve",data%Equipments%DrillingConsole%OpenSafetyValve) +! call json%add(p,"Permission_CloseSafetyValve",data%Equipments%DrillingConsole%Permission_CloseSafetyValve) +! call json%add(p,"CloseSafetyValve",data%Equipments%DrillingConsole%CloseSafetyValve) +! call json%add(p,"Permission_IRSafetyValve",data%Equipments%DrillingConsole%Permission_IRSafetyValve) +! call json%add(p,"IRSafetyValve",data%Equipments%DrillingConsole%IRSafetyValve) +! call json%add(p,"Permission_IRIBop",data%Equipments%DrillingConsole%Permission_IRIBop) +! call json%add(p,"IRIBop",data%Equipments%DrillingConsole%IRIBop) +! call json%add(p,"LatchPipe",data%Equipments%DrillingConsole%LatchPipe) +! call json%add(p,"UnlatchPipe",data%Equipments%DrillingConsole%UnlatchPipe) +! call json%add(p,"Swing",data%Equipments%DrillingConsole%Swing) +! call json%add(p,"FillMouseHole",data%Equipments%DrillingConsole%FillMouseHole) +! call json%add(p,"Slips",data%Equipments%DrillingConsole%Slips) +! call json%add(p,"BrakeLeverCoefficient",data%Equipments%DrillingConsole%BrakeLeverCoefficient) +! call json%add(p,"HideDrillingBrake",data%Equipments%DrillingConsole%HideDrillingBrake) +! call json%add(p,"ParkingBrakeBtn",data%Equipments%DrillingConsole%ParkingBrakeBtn) + + + + call json%add(p,"ParkingBrakeLed",data%Equipments%DrillingConsole%ParkingBrakeLed) + call json%add(p,"GEN1LED",data%Equipments%DrillingConsole%GEN1LED) + call json%add(p,"GEN2LED",data%Equipments%DrillingConsole%GEN2LED) + call json%add(p,"GEN3LED",data%Equipments%DrillingConsole%GEN3LED) + call json%add(p,"GEN4LED",data%Equipments%DrillingConsole%GEN4LED) + call json%add(p,"SCR1LED",data%Equipments%DrillingConsole%SCR1LED) + call json%add(p,"SCR2LED",data%Equipments%DrillingConsole%SCR2LED) + call json%add(p,"SCR3LED",data%Equipments%DrillingConsole%SCR3LED) + call json%add(p,"SCR4LED",data%Equipments%DrillingConsole%SCR4LED) + call json%add(p,"MP1BLWR",data%Equipments%DrillingConsole%MP1BLWR) + call json%add(p,"MP2BLWR",data%Equipments%DrillingConsole%MP2BLWR) + call json%add(p,"DWBLWR",data%Equipments%DrillingConsole%DWBLWR) + call json%add(p,"RTBLWR",data%Equipments%DrillingConsole%RTBLWR) + call json%add(p,"PWRLIM",data%Equipments%DrillingConsole%PWRLIM) + call json%add(p,"PWRLIMMTR",data%Equipments%DrillingConsole%PWRLIMMTR) + call json%add(p,"RTTorqueLimitGauge",data%Equipments%DrillingConsole%RTTorqueLimitGauge) + call json%add(p,"AutoDWLED",data%Equipments%DrillingConsole%AutoDWLED) + call json%add(p,"GEN1BTNLED",data%Equipments%DrillingConsole%GEN1BTNLED) + call json%add(p,"GEN2BTNLED",data%Equipments%DrillingConsole%GEN2BTNLED) + call json%add(p,"GEN3BTNLED",data%Equipments%DrillingConsole%GEN3BTNLED) + call json%add(p,"GEN4BTNLED",data%Equipments%DrillingConsole%GEN4BTNLED) + call json%add(p,"OpenKellyCockLed",data%Equipments%DrillingConsole%OpenKellyCockLed) + call json%add(p,"CloseKellyCockLed",data%Equipments%DrillingConsole%CloseKellyCockLed) + call json%add(p,"OpenSafetyValveLed",data%Equipments%DrillingConsole%OpenSafetyValveLed) + call json%add(p,"CloseSafetyValveLed",data%Equipments%DrillingConsole%CloseSafetyValveLed) + call json%add(p,"IRSafetyValveLed",data%Equipments%DrillingConsole%IRSafetyValveLed) + call json%add(p,"IRIBopLed",data%Equipments%DrillingConsole%IRIBopLed) + call json%add(p,"LatchPipeLED",data%Equipments%DrillingConsole%LatchPipeLED) + call json%add(p,"UnlatchPipeLED",data%Equipments%DrillingConsole%UnlatchPipeLED) + call json%add(p,"SwingLed",data%Equipments%DrillingConsole%SwingLed) + call json%add(p,"FillMouseHoleLed",data%Equipments%DrillingConsole%FillMouseHoleLed) + + call json%add(parent,p) + end subroutine + +end module CDrillingConsole diff --git a/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.f90 b/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.f90 index 78c9204..ef8dcae 100644 --- a/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.f90 +++ b/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.f90 @@ -23,20 +23,13 @@ module CDrillingConsoleVariables real(8) :: DWThrottle integer :: RTSwitch real(8) :: RTThrottle - real(8) :: DWBreak real(8) :: PreviousDWBreak logical :: ForceBreak = .false. - real(8) :: DWAcceleretor real(8) :: DWTransmisionLever real(8) :: DWPowerLever - real(8) :: TongLever - ! ! type(VoidEventHandlerCollection) :: OnBreakoutLeverPress - ! ! type(VoidEventHandlerCollection) :: OnMakeupLeverPress - ! ! type(VoidEventHandlerCollection) :: OnTongNeutralPress - real(8) :: RTTransmissionLever real(8) :: DWClutchLever real(8) :: EddyBreakLever @@ -47,52 +40,23 @@ module CDrillingConsoleVariables logical :: GEN4 logical :: Permission_OpenKellyCock = .false. logical :: OpenKellyCock - ! ! type(VoidEventHandlerCollection) :: OnOpenKellyCockPress - logical :: Permission_CloseKellyCock = .false. logical :: CloseKellyCock - ! ! type(VoidEventHandlerCollection) :: OnCloseKellyCockPress - logical :: Permission_OpenSafetyValve = .false. logical :: OpenSafetyValve - ! typeVoidEventHandlerCollection) :: OnOpenSafetyValvePress - logical :: Permission_CloseSafetyValve = .false. logical :: CloseSafetyValve - ! typeVoidEventHandlerCollection) :: OnCloseSafetyValvePress - logical :: Permission_IRSafetyValve = .false. logical :: IRSafetyValve - ! typeVoidEventHandlerCollection) :: OnIRSafetyValvePress - logical :: Permission_IRIBop = .false. logical :: IRIBop - ! typeVoidEventHandlerCollection) :: OnIRIBopPress - logical :: LatchPipe - ! typeVoidEventHandlerCollection) :: OnLatchPipePress - logical :: UnlatchPipe - ! typeVoidEventHandlerCollection) :: OnUnlatchPipePress - logical :: Swing - ! typeVoidEventHandlerCollection) :: OnSwingPress - logical :: FillMouseHole - ! typeVoidEventHandlerCollection) :: OnFillMouseHolePress - logical :: Slips - ! typeVoidEventHandlerCollection) :: OnSlipsPress - - !logical :: TopDriveIBop - ! - !logical :: TopDriveDrillTorque - !integer :: TopDriveRevOffFwd - !integer :: TopDriveDrillOffTilt - real :: BrakeLeverCoefficient logical :: HideDrillingBrake - logical :: ParkingBrakeBtn ! Output vars diff --git a/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.i90 b/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.i90 new file mode 100644 index 0000000..53acdc0 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.i90 @@ -0,0 +1,98 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CDrillingConsoleVariables.f90" +module CDrillingConsoleVariables + +! use CVoidEventHandlerCollection + implicit none + public + + TYPE, PUBLIC :: DrillingConsoleType +! Input vars + integer :: AssignmentSwitch + logical :: EmergencySwitch + real(8) :: RTTorqueLimitKnob + integer :: MP1CPSwitchI = 0 !for not turning on pump1 on simulation start + integer :: MP1CPSwitchT !for not turning on pump1 on simulation start + integer :: MP1CPSwitch + logical :: MP1ThrottleUpdate = .false. + real(8) :: MP1Throttle = -1.0 + integer :: MP2SwitchI = 0 !for not turning on pump2 on simulation start + logical :: MP2SwitchT !for not turning on pump2 on simulation start + logical :: MP2Switch + logical :: MP2ThrottleUpdate = .false. + real(8) :: MP2Throttle = -1.0 + integer :: DWSwitch + real(8) :: DWThrottle + integer :: RTSwitch + real(8) :: RTThrottle + real(8) :: DWBreak + real(8) :: PreviousDWBreak + logical :: ForceBreak = .false. + real(8) :: DWAcceleretor + real(8) :: DWTransmisionLever + real(8) :: DWPowerLever + real(8) :: TongLever + real(8) :: RTTransmissionLever + real(8) :: DWClutchLever + real(8) :: EddyBreakLever + logical :: AutoDW + logical :: GEN1 + logical :: GEN2 + logical :: GEN3 + logical :: GEN4 + logical :: Permission_OpenKellyCock = .false. + logical :: OpenKellyCock + logical :: Permission_CloseKellyCock = .false. + logical :: CloseKellyCock + logical :: Permission_OpenSafetyValve = .false. + logical :: OpenSafetyValve + logical :: Permission_CloseSafetyValve = .false. + logical :: CloseSafetyValve + logical :: Permission_IRSafetyValve = .false. + logical :: IRSafetyValve + logical :: Permission_IRIBop = .false. + logical :: IRIBop + logical :: LatchPipe + logical :: UnlatchPipe + logical :: Swing + logical :: FillMouseHole + logical :: Slips + real :: BrakeLeverCoefficient + logical :: HideDrillingBrake + logical :: ParkingBrakeBtn + +! Output vars + logical :: ParkingBrakeLed + integer :: GEN1LED + integer :: GEN2LED + integer :: GEN3LED + integer :: GEN4LED + integer :: SCR1LED + integer :: SCR2LED + integer :: SCR3LED + integer :: SCR4LED + integer :: MP1BLWR + integer :: MP2BLWR + integer :: DWBLWR + integer :: RTBLWR + integer :: PWRLIM + real(8) :: PWRLIMMTR + real(8) :: RTTorqueLimitGauge + integer :: AutoDWLED + integer :: GEN1BTNLED + integer :: GEN2BTNLED + integer :: GEN3BTNLED + integer :: GEN4BTNLED + integer :: OpenKellyCockLed + integer :: CloseKellyCockLed + integer :: OpenSafetyValveLed + integer :: CloseSafetyValveLed + integer :: IRSafetyValveLed + integer :: IRIBopLed + + integer :: LatchPipeLED + integer :: UnlatchPipeLED + integer :: SwingLed + integer :: FillMouseHoleLed + END TYPE DrillingConsoleType + +end module CDrillingConsoleVariables diff --git a/CSharp/Equipments/ControlPanels/CHook.f90 b/CSharp/Equipments/ControlPanels/CHook.f90 index 780c07b..bff93cb 100644 --- a/CSharp/Equipments/ControlPanels/CHook.f90 +++ b/CSharp/Equipments/ControlPanels/CHook.f90 @@ -5,6 +5,21 @@ module CHook public contains + subroutine HookFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + ! 1. get related root + ! call json%get(parent,'Hook',p) + + ! ! 2. get member of data type from node + ! call json%get(p,'HookHeight_S',pval) + ! call json%get(pval,data%Equipments%Hook%HookHeight_S) + ! call json%get(p,'HookHeight',pval) + ! call json%get(pval,data%Equipments%Hook%HookHeight) + end subroutine + subroutine HookToJson(parent) type(json_value),pointer :: parent @@ -13,33 +28,32 @@ module CHook ! 1. create new node call json%create_object(p,'Hook') - call json%add(p,"HookHeight_S",data%EquipmentControl%Hook%HookHeight_S) - call json%add(p,"HookHeight",data%EquipmentControl%Hook%HookHeight) + call json%add(p,"HookHeight_S",data%Equipments%Hook%HookHeight_S) + call json%add(p,"HookHeight",data%Equipments%Hook%HookHeight) call json%add(parent,p) end subroutine subroutine Set_HookHeight(v) use CDrillingConsoleVariables - use SimulationVariables - use SimulationVariables + use SimulationVariables implicit none real , intent(in) :: v -#ifdef ExcludeExtraChanges - if(data%EquipmentControl%Hook%HookHeight == v) return -#endif - data%EquipmentControl%Hook%HookHeight = v + #ifdef ExcludeExtraChanges + if(data%Equipments%Hook%HookHeight == v) return + #endif + data%Equipments%Hook%HookHeight = v ! if(associated(HookHeightPtr)) then - ! call HookHeightPtr(data%EquipmentControl%Hook%HookHeight) + ! call HookHeightPtr(data%Equipments%Hook%HookHeight) ! end if -#ifdef deb - print*, 'HookHeight=', data%EquipmentControl%Hook%HookHeight -#endif + #ifdef deb + print*, 'HookHeight=', data%Equipments%Hook%HookHeight + #endif - !**call data%EquipmentControl%Hook%OnHookHeightChange%RunAll(data%EquipmentControl%Hook%HookHeight) + !**call data%Equipments%Hook%OnHookHeightChange%RunAll(data%Equipments%Hook%HookHeight) end subroutine @@ -47,12 +61,12 @@ module CHook implicit none real , intent(in) :: v - if(v == data%EquipmentControl%Hook%HookHeight) then + if(v == data%Equipments%Hook%HookHeight) then return - elseif (v > data%EquipmentControl%Hook%HookHeight) then + elseif (v > data%Equipments%Hook%HookHeight) then loop1: do - call Set_HookHeight(data%EquipmentControl%Hook%HookHeight + 0.2) - if(abs(v - data%EquipmentControl%Hook%HookHeight) <= 0.1) then + call Set_HookHeight(data%Equipments%Hook%HookHeight + 0.2) + if(abs(v - data%Equipments%Hook%HookHeight) <= 0.1) then call Set_HookHeight(v) exit loop1 endif @@ -60,8 +74,8 @@ module CHook enddo loop1 else ! v < HookHeight loop2: do - call Set_HookHeight(data%EquipmentControl%Hook%HookHeight - 0.2) - if(abs(data%EquipmentControl%Hook%HookHeight - v) <= 0.1) then + call Set_HookHeight(data%Equipments%Hook%HookHeight - 0.2) + if(abs(data%Equipments%Hook%HookHeight - v) <= 0.1) then call Set_HookHeight(v) exit loop2 endif @@ -73,6 +87,6 @@ module CHook subroutine Update_HookHeight_From_Snapshot() implicit none - call Set_HookHeight_S(data%EquipmentControl%Hook%HookHeight_S) + call Set_HookHeight_S(data%Equipments%Hook%HookHeight_S) end subroutine end module CHook diff --git a/CSharp/Equipments/ControlPanels/CHook.i90 b/CSharp/Equipments/ControlPanels/CHook.i90 new file mode 100644 index 0000000..48aaa17 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CHook.i90 @@ -0,0 +1,93 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CHook.f90" +module CHook + use CHookVariables + use SimulationVariables + implicit none + public + contains + + subroutine HookFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + +! 1. get related root +! call json%get(parent,'Hook',p) + +! ! 2. get member of data type from node +! call json%get(p,'HookHeight_S',pval) +! call json%get(pval,data%Equipments%Hook%HookHeight_S) +! call json%get(p,'HookHeight',pval) +! call json%get(pval,data%Equipments%Hook%HookHeight) + end subroutine + + subroutine HookToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Hook') + call json%add(p,"HookHeight_S",data%Equipments%Hook%HookHeight_S) + call json%add(p,"HookHeight",data%Equipments%Hook%HookHeight) + + call json%add(parent,p) + end subroutine + + subroutine Set_HookHeight(v) + use CDrillingConsoleVariables + use SimulationVariables + implicit none + real , intent(in) :: v + + #ifdef ExcludeExtraChanges + if(data%Equipments%Hook%HookHeight == v) return + #endif + data%Equipments%Hook%HookHeight = v + +! if(associated(HookHeightPtr)) then +! call HookHeightPtr(data%Equipments%Hook%HookHeight) +! end if + + #ifdef deb + print*, 'HookHeight=', data%Equipments%Hook%HookHeight + #endif + +!**call data%Equipments%Hook%OnHookHeightChange%RunAll(data%Equipments%Hook%HookHeight) + end subroutine + + + subroutine Set_HookHeight_S(v) + implicit none + real , intent(in) :: v + + if(v == data%Equipments%Hook%HookHeight) then + return + elseif (v > data%Equipments%Hook%HookHeight) then + loop1: do + call Set_HookHeight(data%Equipments%Hook%HookHeight + 0.2) + if(abs(v - data%Equipments%Hook%HookHeight) <= 0.1) then + call Set_HookHeight(v) + exit loop1 + endif + call sleepqq(100) + enddo loop1 + else ! v < HookHeight + loop2: do + call Set_HookHeight(data%Equipments%Hook%HookHeight - 0.2) + if(abs(data%Equipments%Hook%HookHeight - v) <= 0.1) then + call Set_HookHeight(v) + exit loop2 + endif + call sleepqq(100) + enddo loop2 + endif + + end subroutine + + subroutine Update_HookHeight_From_Snapshot() + implicit none + call Set_HookHeight_S(data%Equipments%Hook%HookHeight_S) + end subroutine + end module CHook diff --git a/CSharp/Equipments/ControlPanels/CHookVariables.f90 b/CSharp/Equipments/ControlPanels/CHookVariables.f90 index c6e8f06..8bbcad5 100644 --- a/CSharp/Equipments/ControlPanels/CHookVariables.f90 +++ b/CSharp/Equipments/ControlPanels/CHookVariables.f90 @@ -5,7 +5,6 @@ module CHookVariables Type :: HookType real :: HookHeight_S = 0.0 real :: HookHeight - !**type(RealEventHandlerCollection) :: OnHookHeightChange end type HookType diff --git a/CSharp/Equipments/ControlPanels/CHookVariables.i90 b/CSharp/Equipments/ControlPanels/CHookVariables.i90 new file mode 100644 index 0000000..8e080c8 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CHookVariables.i90 @@ -0,0 +1,16 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CHookVariables.f90" +module CHookVariables +!**use CRealEventHandlerCollection +! use CHookActions + implicit none + Type :: HookType + real :: HookHeight_S = 0.0 + real :: HookHeight + end type HookType + + + contains + + + +end module CHookVariables diff --git a/CSharp/Equipments/ControlPanels/CStandPipeManifold.f90 b/CSharp/Equipments/ControlPanels/CStandPipeManifold.f90 index 26fae58..c34cd78 100644 --- a/CSharp/Equipments/ControlPanels/CStandPipeManifold.f90 +++ b/CSharp/Equipments/ControlPanels/CStandPipeManifold.f90 @@ -7,6 +7,52 @@ module CStandPipeManifold contains + subroutine StandPipeManifoldFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + logical::is_found + + ! 1. get related root + call json%get(parent,'StandPipeManifold',p) + + ! 2. get member of data type from node + call json%get(p,'StandPipeManifoldValve1',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve1) + call json%get(p,'StandPipeManifoldValve2',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve2) + call json%get(p,'StandPipeManifoldValve3',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve3) + call json%get(p,'StandPipeManifoldValve4',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve4) + call json%get(p,'StandPipeManifoldValve5',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve5) + call json%get(p,'StandPipeManifoldValve6',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve6) + call json%get(p,'StandPipeManifoldValve7',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve7) + call json%get(p,'StandPipeManifoldValve8',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve8) + call json%get(p,'StandPipeManifoldValve9',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve9) + call json%get(p,'StandPipeManifoldValve10',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve10) + call json%get(p,'StandPipeManifoldValve11',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve11) + call json%get(p,'StandPipeManifoldValve12',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve12) + call json%get(p,'StandPipeManifoldValve13',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve13) + call json%get(p,'StandPipeManifoldValve14',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve14) + call json%get(p,'StandPipeManifoldValve15',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve15) + ! call json%get(p,'StandPipeGauge1',pval) + ! call json%get(pval,data%Equipments%StandPipeManifold%StandPipeGauge1) + ! call json%get(p,'StandPipeGauge2',pval) + ! call json%get(pval,data%Equipments%StandPipeManifold%StandPipeGauge2) + end subroutine + subroutine StandPipeManifoldToJson(parent) type(json_value),pointer :: parent @@ -16,23 +62,24 @@ module CStandPipeManifold ! 1. create new node call json%create_object(p,'StandPipeManifold') - call json%add(p,"StandPipeManifoldValve1",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve1) - call json%add(p,"StandPipeManifoldValve2",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve2) - call json%add(p,"StandPipeManifoldValve3",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve3) - call json%add(p,"StandPipeManifoldValve4",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve4) - call json%add(p,"StandPipeManifoldValve5",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve5) - call json%add(p,"StandPipeManifoldValve6",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve6) - call json%add(p,"StandPipeManifoldValve7",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve7) - call json%add(p,"StandPipeManifoldValve8",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve8) - call json%add(p,"StandPipeManifoldValve9",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve9) - call json%add(p,"StandPipeManifoldValve10",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve10) - call json%add(p,"StandPipeManifoldValve11",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve11) - call json%add(p,"StandPipeManifoldValve12",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve12) - call json%add(p,"StandPipeManifoldValve13",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve13) - call json%add(p,"StandPipeManifoldValve14",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve14) - call json%add(p,"StandPipeManifoldValve15",data%EquipmentControl%StandPipeManifold%StandPipeManifoldValve15) - call json%add(p,"StandPipeGauge1",data%EquipmentControl%StandPipeManifold%StandPipeGauge1) - call json%add(p,"StandPipeGauge2",data%EquipmentControl%StandPipeManifold%StandPipeGauge2) + ! call json%add(p,"StandPipeManifoldValve1",data%Equipments%StandPipeManifold%StandPipeManifoldValve1) + ! call json%add(p,"StandPipeManifoldValve2",data%Equipments%StandPipeManifold%StandPipeManifoldValve2) + ! call json%add(p,"StandPipeManifoldValve3",data%Equipments%StandPipeManifold%StandPipeManifoldValve3) + ! call json%add(p,"StandPipeManifoldValve4",data%Equipments%StandPipeManifold%StandPipeManifoldValve4) + ! call json%add(p,"StandPipeManifoldValve5",data%Equipments%StandPipeManifold%StandPipeManifoldValve5) + ! call json%add(p,"StandPipeManifoldValve6",data%Equipments%StandPipeManifold%StandPipeManifoldValve6) + ! call json%add(p,"StandPipeManifoldValve7",data%Equipments%StandPipeManifold%StandPipeManifoldValve7) + ! call json%add(p,"StandPipeManifoldValve8",data%Equipments%StandPipeManifold%StandPipeManifoldValve8) + ! call json%add(p,"StandPipeManifoldValve9",data%Equipments%StandPipeManifold%StandPipeManifoldValve9) + ! call json%add(p,"StandPipeManifoldValve10",data%Equipments%StandPipeManifold%StandPipeManifoldValve10) + ! call json%add(p,"StandPipeManifoldValve11",data%Equipments%StandPipeManifold%StandPipeManifoldValve11) + ! call json%add(p,"StandPipeManifoldValve12",data%Equipments%StandPipeManifold%StandPipeManifoldValve12) + ! call json%add(p,"StandPipeManifoldValve13",data%Equipments%StandPipeManifold%StandPipeManifoldValve13) + ! call json%add(p,"StandPipeManifoldValve14",data%Equipments%StandPipeManifold%StandPipeManifoldValve14) + ! call json%add(p,"StandPipeManifoldValve15",data%Equipments%StandPipeManifold%StandPipeManifoldValve15) + + call json%add(p,"StandPipeGauge1",data%Equipments%StandPipeManifold%StandPipeGauge1) + call json%add(p,"StandPipeGauge2",data%Equipments%StandPipeManifold%StandPipeGauge2) call json%add(parent,p) end subroutine diff --git a/CSharp/Equipments/ControlPanels/CStandPipeManifold.i90 b/CSharp/Equipments/ControlPanels/CStandPipeManifold.i90 new file mode 100644 index 0000000..1922750 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CStandPipeManifold.i90 @@ -0,0 +1,88 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CStandPipeManifold.f90" +module CStandPipeManifold + use CStandPipeManifoldVariables + use SimulationVariables + use CManifolds + implicit none + public + contains + + + subroutine StandPipeManifoldFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + logical::is_found + +! 1. get related root + call json%get(parent,'StandPipeManifold',p) + +! 2. get member of data type from node + call json%get(p,'StandPipeManifoldValve1',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve1) + call json%get(p,'StandPipeManifoldValve2',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve2) + call json%get(p,'StandPipeManifoldValve3',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve3) + call json%get(p,'StandPipeManifoldValve4',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve4) + call json%get(p,'StandPipeManifoldValve5',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve5) + call json%get(p,'StandPipeManifoldValve6',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve6) + call json%get(p,'StandPipeManifoldValve7',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve7) + call json%get(p,'StandPipeManifoldValve8',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve8) + call json%get(p,'StandPipeManifoldValve9',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve9) + call json%get(p,'StandPipeManifoldValve10',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve10) + call json%get(p,'StandPipeManifoldValve11',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve11) + call json%get(p,'StandPipeManifoldValve12',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve12) + call json%get(p,'StandPipeManifoldValve13',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve13) + call json%get(p,'StandPipeManifoldValve14',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve14) + call json%get(p,'StandPipeManifoldValve15',pval) + call json%get(pval,data%Equipments%StandPipeManifold%StandPipeManifoldValve15) +! call json%get(p,'StandPipeGauge1',pval) +! call json%get(pval,data%Equipments%StandPipeManifold%StandPipeGauge1) +! call json%get(p,'StandPipeGauge2',pval) +! call json%get(pval,data%Equipments%StandPipeManifold%StandPipeGauge2) + end subroutine + + subroutine StandPipeManifoldToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'StandPipeManifold') + +! call json%add(p,"StandPipeManifoldValve1",data%Equipments%StandPipeManifold%StandPipeManifoldValve1) +! call json%add(p,"StandPipeManifoldValve2",data%Equipments%StandPipeManifold%StandPipeManifoldValve2) +! call json%add(p,"StandPipeManifoldValve3",data%Equipments%StandPipeManifold%StandPipeManifoldValve3) +! call json%add(p,"StandPipeManifoldValve4",data%Equipments%StandPipeManifold%StandPipeManifoldValve4) +! call json%add(p,"StandPipeManifoldValve5",data%Equipments%StandPipeManifold%StandPipeManifoldValve5) +! call json%add(p,"StandPipeManifoldValve6",data%Equipments%StandPipeManifold%StandPipeManifoldValve6) +! call json%add(p,"StandPipeManifoldValve7",data%Equipments%StandPipeManifold%StandPipeManifoldValve7) +! call json%add(p,"StandPipeManifoldValve8",data%Equipments%StandPipeManifold%StandPipeManifoldValve8) +! call json%add(p,"StandPipeManifoldValve9",data%Equipments%StandPipeManifold%StandPipeManifoldValve9) +! call json%add(p,"StandPipeManifoldValve10",data%Equipments%StandPipeManifold%StandPipeManifoldValve10) +! call json%add(p,"StandPipeManifoldValve11",data%Equipments%StandPipeManifold%StandPipeManifoldValve11) +! call json%add(p,"StandPipeManifoldValve12",data%Equipments%StandPipeManifold%StandPipeManifoldValve12) +! call json%add(p,"StandPipeManifoldValve13",data%Equipments%StandPipeManifold%StandPipeManifoldValve13) +! call json%add(p,"StandPipeManifoldValve14",data%Equipments%StandPipeManifold%StandPipeManifoldValve14) +! call json%add(p,"StandPipeManifoldValve15",data%Equipments%StandPipeManifold%StandPipeManifoldValve15) + + call json%add(p,"StandPipeGauge1",data%Equipments%StandPipeManifold%StandPipeGauge1) + call json%add(p,"StandPipeGauge2",data%Equipments%StandPipeManifold%StandPipeGauge2) + + call json%add(parent,p) + end subroutine + +end module CStandPipeManifold diff --git a/CSharp/Equipments/ControlPanels/CStandPipeManifoldVariables.i90 b/CSharp/Equipments/ControlPanels/CStandPipeManifoldVariables.i90 new file mode 100644 index 0000000..5bccfae --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CStandPipeManifoldVariables.i90 @@ -0,0 +1,29 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CStandPipeManifoldVariables.f90" +module CStandPipeManifoldVariables + implicit none + public + + Type::StandPipeManifoldType +! Input vars + logical :: StandPipeManifoldValve1 + logical :: StandPipeManifoldValve2 + logical :: StandPipeManifoldValve3 + logical :: StandPipeManifoldValve4 + logical :: StandPipeManifoldValve5 + logical :: StandPipeManifoldValve6 + logical :: StandPipeManifoldValve7 + logical :: StandPipeManifoldValve8 + logical :: StandPipeManifoldValve9 + logical :: StandPipeManifoldValve10 + logical :: StandPipeManifoldValve11 + logical :: StandPipeManifoldValve12 + logical :: StandPipeManifoldValve13 + logical :: StandPipeManifoldValve14 + logical :: StandPipeManifoldValve15 + +! Output vars + real(8) :: StandPipeGauge1 + real(8) :: StandPipeGauge2 + End type StandPipeManifoldType + +end module CStandPipeManifoldVariables diff --git a/CSharp/Equipments/ControlPanels/CTopDrivePanel.f90 b/CSharp/Equipments/ControlPanels/CTopDrivePanel.f90 index cc747dc..157cc45 100644 --- a/CSharp/Equipments/ControlPanels/CTopDrivePanel.f90 +++ b/CSharp/Equipments/ControlPanels/CTopDrivePanel.f90 @@ -6,32 +6,74 @@ module CTopDrivePanel public contains + subroutine TopDrivePanelFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + logical::is_found + + ! 1. get related root + call json%get(parent,'TopDrivePanel',p) + + ! 2. get member of data type from node + call json%get(p,'TopDriveTdsPowerState',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTdsPowerState) + call json%get(p,'TopDriveTorqueWrench',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTorqueWrench) + call json%get(p,'TopDriveDrillTorqueState',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveDrillTorqueState) + call json%get(p,'TopDriveLinkTiltState',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveLinkTiltState) + call json%get(p,'TopDriveIbop',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveIbop) + call json%get(p,'TopDriveTorqueLimitKnob',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTorqueLimitKnob) + call json%get(p,'RpmKnob',pval) + call json%get(pval,data%Equipments%TopDrivePanel%RpmKnob) + + ! call json%get(p,'TopDriveOperationFaultLed',pval) + ! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveOperationFaultLed) + ! call json%get(p,'TopDriveTdsPowerLed',pval) + ! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTdsPowerLed) + ! call json%get(p,'TopDriveTorqueWrenchLed',pval) + ! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed) + ! call json%get(p,'TopDriveLinkTiltLed',pval) + ! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveLinkTiltLed) + ! call json%get(p,'TopDriveIbopLed',pval) + ! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveIbopLed) + ! call json%get(p,'TopDriveTorqueLimitGauge',pval) + ! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTorqueLimitGauge) + ! call json%get(p,'TopDriveTorqueGauge',pval) + ! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTorqueGauge) + ! call json%get(p,'TopDriveRpmGauge',pval) + ! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveRpmGauge) + end subroutine + subroutine TopDrivePanelToJson(parent) type(json_value),pointer :: parent type(json_core) :: json type(json_value),pointer :: p,pform - integer :: i - ! 1. create new node call json%create_object(p,'TopDrivePanel') - - call json%add(pform,"TopDriveTdsPowerState",data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState) - call json%add(pform,"TopDriveTorqueWrench",data%EquipmentControl%TopDrivePanel%TopDriveTorqueWrench) - call json%add(pform,"TopDriveDrillTorqueState",data%EquipmentControl%TopDrivePanel%TopDriveDrillTorqueState) - call json%add(pform,"TopDriveLinkTiltState",data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState) - call json%add(pform,"TopDriveIbop",data%EquipmentControl%TopDrivePanel%TopDriveIbop) - call json%add(pform,"TopDriveTorqueLimitKnob",data%EquipmentControl%TopDrivePanel%TopDriveTorqueLimitKnob) - call json%add(pform,"RpmKnob",data%EquipmentControl%TopDrivePanel%RpmKnob) - call json%add(pform,"TopDriveOperationFaultLed",data%EquipmentControl%TopDrivePanel%TopDriveOperationFaultLed) - call json%add(pform,"TopDriveTdsPowerLed",data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerLed) - call json%add(pform,"TopDriveTorqueWrenchLed",data%EquipmentControl%TopDrivePanel%TopDriveTorqueWrenchLed) - call json%add(pform,"TopDriveLinkTiltLed",data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed) - call json%add(pform,"TopDriveIbopLed",data%EquipmentControl%TopDrivePanel%TopDriveIbopLed) - call json%add(pform,"TopDriveTorqueLimitGauge",data%EquipmentControl%TopDrivePanel%TopDriveTorqueLimitGauge) - call json%add(pform,"TopDriveTorqueGauge",data%EquipmentControl%TopDrivePanel%TopDriveTorqueGauge) - call json%add(pform,"TopDriveRpmGauge",data%EquipmentControl%TopDrivePanel%TopDriveRpmGauge) + + ! call json%add(pform,"TopDriveTdsPowerState",data%Equipments%TopDrivePanel%TopDriveTdsPowerState) + ! call json%add(pform,"TopDriveTorqueWrench",data%Equipments%TopDrivePanel%TopDriveTorqueWrench) + ! call json%add(pform,"TopDriveDrillTorqueState",data%Equipments%TopDrivePanel%TopDriveDrillTorqueState) + ! call json%add(pform,"TopDriveLinkTiltState",data%Equipments%TopDrivePanel%TopDriveLinkTiltState) + ! call json%add(pform,"TopDriveIbop",data%Equipments%TopDrivePanel%TopDriveIbop) + ! call json%add(pform,"TopDriveTorqueLimitKnob",data%Equipments%TopDrivePanel%TopDriveTorqueLimitKnob) + ! call json%add(pform,"RpmKnob",data%Equipments%TopDrivePanel%RpmKnob) + + call json%add(pform,"TopDriveOperationFaultLed",data%Equipments%TopDrivePanel%TopDriveOperationFaultLed) + call json%add(pform,"TopDriveTdsPowerLed",data%Equipments%TopDrivePanel%TopDriveTdsPowerLed) + call json%add(pform,"TopDriveTorqueWrenchLed",data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed) + call json%add(pform,"TopDriveLinkTiltLed",data%Equipments%TopDrivePanel%TopDriveLinkTiltLed) + call json%add(pform,"TopDriveIbopLed",data%Equipments%TopDrivePanel%TopDriveIbopLed) + call json%add(pform,"TopDriveTorqueLimitGauge",data%Equipments%TopDrivePanel%TopDriveTorqueLimitGauge) + call json%add(pform,"TopDriveTorqueGauge",data%Equipments%TopDrivePanel%TopDriveTorqueGauge) + call json%add(pform,"TopDriveRpmGauge",data%Equipments%TopDrivePanel%TopDriveRpmGauge) call json%add(parent,p) diff --git a/CSharp/Equipments/ControlPanels/CTopDrivePanel.i90 b/CSharp/Equipments/ControlPanels/CTopDrivePanel.i90 new file mode 100644 index 0000000..149c763 --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CTopDrivePanel.i90 @@ -0,0 +1,83 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CTopDrivePanel.f90" +module CTopDrivePanel + use CTopDrivePanelVariables + use SimulationVariables + use CLog3 + implicit none + public + contains + + subroutine TopDrivePanelFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + logical::is_found + +! 1. get related root + call json%get(parent,'TopDrivePanel',p) + +! 2. get member of data type from node + call json%get(p,'TopDriveTdsPowerState',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTdsPowerState) + call json%get(p,'TopDriveTorqueWrench',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTorqueWrench) + call json%get(p,'TopDriveDrillTorqueState',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveDrillTorqueState) + call json%get(p,'TopDriveLinkTiltState',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveLinkTiltState) + call json%get(p,'TopDriveIbop',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveIbop) + call json%get(p,'TopDriveTorqueLimitKnob',pval) + call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTorqueLimitKnob) + call json%get(p,'RpmKnob',pval) + call json%get(pval,data%Equipments%TopDrivePanel%RpmKnob) + +! call json%get(p,'TopDriveOperationFaultLed',pval) +! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveOperationFaultLed) +! call json%get(p,'TopDriveTdsPowerLed',pval) +! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTdsPowerLed) +! call json%get(p,'TopDriveTorqueWrenchLed',pval) +! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed) +! call json%get(p,'TopDriveLinkTiltLed',pval) +! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveLinkTiltLed) +! call json%get(p,'TopDriveIbopLed',pval) +! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveIbopLed) +! call json%get(p,'TopDriveTorqueLimitGauge',pval) +! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTorqueLimitGauge) +! call json%get(p,'TopDriveTorqueGauge',pval) +! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveTorqueGauge) +! call json%get(p,'TopDriveRpmGauge',pval) +! call json%get(pval,data%Equipments%TopDrivePanel%TopDriveRpmGauge) + end subroutine + + subroutine TopDrivePanelToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pform + +! 1. create new node + call json%create_object(p,'TopDrivePanel') + +! call json%add(pform,"TopDriveTdsPowerState",data%Equipments%TopDrivePanel%TopDriveTdsPowerState) +! call json%add(pform,"TopDriveTorqueWrench",data%Equipments%TopDrivePanel%TopDriveTorqueWrench) +! call json%add(pform,"TopDriveDrillTorqueState",data%Equipments%TopDrivePanel%TopDriveDrillTorqueState) +! call json%add(pform,"TopDriveLinkTiltState",data%Equipments%TopDrivePanel%TopDriveLinkTiltState) +! call json%add(pform,"TopDriveIbop",data%Equipments%TopDrivePanel%TopDriveIbop) +! call json%add(pform,"TopDriveTorqueLimitKnob",data%Equipments%TopDrivePanel%TopDriveTorqueLimitKnob) +! call json%add(pform,"RpmKnob",data%Equipments%TopDrivePanel%RpmKnob) + + call json%add(pform,"TopDriveOperationFaultLed",data%Equipments%TopDrivePanel%TopDriveOperationFaultLed) + call json%add(pform,"TopDriveTdsPowerLed",data%Equipments%TopDrivePanel%TopDriveTdsPowerLed) + call json%add(pform,"TopDriveTorqueWrenchLed",data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed) + call json%add(pform,"TopDriveLinkTiltLed",data%Equipments%TopDrivePanel%TopDriveLinkTiltLed) + call json%add(pform,"TopDriveIbopLed",data%Equipments%TopDrivePanel%TopDriveIbopLed) + call json%add(pform,"TopDriveTorqueLimitGauge",data%Equipments%TopDrivePanel%TopDriveTorqueLimitGauge) + call json%add(pform,"TopDriveTorqueGauge",data%Equipments%TopDrivePanel%TopDriveTorqueGauge) + call json%add(pform,"TopDriveRpmGauge",data%Equipments%TopDrivePanel%TopDriveRpmGauge) + + + call json%add(parent,p) + end subroutine + +end module CTopDrivePanel diff --git a/CSharp/Equipments/ControlPanels/CTopDrivePanelVariables.f90 b/CSharp/Equipments/ControlPanels/CTopDrivePanelVariables.f90 index 46cfb10..654710e 100644 --- a/CSharp/Equipments/ControlPanels/CTopDrivePanelVariables.f90 +++ b/CSharp/Equipments/ControlPanels/CTopDrivePanelVariables.f90 @@ -21,6 +21,7 @@ module CTopDrivePanelVariables ! Input vars Type::TopDrivePanelType + ! Input vars @mahmood integer :: TopDriveTdsPowerState logical :: TopDriveTorqueWrench integer :: TopDriveDrillTorqueState @@ -28,6 +29,7 @@ module CTopDrivePanelVariables logical :: TopDriveIbop real :: TopDriveTorqueLimitKnob real :: RpmKnob + ! Output vars integer :: TopDriveOperationFaultLed integer :: TopDriveTdsPowerLed diff --git a/CSharp/Equipments/ControlPanels/CTopDrivePanelVariables.i90 b/CSharp/Equipments/ControlPanels/CTopDrivePanelVariables.i90 new file mode 100644 index 0000000..796fe1c --- /dev/null +++ b/CSharp/Equipments/ControlPanels/CTopDrivePanelVariables.i90 @@ -0,0 +1,45 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/ControlPanels/CTopDrivePanelVariables.f90" +module CTopDrivePanelVariables + implicit none + public + +! const + integer :: TdsPower_REV = 1 + integer :: TdsPower_OFF = 0 + integer :: TdsPower_FWD = -1 + + integer :: TdsMu_TORQ = 1 + integer :: TdsMu_SPINE = 0 + integer :: TdsMu_DRILL = -1 + + integer :: TdsLinkTilt_TILT = 1 + integer :: TdsLinkTilt_OFF = 0 + integer :: TdsLinkTilt_DRILL = -1 + + integer :: LED_OFF = 0 + integer :: LED_ON = 1 + integer :: LED_BLINK = 2 + +! Input vars + Type::TopDrivePanelType +! Input vars @mahmood + integer :: TopDriveTdsPowerState + logical :: TopDriveTorqueWrench + integer :: TopDriveDrillTorqueState + integer :: TopDriveLinkTiltState + logical :: TopDriveIbop + real :: TopDriveTorqueLimitKnob + real :: RpmKnob + +! Output vars + integer :: TopDriveOperationFaultLed + integer :: TopDriveTdsPowerLed + integer :: TopDriveTorqueWrenchLed + integer :: TopDriveLinkTiltLed + integer :: TopDriveIbopLed + real :: TopDriveTorqueLimitGauge + real :: TopDriveTorqueGauge + real :: TopDriveRpmGauge + end type TopDrivePanelType + contains + end module CTopDrivePanelVariables diff --git a/CSharp/Equipments/DrillWatch/CDrillWatchVariables.i90 b/CSharp/Equipments/DrillWatch/CDrillWatchVariables.i90 new file mode 100644 index 0000000..e2e1d7e --- /dev/null +++ b/CSharp/Equipments/DrillWatch/CDrillWatchVariables.i90 @@ -0,0 +1,35 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/DrillWatch/CDrillWatchVariables.f90" +module CDrillWatchVariables + implicit none + + public + + +! Input vars + Type, Public::DrillingWatchType +! Output vars + real(8) :: Depth + real(8) :: BitPosition + real(8) :: HookLoad + real(8) :: WeightOnBit + real(8) :: RPM + real(8) :: ROP + real(8) :: Torque + real(8) :: PumpPressure + real(8) :: SPM1 + real(8) :: SPM2 +!real(8) :: SPM3 + real(8) :: CasingPressure + real(8) :: PercentFlow + real(8) :: PitGainLose + real(8) :: PitVolume + real(8) :: KillMudVolume + real(8) :: TripTankVolume + real(8) :: MudWeightIn + real(8) :: FillVolume + real(8) :: MudWeightOut + End Type DrillingWatchType + + + +end module CDrillWatchVariables diff --git a/CSharp/Equipments/DrillWatch/DrillWatch.f90 b/CSharp/Equipments/DrillWatch/DrillWatch.f90 index 9fc488c..1352a91 100644 --- a/CSharp/Equipments/DrillWatch/DrillWatch.f90 +++ b/CSharp/Equipments/DrillWatch/DrillWatch.f90 @@ -2,34 +2,83 @@ module DrillingWatchModule use SimulationVariables contains + ! subroutine DrillingWatchFromJson(parent) + ! type(json_value),pointer :: parent + ! type(json_core) :: json + ! type(json_value),pointer :: p,pval + ! logical::is_found + + ! ! 1. get related root + ! call json%get(parent,'DrillingWatch',p) + + ! ! 2. get member of data type from node + ! call json%get(p,'Depth',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%Depth) + ! call json%get(p,'BitPosition',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%BitPosition) + ! call json%get(p,'HookLoad',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%HookLoad) + ! call json%get(p,'WeightOnBit',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%WeightOnBit) + ! call json%get(p,'RPM',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%RPM) + ! call json%get(p,'ROP',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%ROP) + ! call json%get(p,'Torque',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%Torque) + ! call json%get(p,'PumpPressure',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%PumpPressure) + ! call json%get(p,'SPM1',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%SPM1) + ! call json%get(p,'SPM2',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%SPM2) + ! call json%get(p,'CasingPressure',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%CasingPressure) + ! call json%get(p,'PercentFlow',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%PercentFlow) + ! call json%get(p,'PitGainLose',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%PitGainLose) + ! call json%get(p,'PitVolume',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%PitVolume) + ! call json%get(p,'KillMudVolume',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%KillMudVolume) + ! call json%get(p,'TripTankVolume',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%TripTankVolume) + ! call json%get(p,'MudWeightIn',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%MudWeightIn) + ! call json%get(p,'FillVolume',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%FillVolume) + ! call json%get(p,'MudWeightOut',pval) + ! call json%get(pval,data%Equipments%DrillingWatch%MudWeightOut) + ! end subroutine + subroutine DrillingWatchToJson(parent) type(json_value),pointer :: parent type(json_core) :: json type(json_value),pointer :: p - integer :: i ! 1. create new node call json%create_object(p,'DrillingWatch') - call json%add(p,"Depth",data%EquipmentControl%DrillingWatch%Depth) - call json%add(p,"BitPosition",data%EquipmentControl%DrillingWatch%BitPosition) - call json%add(p,"HookLoad",data%EquipmentControl%DrillingWatch%HookLoad) - call json%add(p,"WeightOnBit",data%EquipmentControl%DrillingWatch%WeightOnBit) - call json%add(p,"RPM",data%EquipmentControl%DrillingWatch%RPM) - call json%add(p,"ROP",data%EquipmentControl%DrillingWatch%ROP) - call json%add(p,"Torque",data%EquipmentControl%DrillingWatch%Torque) - call json%add(p,"PumpPressure",data%EquipmentControl%DrillingWatch%PumpPressure) - call json%add(p,"SPM1",data%EquipmentControl%DrillingWatch%SPM1) - call json%add(p,"SPM2",data%EquipmentControl%DrillingWatch%SPM2) - call json%add(p,"CasingPressure",data%EquipmentControl%DrillingWatch%CasingPressure) - call json%add(p,"PercentFlow",data%EquipmentControl%DrillingWatch%PercentFlow) - call json%add(p,"PitGainLose",data%EquipmentControl%DrillingWatch%PitGainLose) - call json%add(p,"PitVolume",data%EquipmentControl%DrillingWatch%PitVolume) - call json%add(p,"KillMudVolume",data%EquipmentControl%DrillingWatch%KillMudVolume) - call json%add(p,"TripTankVolume",data%EquipmentControl%DrillingWatch%TripTankVolume) - call json%add(p,"MudWeightIn",data%EquipmentControl%DrillingWatch%MudWeightIn) - call json%add(p,"FillVolume",data%EquipmentControl%DrillingWatch%FillVolume) - call json%add(p,"MudWeightOut",data%EquipmentControl%DrillingWatch%MudWeightOut) + call json%add(p,"Depth",data%Equipments%DrillingWatch%Depth) + call json%add(p,"BitPosition",data%Equipments%DrillingWatch%BitPosition) + call json%add(p,"HookLoad",data%Equipments%DrillingWatch%HookLoad) + call json%add(p,"WeightOnBit",data%Equipments%DrillingWatch%WeightOnBit) + call json%add(p,"RPM",data%Equipments%DrillingWatch%RPM) + call json%add(p,"ROP",data%Equipments%DrillingWatch%ROP) + call json%add(p,"Torque",data%Equipments%DrillingWatch%Torque) + call json%add(p,"PumpPressure",data%Equipments%DrillingWatch%PumpPressure) + call json%add(p,"SPM1",data%Equipments%DrillingWatch%SPM1) + call json%add(p,"SPM2",data%Equipments%DrillingWatch%SPM2) + call json%add(p,"CasingPressure",data%Equipments%DrillingWatch%CasingPressure) + call json%add(p,"PercentFlow",data%Equipments%DrillingWatch%PercentFlow) + call json%add(p,"PitGainLose",data%Equipments%DrillingWatch%PitGainLose) + call json%add(p,"PitVolume",data%Equipments%DrillingWatch%PitVolume) + call json%add(p,"KillMudVolume",data%Equipments%DrillingWatch%KillMudVolume) + call json%add(p,"TripTankVolume",data%Equipments%DrillingWatch%TripTankVolume) + call json%add(p,"MudWeightIn",data%Equipments%DrillingWatch%MudWeightIn) + call json%add(p,"FillVolume",data%Equipments%DrillingWatch%FillVolume) + call json%add(p,"MudWeightOut",data%Equipments%DrillingWatch%MudWeightOut) call json%add(parent,p) end subroutine diff --git a/CSharp/Equipments/DrillWatch/DrillWatch.i90 b/CSharp/Equipments/DrillWatch/DrillWatch.i90 new file mode 100644 index 0000000..662059c --- /dev/null +++ b/CSharp/Equipments/DrillWatch/DrillWatch.i90 @@ -0,0 +1,87 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/DrillWatch/DrillWatch.f90" +module DrillingWatchModule + use SimulationVariables + contains + +! subroutine DrillingWatchFromJson(parent) +! type(json_value),pointer :: parent +! type(json_core) :: json +! type(json_value),pointer :: p,pval +! logical::is_found + +! ! 1. get related root +! call json%get(parent,'DrillingWatch',p) + +! ! 2. get member of data type from node +! call json%get(p,'Depth',pval) +! call json%get(pval,data%Equipments%DrillingWatch%Depth) +! call json%get(p,'BitPosition',pval) +! call json%get(pval,data%Equipments%DrillingWatch%BitPosition) +! call json%get(p,'HookLoad',pval) +! call json%get(pval,data%Equipments%DrillingWatch%HookLoad) +! call json%get(p,'WeightOnBit',pval) +! call json%get(pval,data%Equipments%DrillingWatch%WeightOnBit) +! call json%get(p,'RPM',pval) +! call json%get(pval,data%Equipments%DrillingWatch%RPM) +! call json%get(p,'ROP',pval) +! call json%get(pval,data%Equipments%DrillingWatch%ROP) +! call json%get(p,'Torque',pval) +! call json%get(pval,data%Equipments%DrillingWatch%Torque) +! call json%get(p,'PumpPressure',pval) +! call json%get(pval,data%Equipments%DrillingWatch%PumpPressure) +! call json%get(p,'SPM1',pval) +! call json%get(pval,data%Equipments%DrillingWatch%SPM1) +! call json%get(p,'SPM2',pval) +! call json%get(pval,data%Equipments%DrillingWatch%SPM2) +! call json%get(p,'CasingPressure',pval) +! call json%get(pval,data%Equipments%DrillingWatch%CasingPressure) +! call json%get(p,'PercentFlow',pval) +! call json%get(pval,data%Equipments%DrillingWatch%PercentFlow) +! call json%get(p,'PitGainLose',pval) +! call json%get(pval,data%Equipments%DrillingWatch%PitGainLose) +! call json%get(p,'PitVolume',pval) +! call json%get(pval,data%Equipments%DrillingWatch%PitVolume) +! call json%get(p,'KillMudVolume',pval) +! call json%get(pval,data%Equipments%DrillingWatch%KillMudVolume) +! call json%get(p,'TripTankVolume',pval) +! call json%get(pval,data%Equipments%DrillingWatch%TripTankVolume) +! call json%get(p,'MudWeightIn',pval) +! call json%get(pval,data%Equipments%DrillingWatch%MudWeightIn) +! call json%get(p,'FillVolume',pval) +! call json%get(pval,data%Equipments%DrillingWatch%FillVolume) +! call json%get(p,'MudWeightOut',pval) +! call json%get(pval,data%Equipments%DrillingWatch%MudWeightOut) +! end subroutine + + subroutine DrillingWatchToJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'DrillingWatch') + + call json%add(p,"Depth",data%Equipments%DrillingWatch%Depth) + call json%add(p,"BitPosition",data%Equipments%DrillingWatch%BitPosition) + call json%add(p,"HookLoad",data%Equipments%DrillingWatch%HookLoad) + call json%add(p,"WeightOnBit",data%Equipments%DrillingWatch%WeightOnBit) + call json%add(p,"RPM",data%Equipments%DrillingWatch%RPM) + call json%add(p,"ROP",data%Equipments%DrillingWatch%ROP) + call json%add(p,"Torque",data%Equipments%DrillingWatch%Torque) + call json%add(p,"PumpPressure",data%Equipments%DrillingWatch%PumpPressure) + call json%add(p,"SPM1",data%Equipments%DrillingWatch%SPM1) + call json%add(p,"SPM2",data%Equipments%DrillingWatch%SPM2) + call json%add(p,"CasingPressure",data%Equipments%DrillingWatch%CasingPressure) + call json%add(p,"PercentFlow",data%Equipments%DrillingWatch%PercentFlow) + call json%add(p,"PitGainLose",data%Equipments%DrillingWatch%PitGainLose) + call json%add(p,"PitVolume",data%Equipments%DrillingWatch%PitVolume) + call json%add(p,"KillMudVolume",data%Equipments%DrillingWatch%KillMudVolume) + call json%add(p,"TripTankVolume",data%Equipments%DrillingWatch%TripTankVolume) + call json%add(p,"MudWeightIn",data%Equipments%DrillingWatch%MudWeightIn) + call json%add(p,"FillVolume",data%Equipments%DrillingWatch%FillVolume) + call json%add(p,"MudWeightOut",data%Equipments%DrillingWatch%MudWeightOut) + + call json%add(parent,p) + end subroutine + +end module DrillingWatchModule diff --git a/CSharp/Equipments/MudPathFinding/CManifolds.f90 b/CSharp/Equipments/MudPathFinding/CManifolds.f90 index 52334b9..48cddbf 100644 --- a/CSharp/Equipments/MudPathFinding/CManifolds.f90 +++ b/CSharp/Equipments/MudPathFinding/CManifolds.f90 @@ -770,7 +770,7 @@ end subroutine PathFinding_Step print*, 'InstallSafetyValve_KellyMode()' #endif - data%EquipmentControl%DrillingConsole%IRSafetyValveLed = 1 + data%Equipments%DrillingConsole%IRSafetyValveLed = 1 call OpenSafetyValve_KellyMode() end subroutine @@ -787,10 +787,10 @@ end subroutine PathFinding_Step call Manifold%Valve(127)%AdjacentTo(128) call Manifold%Valve(128)%AdjacentTo(127) - data%EquipmentControl%DrillingConsole%IRSafetyValveLed = 0 + data%Equipments%DrillingConsole%IRSafetyValveLed = 0 call CloseSafetyValve_KellyMode() - data%EquipmentControl%DrillingConsole%OpenSafetyValveLed = 0 - data%EquipmentControl%DrillingConsole%CloseSafetyValveLed = 0 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 #ifdef deb print*, 'RemoveSafetyValve_KellyMode()' @@ -801,8 +801,8 @@ end subroutine PathFinding_Step subroutine OpenSafetyValve_KellyMode() implicit none if(.not.Manifold%IsSafetyValveInstalled_KellyMode) return - data%EquipmentControl%DrillingConsole%OpenSafetyValveLed = 1 - data%EquipmentControl%DrillingConsole%CloseSafetyValveLed = 0 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 1 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 Manifold%SafetyValve = .true. call ChangeValve(56, Manifold%SafetyValve) @@ -815,8 +815,8 @@ end subroutine PathFinding_Step subroutine CloseSafetyValve_KellyMode() implicit none if(.not.Manifold%IsSafetyValveInstalled_KellyMode) return - data%EquipmentControl%DrillingConsole%CloseSafetyValveLed = 1 - data%EquipmentControl%DrillingConsole%OpenSafetyValveLed = 0 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 1 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 Manifold%SafetyValve = .false. call ChangeValve(56, Manifold%SafetyValve) @@ -858,7 +858,7 @@ end subroutine PathFinding_Step call Manifold%Valve(54)%AdjacentTo(69) call Manifold%Valve(69)%AdjacentTo(54) - data%EquipmentControl%DrillingConsole%IRSafetyValveLed = 1 + data%Equipments%DrillingConsole%IRSafetyValveLed = 1 call OpenSafetyValve_TripMode() #ifdef deb @@ -880,10 +880,10 @@ end subroutine PathFinding_Step call Manifold%Valve(124)%AdjacentTo(69) call Manifold%Valve(69)%AdjacentTo(124) - data%EquipmentControl%DrillingConsole%IRSafetyValveLed = 0 + data%Equipments%DrillingConsole%IRSafetyValveLed = 0 call CloseSafetyValve_TripMode() - data%EquipmentControl%DrillingConsole%OpenSafetyValveLed = 0 - data%EquipmentControl%DrillingConsole%CloseSafetyValveLed = 0 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 #ifdef deb print*, 'RemoveSafetyValve_TripMode()' @@ -894,8 +894,8 @@ end subroutine PathFinding_Step subroutine OpenSafetyValve_TripMode() implicit none if(.not.Manifold%IsSafetyValveInstalled_TripMode) return - data%EquipmentControl%DrillingConsole%OpenSafetyValveLed = 1 - data%EquipmentControl%DrillingConsole%CloseSafetyValveLed = 0 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 1 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 Manifold%SafetyValve = .true. call ChangeValve(54, Manifold%SafetyValve) @@ -908,8 +908,8 @@ end subroutine PathFinding_Step subroutine CloseSafetyValve_TripMode() implicit none if(.not.Manifold%IsSafetyValveInstalled_TripMode) return - data%EquipmentControl%DrillingConsole%CloseSafetyValveLed = 1 - data%EquipmentControl%DrillingConsole%OpenSafetyValveLed = 0 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 1 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 Manifold%SafetyValve = .false. call ChangeValve(54, Manifold%SafetyValve) @@ -945,7 +945,7 @@ end subroutine PathFinding_Step call Manifold%Valve(54)%AdjacentTo(69) call Manifold%Valve(69)%AdjacentTo(54) - data%EquipmentControl%DrillingConsole%IRSafetyValveLed = 1 + data%Equipments%DrillingConsole%IRSafetyValveLed = 1 call OpenSafetyValve_TopDrive() #ifdef deb @@ -967,10 +967,10 @@ end subroutine PathFinding_Step call Manifold%Valve(124)%AdjacentTo(69) call Manifold%Valve(69)%AdjacentTo(124) - data%EquipmentControl%DrillingConsole%IRSafetyValveLed = 0 + data%Equipments%DrillingConsole%IRSafetyValveLed = 0 call CloseSafetyValve_TopDrive() - data%EquipmentControl%DrillingConsole%OpenSafetyValveLed = 0 - data%EquipmentControl%DrillingConsole%CloseSafetyValveLed = 0 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 #ifdef deb print*, 'RemoveSafetyValve_TopDrive()' @@ -981,8 +981,8 @@ end subroutine PathFinding_Step subroutine OpenSafetyValve_TopDrive() implicit none if(.not.Manifold%IsSafetyValveInstalled_TopDrive) return - data%EquipmentControl%DrillingConsole%OpenSafetyValveLed = 1 - data%EquipmentControl%DrillingConsole%CloseSafetyValveLed = 0 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 1 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 Manifold%SafetyValve = .true. #ifdef deb @@ -995,8 +995,8 @@ end subroutine PathFinding_Step subroutine CloseSafetyValve_TopDrive() implicit none if(.not.Manifold%IsSafetyValveInstalled_TopDrive) return - data%EquipmentControl%DrillingConsole%CloseSafetyValveLed = 1 - data%EquipmentControl%DrillingConsole%OpenSafetyValveLed = 0 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 1 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 Manifold%SafetyValve = .false. #ifdef deb @@ -1031,7 +1031,7 @@ end subroutine PathFinding_Step print*, 'InstallIBop()' #endif - data%EquipmentControl%DrillingConsole%IRIBopLed = 1 + data%Equipments%DrillingConsole%IRIBopLed = 1 call OpenIBop() end subroutine @@ -1052,7 +1052,7 @@ end subroutine PathFinding_Step print*, 'RemoveIBop()' #endif - data%EquipmentControl%DrillingConsole%IRIBopLed = 0 + data%Equipments%DrillingConsole%IRIBopLed = 0 Manifold%IBop = .false. call ChangeValve(55, Manifold%IBop) end subroutine @@ -1122,8 +1122,8 @@ end subroutine PathFinding_Step Manifold%KellyCock = .false. call ChangeValve(68, Manifold%KellyCock) - data%EquipmentControl%DrillingConsole%CloseKellyCockLed = 0 - data%EquipmentControl%DrillingConsole%OpenKellyCockLed = 0 + data%Equipments%DrillingConsole%CloseKellyCockLed = 0 + data%Equipments%DrillingConsole%OpenKellyCockLed = 0 #ifdef deb print*, 'RemoveKellyCock()' @@ -1134,8 +1134,8 @@ end subroutine PathFinding_Step subroutine OpenKellyCock() implicit none if(.not.Manifold%IsKellyCockInstalled) return - data%EquipmentControl%DrillingConsole%OpenKellyCockLed = 1 - data%EquipmentControl%DrillingConsole%CloseKellyCockLed = 0 + data%Equipments%DrillingConsole%OpenKellyCockLed = 1 + data%Equipments%DrillingConsole%CloseKellyCockLed = 0 Manifold%KellyCock = .true. #ifdef deb @@ -1148,8 +1148,8 @@ end subroutine PathFinding_Step subroutine CloseKellyCock() implicit none if(.not.Manifold%IsKellyCockInstalled) return - data%EquipmentControl%DrillingConsole%CloseKellyCockLed = 1 - data%EquipmentControl%DrillingConsole%OpenKellyCockLed = 0 + data%Equipments%DrillingConsole%CloseKellyCockLed = 1 + data%Equipments%DrillingConsole%OpenKellyCockLed = 0 Manifold%KellyCock = .false. #ifdef deb diff --git a/CSharp/Equipments/MudPathFinding/CManifolds.i90 b/CSharp/Equipments/MudPathFinding/CManifolds.i90 new file mode 100644 index 0000000..9cef151 --- /dev/null +++ b/CSharp/Equipments/MudPathFinding/CManifolds.i90 @@ -0,0 +1,1357 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/MudPathFinding/CManifolds.f90" +module CManifolds + use CStack + use CArrangement +! use CPathChangeEvents +! use CDrillingConsoleVariables + use SimulationVariables +! use ConfigurationVariables, only: EquipmentControl + + implicit none + + public + integer, parameter :: ValveCount = 128 + integer, parameter :: MinSource = 71 + integer, parameter :: MaxSource = 90 + integer, parameter :: MinRelation = 91 + integer, parameter :: MaxRelation = 128 + + Type::ManifoldType + type(Arrangement) :: Valve(ValveCount) + type(Path), allocatable :: OpenPaths(:) + type(Stack) :: Fringe + logical :: IsRepititveOutput + + logical :: IsSafetyValveInstalled + logical :: IsSafetyValveInstalled_KellyMode + logical :: IsSafetyValveInstalled_TripMode + logical :: IsSafetyValveInstalled_TopDrive + logical :: SafetyValve + logical :: IsIBopInstalled + logical :: IBop + logical :: IsKellyCockInstalled + logical :: KellyCock + logical :: IsTopDriveIBopInstalled + logical :: TopDriveIBop + logical :: IsFloatValveInstalled + logical :: FloatValve + logical :: IsPathsDirty = .false. + logical :: IsTraverse = .false. + End type ManifoldType + type(ManifoldType)::Manifold + contains + + subroutine PathFinding_Setup() +! use CSimulationVariables + implicit none + Manifold%IsTraverse = .false. + call Setup() +!call OnSimulationInitialization%Add(PathFinding_Init) +!call OnSimulationStop%Add(PathFinding_Init) +!!**call OnpPathFindingStep%Add(PathFinding_Step) +!!**call OnpPathFindingOutput%Add(PathFinding_Output) +! !**call OnpPathFindingMain%Add(PathFindingMainBody) + end subroutine + + subroutine PathFinding_Init + implicit none + Manifold%IsTraverse = .false. + call Setup() + end subroutine PathFinding_Init + + subroutine PathFinding_Step + if (Manifold%IsPathsDirty) then + Manifold%IsPathsDirty = .false. + call Traverse() + endif +end subroutine PathFinding_Step + +! subroutine PathFinding_Output +! implicit none +! end subroutine PathFinding_Output + +! subroutine PathFindingMainBody +! ! use CSimulationVariables +! implicit none +! loop : do +! if(IsStopped) call Quit() +! call sleepqq(50) +! if (Manifold%IsPathsDirty) then +! Manifold%IsPathsDirty = .false. +! call Traverse() +! endif +! end do loop +! end subroutine PathFindingMainBody + + subroutine Traverse() + use CLog5 + implicit none + integer :: i, Duration + integer, dimension(8) :: StartTime,EndTime !TODO: clean up + call DATE_AND_TIME(values=StartTime) !TODO: clean up + +!**call BeforeTraverse%RunAll() + + + if(allocated(Manifold%OpenPaths)) deallocate(Manifold%OpenPaths) + do i=MinSource, MaxSource + if(IsValveOpen(i)) then + call AddRootNode(i) + call AddChildren(Manifold%Valve(i)) + endif + enddo + + call PostProcess(Manifold%OpenPaths) + +!**call AfterTraverse%RunAll() + + Manifold%IsTraverse = .true. + +!TODO: clean up +# 118 + + + endsubroutine + + subroutine PostProcess(pathArr) + implicit none + type(Path), allocatable, intent(inout) :: pathArr(:) + integer :: i + + if(.not.allocated(pathArr)) return + + i = 1 + do + call pathArr(i)%Purge(MinRelation, MaxRelation) + + if(pathArr(i)%Length() <= 2) then + call RemovePath(pathArr, i) + else + i = i + 1 + endif + + if(i > size(pathArr)) exit + enddo + + end subroutine + + subroutine AddRootNode(valve) + implicit none + integer, intent(in) :: valve + call Manifold%Fringe%Push(valve) + end subroutine + + recursive subroutine AddChildren(node) + implicit none + type(Arrangement), intent(inout) :: node + integer :: i,t + + do i=1, Manifold%Valve(node%Number)%Length() + t = Manifold%Valve(node%Number)%Adjacent(i) + + if(IsValveOpen(t)) then + + if(Manifold%Fringe%DoesHave(t)) cycle + + call Manifold%Fringe%Push(t) + + if(Manifold%Valve(t)%IsSource()) then + call AddPath(Manifold%OpenPaths, Manifold%Fringe%List) + call Manifold%Fringe%Pop() + cycle + endif + + call AddChildren(Manifold%Valve(node%Adjacent(i))) + + end if + enddo + call Manifold%Fringe%Pop() + end subroutine + + logical function IsValveOpen(no) + implicit none + integer, intent(in) :: no + + IsValveOpen = Manifold%Valve(no)%Status + + end function + + subroutine AddPath(pathArr, p) + implicit none + type(Path), intent(in) :: p + type(Path), allocatable, intent(inout) :: pathArr(:) + type(Path), allocatable :: tempArr(:) + integer :: i, isize + + if(p%IsNull()) return + if(p%Length()<=1) return + +!**call OnpPathOpen%RunAll(p%Valves) + + if(allocated(pathArr)) then + isize = size(pathArr) + + +! check to see if already have a path same as p + do i=1,isize + if(pathArr(i)%First()==p%First() .and. pathArr(i)%Last()==p%Last()) then +! if there is then +! check to see if both have exacly a same length + if(pathArr(i)%Length()==p%Length())then +! now they are the same so ignore adding this one + return + else +!if they have different lengths then choose the shorter one + if(pathArr(i)%Length()>p%Length())pathArr(i) = p + return + endif + + endif + end do + + + +!TODO: if p last valve is input source then ignore adding it +!TODO: if p start valve is output source then ignore adding it + + + +! if p is a new entry then add it to the collections of found paths + allocate(tempArr(isize+1)) + do i=1,isize + tempArr(i) = pathArr(i) + end do + tempArr(isize+1) = p + deallocate(pathArr) + call move_alloc(tempArr, pathArr) + else + allocate(pathArr(1)) + pathArr(1) = p + end if + + endsubroutine + + subroutine RemovePath(pathArr, index) + implicit none + integer, intent(in) :: index + type(Path), allocatable, intent(inout) :: pathArr(:) + type(Path), allocatable :: tempArr(:) + integer :: i + logical :: found + + if(index <= 0 .or. index > size(pathArr)) return + if(.not.allocated(pathArr))return + allocate(tempArr(size(pathArr)-1)) + found = .false. + do i=1, size(pathArr) + if(i==index) then + found = .true. + cycle + end if + if(found) then + tempArr(i-1) = pathArr(i) +!!**call OnpPathClose%RunAll(pathArr(i)%Valves) + else + tempArr(i) = pathArr(i) + endif + end do + deallocate(pathArr) + call move_alloc(tempArr, pathArr) + + endsubroutine + + subroutine Setup() + implicit none + integer :: i + +! initialize all valves + do i = 1, ValveCount + call Manifold%Valve(i)%init(i) + end do + +! open source valves + do i = MinSource , MaxSource + Manifold%Valve(i)%Status = .true. + Manifold%Valve(i)%ValveType = InputOutput + end do + + do i = MinRelation , MaxRelation + Manifold%Valve(i)%Status = .true. + Manifold%Valve(i)%ValveType = Relation + end do + + + +! make adjustments + call Manifold%Valve(1)%AdjacentTo(91) + + call Manifold%Valve(2)%AdjacentTo(92) + call Manifold%Valve(2)%AdjacentTo(117) + + call Manifold%Valve(3)%AdjacentTo(93) + call Manifold%Valve(3)%AdjacentTo(118) + + call Manifold%Valve(4)%AdjacentTo(94) + + call Manifold%Valve(5)%AdjacentTo(95) + + call Manifold%Valve(6)%AdjacentTo(91) + call Manifold%Valve(6)%AdjacentTo(92) + + call Manifold%Valve(7)%AdjacentTo(92) + call Manifold%Valve(7)%AdjacentTo(93) + + call Manifold%Valve(8)%AdjacentTo(93) + call Manifold%Valve(8)%AdjacentTo(94) + + call Manifold%Valve(9)%AdjacentTo(91) + call Manifold%Valve(9)%AdjacentTo(96) + + call Manifold%Valve(10)%AdjacentTo(94) + call Manifold%Valve(10)%AdjacentTo(98) + + call Manifold%Valve(11)%AdjacentTo(96) + call Manifold%Valve(11)%AdjacentTo(97) + + call Manifold%Valve(12)%AdjacentTo(97) + call Manifold%Valve(12)%AdjacentTo(98) + + call Manifold%Valve(13)%AdjacentTo(96) + call Manifold%Valve(13)%AdjacentTo(99) + + call Manifold%Valve(14)%AdjacentTo(78) + call Manifold%Valve(14)%AdjacentTo(97) +!call Valve(14)%AdjacentTo(126) + + call Manifold%Valve(15)%AdjacentTo(98) + call Manifold%Valve(15)%AdjacentTo(99) + + call Manifold%Valve(16)%AdjacentTo(121) +!call Valve(16)%AdjacentTo() + + call Manifold%Valve(17)%AdjacentTo(122) +!call Valve(17)%AdjacentTo() + + call Manifold%Valve(18)%AdjacentTo(123) +!call Valve(18)%AdjacentTo() + + call Manifold%Valve(19)%AdjacentTo(101) + call Manifold%Valve(19)%AdjacentTo(102) + + call Manifold%Valve(20)%AdjacentTo(100) + + call Manifold%Valve(21)%AdjacentTo(101) + + call Manifold%Valve(22)%AdjacentTo(102) + + call Manifold%Valve(23)%AdjacentTo(71) + + call Manifold%Valve(24)%AdjacentTo(71) + + call Manifold%Valve(25)%AdjacentTo(108) + call Manifold%Valve(25)%AdjacentTo(118) + + call Manifold%Valve(26)%AdjacentTo(109) + call Manifold%Valve(26)%AdjacentTo(117) + + call Manifold%Valve(27)%AdjacentTo(32) + call Manifold%Valve(27)%AdjacentTo(108) + + call Manifold%Valve(28)%AdjacentTo(33) + call Manifold%Valve(28)%AdjacentTo(108) + + call Manifold%Valve(29)%AdjacentTo(110) + call Manifold%Valve(29)%AdjacentTo(113) + + call Manifold%Valve(30)%AdjacentTo(34) + call Manifold%Valve(30)%AdjacentTo(109) + + call Manifold%Valve(31)%AdjacentTo(35) + call Manifold%Valve(31)%AdjacentTo(109) + + call Manifold%Valve(32)%AdjacentTo(27) + call Manifold%Valve(32)%AdjacentTo(61) + + call Manifold%Valve(33)%AdjacentTo(28) + call Manifold%Valve(33)%AdjacentTo(62) + + call Manifold%Valve(34)%AdjacentTo(30) + call Manifold%Valve(34)%AdjacentTo(63) + + call Manifold%Valve(35)%AdjacentTo(31) + call Manifold%Valve(35)%AdjacentTo(64) + + call Manifold%Valve(36)%AdjacentTo(116) + + call Manifold%Valve(37)%AdjacentTo(78) + + call Manifold%Valve(38)%AdjacentTo(71) + + call Manifold%Valve(39)%AdjacentTo(77) + +!call Valve(40)%AdjacentTo(105) + call Manifold%Valve(40)%AdjacentTo(80) + + call Manifold%Valve(41)%AdjacentTo(77) + + call Manifold%Valve(42)%AdjacentTo(71) + + call Manifold%Valve(43)%AdjacentTo(106) + + call Manifold%Valve(44)%AdjacentTo(77) + + call Manifold%Valve(45)%AdjacentTo(71) + + call Manifold%Valve(46)%AdjacentTo(104) + + call Manifold%Valve(47)%AdjacentTo(104) + call Manifold%Valve(47)%AdjacentTo(117) + + call Manifold%Valve(48)%AdjacentTo(69) + call Manifold%Valve(48)%AdjacentTo(79) + + call Manifold%Valve(49)%AdjacentTo(104) + call Manifold%Valve(49)%AdjacentTo(79) + +!call Valve(50)%AdjacentTo(48) + call Manifold%Valve(50)%AdjacentTo(51) +!call Valve(50)%AdjacentTo(54) + call Manifold%Valve(50)%AdjacentTo(104) + + call Manifold%Valve(51)%AdjacentTo(50) + call Manifold%Valve(51)%AdjacentTo(52) + + call Manifold%Valve(52)%AdjacentTo(51) +!call Valve(52)%AdjacentTo(127) + call Manifold%Valve(52)%AdjacentTo(80) + +!call Valve(53)%AdjacentTo(103) +!call Valve(53)%AdjacentTo(105) + call Manifold%Valve(53)%AdjacentTo(80) + +!call Valve(54)%AdjacentTo(69) +!call Valve(54)%AdjacentTo(124) + +!call Valve(55)%AdjacentTo(103) +!call Valve(55)%AdjacentTo(124) + + call Manifold%Valve(56)%AdjacentTo(128) + call Manifold%Valve(56)%AdjacentTo(127) + +!call Valve(57)%AdjacentTo(14) +!call Valve(57)%AdjacentTo(103) +!call Valve(57)%AdjacentTo(126) + + call Manifold%Valve(58)%AdjacentTo(78) + + call Manifold%Valve(59)%AdjacentTo(78) + + call Manifold%Valve(60)%AdjacentTo(78) + + call Manifold%Valve(61)%AdjacentTo(32) + call Manifold%Valve(61)%AdjacentTo(115) + + call Manifold%Valve(62)%AdjacentTo(33) + call Manifold%Valve(62)%AdjacentTo(114) + + call Manifold%Valve(63)%AdjacentTo(112) + call Manifold%Valve(63)%AdjacentTo(34) + + call Manifold%Valve(64)%AdjacentTo(35) + call Manifold%Valve(64)%AdjacentTo(111) + + call Manifold%Valve(65)%AdjacentTo(120) + + call Manifold%Valve(66)%AdjacentTo(120) + + call Manifold%Valve(67)%AdjacentTo(73) + + call Manifold%Valve(68)%AdjacentTo(125) + call Manifold%Valve(68)%AdjacentTo(126) + + call Manifold%Valve(69)%AdjacentTo(48) + call Manifold%Valve(69)%AdjacentTo(124) + +!call Valve(70)%AdjacentTo() +!call Valve(70)%AdjacentTo() + + call Manifold%Valve(71)%AdjacentTo(20) + call Manifold%Valve(71)%AdjacentTo(44) + call Manifold%Valve(71)%AdjacentTo(59) + + call Manifold%Valve(72)%AdjacentTo(21) + call Manifold%Valve(72)%AdjacentTo(23) + + call Manifold%Valve(73)%AdjacentTo(22) + + call Manifold%Valve(74)%AdjacentTo(24) + +!call Valve(75)%AdjacentTo() + +!call Valve(76)%AdjacentTo() + + call Manifold%Valve(77)%AdjacentTo(43) + call Manifold%Valve(77)%AdjacentTo(58) + +!call Valve(78)%AdjacentTo() + + call Manifold%Valve(79)%AdjacentTo(48) + call Manifold%Valve(79)%AdjacentTo(49) + + call Manifold%Valve(80)%AdjacentTo(52) + call Manifold%Valve(80)%AdjacentTo(107) + + call Manifold%Valve(81)%AdjacentTo(53) + + call Manifold%Valve(82)%AdjacentTo(16) + + call Manifold%Valve(83)%AdjacentTo(17) + + call Manifold%Valve(84)%AdjacentTo(18) + +!call Valve(85)%AdjacentTo() + +!call Valve(86)%AdjacentTo() + +!call Valve(87)%AdjacentTo() + +!call Valve(88)%AdjacentTo() + +!!call Valve(89)%AdjacentTo() + +!call Valve(90)%AdjacentTo() + + call Manifold%Valve(91)%AdjacentTo(6) + call Manifold%Valve(91)%AdjacentTo(9) + call Manifold%Valve(91)%AdjacentTo(75) + + call Manifold%Valve(92)%AdjacentTo(6) + call Manifold%Valve(92)%AdjacentTo(7) + call Manifold%Valve(92)%AdjacentTo(2) + + call Manifold%Valve(93)%AdjacentTo(3) + call Manifold%Valve(93)%AdjacentTo(7) + call Manifold%Valve(93)%AdjacentTo(8) + + call Manifold%Valve(94)%AdjacentTo(8) + call Manifold%Valve(94)%AdjacentTo(10) + call Manifold%Valve(94)%AdjacentTo(95) + + call Manifold%Valve(95)%AdjacentTo(76) + call Manifold%Valve(95)%AdjacentTo(94) + + call Manifold%Valve(96)%AdjacentTo(9) + call Manifold%Valve(96)%AdjacentTo(11) + call Manifold%Valve(96)%AdjacentTo(13) + + call Manifold%Valve(97)%AdjacentTo(11) + call Manifold%Valve(97)%AdjacentTo(12) + call Manifold%Valve(97)%AdjacentTo(14) + + call Manifold%Valve(98)%AdjacentTo(10) + call Manifold%Valve(98)%AdjacentTo(12) + call Manifold%Valve(98)%AdjacentTo(15) + + call Manifold%Valve(99)%AdjacentTo(13) + call Manifold%Valve(99)%AdjacentTo(15) + call Manifold%Valve(99)%AdjacentTo(125) + +!call Valve(100)%AdjacentTo(16) + call Manifold%Valve(100)%AdjacentTo(82) + call Manifold%Valve(100)%AdjacentTo(101) + +!call Valve(101)%AdjacentTo(17) + call Manifold%Valve(101)%AdjacentTo(19) + call Manifold%Valve(101)%AdjacentTo(83) + call Manifold%Valve(101)%AdjacentTo(100) + +!call Valve(102)%AdjacentTo(18) + call Manifold%Valve(102)%AdjacentTo(19) + call Manifold%Valve(102)%AdjacentTo(84) + +!call Valve(103)%AdjacentTo(53) +!call Valve(103)%AdjacentTo(56) + call Manifold%Valve(103)%AdjacentTo(124) +!call Valve(103)%AdjacentTo(56) +!call Valve(103)%AdjacentTo(78) + + call Manifold%Valve(104)%AdjacentTo(46) + call Manifold%Valve(104)%AdjacentTo(47) + call Manifold%Valve(104)%AdjacentTo(49) + call Manifold%Valve(104)%AdjacentTo(50) + +!call Valve(105)%AdjacentTo(53) +!call Valve(105)%AdjacentTo(107) +!call Valve(105)%AdjacentTo(127) + + call Manifold%Valve(106)%AdjacentTo(40) + call Manifold%Valve(106)%AdjacentTo(45) + + + call Manifold%Valve(107)%AdjacentTo(41) +!call Valve(107)%AdjacentTo(105) + call Manifold%Valve(107)%AdjacentTo(119) +!call Valve(107)%AdjacentTo(42) + + call Manifold%Valve(108)%AdjacentTo(25) + call Manifold%Valve(108)%AdjacentTo(27) + call Manifold%Valve(108)%AdjacentTo(28) + call Manifold%Valve(108)%AdjacentTo(110) + + call Manifold%Valve(109)%AdjacentTo(26) + call Manifold%Valve(109)%AdjacentTo(30) + call Manifold%Valve(109)%AdjacentTo(31) + call Manifold%Valve(109)%AdjacentTo(110) + + call Manifold%Valve(110)%AdjacentTo(29) + call Manifold%Valve(110)%AdjacentTo(85) + call Manifold%Valve(110)%AdjacentTo(108) + call Manifold%Valve(110)%AdjacentTo(109) + + call Manifold%Valve(111)%AdjacentTo(37) + call Manifold%Valve(111)%AdjacentTo(64) + call Manifold%Valve(111)%AdjacentTo(112) + + call Manifold%Valve(112)%AdjacentTo(63) + call Manifold%Valve(112)%AdjacentTo(111) + call Manifold%Valve(112)%AdjacentTo(113) + + call Manifold%Valve(113)%AdjacentTo(29) + call Manifold%Valve(113)%AdjacentTo(112) + call Manifold%Valve(113)%AdjacentTo(114) + + call Manifold%Valve(114)%AdjacentTo(62) + call Manifold%Valve(114)%AdjacentTo(113) + call Manifold%Valve(114)%AdjacentTo(115) + + call Manifold%Valve(115)%AdjacentTo(36) + call Manifold%Valve(115)%AdjacentTo(61) + call Manifold%Valve(115)%AdjacentTo(114) + + call Manifold%Valve(116)%AdjacentTo(38) + call Manifold%Valve(116)%AdjacentTo(39) + + call Manifold%Valve(117)%AdjacentTo(2) + call Manifold%Valve(117)%AdjacentTo(26) + call Manifold%Valve(117)%AdjacentTo(47) + + call Manifold%Valve(118)%AdjacentTo(3) + call Manifold%Valve(118)%AdjacentTo(25) + call Manifold%Valve(118)%AdjacentTo(46) + + call Manifold%Valve(119)%AdjacentTo(42) + call Manifold%Valve(119)%AdjacentTo(60) + call Manifold%Valve(119)%AdjacentTo(107) + + call Manifold%Valve(120)%AdjacentTo(71) + +!call Valve(121)%AdjacentTo(16) + call Manifold%Valve(121)%AdjacentTo(1) + call Manifold%Valve(121)%AdjacentTo(65) + +!call Valve(122)%AdjacentTo(17) + call Manifold%Valve(122)%AdjacentTo(4) + call Manifold%Valve(122)%AdjacentTo(66) + +!call Valve(123)%AdjacentTo(18) + call Manifold%Valve(123)%AdjacentTo(5) + call Manifold%Valve(123)%AdjacentTo(67) + +!call Valve(124)%AdjacentTo(54) +!call Valve(124)%AdjacentTo(55) + call Manifold%Valve(124)%AdjacentTo(69) + call Manifold%Valve(124)%AdjacentTo(103) + + call Manifold%Valve(125)%AdjacentTo(68) + call Manifold%Valve(125)%AdjacentTo(99) +! call Valve(125)%AdjacentTo(126) + + call Manifold%Valve(126)%AdjacentTo(128) + call Manifold%Valve(126)%AdjacentTo(68) +!call Valve(126)%AdjacentTo(125) + + call Manifold%Valve(127)%AdjacentTo(56) + call Manifold%Valve(127)%AdjacentTo(78) +!call Valve(127)%AdjacentTo(105) + + call Manifold%Valve(128)%AdjacentTo(56) + call Manifold%Valve(128)%AdjacentTo(126) + + +! initialization + call ChangeValve(60, .true.) + call RemoveIBop() + call ToggleFillupHead(.false.) + call ToggleMudBox(.false.) + call RemoveTopDriveIBop() + call InstallSafetyValve_KellyMode() + call KellyDisconnected() + end subroutine + + + + subroutine KellyConnected() +!use CLog3 + implicit none + + call Manifold%Valve(127)%RemoveAdjacent(78) + + call Manifold%Valve(127)%AdjacentTo(103) + call Manifold%Valve(103)%AdjacentTo(127) + +# 711 + + Manifold%IsPathsDirty = .true. + end subroutine + + subroutine KellyDisconnected() +!use CLog3 + implicit none + + call Manifold%Valve(127)%RemoveAdjacent(103) + call Manifold%Valve(103)%RemoveAdjacent(127) + + call Manifold%Valve(127)%AdjacentTo(78) + +# 727 + + + Manifold%IsPathsDirty = .true. + + end subroutine + + + + + + + + + + subroutine InstallSafetyValve_KellyMode() + implicit none + Manifold%IsSafetyValveInstalled_KellyMode = .true. + + call RemoveTopDriveIBop() + +! Remove Safey Valve (54) + call Manifold%Valve(124)%RemoveAdjacent(54) + call Manifold%Valve(54)%RemoveAdjacent(124) + + call Manifold%Valve(69)%RemoveAdjacent(54) + call Manifold%Valve(54)%RemoveAdjacent(69) + +! Remove 126-103 cnn + call Manifold%Valve(128)%RemoveAdjacent(127) + call Manifold%Valve(127)%RemoveAdjacent(128) + +! now make cnn + call Manifold%Valve(124)%AdjacentTo(69) + call Manifold%Valve(69)%AdjacentTo(124) + + call Manifold%Valve(128)%AdjacentTo(56) + + call Manifold%Valve(56)%AdjacentTo(128) + call Manifold%Valve(56)%AdjacentTo(127) + + call Manifold%Valve(127)%AdjacentTo(56) + +# 771 + + + data%Equipments%DrillingConsole%IRSafetyValveLed = 1 + call OpenSafetyValve_KellyMode() + end subroutine + + subroutine RemoveSafetyValve_KellyMode() + implicit none + Manifold%IsSafetyValveInstalled_KellyMode = .false. + + call Manifold%Valve(128)%RemoveAdjacent(56) + call Manifold%Valve(56)%RemoveAdjacent(128) + + call Manifold%Valve(127)%RemoveAdjacent(56) + call Manifold%Valve(56)%RemoveAdjacent(127) + + call Manifold%Valve(127)%AdjacentTo(128) + call Manifold%Valve(128)%AdjacentTo(127) + + data%Equipments%DrillingConsole%IRSafetyValveLed = 0 + call CloseSafetyValve_KellyMode() + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 + +# 797 + + + end subroutine + + subroutine OpenSafetyValve_KellyMode() + implicit none + if(.not.Manifold%IsSafetyValveInstalled_KellyMode) return + data%Equipments%DrillingConsole%OpenSafetyValveLed = 1 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 + Manifold%SafetyValve = .true. + call ChangeValve(56, Manifold%SafetyValve) + +# 811 + + + end subroutine + + subroutine CloseSafetyValve_KellyMode() + implicit none + if(.not.Manifold%IsSafetyValveInstalled_KellyMode) return + data%Equipments%DrillingConsole%CloseSafetyValveLed = 1 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 + Manifold%SafetyValve = .false. + call ChangeValve(56, Manifold%SafetyValve) + +# 825 + + + end subroutine + + + + + + + + + + + subroutine InstallSafetyValve_TripMode() + implicit none + Manifold%IsSafetyValveInstalled_TripMode = .true. + + call Manifold%Valve(128)%RemoveAdjacent(56) + call Manifold%Valve(56)%RemoveAdjacent(128) + + call Manifold%Valve(127)%RemoveAdjacent(56) + call Manifold%Valve(56)%RemoveAdjacent(127) + + call Manifold%Valve(69)%RemoveAdjacent(124) + call Manifold%Valve(124)%RemoveAdjacent(69) + + + call Manifold%Valve(127)%AdjacentTo(128) + call Manifold%Valve(128)%AdjacentTo(127) + + call Manifold%Valve(124)%AdjacentTo(54) + call Manifold%Valve(54)%AdjacentTo(124) + + call Manifold%Valve(54)%AdjacentTo(69) + call Manifold%Valve(69)%AdjacentTo(54) + + data%Equipments%DrillingConsole%IRSafetyValveLed = 1 + call OpenSafetyValve_TripMode() + +# 866 + + + end subroutine + + subroutine RemoveSafetyValve_TripMode() + implicit none + Manifold%IsSafetyValveInstalled_TripMode = .false. + + call Manifold%Valve(124)%RemoveAdjacent(54) + call Manifold%Valve(54)%RemoveAdjacent(124) + + call Manifold%Valve(54)%RemoveAdjacent(69) + call Manifold%Valve(69)%RemoveAdjacent(54) + + call Manifold%Valve(124)%AdjacentTo(69) + call Manifold%Valve(69)%AdjacentTo(124) + + data%Equipments%DrillingConsole%IRSafetyValveLed = 0 + call CloseSafetyValve_TripMode() + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 + +# 890 + + + end subroutine + + subroutine OpenSafetyValve_TripMode() + implicit none + if(.not.Manifold%IsSafetyValveInstalled_TripMode) return + data%Equipments%DrillingConsole%OpenSafetyValveLed = 1 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 + Manifold%SafetyValve = .true. + call ChangeValve(54, Manifold%SafetyValve) + +# 904 + + + end subroutine + + subroutine CloseSafetyValve_TripMode() + implicit none + if(.not.Manifold%IsSafetyValveInstalled_TripMode) return + data%Equipments%DrillingConsole%CloseSafetyValveLed = 1 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 + Manifold%SafetyValve = .false. + call ChangeValve(54, Manifold%SafetyValve) + +# 918 + + + end subroutine + + + + + + + + + subroutine InstallSafetyValve_TopDrive() + implicit none + Manifold%IsSafetyValveInstalled_TopDrive = .true. + + call Manifold%Valve(128)%RemoveAdjacent(56) + call Manifold%Valve(56)%RemoveAdjacent(128) + + call Manifold%Valve(127)%RemoveAdjacent(56) + call Manifold%Valve(56)%RemoveAdjacent(127) + + call Manifold%Valve(69)%RemoveAdjacent(124) + call Manifold%Valve(124)%RemoveAdjacent(69) + + call Manifold%Valve(124)%AdjacentTo(54) + call Manifold%Valve(54)%AdjacentTo(124) + + call Manifold%Valve(54)%AdjacentTo(69) + call Manifold%Valve(69)%AdjacentTo(54) + + data%Equipments%DrillingConsole%IRSafetyValveLed = 1 + call OpenSafetyValve_TopDrive() + +# 953 + + + end subroutine + + subroutine RemoveSafetyValve_TopDrive() + implicit none + Manifold%IsSafetyValveInstalled_TopDrive = .false. + + call Manifold%Valve(124)%RemoveAdjacent(54) + call Manifold%Valve(54)%RemoveAdjacent(124) + + call Manifold%Valve(54)%RemoveAdjacent(69) + call Manifold%Valve(69)%RemoveAdjacent(54) + + call Manifold%Valve(124)%AdjacentTo(69) + call Manifold%Valve(69)%AdjacentTo(124) + + data%Equipments%DrillingConsole%IRSafetyValveLed = 0 + call CloseSafetyValve_TopDrive() + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 + +# 977 + + + end subroutine + + subroutine OpenSafetyValve_TopDrive() + implicit none + if(.not.Manifold%IsSafetyValveInstalled_TopDrive) return + data%Equipments%DrillingConsole%OpenSafetyValveLed = 1 + data%Equipments%DrillingConsole%CloseSafetyValveLed = 0 + Manifold%SafetyValve = .true. + +# 990 + + + call ChangeValve(54, Manifold%SafetyValve) + end subroutine + + subroutine CloseSafetyValve_TopDrive() + implicit none + if(.not.Manifold%IsSafetyValveInstalled_TopDrive) return + data%Equipments%DrillingConsole%CloseSafetyValveLed = 1 + data%Equipments%DrillingConsole%OpenSafetyValveLed = 0 + Manifold%SafetyValve = .false. + +# 1004 + + + call ChangeValve(54, Manifold%SafetyValve) + end subroutine + + + + + + + + + + subroutine InstallIBop() + implicit none + Manifold%IsIBopInstalled = .true. + + call Manifold%Valve(103)%RemoveAdjacent(124) + call Manifold%Valve(124)%RemoveAdjacent(103) + + call Manifold%Valve(55)%AdjacentTo(103) + call Manifold%Valve(55)%AdjacentTo(124) + + call Manifold%Valve(103)%AdjacentTo(55) + call Manifold%Valve(124)%AdjacentTo(55) + +# 1032 + + + data%Equipments%DrillingConsole%IRIBopLed = 1 + call OpenIBop() + end subroutine + + subroutine RemoveIBop() + implicit none + Manifold%IsIBopInstalled = .false. + + call Manifold%Valve(55)%RemoveAdjacent(103) + call Manifold%Valve(55)%RemoveAdjacent(124) + + call Manifold%Valve(103)%RemoveAdjacent(55) + call Manifold%Valve(124)%RemoveAdjacent(55) + + call Manifold%Valve(103)%AdjacentTo(124) + call Manifold%Valve(124)%AdjacentTo(103) + +# 1053 + + + data%Equipments%DrillingConsole%IRIBopLed = 0 + Manifold%IBop = .false. + call ChangeValve(55, Manifold%IBop) + end subroutine + + subroutine OpenIBop() + implicit none + if(.not.Manifold%IsIBopInstalled) return + Manifold%IBop = .true. + +# 1067 + + + call ChangeValve(55, Manifold%IBop) + end subroutine + + subroutine CloseIBop() + implicit none + if(.not.Manifold%IsIBopInstalled) return + Manifold%IBop = .false. + +# 1079 + + + call ChangeValve(55, Manifold%IBop) + end subroutine + + + + + + + subroutine InstallKellyCock() + implicit none + Manifold%IsKellyCockInstalled = .true. + + call Manifold%Valve(125)%RemoveAdjacent(126) + call Manifold%Valve(126)%RemoveAdjacent(125) + + call Manifold%Valve(125)%AdjacentTo(68) + + call Manifold%Valve(68)%AdjacentTo(125) + call Manifold%Valve(68)%AdjacentTo(126) + + call Manifold%Valve(126)%AdjacentTo(68) + +# 1105 + + + call OpenKellyCock() + end subroutine + + subroutine RemoveKellyCock() + implicit none + Manifold%IsKellyCockInstalled = .false. + + call Manifold%Valve(125)%RemoveAdjacent(68) + call Manifold%Valve(126)%RemoveAdjacent(68) + + call Manifold%Valve(68)%RemoveAdjacent(125) + call Manifold%Valve(68)%RemoveAdjacent(126) + + call Manifold%Valve(125)%AdjacentTo(126) + call Manifold%Valve(126)%AdjacentTo(125) + + Manifold%KellyCock = .false. + call ChangeValve(68, Manifold%KellyCock) + data%Equipments%DrillingConsole%CloseKellyCockLed = 0 + data%Equipments%DrillingConsole%OpenKellyCockLed = 0 + +# 1130 + + + end subroutine + + subroutine OpenKellyCock() + implicit none + if(.not.Manifold%IsKellyCockInstalled) return + data%Equipments%DrillingConsole%OpenKellyCockLed = 1 + data%Equipments%DrillingConsole%CloseKellyCockLed = 0 + Manifold%KellyCock = .true. + +# 1143 + + + call ChangeValve(68, Manifold%KellyCock) + end subroutine + + subroutine CloseKellyCock() + implicit none + if(.not.Manifold%IsKellyCockInstalled) return + data%Equipments%DrillingConsole%CloseKellyCockLed = 1 + data%Equipments%DrillingConsole%OpenKellyCockLed = 0 + Manifold%KellyCock = .false. + +# 1157 + + + call ChangeValve(68, Manifold%KellyCock) + end subroutine + + + + + + + + + subroutine InstallTopDriveIBop() + implicit none + Manifold%IsTopDriveIBopInstalled = .true. + + call Manifold%Valve(126)%RemoveAdjacent(128) + call Manifold%Valve(128)%RemoveAdjacent(126) + + + call Manifold%Valve(126)%AdjacentTo(70) + call Manifold%Valve(70)%AdjacentTo(126) + + call Manifold%Valve(128)%AdjacentTo(70) + call Manifold%Valve(70)%AdjacentTo(128) + +# 1185 + + call OpenTopDriveIBop() + end subroutine + + subroutine RemoveTopDriveIBop() + implicit none + Manifold%IsTopDriveIBopInstalled = .false. + + call Manifold%Valve(126)%RemoveAdjacent(70) + call Manifold%Valve(70)%RemoveAdjacent(126) + + call Manifold%Valve(128)%RemoveAdjacent(70) + call Manifold%Valve(70)%RemoveAdjacent(128) + + call Manifold%Valve(126)%AdjacentTo(128) + call Manifold%Valve(128)%AdjacentTo(126) + +# 1204 + + Manifold%TopDriveIBop = .false. + call ChangeValve(70, Manifold%TopDriveIBop) + end subroutine + + subroutine OpenTopDriveIBop() + implicit none + if(.not.Manifold%IsTopDriveIBopInstalled) return + Manifold%TopDriveIBop = .true. + call ChangeValve(70, Manifold%TopDriveIBop) +# 1216 + + end subroutine + + subroutine CloseTopDriveIBop() + implicit none + if(.not.Manifold%IsTopDriveIBopInstalled) return + Manifold%TopDriveIBop = .false. + call ChangeValve(70, Manifold%TopDriveIBop) +# 1226 + + end subroutine + + + + + + + + + + subroutine InstallFloatValve() + implicit none + Manifold%IsFloatValveInstalled = .true. + + call Manifold%Valve(69)%RemoveAdjacent(79) + call Manifold%Valve(79)%RemoveAdjacent(69) + + call Manifold%Valve(48)%AdjacentTo(69) + call Manifold%Valve(48)%AdjacentTo(79) + + call Manifold%Valve(69)%AdjacentTo(48) + call Manifold%Valve(79)%AdjacentTo(48) +# 1251 + + call OpenFloatValve() + end subroutine + + subroutine RemoveFloatValve() + implicit none + Manifold%IsFloatValveInstalled = .false. + + call Manifold%Valve(48)%RemoveAdjacent(69) + call Manifold%Valve(48)%RemoveAdjacent(79) + + call Manifold%Valve(69)%RemoveAdjacent(48) + call Manifold%Valve(79)%RemoveAdjacent(48) + + call Manifold%Valve(69)%AdjacentTo(79) + call Manifold%Valve(79)%AdjacentTo(69) +# 1269 + + Manifold%FloatValve = .false. + call ChangeValve(48, Manifold%FloatValve) + end subroutine + + subroutine OpenFloatValve() + implicit none + if(.not.Manifold%IsFloatValveInstalled) return + Manifold%FloatValve = .true. +# 1280 + + call ChangeValve(48, Manifold%FloatValve) + end subroutine + + subroutine CloseFloatValve() + implicit none + if(.not.Manifold%IsFloatValveInstalled) return + Manifold%FloatValve = .false. +# 1290 + + call ChangeValve(48, Manifold%FloatValve) + end subroutine + + + + + + + + subroutine ToggleFillupHead(v) + implicit none + logical, intent(in) :: v + if(v) then + call Manifold%Valve(14)%RemoveAdjacent(78) + + call Manifold%Valve(14)%AdjacentTo(57) + call Manifold%Valve(57)%AdjacentTo(14) + call Manifold%Valve(57)%AdjacentTo(103) + call Manifold%Valve(103)%AdjacentTo(57) + + else + call Manifold%Valve(14)%RemoveAdjacent(57) + call Manifold%Valve(57)%RemoveAdjacent(14) + call Manifold%Valve(57)%RemoveAdjacent(103) + call Manifold%Valve(103)%RemoveAdjacent(57) + + call Manifold%Valve(14)%AdjacentTo(78) + endif + Manifold%IsPathsDirty = .true. + call ChangeValve(57, .true.) + end subroutine + + subroutine ToggleMudBox(v) + implicit none + logical, intent(in) :: v + call ChangeValve(53, v) + end subroutine + + + + + + + + + + subroutine ToggleMiddleRams(v) + implicit none + logical, intent(in) :: v + Manifold%Valve(50)%Status = v + call ChangeValve(69, v) + end subroutine + + + + + + + + + subroutine ChangeValve(i, state) + implicit none + integer, intent(in) :: i + logical, intent(in) :: state + + if(Manifold%Valve(i)%Status==state) return + Manifold%Valve(i)%Status = state + if(i == 41 .or. i == 42) then + if(Manifold%Valve(41)%Status == .false. .and. Manifold%Valve(42)%Status == .false.) then + Manifold%Valve(60)%Status = .true. + else + Manifold%Valve(60)%Status = .false. + endif + endif +# 1367 + +!call Traverse() + Manifold%IsPathsDirty = .true. + end subroutine + + + + + + subroutine DisplayOpenPaths() + implicit none + integer :: i + if(allocated(Manifold%OpenPaths)) then + do i = 1, size(Manifold%OpenPaths) + call Manifold%OpenPaths(i)%Display() + end do + end if + end subroutine + + subroutine DisplayOpenPathsWrite() + implicit none + integer :: i + if(allocated(Manifold%OpenPaths)) then + do i = 1, size(Manifold%OpenPaths) + call Manifold%OpenPaths(i)%DisplayWrite() + end do + end if + end subroutine + +end module CManifolds diff --git a/CSharp/Equipments/Tanks/CTanks.f90 b/CSharp/Equipments/Tanks/CTanks.f90 index 55f54a2..d48886e 100644 --- a/CSharp/Equipments/Tanks/CTanks.f90 +++ b/CSharp/Equipments/Tanks/CTanks.f90 @@ -7,46 +7,92 @@ contains - subroutine TankToJson(parent) - + subroutine TankFromJson(parent) type(json_value),pointer :: parent type(json_core) :: json - type(json_value),pointer :: p,pform - integer :: i - - call json%create_array(p,'Tank') - - call json%create_object(pform,'') - call json%add(pform,"WaterRate",data%EquipmentControl%Tank%WaterRate) - call json%add(pform,"CementTankVolume",data%EquipmentControl%Tank%CementTankVolume) - call json%add(pform,"CementTankDensity",data%EquipmentControl%Tank%CementTankDensity) - call json%add(pform,"TripTankVolume",data%EquipmentControl%Tank%TripTankVolume) - call json%add(pform,"TripTankDensity",data%EquipmentControl%Tank%TripTankDensity) - call json%add(pform,"ManualPumpPower",data%EquipmentControl%Tank%ManualPumpPower) - call json%add(pform,"Valve1",data%EquipmentControl%Tank%Valve1) - call json%add(pform,"Valve2",data%EquipmentControl%Tank%Valve2) - call json%add(pform,"Valve3",data%EquipmentControl%Tank%Valve3) - call json%add(pform,"Valve4",data%EquipmentControl%Tank%Valve4) - call json%add(pform,"Valve5",data%EquipmentControl%Tank%Valve5) - call json%add(pform,"Valve6",data%EquipmentControl%Tank%Valve6) - call json%add(pform,"Valve7",data%EquipmentControl%Tank%Valve7) - call json%add(pform,"Valve8",data%EquipmentControl%Tank%Valve8) - call json%add(pform,"Valve9",data%EquipmentControl%Tank%Valve9) - call json%add(pform,"Valve10",data%EquipmentControl%Tank%Valve10) - call json%add(pform,"Valve11",data%EquipmentControl%Tank%Valve11) - - call json%add(parent,p) + type(json_value),pointer :: p,pval + logical::is_found + + ! 1. get related root + call json%get(parent,'Tank',p) + + ! 2. get member of data type from node + call json%get(p,'WaterRate',pval) + call json%get(pval,data%Equipments%Tank%WaterRate) + call json%get(p,'CementTankVolume',pval) + call json%get(pval,data%Equipments%Tank%CementTankVolume) + call json%get(p,'CementTankDensity',pval) + call json%get(pval,data%Equipments%Tank%CementTankDensity) + call json%get(p,'TripTankVolume',pval) + call json%get(pval,data%Equipments%Tank%TripTankVolume) + call json%get(p,'TripTankDensity',pval) + call json%get(pval,data%Equipments%Tank%TripTankDensity) + call json%get(p,'ManualPumpPower',pval) + call json%get(pval,data%Equipments%Tank%ManualPumpPower) + call json%get(p,'Valve1',pval) + call json%get(pval,data%Equipments%Tank%Valve1) + call json%get(p,'Valve2',pval) + call json%get(pval,data%Equipments%Tank%Valve2) + call json%get(p,'Valve3',pval) + call json%get(pval,data%Equipments%Tank%Valve3) + call json%get(p,'Valve4',pval) + call json%get(pval,data%Equipments%Tank%Valve4) + call json%get(p,'Valve5',pval) + call json%get(pval,data%Equipments%Tank%Valve5) + call json%get(p,'Valve6',pval) + call json%get(pval,data%Equipments%Tank%Valve6) + call json%get(p,'Valve7',pval) + call json%get(pval,data%Equipments%Tank%Valve7) + call json%get(p,'Valve8',pval) + call json%get(pval,data%Equipments%Tank%Valve8) + call json%get(p,'Valve9',pval) + call json%get(pval,data%Equipments%Tank%Valve9) + call json%get(p,'Valve10',pval) + call json%get(pval,data%Equipments%Tank%Valve10) + call json%get(p,'Valve11',pval) + call json%get(pval,data%Equipments%Tank%Valve11) end subroutine + ! subroutine TankToJson(parent) + + ! type(json_value),pointer :: parent + ! type(json_core) :: json + ! type(json_value),pointer :: p,pform + ! integer :: i + + ! call json%create_array(p,'Tank') + + ! call json%create_object(pform,'') + ! call json%add(pform,"WaterRate",data%Equipments%Tank%WaterRate) + ! call json%add(pform,"CementTankVolume",data%Equipments%Tank%CementTankVolume) + ! call json%add(pform,"CementTankDensity",data%Equipments%Tank%CementTankDensity) + ! call json%add(pform,"TripTankVolume",data%Equipments%Tank%TripTankVolume) + ! call json%add(pform,"TripTankDensity",data%Equipments%Tank%TripTankDensity) + ! call json%add(pform,"ManualPumpPower",data%Equipments%Tank%ManualPumpPower) + ! call json%add(pform,"Valve1",data%Equipments%Tank%Valve1) + ! call json%add(pform,"Valve2",data%Equipments%Tank%Valve2) + ! call json%add(pform,"Valve3",data%Equipments%Tank%Valve3) + ! call json%add(pform,"Valve4",data%Equipments%Tank%Valve4) + ! call json%add(pform,"Valve5",data%Equipments%Tank%Valve5) + ! call json%add(pform,"Valve6",data%Equipments%Tank%Valve6) + ! call json%add(pform,"Valve7",data%Equipments%Tank%Valve7) + ! call json%add(pform,"Valve8",data%Equipments%Tank%Valve8) + ! call json%add(pform,"Valve9",data%Equipments%Tank%Valve9) + ! call json%add(pform,"Valve10",data%Equipments%Tank%Valve10) + ! call json%add(pform,"Valve11",data%Equipments%Tank%Valve11) + + ! call json%add(parent,p) + ! end subroutine + subroutine Set_ManualPumpPower(v) use CManifolds, only:ChangeValve implicit none logical, intent(in) :: v - data%EquipmentControl%Tank%ManualPumpPower = v + data%Equipments%Tank%ManualPumpPower = v call ChangeValve(43, v) #ifdef deb - print*, 'ManualPumpPower=', data%EquipmentControl%Tank%ManualPumpPower + print*, 'ManualPumpPower=', data%Equipments%Tank%ManualPumpPower #endif end subroutine diff --git a/CSharp/Equipments/Tanks/CTanks.i90 b/CSharp/Equipments/Tanks/CTanks.i90 new file mode 100644 index 0000000..8dd77c8 --- /dev/null +++ b/CSharp/Equipments/Tanks/CTanks.i90 @@ -0,0 +1,101 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/Tanks/CTanks.f90" + + module CTanks + use SimulationVariables + use CManifolds + implicit none + public + contains + + + subroutine TankFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + logical::is_found + +! 1. get related root + call json%get(parent,'Tank',p) + +! 2. get member of data type from node + call json%get(p,'WaterRate',pval) + call json%get(pval,data%Equipments%Tank%WaterRate) + call json%get(p,'CementTankVolume',pval) + call json%get(pval,data%Equipments%Tank%CementTankVolume) + call json%get(p,'CementTankDensity',pval) + call json%get(pval,data%Equipments%Tank%CementTankDensity) + call json%get(p,'TripTankVolume',pval) + call json%get(pval,data%Equipments%Tank%TripTankVolume) + call json%get(p,'TripTankDensity',pval) + call json%get(pval,data%Equipments%Tank%TripTankDensity) + call json%get(p,'ManualPumpPower',pval) + call json%get(pval,data%Equipments%Tank%ManualPumpPower) + call json%get(p,'Valve1',pval) + call json%get(pval,data%Equipments%Tank%Valve1) + call json%get(p,'Valve2',pval) + call json%get(pval,data%Equipments%Tank%Valve2) + call json%get(p,'Valve3',pval) + call json%get(pval,data%Equipments%Tank%Valve3) + call json%get(p,'Valve4',pval) + call json%get(pval,data%Equipments%Tank%Valve4) + call json%get(p,'Valve5',pval) + call json%get(pval,data%Equipments%Tank%Valve5) + call json%get(p,'Valve6',pval) + call json%get(pval,data%Equipments%Tank%Valve6) + call json%get(p,'Valve7',pval) + call json%get(pval,data%Equipments%Tank%Valve7) + call json%get(p,'Valve8',pval) + call json%get(pval,data%Equipments%Tank%Valve8) + call json%get(p,'Valve9',pval) + call json%get(pval,data%Equipments%Tank%Valve9) + call json%get(p,'Valve10',pval) + call json%get(pval,data%Equipments%Tank%Valve10) + call json%get(p,'Valve11',pval) + call json%get(pval,data%Equipments%Tank%Valve11) + end subroutine + +! subroutine TankToJson(parent) + +! type(json_value),pointer :: parent +! type(json_core) :: json +! type(json_value),pointer :: p,pform +! integer :: i + +! call json%create_array(p,'Tank') + +! call json%create_object(pform,'') +! call json%add(pform,"WaterRate",data%Equipments%Tank%WaterRate) +! call json%add(pform,"CementTankVolume",data%Equipments%Tank%CementTankVolume) +! call json%add(pform,"CementTankDensity",data%Equipments%Tank%CementTankDensity) +! call json%add(pform,"TripTankVolume",data%Equipments%Tank%TripTankVolume) +! call json%add(pform,"TripTankDensity",data%Equipments%Tank%TripTankDensity) +! call json%add(pform,"ManualPumpPower",data%Equipments%Tank%ManualPumpPower) +! call json%add(pform,"Valve1",data%Equipments%Tank%Valve1) +! call json%add(pform,"Valve2",data%Equipments%Tank%Valve2) +! call json%add(pform,"Valve3",data%Equipments%Tank%Valve3) +! call json%add(pform,"Valve4",data%Equipments%Tank%Valve4) +! call json%add(pform,"Valve5",data%Equipments%Tank%Valve5) +! call json%add(pform,"Valve6",data%Equipments%Tank%Valve6) +! call json%add(pform,"Valve7",data%Equipments%Tank%Valve7) +! call json%add(pform,"Valve8",data%Equipments%Tank%Valve8) +! call json%add(pform,"Valve9",data%Equipments%Tank%Valve9) +! call json%add(pform,"Valve10",data%Equipments%Tank%Valve10) +! call json%add(pform,"Valve11",data%Equipments%Tank%Valve11) + +! call json%add(parent,p) +! end subroutine + + + subroutine Set_ManualPumpPower(v) + use CManifolds, only:ChangeValve + implicit none + logical, intent(in) :: v + data%Equipments%Tank%ManualPumpPower = v + call ChangeValve(43, v) + #ifdef deb + print*, 'ManualPumpPower=', data%Equipments%Tank%ManualPumpPower + #endif + end subroutine + + +end module CTanks diff --git a/CSharp/Equipments/Tanks/CTanksVariables.f90 b/CSharp/Equipments/Tanks/CTanksVariables.f90 index 2454af0..561bc6b 100644 --- a/CSharp/Equipments/Tanks/CTanksVariables.f90 +++ b/CSharp/Equipments/Tanks/CTanksVariables.f90 @@ -23,7 +23,7 @@ module CTanksVariables logical :: Valve11 End Type TankType - contains + contains end module CTanksVariables \ No newline at end of file diff --git a/CSharp/Equipments/Tanks/CTanksVariables.i90 b/CSharp/Equipments/Tanks/CTanksVariables.i90 new file mode 100644 index 0000000..267ec9f --- /dev/null +++ b/CSharp/Equipments/Tanks/CTanksVariables.i90 @@ -0,0 +1,30 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Equipments/Tanks/CTanksVariables.f90" +module CTanksVariables + implicit none + public + Type :: TankType +! Input vars + real(8) :: WaterRate + real(8) :: CementTankVolume + real(8) :: CementTankDensity + real(8) :: TripTankVolume + real(8) :: TripTankDensity + logical :: ManualPumpPower + logical :: Valve1 + logical :: Valve2 + logical :: Valve3 + logical :: Valve4 + logical :: Valve5 + + logical :: Valve6 + logical :: Valve7 + logical :: Valve8 + logical :: Valve9 + logical :: Valve10 + logical :: Valve11 + End Type TankType + + contains + + +end module CTanksVariables diff --git a/CSharp/OperationScenarios/Common/COperationScenariosMain.i90 b/CSharp/OperationScenarios/Common/COperationScenariosMain.i90 new file mode 100644 index 0000000..047cb58 --- /dev/null +++ b/CSharp/OperationScenarios/Common/COperationScenariosMain.i90 @@ -0,0 +1,463 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Common/COperationScenariosMain.f90" +module COperationScenariosMain + use CIActionReference + implicit none + public +! procedure (ActionVoid), pointer :: UpdateUnityPtr + contains + + subroutine OperationScenarios_Step +! use CSimulationVariables + use OperationScenariosModule + use CElevatorConnectionEnum + use CCloseKellyCockLedNotification + use CCloseSafetyValveLedNotification + use CFillMouseHoleLedNotification + use CIrIBopLedNotification + use CIrSafetyValveLedNotification + use CLatchLedNotification + use COpenKellyCockLedNotification + use COpenSafetyValveLedNotification + use CSlipsNotification + use CSwingLedNotification + use CTongNotification + use CUnlatchLedNotification + use CInstallFillupHeadPermission + use CInstallMudBucketPermission + use CIrIbopPermission + use CIrSafetyValvePermission + use CRemoveFillupHeadPermission + use CRemoveMudBucketPermission + use SoftwareInputsVariables +! use CHookHeight +! use CIbopHeight +! use CNearFloorConnection +! use CSafetyValveHeight +! use CSlackOff +! use CStandRack +! use CStringPressure +! use CZeroStringSpeed + use CUnityInputs, only: & + Get_ElevatorConnectionPossible, & + Get_JointConnectionPossible, & + Get_ElevatorPickup, & + Get_NearFloorPosition, & + Get_SingleSetInMouseHole +! use CBucketEnum +! use UnitySignalsModule + use CElevatorEnum +! use CHeadEnum + use CIbopEnum + use CKellyEnum + use CMouseHoleEnum + use UnitySignalsModule + use CSafetyValveEnum + use CSlipsEnum + use CSwingEnum + use CTongEnum +! use CStringUpdate + use CFlowPipeDisconnectEnum + use CFlowKellyDisconnectEnum + use CFillupHeadPermission + use CSwingDrillPermission + use CSwingOffPermission + use CSwingTiltPermission +! use CTdsStemJointHeight +! use UnitySignalsModule !for CTdsConnectionModesEnum + use CTdsElevatorModesEnum + use CTdsSpineEnum + use CTdsSwingEnum + use CTdsTongEnum + use CTdsBackupClamp + use CTdsIbopLedNotification + use CTdsPowerLedNotification + use CTdsTorqueWrenchLedNotification + + implicit none + + call Evaluate_KellyConnection() + call Evaluate_ElevatorConnection() + + call Evaluate_CloseKellyCockLed() + call Evaluate_CloseSafetyValveLed() + call Evaluate_FillMouseHoleLed() + call Evaluate_IrIBopLed() + call Evaluate_IrSafetyValveLed() + call Evaluate_LatchLed() + call Evaluate_OpenKellyCockLed() + call Evaluate_OpenSafetyValveLed() + call Evaluate_SlipsNotification() + call Evaluate_SwingLed() + call Evaluate_TongNotification() + call Evaluate_UnlatchLed() + + call Evaluate_InstallFillupHeadPermission() + call Evaluate_InstallMudBucketPermission() + call Evaluate_IrIbopPermission() + call Evaluate_IrSafetyValvePermission() + call Evaluate_RemoveFillupHeadPermission() + call Evaluate_RemoveMudBucketPermission() + + call Evaluate_MudBucket() + call Evaluate_Elevator() + call Evaluate_FillupHead() + call Evaluate_Ibop() + call Evaluate_Kelly() + call Evaluate_MouseHole() + call Evaluate_MouseHole() + call Evaluate_OperationCondition() + call Evaluate_SafetyValve() + call Evaluate_Slips() + call Evaluate_Swing() + call Evaluate_Tong() + +! call Evaluate_StringUpdate() + + call Evaluate_FlowKellyDisconnect() + call Evaluate_FlowPipeDisconnect() + +!if(Get_FillMouseHoleLed()) then +! call Set_MouseHole(MOUSE_HOLE_FILL) +!else +! if((Get_KellyConnection() == KELLY_CONNECTION_SINGLE .or.& +! Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE) .and.& +! Get_HookHeight() >= 95.0 ) then +! call Set_MouseHole(MOUSE_HOLE_NEUTRAL) +! else +! call Set_MouseHole(MOUSE_HOLE_EMPTY) +! endif +!endif + + + + + + + + +!topdrive + call Evaluate_TdsElevatorModes() + call Evaluate_TdsConnectionModes() + call Evaluate_SwingTiltPermission() + call Evaluate_SwingOffPermission() + call Evaluate_SwingDrillPermission() + call Evaluate_FillupHeadPermission() + call Evaluate_TdsTong() + call Evaluate_TdsBackupClamp() + call Evaluate_TdsSwing() + call Evaluate_TdsSpine() + + call Evaluate_PowerLed() + call Evaluate_IbopLed() + + call Evaluate_TorqueWrenchLed() + + end subroutine OperationScenarios_Step + +! subroutine UpdateUnity() +! implicit none +! if(associated(UpdateUnityPtr)) call UpdateUnityPtr() +! end subroutine + + subroutine Kelly_ConnectionNothing +! use CSwingEnumVariables +! use CSlipsEnumVariables + use UnitySignalVariables + use UnitySignalsModule + use CHook + use SimulationVariables + implicit none + + call Set_HookHeight(75.0) + call sleep(1) + +! first wait for unity to get to starting point + loop1: do + if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1 + call sleepqq(100) + enddo loop1 + call sleep(1) + +!TODO: possibly goto a position to activate swing + +! goto preferred swing position + if(data%State%unitySignals%Swing_S == SWING_MOUSE_HOLE_END) then + call Set_Swing(SWING_MOUSE_HOLE_BEGIN) +!@call UpdateUnity() + loop2: do + if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop2 + call sleepqq(100) + enddo loop2 + elseif (data%State%unitySignals%Swing_S == SWING_RAT_HOLE_END) then + call Set_Swing(SWING_RAT_HOLE_BEGIN) +!@call UpdateUnity() + loop3: do + if(Get_Swing() == SWING_RAT_HOLE_END) exit loop3 + call sleepqq(100) + enddo loop3 +!elseif (Swing_S == SWING_WELL_END) then +! call Set_Swing(SWING_WELL_BEGIN) +! !@call UpdateUnity() +! loop4: do +! if(Get_Swing() == SWING_WELL_END) exit loop4 +! call sleepqq(100) +! enddo loop4 + endif + call sleep(3) + +! move to final hook height + call Update_HookHeight_From_Snapshot() + call sleep(3) + + end subroutine Kelly_ConnectionNothing + + + + + + subroutine Kelly_ConnectionString +! use CSwingEnumVariables +! use CSlipsEnumVariables + use UnitySignalVariables + use UnitySignalsModule + use CHook + use SimulationVariables +! use CTongEnumVariables + implicit none + + call Set_HookHeight(75.0) + call sleep(1) + +! first wait for unity to get to starting point + loop1: do + if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1 + call sleepqq(100) + enddo loop1 + call sleep(1) + +! goto connection to string position + call Set_HookHeight_S(66.7) + call sleep(1) + +! start tong makeup + call Set_Tong(TONG_MAKEUP_BEGIN) +!@call UpdateUnity() + loop2: do + if(Get_Tong() == TONG_MAKEUP_END) exit loop2 + call sleepqq(100) + enddo loop2 + call sleepqq(100) + +! release slips + call Set_Slips(SLIPS_UNSET_BEGIN) +!@call UpdateUnity() + loop3: do + if(Get_Slips() == SLIPS_UNSET_END) exit loop3 + call sleepqq(100) + enddo loop3 + call sleepqq(100) + +! move to final hook height + call Update_HookHeight_From_Snapshot() + call sleep(3) + + +! put slips to saved position + if(data%State%unitySignals%Slips_S == SLIPS_SET_END) then + + call Set_Slips(SLIPS_SET_BEGIN) +!@call UpdateUnity() + loop4: do + if(Get_Slips() == SLIPS_SET_END) exit loop4 + call sleepqq(100) + enddo loop4 + call sleep(1) + endif + + + end subroutine Kelly_ConnectionString + + + + + subroutine Kelly_ConnectionSingle +! use CSwingEnumVariables +! use CSlipsEnumVariables +! use CTongEnumVariables + use UnitySignalVariables + use UnitySignalsModule + use CHook + use SimulationVariables + implicit none + + call Set_HookHeight(75.0) + call sleep(1) + +! first wait for unity to get to starting point + loop1: do + if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1 + call sleepqq(100) + enddo loop1 + call sleep(1) + + +! goto swing mouse hole position + call Set_HookHeight_S(70.0) + call sleep(1) + +! swing mouse hole + call Set_Swing(SWING_MOUSE_HOLE_BEGIN) +!@call UpdateUnity() + loop2: do + if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop2 + call sleepqq(100) + enddo loop2 + call sleepqq(100) + + +! goto makeup pipe location + call Set_HookHeight_S(65.0) + call sleep(1) + + +! start tong makeup + call Set_Tong(TONG_MAKEUP_BEGIN) +!@call UpdateUnity() + loop3: do + if(Get_Tong() == TONG_MAKEUP_END) exit loop3 + call sleepqq(100) + enddo loop3 + call sleepqq(100) + + + + if (data%State%unitySignals%Swing_S == SWING_WELL_END) then ! already in mouse hole + +! goto swing location + call Set_HookHeight_S(98.0) + call sleep(1) + +! goto preferred swing position + call Set_Swing(SWING_WELL_BEGIN) +!@call UpdateUnity() + loop4: do + if(Get_Swing() == SWING_WELL_END) exit loop4 + call sleepqq(100) + enddo loop4 + call sleep(2) + + endif + + +! move to final hook height + call Update_HookHeight_From_Snapshot() + call sleep(3) + + end subroutine Kelly_ConnectionSingle + + subroutine Elevator_ConnectionNothing +! use CSwingEnumVariables +! use CSlipsEnumVariables + use UnitySignalVariables + use UnitySignalsModule + use CHook + use SimulationVariables +! use CKellyEnumVariables + implicit none + + call Set_HookHeight(75.0) + call sleep(1) + +! first wait for unity to get to starting point + loop1: do + if(Get_Swing() == SWING_WELL_END .and. Get_Slips() == SLIPS_SET_END) exit loop1 + call sleepqq(100) + enddo loop1 + call sleep(1) + + +!TODO: possibly goto a position to activate swing + +!! first goto mouse hole +!call Set_Swing(SWING_MOUSE_HOLE_BEGIN) +!!@call UpdateUnity() +!loop2: do +! if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop2 +! call sleepqq(100) +!enddo loop2 +!call sleep(1) +! +!! then goto rat hole +!call Set_Swing(SWING_RAT_HOLE_BEGIN) +!!@call UpdateUnity() +!loop3: do +! if(Get_Swing() == SWING_RAT_HOLE_END) exit loop3 +! call sleepqq(100) +!enddo loop3 +!call sleep(1) + +! kelly back + call Set_Kelly(KELLY_REMOVE) + call sleepqq(100) + +! goto preferred swing position + if(data%State%unitySignals%Swing_S == SWING_MOUSE_HOLE_END) then + call Set_Swing(SWING_MOUSE_HOLE_BEGIN) +!@call UpdateUnity() + loop4: do + if(Get_Swing() == SWING_MOUSE_HOLE_END) exit loop4 + call sleepqq(100) + enddo loop4 + elseif (data%State%unitySignals%Swing_S == SWING_RAT_HOLE_END) then + call Set_Swing(SWING_RAT_HOLE_BEGIN) +!@call UpdateUnity() + loop5: do + if(Get_Swing() == SWING_RAT_HOLE_END) exit loop5 + call sleepqq(100) + enddo loop5 + elseif (data%State%unitySignals%Swing_S == SWING_WELL_END) then + call Set_Swing(SWING_WELL_BEGIN) +!@call UpdateUnity() + loop6: do + if(Get_Swing() == SWING_WELL_END) exit loop6 + call sleepqq(100) + enddo loop6 + endif + call sleepqq(100) + + + +! move to final hook height + call Update_HookHeight_From_Snapshot() + call sleep(3) + + end subroutine Elevator_ConnectionNothing + + + + + + subroutine Elevator_ConnectionString + implicit none + end subroutine Elevator_ConnectionString + + + + + + + + subroutine Elevator_ConnectionStand + implicit none + end subroutine Elevator_ConnectionStand + + + + + + + subroutine Elevator_ConnectionSingle + implicit none + end subroutine Elevator_ConnectionSingle + +end module COperationScenariosMain diff --git a/CSharp/OperationScenarios/Common/OperationScenarios.i90 b/CSharp/OperationScenarios/Common/OperationScenarios.i90 new file mode 100644 index 0000000..924f751 --- /dev/null +++ b/CSharp/OperationScenarios/Common/OperationScenarios.i90 @@ -0,0 +1,260 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Common/OperationScenarios.f90" +module OperationScenariosModule +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!! Paseted From ....Variables.f90 +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +! use OperationScenariosModule ! +! use OperationScenariosModule !!CElevator... +! use COperationScenariosVariables + use SimulationVariables + use PermissionsModule +! use SoftwareInputsVariables + use CUnityInputs + use CUnityOutputs, only: GetRotaryRpm + use UnitySignalVariables + use UnitySignalsModule + use PermissionsModule +! use CTdsElevatorModesEnumVariables ! + use CHoistingVariables + use CTopDrivePanelVariables + use NotificationModule + use SoftwareInputsModule + + contains + + subroutine OperationScenariosToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'OperationScenarios') + +! 2. add member of data type to new node + call json%add(p,"ElevatorConnection",data%State%OperationScenario%ElevatorConnection) + call json%add(p,"StringUpdate",data%State%OperationScenario%StringUpdate) + call json%add(p,"KellyConnection",data%State%OperationScenario%KellyConnection) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + +! moved from kellyConnectionEnum + subroutine Set_KellyConnection(v) + use CManifolds, Only: KellyConnected, KellyDisconnected + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%OperationScenario%KellyConnection == v) return + #endif + + data%State%OperationScenario%KellyConnection = v + + if(data%State%OperationScenario%KellyConnection /= KELLY_CONNECTION_STRING) then + call KellyDisconnected() + else + call KellyConnected() + endif + + #ifdef deb + print*, 'data%State%OperationScenario%KellyConnection=', data%State%OperationScenario%KellyConnection + #endif +!**call data%State%OperationScenario%OnKellyConnectionChange%RunAll() + end subroutine + + integer function Get_KellyConnection() + implicit none + Get_KellyConnection = data%State%OperationScenario%KellyConnection + end function + + subroutine Evaluate_KellyConnection() + implicit none + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 75 + + endif + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 80 + + +!!OPERATION-CODE=4 +!if (Get_OperationCondition() == OPERATION_DRILL .and.& +! Get_KellyConnection() == KELLY_CONNECTION_SINGLE .and.& +! Get_Swing() == SWING_MOUSE_HOLE_END .and.& +! Get_TongNotification() .and.& +! Get_FillMouseHoleLed() == .false. .and.& +! Get_Tong() == TONG_BREAKOUT_END) then +! +! call Set_FillMouseHoleLed(.true.) +! return +!end if + + + +!OPERATION-CODE=1 + if (Get_OperationCondition() == OPERATION_DRILL .and.& +!Get_JointConnectionPossible() .and.& + Get_KellyConnection() == KELLY_CONNECTION_NOTHING .and.& + Get_Swing() == SWING_WELL_END .and.& +!Get_TongNotification() .and.& + Get_Tong() == TONG_MAKEUP_END) then +!call Log_4('KELLY_CONNECTION_STRING') + call Set_Tong(TONG_NEUTRAL) + call Set_KellyConnection(KELLY_CONNECTION_STRING) + return + end if + +!OPERATION-CODE=2 + if (Get_OperationCondition() == OPERATION_DRILL .and.& + Get_StringPressure() == 0 .and.& + Get_HookHeight() <= (data%State%OperationScenario%HKL + Get_NearFloorConnection()) .and.& + Get_KellyConnection() == KELLY_CONNECTION_STRING .and.& + Get_Swing() == SWING_WELL_END .and.& +!Get_TongNotification() .and.& + Get_Tong() == TONG_BREAKOUT_END) then + call Set_Tong(TONG_NEUTRAL) + call Set_KellyConnection(KELLY_CONNECTION_NOTHING) + call Set_SwingLed(.true.) + return + end if + + +!OPERATION-CODE=3 + if (Get_OperationCondition() == OPERATION_DRILL .and.& +!Get_JointConnectionPossible() .and.& + Get_KellyConnection() == KELLY_CONNECTION_NOTHING .and.& + Get_Swing() == SWING_MOUSE_HOLE_END .and.& +!Get_TongNotification() .and.& + Get_FillMouseHoleLed() .and.& + Get_Tong() == TONG_MAKEUP_END) then + call Set_Tong(TONG_NEUTRAL) + call Set_KellyConnection(KELLY_CONNECTION_SINGLE) + call Set_SwingLed(.false.) + call Set_FillMouseHoleLed(.false.) + call Set_MouseHole(MOUSE_HOLE_NEUTRAL) + return + end if + + +!OPERATION-CODE=4 + if (Get_OperationCondition() == OPERATION_DRILL .and.& + Get_KellyConnection() == KELLY_CONNECTION_SINGLE .and.& + Get_Swing() == SWING_MOUSE_HOLE_END .and.& +!Get_TongNotification() .and.& + Get_FillMouseHoleLed() == .false. .and.& + Get_Tong() == TONG_BREAKOUT_END) then + call Set_Tong(TONG_NEUTRAL) + call Set_KellyConnection(KELLY_CONNECTION_NOTHING) + call Set_FillMouseHoleLed(.true.) + call Set_MouseHole(MOUSE_HOLE_NEUTRAL) + return + end if + +!OPERATION-CODE=5 + if (Get_OperationCondition() == OPERATION_DRILL .and.& +!Get_JointConnectionPossible() .and.& + Get_KellyConnection() == KELLY_CONNECTION_SINGLE .and.& + Get_Swing() == SWING_WELL_END .and.& +!Get_TongNotification() .and.& + Get_Tong() == TONG_MAKEUP_END) then + call Set_Tong(TONG_NEUTRAL) + call Set_KellyConnection(KELLY_CONNECTION_STRING) + call Set_StringUpdate(STRING_UPDATE_ADD_SINGLE) + call Set_SwingLed(.false.) + return + end if + +!OPERATION-CODE=6 + if (Get_OperationCondition() == OPERATION_DRILL .and.& + Get_StringPressure() == 0 .and.& + Get_HookHeight() > 70.0 .and.& + Get_KellyConnection() == KELLY_CONNECTION_STRING .and.& +!Get_TongNotification() .and.& + Get_Swing() == SWING_WELL_END .and.& + Get_Tong() == TONG_BREAKOUT_END) then + call Set_Tong(TONG_NEUTRAL) + call Set_KellyConnection(KELLY_CONNECTION_SINGLE) + call Set_StringUpdate(STRING_UPDATE_REMOVE_SINGLE) + return + end if + + endif + + end subroutine + +! subroutine Subscribe_KellyConnection() +! use CDrillingConsoleVariables +! use ConfigurationVariables +! use ConfigurationVariables +! implicit none + +! call OnBreakoutLeverPress%Add(ButtonPress_Breakout) +! call OnMakeupLeverPress%Add(ButtonPress_Makeup) +! end subroutine + + subroutine ButtonPress_Breakout() + implicit none +# 201 + + end subroutine + + subroutine ButtonPress_Makeup() + implicit none +# 208 + + end subroutine + + + subroutine Set_StringUpdate(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%OperationScenario%StringUpdate == v) return + #endif + data%State%OperationScenario%StringUpdate = v +!**call data%State%OperationScenario%OnStringUpdateChange%RunAll(v) + end subroutine + + integer function Get_StringUpdate() + implicit none + Get_StringUpdate = data%State%OperationScenario%StringUpdate + end function + + real(8) function TJH() + use TD_DrillStemComponents + implicit none + TJH = data%State%TD_String%TopJointHeight + end function + + real function TL() + implicit none + TL = 26.97 + end function + + real function NFC() + implicit none + NFC = Get_NearFloorConnection() + end function + + + subroutine Set_ElevatorConnection(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%OperationScenario%ElevatorConnection == v) return + #endif + data%State%OperationScenario%ElevatorConnection = v + + #ifdef deb + print*, 'data%State%OperationScenario%ElevatorConnection=', data%State%OperationScenario%ElevatorConnection + #endif +!**call data%State%OperationScenario%OnElevatorConnectionChange%RunAll() + end subroutine + + integer function Get_ElevatorConnection() + implicit none + Get_ElevatorConnection = data%State%OperationScenario%ElevatorConnection + end function + +end module OperationScenariosModule diff --git a/CSharp/OperationScenarios/Enums/CElevatorConnectionEnum.i90 b/CSharp/OperationScenarios/Enums/CElevatorConnectionEnum.i90 new file mode 100644 index 0000000..24a3f24 --- /dev/null +++ b/CSharp/OperationScenarios/Enums/CElevatorConnectionEnum.i90 @@ -0,0 +1,617 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Enums/CElevatorConnectionEnum.f90" +module CElevatorConnectionEnum + use OperationScenariosModule + use CLog3 + use CLog4 + implicit none + contains + + subroutine Evaluate_ElevatorConnection() + use CHoistingVariables + use SimulationVariables + use CCommon, only: SetStandRack + implicit none + + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 18 + + endif + + + + + + + + + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 32 + + +!!OPERATION-CODE=83 +!if (Get_OperationCondition() == OPERATION_TRIP .and.& +! Get_ElevatorConnection() == ELEVATOR_LATCH_STRING .and.& +! Get_ElevatorPickup() .and.& +! Get_Slips() == SLIPS_SET_END) then +! !call Log_4('OPERATION-CODE=83') +! call Set_ElevatorConnection(ELEVATOR_CONNECTION_STRING) +! return +!end if + + + + + + + + + + + + +!OPERATION-CODE=78 + if (Get_ElevatorPickup() == .false. .and.& + Get_Tong() == TONG_BREAKOUT_END .and.& + Get_HookHeight() <= (data%State%OperationScenario%HL + Get_NearFloorConnection() + data%State%OperationScenario%PL) .and.& + Get_ElevatorConnection() == ELEVATOR_LATCH_STRING) then + call Set_ElevatorConnection(ELEVATOR_LATCH_SINGLE) + return + end if + +!OPERATION-CODE=79 + if (Get_ElevatorPickup() == .false. .and.& + Get_Tong() == TONG_BREAKOUT_END .and.& + Get_HookHeight() >= (data%State%OperationScenario%HL + Get_NearFloorConnection() + data%State%OperationScenario%SL - data%State%OperationScenario%LG) .and.& + Get_ElevatorConnection() == ELEVATOR_LATCH_STRING) then + call Set_ElevatorConnection(ELEVATOR_LATCH_STAND) + return + end if + + + +!OPERATION-CODE=83 + if (Get_ElevatorPickup().and.& + Get_ElevatorConnection() == ELEVATOR_LATCH_SINGLE) then + call Set_ElevatorConnection(ELEVATOR_CONNECTION_SINGLE) + return + end if + + +!OPERATION-CODE=84 + if (Get_ElevatorPickup().and.& + Get_ElevatorConnection() == ELEVATOR_LATCH_STAND) then + call Set_ElevatorConnection(ELEVATOR_CONNECTION_STAND) + return + end if + + + + + + + + + + +!OPERATION-CODE=7 + if (Get_OperationCondition() == OPERATION_TRIP .and.& +!GetRotaryRpm() == 0.0d0 .and.& +!Get_StandRack() > 0 .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING .and.& +!Get_Swing() == SWING_WELL_END .and.& +!Get_Slips() == SLIPS_SET_END .and.& +!Get_LatchLed() .and. + Get_Elevator() == ELEVATOR_LATCH_STAND_END) then +!call Log_4('OPERATION-CODE=7') + call Set_ElevatorConnection(ELEVATOR_CONNECTION_STAND) +!call Set_UnlatchLed(.true.) +!call Set_LatchLed(.false.) + call SetStandRack(Get_StandRack() - 1) + call Set_Elevator(ELEVATOR_NEUTRAL) + return + end if + +!OPERATION-CODE=8 + if (Get_OperationCondition() == OPERATION_TRIP .and.& +!Get_HookHeight() >= (HL + Get_NearFloorConnection() + SL - RE) .and. Get_HookHeight() <= (HL + Get_NearFloorConnection() + SL + LG) .and.& +!GetRotaryRpm() == 0.0d0 .and.& +!Get_StandRack() < 80 .and.& +!Get_ElevatorConnectionPossible() .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_STAND .and.& +!Get_Swing() == SWING_WELL_END .and.& +!Get_Slips() == SLIPS_SET_END .and.& +!Get_UnlatchLed() .and.& + Get_Elevator() == ELEVATOR_UNLATCH_STAND_END) then + call Set_ElevatorConnection(ELEVATOR_CONNECTION_NOTHING) +!call Set_UnlatchLed(.false.) +!call Set_LatchLed(.true.) + call SetStandRack(Get_StandRack() + 1) + call Set_Elevator(ELEVATOR_NEUTRAL) +!call Set_Elevator(ELEVATOR_UNLATCH_STAND_BEGIN) + call Log_3('OPERATION-CODE=8') + return + end if + +!OPERATION-CODE=9 + if (Get_OperationCondition() == OPERATION_TRIP .and.& +!Get_HookHeight() >= 18.0 .and. Get_HookHeight() <= 22.0 .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING .and.& +!Get_Swing() == SWING_WELL_END .and.& +!Get_Slips() == SLIPS_SET_END .and.& +!Get_LatchLed() .and.& +!Get_ElevatorPickup() .and.& + Get_Elevator() == ELEVATOR_LATCH_STRING_END) then +!call Log_4('OPERATION-CODE=9') + call Set_ElevatorConnection(ELEVATOR_LATCH_STRING) + call Set_Elevator(ELEVATOR_NEUTRAL) +!call Set_UnlatchLed(.true.) +!call Set_LatchLed(.false.) +!call Set_UnlatchLed(.false.) +!call Set_Elevator(ELEVATOR_LATCH_STRING_BEGIN) + return + end if + +!OPERATION-CODE=60 + if (Get_OperationCondition() == OPERATION_TRIP .and.& +!Get_HookHeight() <= (HL + Get_NearFloorConnection() - ECG) .and.& + Get_ElevatorPickup() == .false. .and.& + Get_Slips() == SLIPS_SET_END .and.& +!Get_Tong() /= TONG_MAKEUP_END .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING) then + call Set_ElevatorConnection(ELEVATOR_LATCH_STRING) +!call Set_Elevator(ELEVATOR_NEUTRAL) + return + end if + +!OPERATION-CODE=49 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_ElevatorPickup() .and.& + Get_ElevatorConnection() == ELEVATOR_LATCH_STRING) then + call Set_ElevatorConnection(ELEVATOR_CONNECTION_STRING) + return + end if + +!OPERATION-CODE=10 + if (Get_OperationCondition() == OPERATION_TRIP .and.& +!GetRotaryRpm() == 0.0d0 .and.& + (Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING .or. Get_ElevatorConnection() == ELEVATOR_LATCH_STRING) .and.& +!Get_Swing() == SWING_WELL_END .and.& +!Get_Slips() == SLIPS_SET_END .and.& +!Get_UnlatchLed() .and.& + Get_Elevator() == ELEVATOR_UNLATCH_STRING_END) then +!call Log_4('OPERATION-CODE=10') + call Set_ElevatorConnection(ELEVATOR_CONNECTION_NOTHING) + call Set_Elevator(ELEVATOR_NEUTRAL) +!call Set_UnlatchLed(.false.) +!call Set_LatchLed(.true.) +!call Set_Elevator(ELEVATOR_UNLATCH_STRING_BEGIN) + return + end if + +!OPERATION-CODE=11 + if (Get_OperationCondition() == OPERATION_TRIP .and.& +!Get_ElevatorConnectionPossible() .and.& + Get_ElevatorPickup().and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING .and.& +!Get_Swing() == SWING_MOUSE_HOLE_END .and.& +!Get_LatchLed() .and.& +!Get_FillMouseHoleLed() .and.& + Get_Elevator() == ELEVATOR_LATCH_SINGLE_END) then + + call Set_ElevatorConnection(ELEVATOR_CONNECTION_SINGLE) +!call Set_UnlatchLed(.true.) + call Set_FillMouseHoleLed(.false.) + call Set_MouseHole(MOUSE_HOLE_NEUTRAL) + call Set_Elevator(ELEVATOR_NEUTRAL) +!call Set_Elevator(ELEVATOR_LATCH_SINGLE_BEGIN) + return + end if + +!OPERATION-CODE=12 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE .and.& +!Get_Swing() == SWING_MOUSE_HOLE_END .and.& +!Get_UnlatchLed() .and.& +!Get_FillMouseHoleLed() == .false. .and.& + Get_Elevator() == ELEVATOR_UNLATCH_SINGLE_END) then +!call Log_4('OPERATION-CODE=12') + call Set_ElevatorConnection(ELEVATOR_CONNECTION_NOTHING) +!call Set_UnlatchLed(.false.) +!call Set_LatchLed(.true.) + call Set_FillMouseHoleLed(.true.) + call Set_MouseHole(MOUSE_HOLE_NEUTRAL) + call Set_Elevator(ELEVATOR_NEUTRAL) +!call Set_Elevator(ELEVATOR_UNLATCH_SINGLE_BEGIN) + return + end if + +!OPERATION-CODE=13 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_HookHeight() <= (data%State%OperationScenario%HL + Get_NearFloorConnection() + data%State%OperationScenario%PL) .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING .and.& +!Get_Swing() == SWING_WELL_END .and.& +!Get_TongNotification() .and.& + Get_ElevatorPickup().and.& + Get_Tong() == TONG_BREAKOUT_END) then +!call Log_4('OPERATION-CODE=13') + call Set_ElevatorConnection(ELEVATOR_CONNECTION_SINGLE) + call Set_StringUpdate(STRING_UPDATE_REMOVE_SINGLE) +!call Set_StringUpdate(STRING_UPDATE_ADD_SINGLE) + call Set_Tong(TONG_NEUTRAL) + return + end if + +!OPERATION-CODE=14 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_HookHeight() <= (data%State%OperationScenario%HL + Get_NearFloorConnection() + data%State%OperationScenario%PL) .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE .and.& +!Get_Swing() == SWING_WELL_END .and.& +!Get_TongNotification() .and.& + Get_ElevatorPickup().and.& + Get_Tong() == TONG_MAKEUP_END) then +!call Log_4('OPERATION-CODE=14') + call Set_Tong(TONG_NEUTRAL) + call Set_ElevatorConnection(ELEVATOR_CONNECTION_STRING) + call Set_StringUpdate(STRING_UPDATE_ADD_SINGLE) + return + end if + + +!OPERATION-CODE=15 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_HookHeight() >= (data%State%OperationScenario%HL + Get_NearFloorConnection() + data%State%OperationScenario%SL - data%State%OperationScenario%LG) .and.& +!Get_HookHeight() >= (HL + Get_NearFloorConnection() + SL - RE) .and. Get_HookHeight() <= (HL + Get_NearFloorConnection() + SL + LG) .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING .and.& +!Get_Swing() == SWING_WELL_END .and.& +!Get_TongNotification() .and.& + Get_ElevatorPickup().and.& + Get_Tong() == TONG_BREAKOUT_END) then + call Set_Tong(TONG_NEUTRAL) + call Set_ElevatorConnection(ELEVATOR_CONNECTION_STAND) + call Set_StringUpdate(STRING_UPDATE_REMOVE_STAND) + return + end if + +!OPERATION-CODE=16 + if (Get_OperationCondition() == OPERATION_TRIP .and.& +!Get_HookHeight() >= (HL + Get_NearFloorConnection() + SL - RE) .and. Get_HookHeight() <= (HL + Get_NearFloorConnection() + SL + LG) .and.& +!Get_JointConnectionPossible() .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_STAND .and.& +!Get_Swing() == SWING_WELL_END .and.& +!Get_TongNotification() .and.& + Get_ElevatorPickup().and.& + Get_Tong() == TONG_MAKEUP_END) then +!call Log_4('OPERATION-CODE=16') + call Set_Tong(TONG_NEUTRAL) + call Set_ElevatorConnection(ELEVATOR_CONNECTION_STRING) + call Set_StringUpdate(STRING_UPDATE_ADD_STAND) + return + end if + + + + + +!OPERATION-CODE=75 + if (Get_ElevatorPickup() == .false. .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE) then + call Set_ElevatorConnection(ELEVATOR_LATCH_SINGLE) + return + end if + + +!OPERATION-CODE=76 + if (Get_ElevatorPickup() == .false. .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_STAND) then + call Set_ElevatorConnection(ELEVATOR_LATCH_STAND) + return + end if + + + + + + + endif + + + + end subroutine + +! subroutine Subscribe_ElevatorConnection() +! use CDrillingConsoleVariables +! use ConfigurationVariables +! use ConfigurationVariables +! implicit none +! call OnLatchPipePress%Add(ButtonPress_Latch_ElevatorConnection) +! call OnUnlatchPipePress%Add(ButtonPress_Unlatch_ElevatorConnection) +! call OnBreakoutLeverPress%Add(ButtonPress_Breakout_ElevatorConnection) +! call OnMakeupLeverPress%Add(ButtonPress_Makeup_ElevatorConnection) +! end subroutine + + subroutine ButtonPress_Latch_ElevatorConnection() + use CCommon, only: SetStandRack + implicit none + + + + + + + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 348 + + + + + +!TOPDRIVE-CODE=73 + if ((Get_HookHeight() >= (TL() + data%State%OperationScenario%SL - data%State%OperationScenario%ECG + NFC()) .and. Get_HookHeight() <= (TL() + data%State%OperationScenario%SL - data%State%OperationScenario%ECG + NFC() + data%State%OperationScenario%TG)) .and.& + Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& + Get_TdsSwing() == TDS_SWING_OFF_END .and.& + Get_LatchLed()) then + + call Set_Elevator(ELEVATOR_LATCH_STAND_BEGIN) + call Set_LatchLed(.false.) + return + end if + + + + + + + +!TOPDRIVE-CODE=74 + if (Get_HookHeight() <= (TL() + NFC() - data%State%OperationScenario%ECG) .and.& + GetRotaryRpm() == 0.0d0 .and.& + Get_ElevatorConnectionPossible() .and.& + Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& + Get_TdsSwing() == TDS_SWING_OFF_END .and.& + Get_LatchLed()) then + + call Set_Elevator(ELEVATOR_LATCH_STRING_BEGIN) + call Set_LatchLed(.false.) + return + end if + + + + + + + +!TOPDRIVE-CODE=75 + if (Get_ElevatorConnectionPossible() .and.& + Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& + Get_TdsSwing() == TDS_SWING_TILT_END .and.& + Get_LatchLed() .and.& + Get_FillMouseHoleLed()) then + + call Set_Elevator(ELEVATOR_LATCH_SINGLE_BEGIN) + call Set_LatchLed(.false.) + return + end if + + + + + + + + endif + + + + + + + + + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 420 + + +!OPERATION-CODE=86 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_HookHeight() <= (data%State%OperationScenario%HL + Get_NearFloorConnection() - data%State%OperationScenario%ECG) .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING .and.& + Get_LatchLed() .and.& + GetRotaryRpm() == 0.0d0 .and.& + Get_Swing() == SWING_WELL_END .and.& + Get_ElevatorConnectionPossible() .and.& + Get_HookHeight() <= (data%State%OperationScenario%HL + Get_NearFloorConnection())) then + +!call Log_4("OPERATION-CODE=ELEVATOR_LATCH_STRING_BEGIN") + call Set_Elevator(ELEVATOR_LATCH_STRING_BEGIN) + call Set_LatchLed(.false.) + return + endif + +!OPERATION-CODE=85 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_HookHeight() >= (data%State%OperationScenario%HL + data%State%OperationScenario%SL - data%State%OperationScenario%ECG + Get_NearFloorConnection()) .and. Get_HookHeight() <= (data%State%OperationScenario%HL + data%State%OperationScenario%SL - data%State%OperationScenario%ECG + Get_NearFloorConnection() + data%State%OperationScenario%LG) .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING .and.& + Get_LatchLed() .and.& + Get_Swing() == SWING_WELL_END) then +!Get_HookHeight() >= (HL + Get_NearFloorConnection() + SL + RE) .and. Get_HookHeight() <= (HL + Get_NearFloorConnection() + SL + LG) + + call Set_Elevator(ELEVATOR_LATCH_STAND_BEGIN) + call Set_LatchLed(.false.) + return + endif + +!OPERATION-CODE=87 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING .and.& + Get_LatchLed() .and.& + Get_FillMouseHoleLed() .and.& + Get_ElevatorConnectionPossible() .and.& + Get_Swing() == SWING_MOUSE_HOLE_END) then + + call Set_Elevator(ELEVATOR_LATCH_SINGLE_BEGIN) + call Set_LatchLed(.false.) + return + endif + + + endif + + + + + + + + + + + + + end subroutine + + subroutine ButtonPress_Unlatch_ElevatorConnection() + use CCommon, only: SetStandRack + implicit none + + + + + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 491 + + + + +!TOPDRIVE-CODE=76 + if ((Get_HookHeight() >= (TL() + data%State%OperationScenario%SL - data%State%OperationScenario%ECG + NFC()) .and. Get_HookHeight() <= (TL() + data%State%OperationScenario%SL - data%State%OperationScenario%ECG + NFC() + data%State%OperationScenario%TG)) .and.& + Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_STAND .and.& + Get_TdsSwing() == TDS_SWING_OFF_END .and.& + Get_UnlatchLed()) then + + call Set_Elevator(ELEVATOR_UNLATCH_STAND_BEGIN) + call Set_UnlatchLed(.false.) + return + end if + + + + + + + + +!TOPDRIVE-CODE=77 + if (Get_HookHeight() <= (TL() + NFC() - data%State%OperationScenario%ECG) .and.& + GetRotaryRpm() == 0.0d0 .and.& + Get_NearFloorConnection() >= 3.0 .and. Get_NearFloorConnection() <= 6.0 .and.& + (Get_TdsElevatorModes() == TDS_ELEVATOR_LATCH_STRING .or. Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_STRING) .and.& + Get_TdsSwing() == TDS_SWING_OFF_END .and.& + Get_UnlatchLed()) then + + call Set_Elevator(ELEVATOR_UNLATCH_STRING_BEGIN) + call Set_UnlatchLed(.false.) + return + end if + + + + + + + +!TOPDRIVE-CODE=78 + if ((Get_HookHeight() > TL() .and. Get_HookHeight() < (TL() + NFC() + data%State%OperationScenario%SG)) .and.& + Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_SINGLE .and.& + Get_TdsSwing() == TDS_SWING_TILT_END .and.& + Get_UnlatchLed() .and.& + Get_FillMouseHoleLed() == .false.) then + + call Set_Elevator(ELEVATOR_UNLATCH_SINGLE_BEGIN) + call Set_UnlatchLed(.false.) + return + end if + + + + + + endif + + + + + + + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 559 + +!OPERATION-CODE=89 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_HookHeight() <= (data%State%OperationScenario%HL + Get_NearFloorConnection() - data%State%OperationScenario%ECG) .and.& + (Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING .or. Get_ElevatorConnection() == ELEVATOR_LATCH_STRING) .and.& + Get_HookHeight() <= (data%State%OperationScenario%HL + Get_NearFloorConnection()) .and.& + Get_UnlatchLed() .and.& + GetRotaryRpm() == 0.0d0 .and.& + Get_Swing() == SWING_WELL_END .and.& + Get_NearFloorConnection() >= 3.0 .and. Get_NearFloorConnection() <= 6.0) then +!Get_HookHeight() >= (HL + Get_NearFloorConnection() - 4.0) .and. Get_HookHeight() <= (HL + Get_NearFloorConnection() - 2.0)) then + + call Set_Elevator(ELEVATOR_UNLATCH_STRING_BEGIN) + call Set_UnlatchLed(.false.) + return + endif + +!OPERATION-CODE=88 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_HookHeight() >= (data%State%OperationScenario%HL + data%State%OperationScenario%SL - data%State%OperationScenario%ECG + Get_NearFloorConnection()) .and. Get_HookHeight() <= (data%State%OperationScenario%HL + data%State%OperationScenario%SL - data%State%OperationScenario%ECG + Get_NearFloorConnection() + data%State%OperationScenario%LG) .and.& +!Get_HookHeight() >= (HL + Get_NearFloorConnection() + SL + RE) .and. Get_HookHeight() <= (HL + Get_NearFloorConnection() + SL + LG) + Get_ElevatorConnection() == ELEVATOR_CONNECTION_STAND .and.& + Get_UnlatchLed() .and.& + Get_Swing() == SWING_WELL_END) then + + call Set_Elevator(ELEVATOR_UNLATCH_STAND_BEGIN) + call Set_UnlatchLed(.false.) + return + endif + +!OPERATION-CODE=90 + if (Get_OperationCondition() == OPERATION_TRIP .and.& + Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE .and.& + Get_UnlatchLed() .and.& + Get_HookHeight() >= data%State%OperationScenario%HL .and. Get_HookHeight() <= (data%State%OperationScenario%HL + Get_NearFloorConnection() + data%State%OperationScenario%SG) .and.& +!Get_JointConnectionPossible() .and.& + Get_Swing() == SWING_MOUSE_HOLE_END) then + + call Set_Elevator(ELEVATOR_UNLATCH_SINGLE_BEGIN) + call Set_UnlatchLed(.false.) + return + endif + + endif + + + + + + + + end subroutine + + subroutine ButtonPress_Breakout_ElevatorConnection() + implicit none + + end subroutine + + subroutine ButtonPress_Makeup_ElevatorConnection() + implicit none + + end subroutine + +end module CElevatorConnectionEnum diff --git a/CSharp/OperationScenarios/Notifications/CCloseKellyCockLedNotification.i90 b/CSharp/OperationScenarios/Notifications/CCloseKellyCockLedNotification.i90 new file mode 100644 index 0000000..d83517a --- /dev/null +++ b/CSharp/OperationScenarios/Notifications/CCloseKellyCockLedNotification.i90 @@ -0,0 +1,75 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Notifications/CCloseKellyCockLedNotification.f90" +module CCloseKellyCockLedNotification + use OperationScenariosModule + implicit none + contains + + subroutine Evaluate_CloseKellyCockLed() + implicit none + + +! if (DriveType == TopDrive_DriveType) then +!#ifdef OST +! print*, 'Evaluate_CloseKellyCockLed=TopDrive' +!#endif +! endif +! +! +! +! +! +! +! +! +! +! +! if (DriveType == Kelly_DriveType) then +!#ifdef OST +! print*, 'Evaluate_CloseKellyCockLed=Kelly' +!#endif +! endif + + + end subroutine + +! subroutine Subscribe_CloseKellyCockLed() +! use CDrillingConsoleVariables +! use ConfigurationVariables +! use ConfigurationVariables +! implicit none +! call OnCloseKellyCockPress%Add(ButtonPress_CloseKellyCock) +! end subroutine + + subroutine ButtonPress_CloseKellyCock() + implicit none + + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 49 + + endif + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 55 + + +!OPERATION-CODE=66 + if (Get_OperationCondition() == OPERATION_DRILL .and.& + Get_CloseKellyCockLed() == .false. .and.& + Get_OpenKellyCockLed()) then + call Set_OpenKellyCockLed(.false.) + call Set_CloseKellyCockLed(.true.) + return + end if + + + endif + + + + + + + end subroutine + +end module CCloseKellyCockLedNotification diff --git a/CSharp/OperationScenarios/Notifications/CIrIBopLedNotification.f90 b/CSharp/OperationScenarios/Notifications/CIrIBopLedNotification.f90 index 846ec14..3b647a6 100644 --- a/CSharp/OperationScenarios/Notifications/CIrIBopLedNotification.f90 +++ b/CSharp/OperationScenarios/Notifications/CIrIBopLedNotification.f90 @@ -70,7 +70,7 @@ module CIrIBopLedNotification !TOPDRIVE-CODE=60 if (Get_IrIbopPermission() .and.& Get_IrIBopLed() == .true. .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF) then call Set_IrIBopLed(.false.) return diff --git a/CSharp/OperationScenarios/Notifications/CIrIBopLedNotification.i90 b/CSharp/OperationScenarios/Notifications/CIrIBopLedNotification.i90 new file mode 100644 index 0000000..bc38a51 --- /dev/null +++ b/CSharp/OperationScenarios/Notifications/CIrIBopLedNotification.i90 @@ -0,0 +1,119 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Notifications/CIrIBopLedNotification.f90" +module CIrIBopLedNotification + use OperationScenariosModule +! use CTopDrivePanelVariables + use SimulationVariables + implicit none + contains + + subroutine Evaluate_IrIBopLed() + implicit none + + + +! if (DriveType == TopDrive_DriveType) then +!#ifdef OST +! print*, 'Evaluate_IrIBopLed=TopDrive' +!#endif +! endif +! +! +! +! +! +! +! +! +! if (DriveType == Kelly_DriveType) then +!#ifdef OST +! print*, 'Evaluate_IrIBopLed=Kelly' +!#endif +! endif + + + + + end subroutine + +! subroutine Subscribe_IrIBopLed() +! use CDrillingConsoleVariables +!@ use ConfigurationVariables +!@ use ConfigurationVariables +! implicit none +! call OnIRIBopPress%Add(ButtonPress_IrIBop) +! end subroutine + + subroutine ButtonPress_IrIBop() + implicit none + + + + + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 55 + + + + +!TOPDRIVE-CODE=59 + if (Get_IrIbopPermission() .and.& + Get_IrIBopLed() == .false.) then + + call Set_IrIBopLed(.true.) + return + end if + + + + +!TOPDRIVE-CODE=60 + if (Get_IrIbopPermission() .and.& + Get_IrIBopLed() == .true. .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF) then + + call Set_IrIBopLed(.false.) + return + end if + + + + endif + + + + + + + + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 93 + + +!OPERATION-CODE=63 + if (Get_IrIbopPermission() .and.& + Get_IrIBopLed() == .false.) then + call Set_IrIBopLed(.true.) + return + end if + + +!OPERATION-CODE=64 + if (Get_IrIbopPermission() .and.& + Get_IrIBopLed()) then + call Set_IrIBopLed(.false.) + return + end if + + endif + + + + + + + + end subroutine + +end module CIrIBopLedNotification diff --git a/CSharp/OperationScenarios/Notifications/CTdsIbopLedNotification.f90 b/CSharp/OperationScenarios/Notifications/CTdsIbopLedNotification.f90 index bd37df5..e9385ac 100644 --- a/CSharp/OperationScenarios/Notifications/CTdsIbopLedNotification.f90 +++ b/CSharp/OperationScenarios/Notifications/CTdsIbopLedNotification.f90 @@ -18,11 +18,11 @@ module CTdsIbopLedNotification !TOPDRIVE-CODE=61 if (Get_IbopLed() == .false. .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF .and.& - data%EquipmentControl%TopDrivePanel%TopDriveIbop == .false.) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF .and.& + data%Equipments%TopDrivePanel%TopDriveIbop == .false.) then call Set_IbopLed(.true.) - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_OFF + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_OFF return end if @@ -31,11 +31,11 @@ module CTdsIbopLedNotification !TOPDRIVE-CODE=62 if (Get_IbopLed() .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF .and.& - data%EquipmentControl%TopDrivePanel%TopDriveIbop) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF .and.& + data%Equipments%TopDrivePanel%TopDriveIbop) then call Set_IbopLed(.false.) - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON return end if diff --git a/CSharp/OperationScenarios/Notifications/CTdsIbopLedNotification.i90 b/CSharp/OperationScenarios/Notifications/CTdsIbopLedNotification.i90 new file mode 100644 index 0000000..47abeba --- /dev/null +++ b/CSharp/OperationScenarios/Notifications/CTdsIbopLedNotification.i90 @@ -0,0 +1,72 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Notifications/CTdsIbopLedNotification.f90" +module CTdsIbopLedNotification + use OperationScenariosModule + implicit none + contains + + subroutine Evaluate_IbopLed() + use CCommon + implicit none + + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 14 + + + + + +!TOPDRIVE-CODE=61 + if (Get_IbopLed() == .false. .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF .and.& + data%Equipments%TopDrivePanel%TopDriveIbop == .false.) then + + call Set_IbopLed(.true.) + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_OFF + return + end if + + + + +!TOPDRIVE-CODE=62 + if (Get_IbopLed() .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF .and.& + data%Equipments%TopDrivePanel%TopDriveIbop) then + + call Set_IbopLed(.false.) + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + return + end if + + + + + + endif + + + + + + + + +! if (DriveType == Kelly_DriveType) then +!#ifdef OST +! print*, 'Evaluate_IbopLed=Kelly' +!#endif +! +! endif + + + + + + end subroutine + +! subroutine Subscribe_IbopLed() +! implicit none +! end subroutine + +end module CTdsIbopLedNotification diff --git a/CSharp/OperationScenarios/Notifications/CTdsPowerLedNotification.f90 b/CSharp/OperationScenarios/Notifications/CTdsPowerLedNotification.f90 index f3ff095..dd5fe9a 100644 --- a/CSharp/OperationScenarios/Notifications/CTdsPowerLedNotification.f90 +++ b/CSharp/OperationScenarios/Notifications/CTdsPowerLedNotification.f90 @@ -15,7 +15,7 @@ module CTdsPowerLedNotification #endif !TOPDRIVE-CODE=63 - if (data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF) then + if (data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF) then call Set_PowerLed(.true.) return end if diff --git a/CSharp/OperationScenarios/Notifications/CTdsPowerLedNotification.i90 b/CSharp/OperationScenarios/Notifications/CTdsPowerLedNotification.i90 new file mode 100644 index 0000000..0be2146 --- /dev/null +++ b/CSharp/OperationScenarios/Notifications/CTdsPowerLedNotification.i90 @@ -0,0 +1,48 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Notifications/CTdsPowerLedNotification.f90" +module CTdsPowerLedNotification + use OperationScenariosModule + use SimulationVariables + implicit none + contains + + subroutine Evaluate_PowerLed() + use CCommon + implicit none + + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 15 + + +!TOPDRIVE-CODE=63 + if (data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_OFF) then + call Set_PowerLed(.true.) + return + end if + + endif + + + + + + + + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 35 + + + endif + + + + + + end subroutine + +! subroutine Subscribe_PowerLed() +! implicit none +! end subroutine + +end module CTdsPowerLedNotification diff --git a/CSharp/OperationScenarios/Notifications/CTdsTorqueWrenchLedNotification.f90 b/CSharp/OperationScenarios/Notifications/CTdsTorqueWrenchLedNotification.f90 index 212f6d6..397b66a 100644 --- a/CSharp/OperationScenarios/Notifications/CTdsTorqueWrenchLedNotification.f90 +++ b/CSharp/OperationScenarios/Notifications/CTdsTorqueWrenchLedNotification.f90 @@ -14,14 +14,14 @@ module CTdsTorqueWrenchLedNotification !TOPDRIVE-CODE=81 if((Get_TdsBackupClamp() == BACKUP_CLAMP_OFF_BEGIN .or.& Get_TdsBackupClamp() == BACKUP_CLAMP_FW_BEGIN) .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then call Set_TorqueWrenchLed(LED_BLINK) return endif !TOPDRIVE-CODE=81 if(Get_TdsBackupClamp() == BACKUP_CLAMP_FW_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then call Set_TorqueWrenchLed(LED_ON) return endif diff --git a/CSharp/OperationScenarios/Notifications/CTdsTorqueWrenchLedNotification.i90 b/CSharp/OperationScenarios/Notifications/CTdsTorqueWrenchLedNotification.i90 new file mode 100644 index 0000000..ab4416b --- /dev/null +++ b/CSharp/OperationScenarios/Notifications/CTdsTorqueWrenchLedNotification.i90 @@ -0,0 +1,58 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Notifications/CTdsTorqueWrenchLedNotification.f90" +module CTdsTorqueWrenchLedNotification + use OperationScenariosModule + implicit none + contains + + subroutine Evaluate_TorqueWrenchLed() + implicit none + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 12 + + +!TOPDRIVE-CODE=81 + if((Get_TdsBackupClamp() == BACKUP_CLAMP_OFF_BEGIN .or.& + Get_TdsBackupClamp() == BACKUP_CLAMP_FW_BEGIN) .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + call Set_TorqueWrenchLed(LED_BLINK) + return + endif + +!TOPDRIVE-CODE=81 + if(Get_TdsBackupClamp() == BACKUP_CLAMP_FW_END .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + call Set_TorqueWrenchLed(LED_ON) + return + endif + + + call Set_TorqueWrenchLed(LED_OFF) + + endif + + + + + + + + + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 45 + + + + endif + + + + end subroutine + +! subroutine Subscribe_TorqueWrenchLed() +! implicit none + +! end subroutine + +end module CTdsTorqueWrenchLedNotification diff --git a/CSharp/OperationScenarios/Notifications/Notifications.f90 b/CSharp/OperationScenarios/Notifications/Notifications.f90 index a810ef7..b51568a 100644 --- a/CSharp/OperationScenarios/Notifications/Notifications.f90 +++ b/CSharp/OperationScenarios/Notifications/Notifications.f90 @@ -14,10 +14,10 @@ contains data%State%notifications%UnlatchLed = v if(data%State%notifications%UnlatchLed) then - data%EquipmentControl%DrillingConsole%UnlatchPipeLED = 1 + data%Equipments%DrillingConsole%UnlatchPipeLED = 1 !call Set_LatchLed(.false.) else - data%EquipmentControl%DrillingConsole%UnlatchPipeLED = 0 + data%Equipments%DrillingConsole%UnlatchPipeLED = 0 endif !**call data%State%notifications%OnUnlatchLedChange%RunAll() @@ -49,7 +49,7 @@ contains subroutine Set_TorqueWrenchLed(v) use CTopDrivePanelVariables - use SimulationVariables!, only: data%EquipmentControl%TopDrivePanel%TopDriveTorqueWrenchLed + use SimulationVariables!, only: data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed implicit none integer , intent(in) :: v @@ -57,7 +57,7 @@ contains if(data%State%notifications%TorqueWrenchLed == v) return #endif data%State%notifications%TorqueWrenchLed = v - data%EquipmentControl%TopDrivePanel%TopDriveTorqueWrenchLed = v + data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed = v !**call data%State%notifications%OnTorqueWrenchLedChange%RunAll() end subroutine @@ -68,7 +68,7 @@ contains subroutine Set_PowerLed(v) use CTopDrivePanelVariables - use SimulationVariables!, only: data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerLed + use SimulationVariables!, only: data%Equipments%TopDrivePanel%TopDriveTdsPowerLed !use CLatchLedNotification implicit none logical , intent(in) :: v @@ -78,10 +78,10 @@ contains data%State%notifications%PowerLed = v if(data%State%notifications%PowerLed) then - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerLed = 1 + data%Equipments%TopDrivePanel%TopDriveTdsPowerLed = 1 !call Set_LatchLed(.false.) else - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerLed = 0 + data%Equipments%TopDrivePanel%TopDriveTdsPowerLed = 0 endif !**call data%State%notifications%OnPowerLedChange%RunAll() @@ -94,7 +94,7 @@ contains subroutine Set_IbopLed(v) use CTopDrivePanelVariables - use SimulationVariables!, only: data%EquipmentControl%TopDrivePanel%TopDriveIbopLed + use SimulationVariables!, only: data%Equipments%TopDrivePanel%TopDriveIbopLed use CManifolds, Only: OpenTopDriveIBop, CloseTopDriveIBop !use CLatchLedNotification implicit none @@ -105,10 +105,10 @@ contains data%State%notifications%IbopLed = v if(data%State%notifications%IbopLed) then - data%EquipmentControl%TopDrivePanel%TopDriveIbopLed = 1 + data%Equipments%TopDrivePanel%TopDriveIbopLed = 1 call CloseTopDriveIBop() else - data%EquipmentControl%TopDrivePanel%TopDriveIbopLed = 0 + data%Equipments%TopDrivePanel%TopDriveIbopLed = 0 call OpenTopDriveIBop() endif @@ -132,9 +132,9 @@ contains #endif data%State%notifications%SwingLed = v if(data%State%notifications%SwingLed) then - data%EquipmentControl%DrillingConsole%SwingLed = 1 + data%Equipments%DrillingConsole%SwingLed = 1 else - data%EquipmentControl%DrillingConsole%SwingLed = 0 + data%Equipments%DrillingConsole%SwingLed = 0 endif !**call data%State%notifications%OnSwingLedChange%RunAll() end subroutine @@ -227,7 +227,7 @@ contains subroutine Set_LatchLed(v) use CDrillingConsoleVariables use SimulationVariables - use SimulationVariables!, only: data%EquipmentControl%DrillingConsole%LatchPipeLED + use SimulationVariables!, only: data%Equipments%DrillingConsole%LatchPipeLED !use CUnlatchLedNotification implicit none logical , intent(in) :: v @@ -236,10 +236,10 @@ contains #endif data%State%notifications%LatchLed = v if(data%State%notifications%LatchLed) then - data%EquipmentControl%DrillingConsole%LatchPipeLED = 1 + data%Equipments%DrillingConsole%LatchPipeLED = 1 !call Set_UnlatchLed(.false.) else - data%EquipmentControl%DrillingConsole%LatchPipeLED = 0 + data%Equipments%DrillingConsole%LatchPipeLED = 0 endif !**call data%State%notifications%OnLatchLedChange%RunAll() end subroutine @@ -252,7 +252,7 @@ contains subroutine Set_IrSafetyValveLed(v) use CDrillingConsoleVariables use SimulationVariables - use SimulationVariables!, only: data%EquipmentControl%DrillingConsole%CloseKellyCockLed => IRSafetyValveLed + use SimulationVariables!, only: data%Equipments%DrillingConsole%CloseKellyCockLed => IRSafetyValveLed use CManifolds, only: & InstallSafetyValve_TopDrive, & InstallSafetyValve_KellyMode, & @@ -272,7 +272,7 @@ contains data%State%notifications%IrSafetyValveLed = v if(data%State%notifications%IrSafetyValveLed) then - data%EquipmentControl%DrillingConsole%IRSafetyValveLed = 1 + data%Equipments%DrillingConsole%IRSafetyValveLed = 1 if(data%Configuration%Hoisting%DriveType == TopDrive_DriveType) call InstallSafetyValve_TopDrive() if(data%Configuration%Hoisting%DriveType == Kelly_DriveType .and. data%State%notifications%operation_IrSafetyValveLed == 0) call InstallSafetyValve_KellyMode() @@ -280,7 +280,7 @@ contains call Set_SafetyValve_Install() else - data%EquipmentControl%DrillingConsole%IRSafetyValveLed = 0 + data%Equipments%DrillingConsole%IRSafetyValveLed = 0 if(data%Configuration%Hoisting%DriveType == TopDrive_DriveType) call RemoveSafetyValve_TopDrive() if(data%Configuration%Hoisting%DriveType == Kelly_DriveType .and. data%State%notifications%operation_IrSafetyValveLed == 0) call RemoveSafetyValve_KellyMode() @@ -311,11 +311,11 @@ contains #endif data%State%notifications%IrIBopLed = v if(data%State%notifications%IrIBopLed) then - data%EquipmentControl%DrillingConsole%IRIBopLed = 1 + data%Equipments%DrillingConsole%IRIBopLed = 1 call InstallIBop() call Set_Ibop_Install() else - data%EquipmentControl%DrillingConsole%IRIBopLed = 0 + data%Equipments%DrillingConsole%IRIBopLed = 0 call RemoveIBop() call Set_Ibop_Remove() endif @@ -341,10 +341,10 @@ contains #endif data%State%notifications%FillMouseHoleLed = v if(data%State%notifications%FillMouseHoleLed) then - data%EquipmentControl%DrillingConsole%FillMouseHoleLed = 1 + data%Equipments%DrillingConsole%FillMouseHoleLed = 1 !call Set_MouseHole(MOUSE_HOLE_FILL) else - data%EquipmentControl%DrillingConsole%FillMouseHoleLed = 0 + data%Equipments%DrillingConsole%FillMouseHoleLed = 0 !call Set_MouseHole(MOUSE_HOLE_EMPTY) endif !**call data%State%notifications%OnFillMouseHoleLedChange%RunAll() diff --git a/CSharp/OperationScenarios/Notifications/Notifications.i90 b/CSharp/OperationScenarios/Notifications/Notifications.i90 new file mode 100644 index 0000000..31a007a --- /dev/null +++ b/CSharp/OperationScenarios/Notifications/Notifications.i90 @@ -0,0 +1,409 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Notifications/Notifications.f90" +module NotificationModule + use SimulationVariables + implicit none +contains + subroutine Set_UnlatchLed(v) + use CDrillingConsoleVariables + use SimulationVariables +!use CLatchLedNotification + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%UnlatchLed == v) return + #endif + data%State%notifications%UnlatchLed = v + + if(data%State%notifications%UnlatchLed) then + data%Equipments%DrillingConsole%UnlatchPipeLED = 1 +!call Set_LatchLed(.false.) + else + data%Equipments%DrillingConsole%UnlatchPipeLED = 0 + endif + +!**call data%State%notifications%OnUnlatchLedChange%RunAll() + end subroutine + + logical function Get_UnlatchLed() + implicit none + Get_UnlatchLed = data%State%notifications%UnlatchLed + end function + + subroutine Set_TongNotification(v) + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%TongNotification == v) return + #endif + data%State%notifications%TongNotification = v +! if(associated(data%State%notifications%TongNotificationPtr)) !**call data%State%notifications%TongNotificationPtr(data%State%notifications%TongNotification) + #ifdef deb + print*, 'data%State%notifications%TongNotification=', data%State%notifications%TongNotification + #endif +!**call data%State%notifications%OnTongNotificationChange%RunAll() + end subroutine + + logical function Get_TongNotification() + implicit none + Get_TongNotification = data%State%notifications%TongNotification + end function + + subroutine Set_TorqueWrenchLed(v) + use CTopDrivePanelVariables + use SimulationVariables!, only: data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed + implicit none + integer , intent(in) :: v + + #ifdef ExcludeExtraChanges + if(data%State%notifications%TorqueWrenchLed == v) return + #endif + data%State%notifications%TorqueWrenchLed = v + data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed = v +!**call data%State%notifications%OnTorqueWrenchLedChange%RunAll() + end subroutine + + logical function Get_TorqueWrenchLed() + implicit none + Get_TorqueWrenchLed = data%State%notifications%TorqueWrenchLed + end function + + subroutine Set_PowerLed(v) + use CTopDrivePanelVariables + use SimulationVariables!, only: data%Equipments%TopDrivePanel%TopDriveTdsPowerLed +!use CLatchLedNotification + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%PowerLed == v) return + #endif + data%State%notifications%PowerLed = v + + if(data%State%notifications%PowerLed) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerLed = 1 +!call Set_LatchLed(.false.) + else + data%Equipments%TopDrivePanel%TopDriveTdsPowerLed = 0 + endif + +!**call data%State%notifications%OnPowerLedChange%RunAll() + end subroutine + + logical function Get_PowerLed() + implicit none + Get_PowerLed = data%State%notifications%PowerLed + end function + + subroutine Set_IbopLed(v) + use CTopDrivePanelVariables + use SimulationVariables!, only: data%Equipments%TopDrivePanel%TopDriveIbopLed + use CManifolds, Only: OpenTopDriveIBop, CloseTopDriveIBop +!use CLatchLedNotification + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%IbopLed == v) return + #endif + data%State%notifications%IbopLed = v + + if(data%State%notifications%IbopLed) then + data%Equipments%TopDrivePanel%TopDriveIbopLed = 1 + call CloseTopDriveIBop() + else + data%Equipments%TopDrivePanel%TopDriveIbopLed = 0 + call OpenTopDriveIBop() + endif + +!**call data%State%notifications%OnIbopLedChange%RunAll() + end subroutine + + logical function Get_IbopLed() + implicit none + Get_IbopLed = data%State%notifications%IbopLed + end function + + subroutine Set_SwingLed(v) + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables!, only: SwingLedHw => SwingLed + implicit none + logical , intent(in) :: v + + #ifdef ExcludeExtraChanges + if(data%State%notifications%SwingLed == v) return + #endif + data%State%notifications%SwingLed = v + if(data%State%notifications%SwingLed) then + data%Equipments%DrillingConsole%SwingLed = 1 + else + data%Equipments%DrillingConsole%SwingLed = 0 + endif +!**call data%State%notifications%OnSwingLedChange%RunAll() + end subroutine + + logical function Get_SwingLed() + implicit none + Get_SwingLed = data%State%notifications%SwingLed + end function + + subroutine Set_SlipsNotification(v) + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%SlipsNotification == v) return + #endif + data%State%notifications%SlipsNotification = v +! if(associated(data%State%notifications%SlipsNotificationPtr)) !**call data%State%notifications%SlipsNotificationPtr(data%State%notifications%SlipsNotification) + #ifdef deb + print*, 'data%State%notifications%SlipsNotification=', data%State%notifications%SlipsNotification + #endif +!**call data%State%notifications%OnSlipsNotificationChange%RunAll() + end subroutine + + logical function Get_SlipsNotification() + implicit none + Get_SlipsNotification = data%State%notifications%SlipsNotification + end function + + subroutine Set_OpenSafetyValveLed(v) + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables!, only: OpenSafetyValveLedHw => OpenSafetyValveLed + use CManifolds, only: OpenSafetyValve_TopDrive, OpenSafetyValve_KellyMode, OpenSafetyValve_TripMode + use CHoistingVariables + use SimulationVariables!, only: data%Configuration%Hoisting%DriveType, TopDrive_DriveType, Kelly_DriveType + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%OpenSafetyValveLed == v) return + #endif + data%State%notifications%OpenSafetyValveLed = v + + if(data%State%notifications%OpenSafetyValveLed) then +!!call OpenSafetyValve() + if(data%Configuration%Hoisting%DriveType == TopDrive_DriveType) call OpenSafetyValve_TopDrive() + if(data%Configuration%Hoisting%DriveType == Kelly_DriveType .and. data%State%notifications%operation_OpenSafetyValveLed == 0) call OpenSafetyValve_KellyMode() + if(data%Configuration%Hoisting%DriveType == Kelly_DriveType .and. data%State%notifications%operation_OpenSafetyValveLed == 1) call OpenSafetyValve_TripMode() + endif + +!**call data%State%notifications%OnOpenSafetyValveLedChange%RunAll() + end subroutine + + logical function Get_OpenSafetyValveLed() + implicit none + Get_OpenSafetyValveLed = data%State%notifications%OpenSafetyValveLed + end function + + subroutine Set_OpenKellyCockLed(v) +! use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables!, only: OpenKellyCockLedHw => OpenKellyCockLed + use CManifolds, only: OpenKellyCock + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%OpenKellyCockLed == v) return + #endif + data%State%notifications%OpenKellyCockLed = v + + if(data%State%notifications%OpenKellyCockLed) then + call OpenKellyCock() + endif + +! HAS BEEN IMPLEMENTED IN CMANIFOLD + +!if(OpenKellyCockLed) then +! OpenKellyCockLedHw = 1 +!else +! OpenKellyCockLedHw = 0 +!endif + +!**call data%State%notifications%OnOpenKellyCockLedChange%RunAll() + end subroutine + + logical function Get_OpenKellyCockLed() + implicit none + Get_OpenKellyCockLed = data%State%notifications%OpenKellyCockLed + end function + + subroutine Set_LatchLed(v) + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables!, only: data%Equipments%DrillingConsole%LatchPipeLED +!use CUnlatchLedNotification + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%LatchLed == v) return + #endif + data%State%notifications%LatchLed = v + if(data%State%notifications%LatchLed) then + data%Equipments%DrillingConsole%LatchPipeLED = 1 +!call Set_UnlatchLed(.false.) + else + data%Equipments%DrillingConsole%LatchPipeLED = 0 + endif +!**call data%State%notifications%OnLatchLedChange%RunAll() + end subroutine + + logical function Get_LatchLed() + implicit none + Get_LatchLed = data%State%notifications%LatchLed + end function + + subroutine Set_IrSafetyValveLed(v) + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables!, only: data%Equipments%DrillingConsole%CloseKellyCockLed => IRSafetyValveLed + use CManifolds, only: & + InstallSafetyValve_TopDrive, & + InstallSafetyValve_KellyMode, & + InstallSafetyValve_TripMode, & + RemoveSafetyValve_TopDrive, & + RemoveSafetyValve_KellyMode, & + RemoveSafetyValve_TripMode + use UnitySignalVariables + use UnitySignalsModule, only: Set_SafetyValve_Install, Set_SafetyValve_Remove + use CHoistingVariables + use SimulationVariables!, only: data%Configuration%Hoisting%DriveType, TopDrive_DriveType, Kelly_DriveType + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%IrSafetyValveLed == v) return + #endif + data%State%notifications%IrSafetyValveLed = v + + if(data%State%notifications%IrSafetyValveLed) then + data%Equipments%DrillingConsole%IRSafetyValveLed = 1 + + if(data%Configuration%Hoisting%DriveType == TopDrive_DriveType) call InstallSafetyValve_TopDrive() + if(data%Configuration%Hoisting%DriveType == Kelly_DriveType .and. data%State%notifications%operation_IrSafetyValveLed == 0) call InstallSafetyValve_KellyMode() + if(data%Configuration%Hoisting%DriveType == Kelly_DriveType .and. data%State%notifications%operation_IrSafetyValveLed == 1) call InstallSafetyValve_TripMode() + + call Set_SafetyValve_Install() + else + data%Equipments%DrillingConsole%IRSafetyValveLed = 0 + + if(data%Configuration%Hoisting%DriveType == TopDrive_DriveType) call RemoveSafetyValve_TopDrive() + if(data%Configuration%Hoisting%DriveType == Kelly_DriveType .and. data%State%notifications%operation_IrSafetyValveLed == 0) call RemoveSafetyValve_KellyMode() + if(data%Configuration%Hoisting%DriveType == Kelly_DriveType .and. data%State%notifications%operation_IrSafetyValveLed == 1) call RemoveSafetyValve_TripMode() + + call Set_SafetyValve_Remove() + endif + +!**call data%State%notifications%OnIrSafetyValveLedChange%RunAll() + end subroutine + + logical function Get_IrSafetyValveLed() + implicit none + Get_IrSafetyValveLed = data%State%notifications%IrSafetyValveLed + end function + + subroutine Set_IrIBopLed(v) + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables!, only: IRIBopLedHw => IRIBopLed + use CManifolds, only: InstallIBop, RemoveIBop + use UnitySignalVariables + use UnitySignalsModule, only: Set_Ibop_Install, Set_Ibop_Remove + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%IrIBopLed == v) return + #endif + data%State%notifications%IrIBopLed = v + if(data%State%notifications%IrIBopLed) then + data%Equipments%DrillingConsole%IRIBopLed = 1 + call InstallIBop() + call Set_Ibop_Install() + else + data%Equipments%DrillingConsole%IRIBopLed = 0 + call RemoveIBop() + call Set_Ibop_Remove() + endif +!**call data%State%notifications%OnIrIBopLedChange%RunAll() + end subroutine + + logical function Get_IrIBopLed() + implicit none + Get_IrIBopLed = data%State%notifications%IrIBopLed + end function + + subroutine Set_FillMouseHoleLed(v) + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables!, only: FillMouseHoleLedHw => FillMouseHoleLed +! use CMouseHoleEnumVariables + use UnitySignalVariables + use UnitySignalsModule + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%FillMouseHoleLed == v) return + #endif + data%State%notifications%FillMouseHoleLed = v + if(data%State%notifications%FillMouseHoleLed) then + data%Equipments%DrillingConsole%FillMouseHoleLed = 1 +!call Set_MouseHole(MOUSE_HOLE_FILL) + else + data%Equipments%DrillingConsole%FillMouseHoleLed = 0 +!call Set_MouseHole(MOUSE_HOLE_EMPTY) + endif +!**call data%State%notifications%OnFillMouseHoleLedChange%RunAll() + end subroutine + + logical function Get_FillMouseHoleLed() + implicit none + Get_FillMouseHoleLed = data%State%notifications%FillMouseHoleLed + end function + + subroutine Set_CloseKellyCockLed(v) + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables!, only: CloseKellyCockLedHw => CloseKellyCockLed + use CManifolds, only: CloseKellyCock + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%CloseKellyCockLed == v) return + #endif + data%State%notifications%CloseKellyCockLed = v + if(data%State%notifications%CloseKellyCockLed) then + call CloseKellyCock() + endif +!**call data%State%notifications%OnCloseKellyCockLedChange%RunAll() + end subroutine + + logical function Get_CloseKellyCockLed() + implicit none + Get_CloseKellyCockLed = data%State%notifications%CloseKellyCockLed + end function + + subroutine Set_CloseSafetyValveLed(v) +! use CDrillingConsoleVariables + use SimulationVariables +!@use ConfigurationVariables, only: CloseSafetyValveLedHw => CloseSafetyValveLed + use CManifolds, only: CloseSafetyValve_TopDrive, CloseSafetyValve_KellyMode, CloseSafetyValve_TripMode + use CHoistingVariables + use SimulationVariables!, only: data%Configuration%Hoisting%DriveType, TopDrive_DriveType, Kelly_DriveType + implicit none + logical , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%notifications%CloseSafetyValveLed == v) return + #endif + data%State%notifications%CloseSafetyValveLed = v + if(data%State%notifications%CloseSafetyValveLed) then +!!call CloseSafetyValve() + if(data%Configuration%Hoisting%DriveType == TopDrive_DriveType) call CloseSafetyValve_TopDrive() + if(data%Configuration%Hoisting%DriveType == Kelly_DriveType .and. data%State%notifications%operation_CloseSafetyValveLed == 0) call CloseSafetyValve_KellyMode() + if(data%Configuration%Hoisting%DriveType == Kelly_DriveType .and. data%State%notifications%operation_CloseSafetyValveLed == 1) call CloseSafetyValve_TripMode() + endif +!**call data%State%notifications%OnCloseSafetyValveLedChange%RunAll() + end subroutine + + logical function Get_CloseSafetyValveLed() + implicit none + Get_CloseSafetyValveLed = data%State%notifications%CloseSafetyValveLed + end function + +end module NotificationModule + diff --git a/CSharp/OperationScenarios/Permissions/CSwingDrillPermission.f90 b/CSharp/OperationScenarios/Permissions/CSwingDrillPermission.f90 index f305229..4789051 100644 --- a/CSharp/OperationScenarios/Permissions/CSwingDrillPermission.f90 +++ b/CSharp/OperationScenarios/Permissions/CSwingDrillPermission.f90 @@ -18,7 +18,7 @@ module CSwingDrillPermission !TOPDRIVE-CODE=33 if (Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& Get_TdsSwing() == TDS_SWING_OFF_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then call Set_SwingDrillPermission(.true.) return diff --git a/CSharp/OperationScenarios/Permissions/CSwingDrillPermission.i90 b/CSharp/OperationScenarios/Permissions/CSwingDrillPermission.i90 new file mode 100644 index 0000000..4de1c65 --- /dev/null +++ b/CSharp/OperationScenarios/Permissions/CSwingDrillPermission.i90 @@ -0,0 +1,61 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Permissions/CSwingDrillPermission.f90" +module CSwingDrillPermission + use OperationScenariosModule + use CTopDrivePanelVariables + use SimulationVariables + implicit none + + contains + + subroutine Evaluate_SwingDrillPermission() + implicit none + + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 16 + + +!TOPDRIVE-CODE=33 + if (Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& + Get_TdsSwing() == TDS_SWING_OFF_END .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + + call Set_SwingDrillPermission(.true.) + return + end if + + + + + + + call Set_SwingDrillPermission(.false.) + + + + + + endif + + + + + + + + + +! if (DriveType == Kelly_DriveType) then +!#ifdef OST +! print*, 'Evaluate_SwingDrillPermission=Kelly' +!#endif +! endif + + + end subroutine + + subroutine Subscribe_SwingDrillPermission() + implicit none + end subroutine + +end module CSwingDrillPermission diff --git a/CSharp/OperationScenarios/Permissions/CSwingOffPermission.f90 b/CSharp/OperationScenarios/Permissions/CSwingOffPermission.f90 index 2fab1ea..85038e2 100644 --- a/CSharp/OperationScenarios/Permissions/CSwingOffPermission.f90 +++ b/CSharp/OperationScenarios/Permissions/CSwingOffPermission.f90 @@ -20,7 +20,7 @@ module CSwingOffPermission Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.& Get_TdsSwing() == TDS_SWING_TILT_END .and.& Get_Slips() == SLIPS_SET_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then call Set_SwingOffPermission(.true.) return @@ -33,7 +33,7 @@ module CSwingOffPermission if (Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.& Get_TdsSwing() == TDS_SWING_DRILL_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then call Set_SwingOffPermission(.true.) return diff --git a/CSharp/OperationScenarios/Permissions/CSwingOffPermission.i90 b/CSharp/OperationScenarios/Permissions/CSwingOffPermission.i90 new file mode 100644 index 0000000..c099ab0 --- /dev/null +++ b/CSharp/OperationScenarios/Permissions/CSwingOffPermission.i90 @@ -0,0 +1,67 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Permissions/CSwingOffPermission.f90" +module CSwingOffPermission + use OperationScenariosModule + implicit none + + contains + + subroutine Evaluate_SwingOffPermission() + implicit none + + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 14 + + + + +!TOPDRIVE-CODE=35 + if (Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& + Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.& + Get_TdsSwing() == TDS_SWING_TILT_END .and.& + Get_Slips() == SLIPS_SET_END .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + + call Set_SwingOffPermission(.true.) + return + end if + + + + +!TOPDRIVE-CODE=36 + if (Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& + Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.& + Get_TdsSwing() == TDS_SWING_DRILL_END .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + + call Set_SwingOffPermission(.true.) + return + end if + + + + call Set_SwingOffPermission(.false.) + + endif + + + + + + + + +! if (DriveType == Kelly_DriveType) then +!#ifdef OST +! print*, 'Evaluate_SwingOffPermission=Kelly' +!#endif +! endif + + end subroutine + + subroutine Subscribe_SwingOffPermission() + implicit none + end subroutine + +end module CSwingOffPermission diff --git a/CSharp/OperationScenarios/Permissions/CSwingTiltPermission.f90 b/CSharp/OperationScenarios/Permissions/CSwingTiltPermission.f90 index ddcf44f..eac2df9 100644 --- a/CSharp/OperationScenarios/Permissions/CSwingTiltPermission.f90 +++ b/CSharp/OperationScenarios/Permissions/CSwingTiltPermission.f90 @@ -20,7 +20,7 @@ module CSwingTiltPermission Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.& Get_TdsSwing() == TDS_SWING_OFF_END .and.& Get_Slips() == SLIPS_SET_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then call Set_SwingTiltPermission(.true.) return diff --git a/CSharp/OperationScenarios/Permissions/CSwingTiltPermission.i90 b/CSharp/OperationScenarios/Permissions/CSwingTiltPermission.i90 new file mode 100644 index 0000000..920be54 --- /dev/null +++ b/CSharp/OperationScenarios/Permissions/CSwingTiltPermission.i90 @@ -0,0 +1,54 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Permissions/CSwingTiltPermission.f90" +module CSwingTiltPermission + use UnitySignalsModule + use OperationScenariosModule + use SimulationVariables + implicit none + + contains + + subroutine Evaluate_SwingTiltPermission() + implicit none + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 15 + + + +!TOPDRIVE-CODE=34 + if (Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& + Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.& + Get_TdsSwing() == TDS_SWING_OFF_END .and.& + Get_Slips() == SLIPS_SET_END .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF) then + + call Set_SwingTiltPermission(.true.) + return + end if + + + call Set_SwingTiltPermission(.false.) + + endif + + + + + + + + + +! if (DriveType == Kelly_DriveType) then +!#ifdef OST +! print*, 'Evaluate_SwingTiltPermission=Kelly' +!#endif +! endif + + end subroutine + + subroutine Subscribe_SwingTiltPermission() + implicit none + end subroutine + +end module CSwingTiltPermission diff --git a/CSharp/OperationScenarios/Unity/CUnityOutputs.f90 b/CSharp/OperationScenarios/Unity/CUnityOutputs.f90 index 9098fde..1f8df34 100644 --- a/CSharp/OperationScenarios/Unity/CUnityOutputs.f90 +++ b/CSharp/OperationScenarios/Unity/CUnityOutputs.f90 @@ -23,7 +23,7 @@ module CUnityOutputs ! use ConfigurationVariables ! implicit none ! ! PumpsSpmChanges => Calc_KellyHoseVibrationRate - ! ! call data%EquipmentControl%DataDisplayConsole%OnRotaryRpmChange%Add(Set_RotaryRpm) + ! ! call data%Equipments%DataDisplayConsole%OnRotaryRpmChange%Add(Set_RotaryRpm) ! end subroutine diff --git a/CSharp/OperationScenarios/Unity/CUnityOutputs.i90 b/CSharp/OperationScenarios/Unity/CUnityOutputs.i90 new file mode 100644 index 0000000..b4f0ad3 --- /dev/null +++ b/CSharp/OperationScenarios/Unity/CUnityOutputs.i90 @@ -0,0 +1,215 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/Unity/CUnityOutputs.f90" +module CUnityOutputs + implicit none + type :: UnityOutputsType + real(8) :: KellyHoseVibrationRate + real(8) :: BlowoutFromStringPercent + real(8) :: Pedal + real(8) :: FlowRate + real(8) :: RotaryRpm + logical :: BlowoutFromString + logical :: BlowoutFromAnnular + logical :: FlowFromReturnLine + real :: FlowFromKelly + real :: FlowFromFillupHead + logical :: FlowKellyDisconnect + logical :: FlowPipeDisconnect + end type UnityOutputsType + type(UnityOutputsType):: UnityOutputs + + contains + +! subroutine Setup() +! use CDataDisplayConsole +! use ConfigurationVariables +! implicit none +! ! PumpsSpmChanges => Calc_KellyHoseVibrationRate +! ! call data%Equipments%DataDisplayConsole%OnRotaryRpmChange%Add(Set_RotaryRpm) +! end subroutine + + + + + + + + + + + subroutine Set_BlowoutFromString(v) + implicit none + logical, intent (in) :: v + UnityOutputs%BlowoutFromString = v +# 44 + + end subroutine + + logical function Get_BlowoutFromString() + implicit none + Get_BlowoutFromString = UnityOutputs%BlowoutFromString + end function + + subroutine Set_BlowoutFromAnnular(v) + implicit none + logical, intent (in) :: v + UnityOutputs%BlowoutFromAnnular = v +# 58 + + end subroutine + + logical function Get_BlowoutFromAnnular() + implicit none + Get_BlowoutFromAnnular = UnityOutputs%BlowoutFromAnnular + end function + + + + + + subroutine Set_FlowFromReturnLine(v) + implicit none + logical, intent (in) :: v + UnityOutputs%FlowFromReturnLine = v +# 76 + + end subroutine + + logical function Get_FlowFromReturnLine() + implicit none + Get_FlowFromReturnLine = UnityOutputs%FlowFromReturnLine + end function + + + + subroutine Set_FlowFromKelly(v) + implicit none + real, intent (in) :: v + UnityOutputs%FlowFromKelly = v +# 92 + + end subroutine + + real function Get_FlowFromKelly() + implicit none + Get_FlowFromKelly = UnityOutputs%FlowFromKelly + end function + + + + + + subroutine Set_FlowFromFillupHead(v) + implicit none + real, intent (in) :: v + UnityOutputs%FlowFromFillupHead = v +# 110 + + end subroutine + + real function Get_FlowFromFillupHead() + implicit none + Get_FlowFromFillupHead = UnityOutputs%FlowFromFillupHead + end function + + + + + + + subroutine Set_FlowKellyDisconnect(v) + implicit none + logical, intent (in) :: v + UnityOutputs%FlowKellyDisconnect = v +# 129 + + end subroutine + + logical function Get_FlowKellyDisconnect() + implicit none + Get_FlowKellyDisconnect = UnityOutputs%FlowKellyDisconnect + end function + + + + + subroutine Set_FlowPipeDisconnect(v) + implicit none + logical, intent (in) :: v + UnityOutputs%FlowPipeDisconnect = v +# 146 + + end subroutine + + logical function Get_FlowPipeDisconnect() + implicit none + Get_FlowPipeDisconnect = UnityOutputs%FlowPipeDisconnect + end function + + subroutine Set_BlowoutFromStringPercent(v) + implicit none + real(8), intent (in) :: v + UnityOutputs%BlowoutFromStringPercent = v +# 160 + + end subroutine + + real(8) function GetBlowoutFromStringPercent() + implicit none + GetBlowoutFromStringPercent = UnityOutputs%BlowoutFromStringPercent + end function + + subroutine Calc_KellyHoseVibrationRate(spm1, spm2) + use CScaleRange + implicit none + real(8), intent (in) :: spm1, spm2 + real :: total + total = (spm1 + spm2)/2 + UnityOutputs%KellyHoseVibrationRate = ScaleRange(total, 0.0, 10.0, 0.0, 120.0) +# 177 + + end subroutine + + real(8) function GetKellyHoseVibrationRate() + implicit none + GetKellyHoseVibrationRate = UnityOutputs%KellyHoseVibrationRate + end function + + subroutine Set_Pedal(v) + implicit none + real(8), intent (in) :: v + UnityOutputs%Pedal = v +# 191 + + end subroutine + + real(8) function GetPedal() + implicit none + GetPedal = UnityOutputs%Pedal + end function + + subroutine Set_FlowRate(v) + implicit none + real(8), intent (in) :: v + UnityOutputs%FlowRate = v +# 205 + + end subroutine + + + real(8) function GetFlowRate() + implicit none + GetFlowRate = UnityOutputs%FlowRate + end function + subroutine Set_RotaryRpm(v) + implicit none + real(8), intent (in) :: v + UnityOutputs%RotaryRpm = v +# 219 + + end subroutine + + real(8) function GetRotaryRpm() + implicit none + GetRotaryRpm = UnityOutputs%RotaryRpm + end function +end module CUnityOutputs diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsBackupClamp.f90 b/CSharp/OperationScenarios/UnitySignals/CTdsBackupClamp.f90 index 177a988..153fb2c 100644 --- a/CSharp/OperationScenarios/UnitySignals/CTdsBackupClamp.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CTdsBackupClamp.f90 @@ -13,8 +13,8 @@ module CTdsBackupClamp !TOPDRIVE-CODE=79 if(Get_TdsBackupClamp() == BACKUP_CLAMP_OFF_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTorqueWrench) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF .and.& + data%Equipments%TopDrivePanel%TopDriveTorqueWrench) then call Set_TdsBackupClamp(BACKUP_CLAMP_FW_BEGIN) @@ -23,8 +23,8 @@ module CTdsBackupClamp !TOPDRIVE-CODE=80 if(Get_TdsBackupClamp() /= BACKUP_CLAMP_OFF_END .and.& Get_TdsBackupClamp() /= BACKUP_CLAMP_OFF_BEGIN .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTorqueWrench == .false.) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF .and.& + data%Equipments%TopDrivePanel%TopDriveTorqueWrench == .false.) then call Set_TdsBackupClamp(BACKUP_CLAMP_OFF_BEGIN) diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsBackupClamp.i90 b/CSharp/OperationScenarios/UnitySignals/CTdsBackupClamp.i90 new file mode 100644 index 0000000..8d9b84c --- /dev/null +++ b/CSharp/OperationScenarios/UnitySignals/CTdsBackupClamp.i90 @@ -0,0 +1,58 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/UnitySignals/CTdsBackupClamp.f90" +module CTdsBackupClamp + use OperationScenariosModule + implicit none + contains + + subroutine Evaluate_TdsBackupClamp() + implicit none + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 12 + + +!TOPDRIVE-CODE=79 + if(Get_TdsBackupClamp() == BACKUP_CLAMP_OFF_END .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF .and.& + data%Equipments%TopDrivePanel%TopDriveTorqueWrench) then + + call Set_TdsBackupClamp(BACKUP_CLAMP_FW_BEGIN) + + endif + +!TOPDRIVE-CODE=80 + if(Get_TdsBackupClamp() /= BACKUP_CLAMP_OFF_END .and.& + Get_TdsBackupClamp() /= BACKUP_CLAMP_OFF_BEGIN .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState /= TdsPower_OFF .and.& + data%Equipments%TopDrivePanel%TopDriveTorqueWrench == .false.) then + + call Set_TdsBackupClamp(BACKUP_CLAMP_OFF_BEGIN) + + endif + + + endif + + + + + + + + + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 47 + + endif + + end subroutine + + subroutine Subscribe_TdsBackupClamp() + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables + implicit none + end subroutine + +end module CTdsBackupClamp diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnum.f90 b/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnum.f90 index c0234bd..13f4a6e 100644 --- a/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnum.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnum.f90 @@ -16,8 +16,8 @@ module CTdsSpineEnum if (Get_TdsStemIn() .and.& Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.& !Get_TdsConnectionPossible() .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState == TdsPower_FWD .and.& - data%EquipmentControl%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_SPINE) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_FWD .and.& + data%Equipments%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_SPINE) then call Set_TdsSpine(TDS_SPINE_CONNECT_BEGIN) return @@ -27,8 +27,8 @@ module CTdsSpineEnum if (Get_TdsStemIn() .and.& Get_TdsTong() == TDS_TONG_BREAKOUT_END .and.& Get_TdsConnectionModes() == TDS_CONNECTION_SPINE .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState == TdsPower_REV .and.& - data%EquipmentControl%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_SPINE) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_REV .and.& + data%Equipments%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_SPINE) then call Set_TdsSpine(TDS_SPINE_DISCONNECT_BEGIN) return diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnum.i90 b/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnum.i90 new file mode 100644 index 0000000..8c9e85c --- /dev/null +++ b/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnum.i90 @@ -0,0 +1,63 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/UnitySignals/CTdsSpineEnum.f90" +module CTdsSpineEnum + use OperationScenariosModule + use UnitySignalsModule !for CTdsConnectionModesEnum, only:Get_TdsConnectionModes + implicit none + contains + + subroutine Evaluate_TdsSpine() + implicit none + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 13 + + +!TOPDRIVE-CODE=83 + if (Get_TdsStemIn() .and.& + Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.& +!Get_TdsConnectionPossible() .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_FWD .and.& + data%Equipments%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_SPINE) then + + call Set_TdsSpine(TDS_SPINE_CONNECT_BEGIN) + return + end if + +!TOPDRIVE-CODE=84 + if (Get_TdsStemIn() .and.& + Get_TdsTong() == TDS_TONG_BREAKOUT_END .and.& + Get_TdsConnectionModes() == TDS_CONNECTION_SPINE .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_REV .and.& + data%Equipments%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_SPINE) then + + call Set_TdsSpine(TDS_SPINE_DISCONNECT_BEGIN) + return + end if + + + + endif + + + + + + + + + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 52 + + endif + + end subroutine + + subroutine Subscribe_TdsSpine() + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables + implicit none + end subroutine + +end module CTdsSpineEnum diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnum.f90 b/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnum.f90 index e43da98..090f97c 100644 --- a/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnum.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnum.f90 @@ -18,10 +18,10 @@ module CTdsSwingEnum if (Get_SwingDrillPermission() .and.& Get_TdsSwing() == TDS_SWING_OFF_END .and.& Get_FillMouseHoleLed() == .false. .and.& - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_DRILL) then + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_DRILL) then call Set_TdsSwing(TDS_SWING_DRILL_BEGIN) - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON return end if @@ -30,10 +30,10 @@ module CTdsSwingEnum !TOPDRIVE-CODE=38 if (Get_SwingTiltPermission() .and.& Get_TdsSwing() == TDS_SWING_TILT_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then call Set_TdsSwing(TDS_SWING_TILT_BEGIN) - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON return end if @@ -43,10 +43,10 @@ module CTdsSwingEnum if (Get_SwingOffPermission() .and.& Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.& Get_TdsSwing() == TDS_SWING_OFF_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then call Set_TdsSwing(TDS_SWING_OFF_BEGIN) - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON return end if @@ -58,10 +58,10 @@ module CTdsSwingEnum if (Get_SwingTiltPermission() .and.& Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& Get_TdsSwing() == TDS_SWING_OFF_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then call Set_TdsSwing(TDS_SWING_TILT_BEGIN) - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON return end if @@ -73,10 +73,10 @@ module CTdsSwingEnum if (Get_SwingOffPermission() .and.& Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& Get_TdsSwing() == TDS_SWING_TILT_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then call Set_TdsSwing(TDS_SWING_OFF_BEGIN) - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON return end if @@ -89,10 +89,10 @@ module CTdsSwingEnum Get_SwingTiltPermission() .and.& Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_SINGLE .and.& Get_TdsSwing() == TDS_SWING_OFF_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then call Set_TdsSwing(TDS_SWING_TILT_BEGIN) - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON return end if @@ -104,10 +104,10 @@ module CTdsSwingEnum Get_SwingOffPermission() .and.& Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_SINGLE .and.& Get_TdsSwing() == TDS_SWING_TILT_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then call Set_TdsSwing(TDS_SWING_OFF_BEGIN) - data%EquipmentControl%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON return end if diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnum.i90 b/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnum.i90 new file mode 100644 index 0000000..2474ec2 --- /dev/null +++ b/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnum.i90 @@ -0,0 +1,144 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/UnitySignals/CTdsSwingEnum.f90" +module CTdsSwingEnum + use OperationScenariosModule + use SimulationVariables + use UnitySignalsModule + implicit none + contains + + subroutine Evaluate_TdsSwing() + implicit none + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 14 + + + +!TOPDRIVE-CODE=37 + if (Get_SwingDrillPermission() .and.& + Get_TdsSwing() == TDS_SWING_OFF_END .and.& + Get_FillMouseHoleLed() == .false. .and.& + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_DRILL) then + + call Set_TdsSwing(TDS_SWING_DRILL_BEGIN) + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + return + end if + + + +!TOPDRIVE-CODE=38 + if (Get_SwingTiltPermission() .and.& + Get_TdsSwing() == TDS_SWING_TILT_END .and.& + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then + + call Set_TdsSwing(TDS_SWING_TILT_BEGIN) + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + return + end if + + + +!TOPDRIVE-CODE=39 + if (Get_SwingOffPermission() .and.& + Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING .and.& + Get_TdsSwing() == TDS_SWING_OFF_END .and.& + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then + + call Set_TdsSwing(TDS_SWING_OFF_BEGIN) + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + return + end if + + + + + +!TOPDRIVE-CODE=40 + if (Get_SwingTiltPermission() .and.& + Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& + Get_TdsSwing() == TDS_SWING_OFF_END .and.& + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then + + call Set_TdsSwing(TDS_SWING_TILT_BEGIN) + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + return + end if + + + + + +!TOPDRIVE-CODE=41 + if (Get_SwingOffPermission() .and.& + Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_NOTHING .and.& + Get_TdsSwing() == TDS_SWING_TILT_END .and.& + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then + + call Set_TdsSwing(TDS_SWING_OFF_BEGIN) + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + return + end if + + + + + +!TOPDRIVE-CODE=42 + if (Get_HookHeight() > (TL() + NFC() + data%State%OperationScenario%PL - data%State%OperationScenario%ECG) .and.& + Get_SwingTiltPermission() .and.& + Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_SINGLE .and.& + Get_TdsSwing() == TDS_SWING_OFF_END .and.& + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_TILT) then + + call Set_TdsSwing(TDS_SWING_TILT_BEGIN) + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + return + end if + + + + +!TOPDRIVE-CODE=43 + if (Get_HookHeight() > (TL() + NFC() + data%State%OperationScenario%PL - data%State%OperationScenario%ECG) .and.& + Get_SwingOffPermission() .and.& + Get_TdsElevatorModes() == TDS_ELEVATOR_CONNECTION_SINGLE .and.& + Get_TdsSwing() == TDS_SWING_TILT_END .and.& + data%Equipments%TopDrivePanel%TopDriveLinkTiltState == TdsLinkTilt_OFF) then + + call Set_TdsSwing(TDS_SWING_OFF_BEGIN) + data%Equipments%TopDrivePanel%TopDriveLinkTiltLed = LED_ON + return + end if + + + + endif + + + + + + + + + + + + +! if (DriveType == Kelly_DriveType) then +!#ifdef OST +! print*, 'Evaluate_TdsSwing=Kelly' +!#endif +! endif + + end subroutine + + subroutine Subscribe_TdsSwing() + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables + implicit none + end subroutine + +end module CTdsSwingEnum diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsTongEnum.f90 b/CSharp/OperationScenarios/UnitySignals/CTdsTongEnum.f90 index 0c70421..88bca0f 100644 --- a/CSharp/OperationScenarios/UnitySignals/CTdsTongEnum.f90 +++ b/CSharp/OperationScenarios/UnitySignals/CTdsTongEnum.f90 @@ -16,8 +16,8 @@ module CTdsTongEnum !TOPDRIVE-CODE=1 if (Get_TdsConnectionModes() == TDS_CONNECTION_SPINE .and.& Get_TdsBackupClamp() == BACKUP_CLAMP_FW_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState == TdsPower_FWD .and.& - data%EquipmentControl%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_TORQ) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_FWD .and.& + data%Equipments%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_TORQ) then call Set_TdsTong(TDS_TONG_MAKEUP_BEGIN) !TopDriveTorqueWrenchLed = LED_ON @@ -29,8 +29,8 @@ module CTdsTongEnum !TOPDRIVE-CODE=2 if (Get_TdsConnectionModes() == TDS_CONNECTION_STRING .and.& Get_TdsBackupClamp() == BACKUP_CLAMP_FW_END .and.& - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState == TdsPower_REV .and.& - data%EquipmentControl%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_TORQ) then + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_REV .and.& + data%Equipments%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_TORQ) then call Set_TdsTong(TDS_TONG_BREAKOUT_BEGIN) !TopDriveTorqueWrenchLed = LED_ON diff --git a/CSharp/OperationScenarios/UnitySignals/CTdsTongEnum.i90 b/CSharp/OperationScenarios/UnitySignals/CTdsTongEnum.i90 new file mode 100644 index 0000000..cf1a10a --- /dev/null +++ b/CSharp/OperationScenarios/UnitySignals/CTdsTongEnum.i90 @@ -0,0 +1,65 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/UnitySignals/CTdsTongEnum.f90" +module CTdsTongEnum + use OperationScenariosModule + implicit none + contains + + subroutine Evaluate_TdsTong() + implicit none + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 12 + + + + +!TOPDRIVE-CODE=1 + if (Get_TdsConnectionModes() == TDS_CONNECTION_SPINE .and.& + Get_TdsBackupClamp() == BACKUP_CLAMP_FW_END .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_FWD .and.& + data%Equipments%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_TORQ) then + + call Set_TdsTong(TDS_TONG_MAKEUP_BEGIN) +!TopDriveTorqueWrenchLed = LED_ON + return + end if + + + +!TOPDRIVE-CODE=2 + if (Get_TdsConnectionModes() == TDS_CONNECTION_STRING .and.& + Get_TdsBackupClamp() == BACKUP_CLAMP_FW_END .and.& + data%Equipments%TopDrivePanel%TopDriveTdsPowerState == TdsPower_REV .and.& + data%Equipments%TopDrivePanel%TopDriveDrillTorqueState == TdsMu_TORQ) then + + call Set_TdsTong(TDS_TONG_BREAKOUT_BEGIN) +!TopDriveTorqueWrenchLed = LED_ON + return + end if + + + endif + + + + + + + + + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 54 + + endif + + end subroutine + + subroutine Subscribe_TdsTong() + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables + implicit none + end subroutine + +end module CTdsTongEnum diff --git a/CSharp/OperationScenarios/UnitySignals/UnitySignals.f90 b/CSharp/OperationScenarios/UnitySignals/UnitySignals.f90 index 7ce580e..286f239 100644 --- a/CSharp/OperationScenarios/UnitySignals/UnitySignals.f90 +++ b/CSharp/OperationScenarios/UnitySignals/UnitySignals.f90 @@ -454,7 +454,7 @@ subroutine Evaluate_TdsConnectionModes() Get_TdsConnectionModes() == TDS_CONNECTION_SPINE ) then call Set_TdsConnectionModes(TDS_CONNECTION_STRING) - data%EquipmentControl%TopDrivePanel%TopDriveTorqueWrenchLed = LED_OFF + data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed = LED_OFF return end if @@ -463,7 +463,7 @@ subroutine Evaluate_TdsConnectionModes() Get_TdsConnectionModes() == TDS_CONNECTION_STRING ) then call Set_TdsConnectionModes(TDS_CONNECTION_SPINE) - data%EquipmentControl%TopDrivePanel%TopDriveTorqueWrenchLed = LED_OFF + data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed = LED_OFF return end if diff --git a/CSharp/OperationScenarios/UnitySignals/UnitySignals.i90 b/CSharp/OperationScenarios/UnitySignals/UnitySignals.i90 new file mode 100644 index 0000000..6754e4d --- /dev/null +++ b/CSharp/OperationScenarios/UnitySignals/UnitySignals.i90 @@ -0,0 +1,479 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/OperationScenarios/UnitySignals/UnitySignals.f90" +module UnitySignalsModule + use UnitySignalVariables + use SimulationVariables +contains + +subroutine Set_TdsElevatorModes(v) + implicit none + integer , intent(in) :: v +# 11 + + data%State%unitySignals%TdsElevatorModes = v +!**call TdsElevatorModesEnum%OnTdsElevatorModesChange%RunAll() +end subroutine + +integer function Get_TdsElevatorModes() + implicit none + Get_TdsElevatorModes = data%State%unitySignals%TdsElevatorModes +end function + +subroutine Set_Ibop_Install() + implicit none + call Set_Ibop(IBOP_INSTALL) +end subroutine + +subroutine Set_Ibop_Remove() + implicit none + call Set_Ibop(IBOP_REMOVE) +end subroutine + +subroutine Set_Tong(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%Tong == v) return + #endif + data%State%unitySignals%Tong = v + #ifdef deb + print*, 'Tong=', data%State%unitySignals%Tong + #endif +!**call data%State%unitySignals%OnTongChange%RunAll() +end subroutine + +integer function Get_Tong() + implicit none + Get_Tong = data%State%unitySignals%Tong +end function + + +subroutine Set_TdsTong(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%TdsTong == v) return + #endif + data%State%unitySignals%TdsTong = v + #ifdef deb + print*, 'TdsTong=', data%State%unitySignals%TdsTong + #endif +!**call data%State%unitySignals%OnTdsTongChange%RunAll() +end subroutine + +integer function Get_TdsTong() + implicit none + Get_TdsTong = data%State%unitySignals%TdsTong +end function + + +subroutine Set_TdsSwing(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%TdsSwing == v) return + #endif + data%State%unitySignals%TdsSwing = v + #ifdef deb + print*, 'TdsSwing=', data%State%unitySignals%TdsSwing + #endif +!**call data%State%unitySignals%OnTdsSwingChange%RunAll() +end subroutine + +integer function Get_TdsSwing() + implicit none + Get_TdsSwing = data%State%unitySignals%TdsSwing +end function + + +subroutine Set_TdsSpine(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%TdsSpine == v) return + #endif + data%State%unitySignals%TdsSpine = v + #ifdef deb + print*, 'TdsSpine=', data%State%unitySignals%TdsSpine + #endif +!**call data%State%unitySignals%OnTdsSpineChange%RunAll() +end subroutine + +integer function Get_TdsSpine() + implicit none + Get_TdsSpine = data%State%unitySignals%TdsSpine +end function + + +subroutine Set_TdsBackupClamp(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%TdsBackupClamp == v) return + #endif + data%State%unitySignals%TdsBackupClamp = v + #ifdef deb + print*, 'TdsBackupClamp=', data%State%unitySignals%TdsBackupClamp + #endif +!**call data%State%unitySignals%OnTdsBackupClampChange%RunAll() +end subroutine + +integer function Get_TdsBackupClamp() + implicit none + Get_TdsBackupClamp = data%State%unitySignals%TdsBackupClamp +end function + + +subroutine Set_Swing(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%Swing == v) return + #endif + data%State%unitySignals%Swing = v + #ifdef deb + print*, 'Swing=', data%State%unitySignals%Swing + #endif +!**call data%State%unitySignals%OnSwingChange%RunAll() +end subroutine + +integer function Get_Swing() + implicit none + Get_Swing = data%State%unitySignals%Swing +end function + + +subroutine Set_Slips(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%Slips == v) return + #endif + data%State%unitySignals%Slips = v + #ifdef deb + print*, 'Slips=', data%State%unitySignals%Slips + #endif +!**call data%State%unitySignals%OnSlipsChange%RunAll() +end subroutine + +integer function Get_Slips() + implicit none + Get_Slips = data%State%unitySignals%Slips +end function + +subroutine Set_Operation(i) + implicit none + integer, intent (in) :: i + data%State%unitySignals%operation = i +end subroutine + +subroutine Set_SafetyValve(v) + implicit none + integer , intent(in) :: v +# 174 + + data%State%unitySignals%SafetyValve = v +# 184 + +!**call data%State%unitySignals%OnSafetyValveChange%RunAll() +end subroutine + +integer function Get_SafetyValve() + implicit none + Get_SafetyValve = data%State%unitySignals%SafetyValve +end function + +subroutine Set_SafetyValve_Install() + implicit none + call Set_SafetyValve(SAFETY_VALVE_INSTALL) +end subroutine + +subroutine Set_SafetyValve_Remove() + implicit none + call Set_SafetyValve(SAFETY_VALVE_REMOVE) +end subroutine + + +subroutine Set_OperationCondition(v) +! use CKellyEnumVariables + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%OperationCondition == v) return + #endif + data%State%unitySignals%OperationCondition = v + #ifdef deb + print*, 'OperationCondition=', data%State%unitySignals%OperationCondition + #endif +!**call data%State%unitySignals%OnOperationConditionChange%RunAll() +!**call data%State%unitySignals%OnOperationConditionChangeInt%RunAll(data%State%unitySignals%OperationCondition) +end subroutine + +integer function Get_OperationCondition() + implicit none + Get_OperationCondition = data%State%unitySignals%OperationCondition +end function + +subroutine Evaluate_OperationCondition() + implicit none +end subroutine + + +subroutine Set_MouseHole(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%MouseHole == v) return + #endif +!call sleep(2) + data%State%unitySignals%MouseHole = v + #ifdef deb + print*, 'MouseHole=', data%State%unitySignals%MouseHole + #endif +!**call data%State%unitySignals%OnMouseHoleChange%RunAll() +end subroutine + +integer function Get_MouseHole() + implicit none + Get_MouseHole = data%State%unitySignals%MouseHole +end function + + + +subroutine Set_Kelly(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%Kelly == v) return + #endif + data%State%unitySignals%Kelly = v + #ifdef deb + print*, 'Kelly=', data%State%unitySignals%Kelly + #endif +!**call data%State%unitySignals%OnKellyChange%RunAll() +end subroutine + +integer function Get_Kelly() + implicit none + Get_Kelly = data%State%unitySignals%Kelly +end function + + +subroutine Set_Ibop(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%Ibop == v) return + #endif + data%State%unitySignals%Ibop = v + #ifdef deb + print*, 'Ibop=', data%State%unitySignals%Ibop + #endif +!**call data%State%unitySignals%OnIbopChange%RunAll() +end subroutine + +integer function Get_Ibop() + implicit none + Get_Ibop = data%State%unitySignals%Ibop +end function + + +subroutine Set_FillupHead(v) + use CManifolds, only: ToggleFillupHead + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%FillupHead == v) return + #endif + data%State%unitySignals%FillupHead = v + + if (data%State%unitySignals%FillupHead == FILLUP_HEAD_INSTALL) then + call ToggleFillupHead(.true.) + else if (data%State%unitySignals%FillupHead == FILLUP_HEAD_REMOVE) then + call ToggleFillupHead(.false.) + endif + + #ifdef deb + print*, 'FillupHead=', data%State%unitySignals%FillupHead + #endif +!**call data%State%unitySignals%OnFillupHeadChange%RunAll() +end subroutine + +integer function Get_FillupHead() + implicit none + Get_FillupHead = data%State%unitySignals%FillupHead +end function + +subroutine Evaluate_FillupHead() + use CHoistingVariables + use SimulationVariables + use CStudentStationVariables!, only: data%State%StudentStation%FillupHeadInstallation + implicit none + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then +# 323 + + endif + + + + + + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then +# 334 + + endif + + + if (Get_FillupHead() == FILLUP_HEAD_INSTALL) then + data%State%StudentStation%FillupHeadInstallation = .true. + else if (Get_FillupHead() == FILLUP_HEAD_REMOVE) then + data%State%StudentStation%FillupHeadInstallation = .false. + endif + +end subroutine + + +subroutine Set_Elevator(v) + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%Elevator == v) return + #endif + data%State%unitySignals%Elevator = v + #ifdef deb + print*, 'Elevator=', data%State%unitySignals%Elevator + #endif +!**call data%State%unitySignals%OnElevatorChange%RunAll() +end subroutine + +integer function Get_Elevator() + implicit none + Get_Elevator = data%State%unitySignals%Elevator +end function + + + +subroutine Set_MudBucket(v) + use CManifolds, only: ToggleMudBox + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%MudBucket == v) return + #endif + data%State%unitySignals%MudBucket = v + if (data%State%unitySignals%MudBucket == MUD_BUCKET_INSTALL) then + call ToggleMudBox(.true.) + else if (data%State%unitySignals%MudBucket == MUD_BUCKET_REMOVE) then + call ToggleMudBox(.false.) + endif + #ifdef deb + print*, 'MudBucket=', data%State%unitySignals%MudBucket + #endif +!**call data%State%unitySignals%OnMudBucketChange%RunAll() +end subroutine + +integer function Get_MudBucket() + implicit none + Get_MudBucket = data%State%unitySignals%MudBucket +end function + +subroutine Evaluate_MudBucket() + use CStudentStationVariables!, only: data%State%StudentStation%MudBoxInstallation + implicit none + + if (Get_MudBucket() == MUD_BUCKET_INSTALL) then + data%State%StudentStation%MudBoxInstallation = .true. + else if (Get_MudBucket() == MUD_BUCKET_REMOVE) then + data%State%StudentStation%MudBoxInstallation = .false. + endif + +end subroutine + + +!! Moved from CTdsConnectionModeEnum + +subroutine Set_TdsConnectionModes(v) + use CManifolds, Only: KellyConnected, KellyDisconnected + implicit none + integer , intent(in) :: v + #ifdef ExcludeExtraChanges + if(data%State%unitySignals%TdsConnectionModes == v) return + #endif + data%State%unitySignals%TdsConnectionModes = v + + if(data%State%unitySignals%TdsConnectionModes == TDS_CONNECTION_NOTHING) then + call KellyDisconnected() + else + call KellyConnected() + endif + + #ifdef deb + print*, 'data%State%unitySignals%TdsConnectionModes=', data%State%unitySignals%TdsConnectionModes + #endif +!**call data%State%unitySignals%OnTdsConnectionModesChange%RunAll() +end subroutine + +integer function Get_TdsConnectionModes() + use SimulationVariables + implicit none + Get_TdsConnectionModes = data%State%unitySignals%TdsConnectionModes +end function + +subroutine Evaluate_TdsConnectionModes() + use CUnityInputs + use SimulationVariables + implicit none + + if (data%Configuration%Hoisting%DriveType == TopDrive_DriveType) then + #ifdef OST + print*, 'Evaluate_TdsConnectionModes=TopDrive' + #endif +!TOPDRIVE-CODE=3 + if (Get_TdsStemIn() .and.& + Get_TdsSpine() == TDS_SPINE_CONNECT_END .and.& +!TopDriveDrillTorqueState == TdsMu_SPINE + Get_TdsConnectionModes() == TDS_CONNECTION_NOTHING) then + + call Set_TdsConnectionModes(TDS_CONNECTION_SPINE) + return + end if + +!TOPDRIVE-CODE=4 + if (Get_TdsTong() == TDS_TONG_MAKEUP_END .and.& + Get_TdsConnectionModes() == TDS_CONNECTION_SPINE ) then + + call Set_TdsConnectionModes(TDS_CONNECTION_STRING) + data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed = LED_OFF + return + end if + +!TOPDRIVE-CODE=5 + if (Get_TdsTong() == TDS_TONG_BREAKOUT_END .and.& + Get_TdsConnectionModes() == TDS_CONNECTION_STRING ) then + + call Set_TdsConnectionModes(TDS_CONNECTION_SPINE) + data%Equipments%TopDrivePanel%TopDriveTorqueWrenchLed = LED_OFF + return + end if + +!TOPDRIVE-CODE=6 + if (Get_TdsSpine() == TDS_SPINE_DISCONNECT_END .and.& +!Get_TdsStemIn() == .false. .and.& + Get_TdsConnectionModes() == TDS_CONNECTION_SPINE) then + + call Set_TdsConnectionModes(TDS_CONNECTION_NOTHING) + return + end if + + endif + + if (data%Configuration%Hoisting%DriveType == Kelly_DriveType) then + #ifdef OST + print*, 'Evaluate_TdsConnectionModes=Kelly' + #endif + endif + +end subroutine + +end module UnitySignalsModule diff --git a/CSharp/Problems/CBitProblems.f90 b/CSharp/Problems/CBitProblems.f90 index 8d3d411..cc38793 100644 --- a/CSharp/Problems/CBitProblems.f90 +++ b/CSharp/Problems/CBitProblems.f90 @@ -5,6 +5,20 @@ module CBitProblems public contains + subroutine BitProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'BitProblems',p) + call ProblemFromJson(p,"JetWashout",data%problems%BitProblems%JetWashout) + call ProblemFromJson(p,"PlugJets",data%problems%BitProblems%PlugJets) + call json%get(p,"JetWashoutCount",pval) + call json%get(pval,data%problems%BitProblems%JetWashoutCount) + call json%get(p,"PlugJetsCount",pval) + call json%get(pval,data%problems%BitProblems%PlugJetsCount) + end subroutine + subroutine BitProblemsToJson(parent) type(json_value),pointer :: parent diff --git a/CSharp/Problems/CBitProblems.i90 b/CSharp/Problems/CBitProblems.i90 new file mode 100644 index 0000000..8cd1f45 --- /dev/null +++ b/CSharp/Problems/CBitProblems.i90 @@ -0,0 +1,95 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CBitProblems.f90" +module CBitProblems + use SimulationVariables + use json_module + implicit none + public + contains + + subroutine BitProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'BitProblems',p) + call ProblemFromJson(p,"JetWashout",data%problems%BitProblems%JetWashout) + call ProblemFromJson(p,"PlugJets",data%problems%BitProblems%PlugJets) + call json%get(p,"JetWashoutCount",pval) + call json%get(pval,data%problems%BitProblems%JetWashoutCount) + call json%get(p,"PlugJetsCount",pval) + call json%get(pval,data%problems%BitProblems%PlugJetsCount) + end subroutine + + subroutine BitProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'BitProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"JetWashout",data%problems%BitProblems%JetWashout) + call ProblemToJson(p,"PlugJets",data%problems%BitProblems%PlugJets) + call json%add(p, "JetWashoutCount",data%problems%BitProblems%JetWashoutCount) + call json%add(p, "PlugJetsCount",data%problems%BitProblems%PlugJetsCount) +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + + subroutine ProcessBitProblemsDueTime(time) + implicit none + integer :: time + if(data%problems%BitProblems%PlugJets%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BitProblems%PlugJets, ChangePlugJets, time) + if(data%problems%BitProblems%JetWashout%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BitProblems%JetWashout, ChangeJetWashout, time) + end subroutine + + subroutine ProcessBitProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + + if(data%problems%BitProblems%PlugJets%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BitProblems%PlugJets, ChangePlugJets, strokes) + if(data%problems%BitProblems%JetWashout%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BitProblems%JetWashout, ChangeJetWashout, strokes) + + end subroutine + + subroutine ProcessBitProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + + if(data%problems%BitProblems%PlugJets%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BitProblems%PlugJets, ChangePlugJets, volume) + if(data%problems%BitProblems%JetWashout%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BitProblems%JetWashout, ChangeJetWashout, volume) + + end subroutine + + subroutine ProcessBitProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + + if(data%problems%BitProblems%PlugJets%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BitProblems%PlugJets, ChangePlugJets, distance) + if(data%problems%BitProblems%JetWashout%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BitProblems%JetWashout, ChangeJetWashout, distance) + + end subroutine + + subroutine ChangePlugJets(status) + USE FricPressDropVarsModule + implicit none + integer, intent (in) :: status +! if(associated(data%problems%BitProblems%PlugJetsPtr)) call data%problems%BitProblems%PlugJetsPtr(status) + if(status == Clear_StatusType) data%State%FricPressDrop%BitJetsPlugged = 0 + if(status == Executed_StatusType) data%State%FricPressDrop%BitJetsPlugged = 1 + endsubroutine + + subroutine ChangeJetWashout(status) + USE FricPressDropVarsModule + implicit none + integer, intent (in) :: status +! if(associated(data%problems%BitProblems%JetWashoutPtr)) call data%problems%BitProblems%JetWashoutPtr(status) + if(status == Clear_StatusType) data%State%FricPressDrop%BitJetsWashedOut = 0 + if(status == Executed_StatusType) data%State%FricPressDrop%BitJetsWashedOut = 1 + endsubroutine + + +end module CBitProblems diff --git a/CSharp/Problems/CBitProblemsVariables.i90 b/CSharp/Problems/CBitProblemsVariables.i90 new file mode 100644 index 0000000..bb139e1 --- /dev/null +++ b/CSharp/Problems/CBitProblemsVariables.i90 @@ -0,0 +1,16 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CBitProblemsVariables.f90" +module CBitProblemsVariables + use CProblemDifinition + implicit none + public + +! Input vars + type:: BitProblemsType + type(CProblem) :: PlugJets + type(CProblem) :: JetWashout + integer :: PlugJetsCount + integer :: JetWashoutCount + end type BitProblemsType + + contains +end module CBitProblemsVariables diff --git a/CSharp/Problems/CBopProblems.f90 b/CSharp/Problems/CBopProblems.f90 index dd0e84d..3ea0cf9 100644 --- a/CSharp/Problems/CBopProblems.f90 +++ b/CSharp/Problems/CBopProblems.f90 @@ -4,6 +4,31 @@ module CBopProblems public contains + subroutine BopProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'BitProblems',p) + + call ProblemFromJson(p,"AnnularWash",data%problems%BopProblems%AnnularWash) + call ProblemFromJson(p,"AnnularFail",data%problems%BopProblems%AnnularFail) + call ProblemFromJson(p,"AnnularLeak",data%problems%BopProblems%AnnularLeak) + call ProblemFromJson(p,"UpperRamWash",data%problems%BopProblems%UpperRamWash) + call ProblemFromJson(p,"UpperRamFail",data%problems%BopProblems%UpperRamFail) + call ProblemFromJson(p,"UpperRamLeak",data%problems%BopProblems%UpperRamLeak) + call ProblemFromJson(p,"MiddleRamWash",data%problems%BopProblems%MiddleRamWash) + call ProblemFromJson(p,"MiddleRamFail",data%problems%BopProblems%MiddleRamFail) + call ProblemFromJson(p,"MiddleRamLeak",data%problems%BopProblems%MiddleRamLeak) + call ProblemFromJson(p,"LowerRamWash",data%problems%BopProblems%LowerRamWash) + call ProblemFromJson(p,"LowerRamFail",data%problems%BopProblems%LowerRamFail) + call ProblemFromJson(p,"LowerRamLeak",data%problems%BopProblems%LowerRamLeak) + call ProblemFromJson(p,"AccumulatorPumpFail",data%problems%BopProblems%AccumulatorPumpFail) + call ProblemFromJson(p,"AccumulatorPumpLeak",data%problems%BopProblems%AccumulatorPumpLeak) + call ProblemFromJson(p,"AccumulatorSystemFail",data%problems%BopProblems%AccumulatorSystemFail) + call ProblemFromJson(p,"AccumulatorSystemLeak",data%problems%BopProblems%AccumulatorSystemLeak) + end subroutine + subroutine BopProblemsToJson(parent) type(json_value),pointer :: parent diff --git a/CSharp/Problems/CBopProblems.i90 b/CSharp/Problems/CBopProblems.i90 new file mode 100644 index 0000000..194d3af --- /dev/null +++ b/CSharp/Problems/CBopProblems.i90 @@ -0,0 +1,291 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CBopProblems.f90" +module CBopProblems + use SimulationVariables + implicit none + public + contains + + subroutine BopProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'BitProblems',p) + + call ProblemFromJson(p,"AnnularWash",data%problems%BopProblems%AnnularWash) + call ProblemFromJson(p,"AnnularFail",data%problems%BopProblems%AnnularFail) + call ProblemFromJson(p,"AnnularLeak",data%problems%BopProblems%AnnularLeak) + call ProblemFromJson(p,"UpperRamWash",data%problems%BopProblems%UpperRamWash) + call ProblemFromJson(p,"UpperRamFail",data%problems%BopProblems%UpperRamFail) + call ProblemFromJson(p,"UpperRamLeak",data%problems%BopProblems%UpperRamLeak) + call ProblemFromJson(p,"MiddleRamWash",data%problems%BopProblems%MiddleRamWash) + call ProblemFromJson(p,"MiddleRamFail",data%problems%BopProblems%MiddleRamFail) + call ProblemFromJson(p,"MiddleRamLeak",data%problems%BopProblems%MiddleRamLeak) + call ProblemFromJson(p,"LowerRamWash",data%problems%BopProblems%LowerRamWash) + call ProblemFromJson(p,"LowerRamFail",data%problems%BopProblems%LowerRamFail) + call ProblemFromJson(p,"LowerRamLeak",data%problems%BopProblems%LowerRamLeak) + call ProblemFromJson(p,"AccumulatorPumpFail",data%problems%BopProblems%AccumulatorPumpFail) + call ProblemFromJson(p,"AccumulatorPumpLeak",data%problems%BopProblems%AccumulatorPumpLeak) + call ProblemFromJson(p,"AccumulatorSystemFail",data%problems%BopProblems%AccumulatorSystemFail) + call ProblemFromJson(p,"AccumulatorSystemLeak",data%problems%BopProblems%AccumulatorSystemLeak) + end subroutine + + subroutine BopProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'BopProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"AnnularWash",data%problems%BopProblems%AnnularWash) + call ProblemToJson(p,"AnnularFail",data%problems%BopProblems%AnnularFail) + call ProblemToJson(p,"AnnularLeak",data%problems%BopProblems%AnnularLeak) + call ProblemToJson(p,"UpperRamWash",data%problems%BopProblems%UpperRamWash) + call ProblemToJson(p,"UpperRamFail",data%problems%BopProblems%UpperRamFail) + call ProblemToJson(p,"UpperRamLeak",data%problems%BopProblems%UpperRamLeak) + call ProblemToJson(p,"MiddleRamWash",data%problems%BopProblems%MiddleRamWash) + call ProblemToJson(p,"MiddleRamFail",data%problems%BopProblems%MiddleRamFail) + call ProblemToJson(p,"MiddleRamLeak",data%problems%BopProblems%MiddleRamLeak) + call ProblemToJson(p,"LowerRamWash",data%problems%BopProblems%LowerRamWash) + call ProblemToJson(p,"LowerRamFail",data%problems%BopProblems%LowerRamFail) + call ProblemToJson(p,"LowerRamLeak",data%problems%BopProblems%LowerRamLeak) + call ProblemToJson(p,"AccumulatorPumpFail",data%problems%BopProblems%AccumulatorPumpFail) + call ProblemToJson(p,"AccumulatorPumpLeak",data%problems%BopProblems%AccumulatorPumpLeak) + call ProblemToJson(p,"AccumulatorSystemFail",data%problems%BopProblems%AccumulatorSystemFail) + call ProblemToJson(p,"AccumulatorSystemLeak",data%problems%BopProblems%AccumulatorSystemLeak) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProcessBopProblemsDueTime(time) + implicit none + integer :: time + if(data%problems%BopProblems%AnnularWash%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%AnnularWash, ChangeAnnularWash, time) + if(data%problems%BopProblems%AnnularFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%AnnularFail, ChangeAnnularFail, time) + if(data%problems%BopProblems%AnnularLeak%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%AnnularLeak, ChangeAnnularLeak, time) + if(data%problems%BopProblems%UpperRamWash%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%UpperRamWash, ChangeUpperRamWash, time) + if(data%problems%BopProblems%UpperRamFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%UpperRamFail, ChangeUpperRamFail, time) + if(data%problems%BopProblems%UpperRamLeak%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%UpperRamLeak, ChangeUpperRamLeak, time) + if(data%problems%BopProblems%MiddleRamWash%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%MiddleRamWash, ChangeMiddleRamWash, time) + if(data%problems%BopProblems%MiddleRamFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%MiddleRamFail, ChangeMiddleRamFail, time) + if(data%problems%BopProblems%MiddleRamLeak%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%MiddleRamLeak, ChangeMiddleRamLeak, time) + if(data%problems%BopProblems%LowerRamWash%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%LowerRamWash, ChangeLowerRamWash, time) + if(data%problems%BopProblems%LowerRamFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%LowerRamFail, ChangeLowerRamFail, time) + if(data%problems%BopProblems%LowerRamLeak%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%LowerRamLeak, ChangeLowerRamLeak, time) + if(data%problems%BopProblems%AccumulatorPumpFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%AccumulatorPumpFail, ChangeAccumulatorPumpFail, time) + if(data%problems%BopProblems%AccumulatorPumpLeak%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%AccumulatorPumpLeak, ChangeAccumulatorPumpLeak, time) + if(data%problems%BopProblems%AccumulatorSystemFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%AccumulatorSystemFail, ChangeAccumulatorSystemFail, time) + if(data%problems%BopProblems%AccumulatorSystemLeak%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%BopProblems%AccumulatorSystemLeak, ChangeAccumulatorSystemLeak, time) + end subroutine + + subroutine ProcessBopProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + if(data%problems%BopProblems%AnnularWash%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%AnnularWash, ChangeAnnularWash, strokes) + if(data%problems%BopProblems%AnnularFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%AnnularFail, ChangeAnnularFail, strokes) + if(data%problems%BopProblems%AnnularLeak%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%AnnularLeak, ChangeAnnularLeak, strokes) + if(data%problems%BopProblems%UpperRamWash%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%UpperRamWash, ChangeUpperRamWash, strokes) + if(data%problems%BopProblems%UpperRamFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%UpperRamFail, ChangeUpperRamFail, strokes) + if(data%problems%BopProblems%UpperRamLeak%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%UpperRamLeak, ChangeUpperRamLeak, strokes) + if(data%problems%BopProblems%MiddleRamWash%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%MiddleRamWash, ChangeMiddleRamWash, strokes) + if(data%problems%BopProblems%MiddleRamFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%MiddleRamFail, ChangeMiddleRamFail, strokes) + if(data%problems%BopProblems%MiddleRamLeak%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%MiddleRamLeak, ChangeMiddleRamLeak, strokes) + if(data%problems%BopProblems%LowerRamWash%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%LowerRamWash, ChangeLowerRamWash, strokes) + if(data%problems%BopProblems%LowerRamFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%LowerRamFail, ChangeLowerRamFail, strokes) + if(data%problems%BopProblems%LowerRamLeak%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%LowerRamLeak, ChangeLowerRamLeak, strokes) + if(data%problems%BopProblems%AccumulatorPumpFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%AccumulatorPumpFail, ChangeAccumulatorPumpFail, strokes) + if(data%problems%BopProblems%AccumulatorPumpLeak%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%AccumulatorPumpLeak, ChangeAccumulatorPumpLeak, strokes) + if(data%problems%BopProblems%AccumulatorSystemFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%AccumulatorSystemFail, ChangeAccumulatorSystemFail, strokes) + if(data%problems%BopProblems%AccumulatorSystemLeak%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%BopProblems%AccumulatorSystemLeak, ChangeAccumulatorSystemLeak, strokes) + end subroutine + + subroutine ProcessBopProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + if(data%problems%BopProblems%AnnularWash%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%AnnularWash, ChangeAnnularWash, volume) + if(data%problems%BopProblems%AnnularFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%AnnularFail, ChangeAnnularFail, volume) + if(data%problems%BopProblems%AnnularLeak%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%AnnularLeak, ChangeAnnularLeak, volume) + if(data%problems%BopProblems%UpperRamWash%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%UpperRamWash, ChangeUpperRamWash, volume) + if(data%problems%BopProblems%UpperRamFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%UpperRamFail, ChangeUpperRamFail, volume) + if(data%problems%BopProblems%UpperRamLeak%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%UpperRamLeak, ChangeUpperRamLeak, volume) + if(data%problems%BopProblems%MiddleRamWash%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%MiddleRamWash, ChangeMiddleRamWash, volume) + if(data%problems%BopProblems%MiddleRamFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%MiddleRamFail, ChangeMiddleRamFail, volume) + if(data%problems%BopProblems%MiddleRamLeak%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%MiddleRamLeak, ChangeMiddleRamLeak, volume) + if(data%problems%BopProblems%LowerRamWash%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%LowerRamWash, ChangeLowerRamWash, volume) + if(data%problems%BopProblems%LowerRamFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%LowerRamFail, ChangeLowerRamFail, volume) + if(data%problems%BopProblems%LowerRamLeak%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%LowerRamLeak, ChangeLowerRamLeak, volume) + if(data%problems%BopProblems%AccumulatorPumpFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%AccumulatorPumpFail, ChangeAccumulatorPumpFail, volume) + if(data%problems%BopProblems%AccumulatorPumpLeak%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%AccumulatorPumpLeak, ChangeAccumulatorPumpLeak, volume) + if(data%problems%BopProblems%AccumulatorSystemFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%AccumulatorSystemFail, ChangeAccumulatorSystemFail,volume) + if(data%problems%BopProblems%AccumulatorSystemLeak%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%BopProblems%AccumulatorSystemLeak, ChangeAccumulatorSystemLeak, volume) + end subroutine + + subroutine ProcessBopProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + if(data%problems%BopProblems%AnnularWash%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%AnnularWash, ChangeAnnularWash, distance) + if(data%problems%BopProblems%AnnularFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%AnnularFail, ChangeAnnularFail, distance) + if(data%problems%BopProblems%AnnularLeak%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%AnnularLeak, ChangeAnnularLeak, distance) + if(data%problems%BopProblems%UpperRamWash%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%UpperRamWash, ChangeUpperRamWash, distance) + if(data%problems%BopProblems%UpperRamFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%UpperRamFail, ChangeUpperRamFail, distance) + if(data%problems%BopProblems%UpperRamLeak%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%UpperRamLeak, ChangeUpperRamLeak, distance) + if(data%problems%BopProblems%MiddleRamWash%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%MiddleRamWash, ChangeMiddleRamWash, distance) + if(data%problems%BopProblems%MiddleRamFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%MiddleRamFail, ChangeMiddleRamFail, distance) + if(data%problems%BopProblems%MiddleRamLeak%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%MiddleRamLeak, ChangeMiddleRamLeak, distance) + if(data%problems%BopProblems%LowerRamWash%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%LowerRamWash, ChangeLowerRamWash, distance) + if(data%problems%BopProblems%LowerRamFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%LowerRamFail, ChangeLowerRamFail, distance) + if(data%problems%BopProblems%LowerRamLeak%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%LowerRamLeak, ChangeLowerRamLeak, distance) + if(data%problems%BopProblems%AccumulatorPumpFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%AccumulatorPumpFail, ChangeAccumulatorPumpFail, distance) + if(data%problems%BopProblems%AccumulatorPumpLeak%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%AccumulatorPumpLeak, ChangeAccumulatorPumpLeak, distance) + if(data%problems%BopProblems%AccumulatorSystemFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%AccumulatorSystemFail, ChangeAccumulatorSystemFail, distance) + if(data%problems%BopProblems%AccumulatorSystemLeak%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%BopProblems%AccumulatorSystemLeak, ChangeAccumulatorSystemLeak, distance) + end subroutine + + + subroutine ChangeAnnularWash(status) + implicit none + integer, intent (in) :: status +! ! if(associated(AnnularWashPtr)) call AnnularWashPtr(status) +!if(status == Clear_StatusType) print*,'On_AnnularWash_Clear' +!if(status == Executed_StatusType) print*,'On_AnnularWash_Execute' + endsubroutine + + subroutine ChangeAnnularFail(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! ! if(associated(AnnularFailPtr)) call AnnularFailPtr(status) + if(status == Clear_StatusType) data%State%Annular%AnnularFailureMalf = 0 + if(status == Executed_StatusType) data%State%Annular%AnnularFailureMalf = 1 + endsubroutine + + subroutine ChangeAnnularLeak(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! ! if(associated(AnnularLeakPtr)) call AnnularLeakPtr(status) + if(status == Clear_StatusType) data%State%Annular%AnnularLeakMalf = 0 + if(status == Executed_StatusType) data%State%Annular%AnnularLeakMalf = 1 + endsubroutine + + + + subroutine ChangeUpperRamWash(status) + implicit none + integer, intent (in) :: status +! ! if(associated(UpperRamWashPtr)) call UpperRamWashPtr(status) +!if(status == Clear_StatusType) print*,'On_UpperRamWash_Clear' +!if(status == Executed_StatusType) print*,'On_UpperRamWash_Execute' + endsubroutine + + subroutine ChangeUpperRamFail(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! ! if(associated(UpperRamFailPtr)) call UpperRamFailPtr(status) + if(status == Clear_StatusType) data%State%PipeRam1%UpperRamsFailureMalf = 0 + if(status == Executed_StatusType) data%State%PipeRam1%UpperRamsFailureMalf = 1 + endsubroutine + + subroutine ChangeUpperRamLeak(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! ! if(associated(UpperRamLeakPtr)) call UpperRamLeakPtr(status) + if(status == Clear_StatusType) data%State%PipeRam1%UpperRamsLeakMalf = 0 + if(status == Executed_StatusType) data%State%PipeRam1%UpperRamsLeakMalf = 1 + endsubroutine + + + subroutine ChangeMiddleRamWash(status) + implicit none + integer, intent (in) :: status +! ! if(associated(MiddleRamWashPtr)) call MiddleRamWashPtr(status) +!if(status == Clear_StatusType) print*,'On_MiddleRamWash_Clear' +!if(status == Executed_StatusType) print*,'On_MiddleRamWash_Execute' + endsubroutine + + subroutine ChangeMiddleRamFail(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(MiddleRamFailPtr)) call MiddleRamFailPtr(status) + if(status == Clear_StatusType) data%State%ShearRAM%MiddleRamsFailureMalf = 0 + if(status == Executed_StatusType) data%State%ShearRAM%MiddleRamsFailureMalf = 1 + endsubroutine + + subroutine ChangeMiddleRamLeak(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! ! if(associated(MiddleRamLeakPtr)) call MiddleRamLeakPtr(status) + if(status == Clear_StatusType) data%State%ShearRAM%MiddleRamsLeakMalf = 0 + if(status == Executed_StatusType) data%State%ShearRAM%MiddleRamsLeakMalf = 1 + endsubroutine + + + + subroutine ChangeLowerRamWash(status) + implicit none + integer, intent (in) :: status +! ! if(associated(LowerRamWashPtr)) call LowerRamWashPtr(status) +!if(status == Clear_StatusType) print*,'On_LowerRamWash_Clear' +!if(status == Executed_StatusType) print*,'On_LowerRamWash_Execute' + endsubroutine + + subroutine ChangeLowerRamFail(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! ! if(associated(LowerRamFailPtr)) call LowerRamFailPtr(status) + if(status == Clear_StatusType) data%State%PipeRam2%LowerRamsFailureMalf = 0 + if(status == Executed_StatusType) data%State%PipeRam2%LowerRamsFailureMalf = 1 + endsubroutine + + subroutine ChangeLowerRamLeak(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(LowerRamLeakPtr)) call LowerRamLeakPtr(status) + if(status == Clear_StatusType) data%State%PipeRam2%LowerRamsLeakMalf = 0 + if(status == Executed_StatusType) data%State%PipeRam2%LowerRamsLeakMalf = 1 + endsubroutine + + subroutine ChangeAccumulatorPumpFail(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(AccumulatorPumpFailPtr)) call AccumulatorPumpFailPtr(status) + if(status == Clear_StatusType) data%State%BopStackAcc%AccPupmsFailMalf = 0 + if(status == Executed_StatusType) data%State%BopStackAcc%AccPupmsFailMalf = 1 + endsubroutine + + subroutine ChangeAccumulatorPumpLeak(status) + implicit none + integer, intent (in) :: status +! if(associated(AccumulatorPumpLeakPtr)) call AccumulatorPumpLeakPtr(status) +!if(status == Clear_StatusType) print*,'On_AccumulatorPumpLeak_Clear' +!if(status == Executed_StatusType) print*,'On_AccumulatorPumpLeak_Execute' + endsubroutine + + subroutine ChangeAccumulatorSystemFail(status) + implicit none + integer, intent (in) :: status +! if(associated(AccumulatorSystemFailPtr)) call AccumulatorSystemFailPtr(status) +!if(status == Clear_StatusType) print*,'On_AccumulatorSystemFail_Clear' +!if(status == Executed_StatusType) print*,'On_AccumulatorSystemFail_Execute' + endsubroutine + + subroutine ChangeAccumulatorSystemLeak(status) + implicit none + integer, intent (in) :: status +! if(associated(AccumulatorSystemLeakPtr)) call AccumulatorSystemLeakPtr(status) +!if(status == Clear_StatusType) print*,'On_AccumulatorSystemLeak_Clear' +!if(status == Executed_StatusType) print*,'On_AccumulatorSystemLeak_Execute' + endsubroutine + +end module CBopProblems diff --git a/CSharp/Problems/CBopProblemsVariables.i90 b/CSharp/Problems/CBopProblemsVariables.i90 new file mode 100644 index 0000000..bb5256f --- /dev/null +++ b/CSharp/Problems/CBopProblemsVariables.i90 @@ -0,0 +1,176 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CBopProblemsVariables.f90" +module CBopProblemsVariables + use CProblemDifinition + implicit none + public + +! Input vars + type::BopProblemsType + type(CProblem) :: AnnularWash + type(CProblem) :: AnnularFail + type(CProblem) :: AnnularLeak + type(CProblem) :: UpperRamWash + type(CProblem) :: UpperRamFail + type(CProblem) :: UpperRamLeak + type(CProblem) :: MiddleRamWash + type(CProblem) :: MiddleRamFail + type(CProblem) :: MiddleRamLeak + type(CProblem) :: LowerRamWash + type(CProblem) :: LowerRamFail + type(CProblem) :: LowerRamLeak + type(CProblem) :: AccumulatorPumpFail + type(CProblem) :: AccumulatorPumpLeak + type(CProblem) :: AccumulatorSystemFail + type(CProblem) :: AccumulatorSystemLeak + end type BopProblemsType + + contains + + + + + + + + + + + + + +! subroutine SubscribeAnnularWash(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeAnnularWash +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeAnnularWash' :: SubscribeAnnularWash +! implicit none +! procedure (ActionInteger) :: v +! AnnularWashPtr => v +! end subroutine + +! subroutine SubscribeAnnularFail(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeAnnularFail +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeAnnularFail' :: SubscribeAnnularFail +! implicit none +! procedure (ActionInteger) :: v +! AnnularFailPtr => v +! end subroutine + +! subroutine SubscribeAnnularLeak(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeAnnularLeak +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeAnnularLeak' :: SubscribeAnnularLeak +! implicit none +! procedure (ActionInteger) :: v +! AnnularLeakPtr => v +! end subroutine + + +! subroutine SubscribeUpperRamWash(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeUpperRamWash +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeUpperRamWash' :: SubscribeUpperRamWash +! implicit none +! procedure (ActionInteger) :: v +! UpperRamWashPtr => v +! end subroutine + +! subroutine SubscribeUpperRamFail(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeUpperRamFail +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeUpperRamFail' :: SubscribeUpperRamFail +! implicit none +! procedure (ActionInteger) :: v +! UpperRamFailPtr => v +! end subroutine + +! subroutine SubscribeUpperRamLeak(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeUpperRamLeak +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeUpperRamLeak' :: SubscribeUpperRamLeak +! implicit none +! procedure (ActionInteger) :: v +! UpperRamLeakPtr => v +! end subroutine + + +! subroutine SubscribeMiddleRamWash(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeMiddleRamWash +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeMiddleRamWash' :: SubscribeMiddleRamWash +! implicit none +! procedure (ActionInteger) :: v +! MiddleRamWashPtr => v +! end subroutine + +! subroutine SubscribeMiddleRamFail(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeMiddleRamFail +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeMiddleRamFail' :: SubscribeMiddleRamFail +! implicit none +! procedure (ActionInteger) :: v +! MiddleRamFailPtr => v +! end subroutine + +! subroutine SubscribeMiddleRamLeak(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeMiddleRamLeak +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeMiddleRamLeak' :: SubscribeMiddleRamLeak +! implicit none +! procedure (ActionInteger) :: v +! MiddleRamLeakPtr => v +! end subroutine + + +! subroutine SubscribeLowerRamWash(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeLowerRamWash +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeLowerRamWash' :: SubscribeLowerRamWash +! implicit none +! procedure (ActionInteger) :: v +! LowerRamWashPtr => v +! end subroutine + +! subroutine SubscribeLowerRamFail(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeLowerRamFail +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeLowerRamFail' :: SubscribeLowerRamFail +! implicit none +! procedure (ActionInteger) :: v +! LowerRamFailPtr => v +! end subroutine + +! subroutine SubscribeLowerRamLeak(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeLowerRamLeak +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeLowerRamLeak' :: SubscribeLowerRamLeak +! implicit none +! procedure (ActionInteger) :: v +! LowerRamLeakPtr => v +! end subroutine + +! subroutine SubscribeAccumulatorPumpFail(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeAccumulatorPumpFail +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeAccumulatorPumpFail' :: SubscribeAccumulatorPumpFail +! implicit none +! procedure (ActionInteger) :: v +! AccumulatorPumpFailPtr => v +! end subroutine + +! subroutine SubscribeAccumulatorPumpLeak(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeAccumulatorPumpLeak +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeAccumulatorPumpLeak' :: SubscribeAccumulatorPumpLeak +! implicit none +! procedure (ActionInteger) :: v +! AccumulatorPumpLeakPtr => v +! end subroutine + +! subroutine SubscribeAccumulatorSystemFail(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeAccumulatorSystemFail +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeAccumulatorSystemFail' :: SubscribeAccumulatorSystemFail +! implicit none +! procedure (ActionInteger) :: v +! AccumulatorSystemFailPtr => v +! end subroutine + +! subroutine SubscribeAccumulatorSystemLeak(v) +! !DEC$ ATTRIBUTES DLLEXPORT :: SubscribeAccumulatorSystemLeak +! !DEC$ ATTRIBUTES ALIAS: 'SubscribeAccumulatorSystemLeak' :: SubscribeAccumulatorSystemLeak +! implicit none +! procedure (ActionInteger) :: v +! AccumulatorSystemLeakPtr => v +! end subroutine + + + + + +end module CBopProblemsVariables diff --git a/CSharp/Problems/CChokeProblems.f90 b/CSharp/Problems/CChokeProblems.f90 index 6756fab..c593a8e 100644 --- a/CSharp/Problems/CChokeProblems.f90 +++ b/CSharp/Problems/CChokeProblems.f90 @@ -4,6 +4,37 @@ module CChokeProblems public contains + subroutine ChokeProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'ChokeProblems',p) + call ProblemFromJson(p,"HydraulicChoke1Plugged",data%problems%ChokeProblems%HydraulicChoke1Plugged) + call ProblemFromJson(p,"HydraulicChoke1Fail",data%problems%ChokeProblems%HydraulicChoke1Fail) + call ProblemFromJson(p,"HydraulicChoke1Washout",data%problems%ChokeProblems%HydraulicChoke1Washout) + call ProblemFromJson(p,"HydraulicChoke2Plugged",data%problems%ChokeProblems%HydraulicChoke2Plugged) + call ProblemFromJson(p,"HydraulicChoke2Fail",data%problems%ChokeProblems%HydraulicChoke2Fail) + call ProblemFromJson(p,"HydraulicChoke2Washout",data%problems%ChokeProblems%HydraulicChoke2Washout) + call ProblemFromJson(p,"ManualChoke1Plugged",data%problems%ChokeProblems%ManualChoke1Plugged) + call ProblemFromJson(p,"ManualChoke1Fail",data%problems%ChokeProblems%ManualChoke1Fail) + call ProblemFromJson(p,"ManualChoke1Washout",data%problems%ChokeProblems%ManualChoke1Washout) + call ProblemFromJson(p,"ManualChoke2Plugged",data%problems%ChokeProblems%ManualChoke2Plugged) + call ProblemFromJson(p,"ManualChoke2Fail",data%problems%ChokeProblems%ManualChoke2Fail) + call ProblemFromJson(p,"ManualChoke2Washout",data%problems%ChokeProblems%ManualChoke2Washout) + call ProblemFromJson(p,"ChokePanelAirFail",data%problems%ChokeProblems%ChokePanelAirFail) + + call json%get(p,'ManualChoke1PluggedPercent',pval) + call json%get(pval,data%problems%ChokeProblems%ManualChoke1PluggedPercent) + call json%get(p,'HydraulicChoke2PluggedPercent',pval) + call json%get(pval,data%problems%ChokeProblems%HydraulicChoke2PluggedPercent) + call json%get(p,'HydraulicChoke1PluggedPercent',pval) + call json%get(pval,data%problems%ChokeProblems%HydraulicChoke1PluggedPercent) + call json%get(p,'ManualChoke2PluggedPercent',pval) + call json%get(pval,data%problems%ChokeProblems%ManualChoke2PluggedPercent) + + end subroutine + subroutine ChokeProblemsToJson(parent) type(json_value),pointer :: parent @@ -27,7 +58,11 @@ module CChokeProblems call ProblemToJson(p,"ManualChoke2Fail",data%problems%ChokeProblems%ManualChoke2Fail) call ProblemToJson(p,"ManualChoke2Washout",data%problems%ChokeProblems%ManualChoke2Washout) call ProblemToJson(p,"ChokePanelAirFail",data%problems%ChokeProblems%ChokePanelAirFail) - + + call json%add(p,"ManualChoke1PluggedPercent",data%problems%ChokeProblems%ManualChoke1PluggedPercent) + call json%add(p,"HydraulicChoke2PluggedPercent",data%problems%ChokeProblems%HydraulicChoke2PluggedPercent) + call json%add(p,"HydraulicChoke1PluggedPercent",data%problems%ChokeProblems%HydraulicChoke1PluggedPercent) + call json%add(p,"ManualChoke2PluggedPercent",data%problems%ChokeProblems%ManualChoke2PluggedPercent) ! 3. add new node to parent call json%add(parent,p) end subroutine @@ -138,8 +173,8 @@ use SimulationVariables !@ if(status == Clear_StatusType) data%State%CHOOKE(1)%WashoutMalf = 0 if(status == Executed_StatusType) data%State%CHOOKE(1)%WashoutMalf = 1 - if(status == Clear_StatusType) data%EquipmentControl%ChokeManifold%HyChock1OnProblem = .false. - if(status == Executed_StatusType) data%EquipmentControl%ChokeManifold%HyChock1OnProblem = .true. + if(status == Clear_StatusType) data%Equipments%ChokeManifold%HyChock1OnProblem = .false. + if(status == Executed_StatusType) data%Equipments%ChokeManifold%HyChock1OnProblem = .true. endsubroutine subroutine ChangeHydraulicChoke2Plugged(status) @@ -173,8 +208,8 @@ use SimulationVariables !@ if(status == Clear_StatusType) data%State%CHOOKE(2)%WashoutMalf = 0 if(status == Executed_StatusType) data%State%CHOOKE(2)%WashoutMalf = 1 - if(status == Clear_StatusType) data%EquipmentControl%ChokeManifold%HyChock2OnProblem = .false. - if(status == Executed_StatusType) data%EquipmentControl%ChokeManifold%HyChock2OnProblem = .true. + if(status == Clear_StatusType) data%Equipments%ChokeManifold%HyChock2OnProblem = .false. + if(status == Executed_StatusType) data%Equipments%ChokeManifold%HyChock2OnProblem = .true. endsubroutine subroutine ChangeManualChoke1Plugged(status) @@ -197,15 +232,15 @@ use SimulationVariables !@ subroutine ChangeManualChoke1Washout(status) USE FricPressDropVarsModule use CChokeManifoldVariables - use SimulationVariables + use SimulationVariables implicit none integer, intent (in) :: status ! if(associated(ManualChoke1WashoutPtr)) call ManualChoke1WashoutPtr(status) if(status == Clear_StatusType) data%State%FricPressDrop%ManChoke1Washout = 0 if(status == Executed_StatusType) data%State%FricPressDrop%ManChoke1Washout = 1 - if(status == Clear_StatusType) data%EquipmentControl%ChokeManifold%LeftManChokeOnProblem = .false. - if(status == Executed_StatusType) data%EquipmentControl%ChokeManifold%LeftManChokeOnProblem = .true. + if(status == Clear_StatusType) data%Equipments%ChokeManifold%LeftManChokeOnProblem = .false. + if(status == Executed_StatusType) data%Equipments%ChokeManifold%LeftManChokeOnProblem = .true. endsubroutine subroutine ChangeManualChoke2Plugged(status) @@ -235,8 +270,8 @@ use SimulationVariables !@ if(status == Clear_StatusType) data%State%FricPressDrop%ManChoke2Washout = 0 if(status == Executed_StatusType) data%State%FricPressDrop%ManChoke2Washout = 1 - if(status == Clear_StatusType) data%EquipmentControl%ChokeManifold%RightManChokeOnProblem = .false. - if(status == Executed_StatusType) data%EquipmentControl%ChokeManifold%RightManChokeOnProblem = .true. + if(status == Clear_StatusType) data%Equipments%ChokeManifold%RightManChokeOnProblem = .false. + if(status == Executed_StatusType) data%Equipments%ChokeManifold%RightManChokeOnProblem = .true. endsubroutine subroutine ChangeChokePanelAirFail(status) diff --git a/CSharp/Problems/CChokeProblems.i90 b/CSharp/Problems/CChokeProblems.i90 new file mode 100644 index 0000000..dece845 --- /dev/null +++ b/CSharp/Problems/CChokeProblems.i90 @@ -0,0 +1,288 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CChokeProblems.f90" +module CChokeProblems + use SimulationVariables + implicit none + public + contains + + subroutine ChokeProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'ChokeProblems',p) + call ProblemFromJson(p,"HydraulicChoke1Plugged",data%problems%ChokeProblems%HydraulicChoke1Plugged) + call ProblemFromJson(p,"HydraulicChoke1Fail",data%problems%ChokeProblems%HydraulicChoke1Fail) + call ProblemFromJson(p,"HydraulicChoke1Washout",data%problems%ChokeProblems%HydraulicChoke1Washout) + call ProblemFromJson(p,"HydraulicChoke2Plugged",data%problems%ChokeProblems%HydraulicChoke2Plugged) + call ProblemFromJson(p,"HydraulicChoke2Fail",data%problems%ChokeProblems%HydraulicChoke2Fail) + call ProblemFromJson(p,"HydraulicChoke2Washout",data%problems%ChokeProblems%HydraulicChoke2Washout) + call ProblemFromJson(p,"ManualChoke1Plugged",data%problems%ChokeProblems%ManualChoke1Plugged) + call ProblemFromJson(p,"ManualChoke1Fail",data%problems%ChokeProblems%ManualChoke1Fail) + call ProblemFromJson(p,"ManualChoke1Washout",data%problems%ChokeProblems%ManualChoke1Washout) + call ProblemFromJson(p,"ManualChoke2Plugged",data%problems%ChokeProblems%ManualChoke2Plugged) + call ProblemFromJson(p,"ManualChoke2Fail",data%problems%ChokeProblems%ManualChoke2Fail) + call ProblemFromJson(p,"ManualChoke2Washout",data%problems%ChokeProblems%ManualChoke2Washout) + call ProblemFromJson(p,"ChokePanelAirFail",data%problems%ChokeProblems%ChokePanelAirFail) + + call json%get(p,'ManualChoke1PluggedPercent',pval) + call json%get(pval,data%problems%ChokeProblems%ManualChoke1PluggedPercent) + call json%get(p,'HydraulicChoke2PluggedPercent',pval) + call json%get(pval,data%problems%ChokeProblems%HydraulicChoke2PluggedPercent) + call json%get(p,'HydraulicChoke1PluggedPercent',pval) + call json%get(pval,data%problems%ChokeProblems%HydraulicChoke1PluggedPercent) + call json%get(p,'ManualChoke2PluggedPercent',pval) + call json%get(pval,data%problems%ChokeProblems%ManualChoke2PluggedPercent) + + end subroutine + + subroutine ChokeProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'ChokeProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"HydraulicChoke1Plugged",data%problems%ChokeProblems%HydraulicChoke1Plugged) + call ProblemToJson(p,"HydraulicChoke1Fail",data%problems%ChokeProblems%HydraulicChoke1Fail) + call ProblemToJson(p,"HydraulicChoke1Washout",data%problems%ChokeProblems%HydraulicChoke1Washout) + call ProblemToJson(p,"HydraulicChoke2Plugged",data%problems%ChokeProblems%HydraulicChoke2Plugged) + call ProblemToJson(p,"HydraulicChoke2Fail",data%problems%ChokeProblems%HydraulicChoke2Fail) + call ProblemToJson(p,"HydraulicChoke2Washout",data%problems%ChokeProblems%HydraulicChoke2Washout) + call ProblemToJson(p,"ManualChoke1Plugged",data%problems%ChokeProblems%ManualChoke1Plugged) + call ProblemToJson(p,"ManualChoke1Fail",data%problems%ChokeProblems%ManualChoke1Fail) + call ProblemToJson(p,"ManualChoke1Washout",data%problems%ChokeProblems%ManualChoke1Washout) + call ProblemToJson(p,"ManualChoke2Plugged",data%problems%ChokeProblems%ManualChoke2Plugged) + call ProblemToJson(p,"ManualChoke2Fail",data%problems%ChokeProblems%ManualChoke2Fail) + call ProblemToJson(p,"ManualChoke2Washout",data%problems%ChokeProblems%ManualChoke2Washout) + call ProblemToJson(p,"ChokePanelAirFail",data%problems%ChokeProblems%ChokePanelAirFail) + + call json%add(p,"ManualChoke1PluggedPercent",data%problems%ChokeProblems%ManualChoke1PluggedPercent) + call json%add(p,"HydraulicChoke2PluggedPercent",data%problems%ChokeProblems%HydraulicChoke2PluggedPercent) + call json%add(p,"HydraulicChoke1PluggedPercent",data%problems%ChokeProblems%HydraulicChoke1PluggedPercent) + call json%add(p,"ManualChoke2PluggedPercent",data%problems%ChokeProblems%ManualChoke2PluggedPercent) +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProcessChokeProblemsDueTime(time) + implicit none + integer :: time + if(data%problems%ChokeProblems%HydraulicChoke1Plugged%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%HydraulicChoke1Plugged, ChangeHydraulicChoke1Plugged, time) + if(data%problems%ChokeProblems%HydraulicChoke1Fail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%HydraulicChoke1Fail, ChangeHydraulicChoke1Fail, time) + if(data%problems%ChokeProblems%HydraulicChoke1Washout%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%HydraulicChoke1Washout, ChangeHydraulicChoke1Washout, time) + if(data%problems%ChokeProblems%HydraulicChoke2Plugged%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%HydraulicChoke2Plugged, ChangeHydraulicChoke2Plugged, time) + if(data%problems%ChokeProblems%HydraulicChoke2Fail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%HydraulicChoke2Fail, ChangeHydraulicChoke2Fail, time) + if(data%problems%ChokeProblems%HydraulicChoke2Washout%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%HydraulicChoke2Washout, ChangeHydraulicChoke2Washout, time) + if(data%problems%ChokeProblems%ManualChoke1Plugged%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%ManualChoke1Plugged, ChangeManualChoke1Plugged, time) + if(data%problems%ChokeProblems%ManualChoke1Fail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%ManualChoke1Fail, ChangeManualChoke1Fail, time) + if(data%problems%ChokeProblems%ManualChoke1Washout%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%ManualChoke1Washout, ChangeManualChoke1Washout, time) + if(data%problems%ChokeProblems%ManualChoke2Plugged%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%ManualChoke2Plugged, ChangeManualChoke2Plugged, time) + if(data%problems%ChokeProblems%ManualChoke2Fail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%ManualChoke2Fail, ChangeManualChoke2Fail, time) + if(data%problems%ChokeProblems%ManualChoke2Washout%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%ManualChoke2Washout, ChangeManualChoke2Washout, time) + if(data%problems%ChokeProblems%ChokePanelAirFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%ChokeProblems%ChokePanelAirFail, ChangeChokePanelAirFail, time) + end subroutine + + subroutine ProcessChokeProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + if(data%problems%ChokeProblems%HydraulicChoke1Plugged%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%HydraulicChoke1Plugged, ChangeHydraulicChoke1Plugged, strokes) + if(data%problems%ChokeProblems%HydraulicChoke1Fail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%HydraulicChoke1Fail, ChangeHydraulicChoke1Fail, strokes) + if(data%problems%ChokeProblems%HydraulicChoke1Washout%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%HydraulicChoke1Washout, ChangeHydraulicChoke1Washout, strokes) + if(data%problems%ChokeProblems%HydraulicChoke2Plugged%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%HydraulicChoke2Plugged, ChangeHydraulicChoke2Plugged, strokes) + if(data%problems%ChokeProblems%HydraulicChoke2Fail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%HydraulicChoke2Fail, ChangeHydraulicChoke2Fail, strokes) + if(data%problems%ChokeProblems%HydraulicChoke2Washout%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%HydraulicChoke2Washout, ChangeHydraulicChoke2Washout, strokes) + if(data%problems%ChokeProblems%ManualChoke1Plugged%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%ManualChoke1Plugged, ChangeManualChoke1Plugged, strokes) + if(data%problems%ChokeProblems%ManualChoke1Fail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%ManualChoke1Fail, ChangeManualChoke1Fail, strokes) + if(data%problems%ChokeProblems%ManualChoke1Washout%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%ManualChoke1Washout, ChangeManualChoke1Washout, strokes) + if(data%problems%ChokeProblems%ManualChoke2Plugged%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%ManualChoke2Plugged, ChangeManualChoke2Plugged, strokes) + if(data%problems%ChokeProblems%ManualChoke2Fail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%ManualChoke2Fail, ChangeManualChoke2Fail, strokes) + if(data%problems%ChokeProblems%ManualChoke2Washout%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%ManualChoke2Washout, ChangeManualChoke2Washout, strokes) + if(data%problems%ChokeProblems%ChokePanelAirFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%ChokeProblems%ChokePanelAirFail, ChangeChokePanelAirFail, strokes) + end subroutine + + subroutine ProcessChokeProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + if(data%problems%ChokeProblems%HydraulicChoke1Plugged%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%HydraulicChoke1Plugged, ChangeHydraulicChoke1Plugged, volume) + if(data%problems%ChokeProblems%HydraulicChoke1Fail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%HydraulicChoke1Fail, ChangeHydraulicChoke1Fail, volume) + if(data%problems%ChokeProblems%HydraulicChoke1Washout%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%HydraulicChoke1Washout, ChangeHydraulicChoke1Washout, volume) + if(data%problems%ChokeProblems%HydraulicChoke2Plugged%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%HydraulicChoke2Plugged, ChangeHydraulicChoke2Plugged, volume) + if(data%problems%ChokeProblems%HydraulicChoke2Fail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%HydraulicChoke2Fail, ChangeHydraulicChoke2Fail, volume) + if(data%problems%ChokeProblems%HydraulicChoke2Washout%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%HydraulicChoke2Washout, ChangeHydraulicChoke2Washout, volume) + if(data%problems%ChokeProblems%ManualChoke1Plugged%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%ManualChoke1Plugged, ChangeManualChoke1Plugged, volume) + if(data%problems%ChokeProblems%ManualChoke1Fail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%ManualChoke1Fail, ChangeManualChoke1Fail, volume) + if(data%problems%ChokeProblems%ManualChoke1Washout%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%ManualChoke1Washout, ChangeManualChoke1Washout, volume) + if(data%problems%ChokeProblems%ManualChoke2Plugged%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%ManualChoke2Plugged, ChangeManualChoke2Plugged, volume) + if(data%problems%ChokeProblems%ManualChoke2Fail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%ManualChoke2Fail, ChangeManualChoke2Fail, volume) + if(data%problems%ChokeProblems%ManualChoke2Washout%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%ManualChoke2Washout, ChangeManualChoke2Washout, volume) + if(data%problems%ChokeProblems%ChokePanelAirFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%ChokeProblems%ChokePanelAirFail, ChangeChokePanelAirFail, volume) + end subroutine + + subroutine ProcessChokeProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + if(data%problems%ChokeProblems%HydraulicChoke1Plugged%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%HydraulicChoke1Plugged, ChangeHydraulicChoke1Plugged, distance) + if(data%problems%ChokeProblems%HydraulicChoke1Fail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%HydraulicChoke1Fail, ChangeHydraulicChoke1Fail, distance) + if(data%problems%ChokeProblems%HydraulicChoke1Washout%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%HydraulicChoke1Washout, ChangeHydraulicChoke1Washout, distance) + if(data%problems%ChokeProblems%HydraulicChoke2Plugged%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%HydraulicChoke2Plugged, ChangeHydraulicChoke2Plugged, distance) + if(data%problems%ChokeProblems%HydraulicChoke2Fail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%HydraulicChoke2Fail, ChangeHydraulicChoke2Fail, distance) + if(data%problems%ChokeProblems%HydraulicChoke2Washout%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%HydraulicChoke2Washout, ChangeHydraulicChoke2Washout, distance) + if(data%problems%ChokeProblems%ManualChoke1Plugged%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%ManualChoke1Plugged, ChangeManualChoke1Plugged, distance) + if(data%problems%ChokeProblems%ManualChoke1Fail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%ManualChoke1Fail, ChangeManualChoke1Fail, distance) + if(data%problems%ChokeProblems%ManualChoke1Washout%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%ManualChoke1Washout, ChangeManualChoke1Washout, distance) + if(data%problems%ChokeProblems%ManualChoke2Plugged%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%ManualChoke2Plugged, ChangeManualChoke2Plugged, distance) + if(data%problems%ChokeProblems%ManualChoke2Fail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%ManualChoke2Fail, ChangeManualChoke2Fail, distance) + if(data%problems%ChokeProblems%ManualChoke2Washout%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%ManualChoke2Washout, ChangeManualChoke2Washout, distance) + if(data%problems%ChokeProblems%ChokePanelAirFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%ChokeProblems%ChokePanelAirFail, ChangeChokePanelAirFail, distance) + end subroutine + + + + + subroutine ChangeHydraulicChoke1Plugged(status) + USE CHOKEVARIABLES +use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(HydraulicChoke1PluggedPtr)) call HydraulicChoke1PluggedPtr(status) + if(status == Clear_StatusType) data%State%CHOOKE(1)%PlugMalf = 0 + if(status == Executed_StatusType) data%State%CHOOKE(1)%PlugMalf = 1 + endsubroutine + + subroutine ChangeHydraulicChoke1Fail(status) + USE CHOKEVARIABLES +use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(HydraulicChoke1FailPtr)) call HydraulicChoke1FailPtr(status) + if(status == Clear_StatusType) data%State%CHOOKE(1)%FailMalf = 0 + if(status == Executed_StatusType) data%State%CHOOKE(1)%FailMalf = 1 + endsubroutine + + subroutine ChangeHydraulicChoke1Washout(status) + USE CHOKEVARIABLES +use SimulationVariables !@ + use CChokeManifoldVariables + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(HydraulicChoke1WashoutPtr)) call HydraulicChoke1WashoutPtr(status) + if(status == Clear_StatusType) data%State%CHOOKE(1)%WashoutMalf = 0 + if(status == Executed_StatusType) data%State%CHOOKE(1)%WashoutMalf = 1 + + if(status == Clear_StatusType) data%Equipments%ChokeManifold%HyChock1OnProblem = .false. + if(status == Executed_StatusType) data%Equipments%ChokeManifold%HyChock1OnProblem = .true. + endsubroutine + + subroutine ChangeHydraulicChoke2Plugged(status) + USE CHOKEVARIABLES +use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(HydraulicChoke2PluggedPtr)) call HydraulicChoke2PluggedPtr(status) + if(status == Clear_StatusType) data%State%CHOOKE(2)%PlugMalf = 0 + if(status == Executed_StatusType) data%State%CHOOKE(2)%PlugMalf = 1 + endsubroutine + + subroutine ChangeHydraulicChoke2Fail(status) + USE CHOKEVARIABLES +use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(HydraulicChoke2FailPtr)) call HydraulicChoke2FailPtr(status) + if(status == Clear_StatusType) data%State%CHOOKE(2)%FailMalf = 0 + if(status == Executed_StatusType) data%State%CHOOKE(2)%FailMalf = 1 + endsubroutine + + subroutine ChangeHydraulicChoke2Washout(status) + USE CHOKEVARIABLES +use SimulationVariables !@ + use CChokeManifoldVariables + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(HydraulicChoke2WashoutPtr)) call HydraulicChoke2WashoutPtr(status) + if(status == Clear_StatusType) data%State%CHOOKE(2)%WashoutMalf = 0 + if(status == Executed_StatusType) data%State%CHOOKE(2)%WashoutMalf = 1 + + if(status == Clear_StatusType) data%Equipments%ChokeManifold%HyChock2OnProblem = .false. + if(status == Executed_StatusType) data%Equipments%ChokeManifold%HyChock2OnProblem = .true. + endsubroutine + + subroutine ChangeManualChoke1Plugged(status) + USE FricPressDropVarsModule + implicit none + integer, intent (in) :: status +! if(associated(ManualChoke1PluggedPtr)) call ManualChoke1PluggedPtr(status) + if(status == Clear_StatusType) data%State%FricPressDrop%ManChoke1Plug = 0 + if(status == Executed_StatusType) data%State%FricPressDrop%ManChoke1Plug = 1 + endsubroutine + + subroutine ChangeManualChoke1Fail(status) + implicit none + integer, intent (in) :: status +! if(associated(ManualChoke1FailPtr)) call ManualChoke1FailPtr(status) +!if(status == Clear_StatusType) print*,'On_ManualChoke1Fail_Clear' +!if(status == Executed_StatusType) print*,'On_ManualChoke1Fail_Execute' + endsubroutine + + subroutine ChangeManualChoke1Washout(status) + USE FricPressDropVarsModule + use CChokeManifoldVariables + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(ManualChoke1WashoutPtr)) call ManualChoke1WashoutPtr(status) + if(status == Clear_StatusType) data%State%FricPressDrop%ManChoke1Washout = 0 + if(status == Executed_StatusType) data%State%FricPressDrop%ManChoke1Washout = 1 + + if(status == Clear_StatusType) data%Equipments%ChokeManifold%LeftManChokeOnProblem = .false. + if(status == Executed_StatusType) data%Equipments%ChokeManifold%LeftManChokeOnProblem = .true. + endsubroutine + + subroutine ChangeManualChoke2Plugged(status) + USE FricPressDropVarsModule + implicit none + integer, intent (in) :: status +! if(associated(ManualChoke2PluggedPtr)) call ManualChoke2PluggedPtr(status) + if(status == Clear_StatusType) data%State%FricPressDrop%ManChoke2Plug = 0 + if(status == Executed_StatusType) data%State%FricPressDrop%ManChoke2Plug = 1 + endsubroutine + + subroutine ChangeManualChoke2Fail(status) + implicit none + integer, intent (in) :: status +! if(associated(ManualChoke2FailPtr)) call ManualChoke2FailPtr(status) +!if(status == Clear_StatusType) print*,'On_ManualChoke2Fail_Clear' +!if(status == Executed_StatusType) print*,'On_ManualChoke2Fail_Execute' + endsubroutine + + subroutine ChangeManualChoke2Washout(status) + USE FricPressDropVarsModule + use CChokeManifoldVariables + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(ManualChoke2WashoutPtr)) call ManualChoke2WashoutPtr(status) + if(status == Clear_StatusType) data%State%FricPressDrop%ManChoke2Washout = 0 + if(status == Executed_StatusType) data%State%FricPressDrop%ManChoke2Washout = 1 + + if(status == Clear_StatusType) data%Equipments%ChokeManifold%RightManChokeOnProblem = .false. + if(status == Executed_StatusType) data%Equipments%ChokeManifold%RightManChokeOnProblem = .true. + endsubroutine + + subroutine ChangeChokePanelAirFail(status) + USE CHOKEVARIABLES +use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(ChokePanelAirFailPtr)) call ChokePanelAirFailPtr(status) + if(status == Clear_StatusType) data%State%AirDrivenPump%ChokeAirFail = 0 + if(status == Executed_StatusType) data%State%AirDrivenPump%ChokeAirFail = 1 + endsubroutine + +end module CChokeProblems diff --git a/CSharp/Problems/CChokeProblemsVariables.f90 b/CSharp/Problems/CChokeProblemsVariables.f90 index 79ca9b2..bb4ca30 100644 --- a/CSharp/Problems/CChokeProblemsVariables.f90 +++ b/CSharp/Problems/CChokeProblemsVariables.f90 @@ -9,20 +9,21 @@ module CChokeProblemsVariables type(CProblem) :: HydraulicChoke1Plugged type(CProblem) :: HydraulicChoke1Fail type(CProblem) :: HydraulicChoke1Washout - integer :: HydraulicChoke1PluggedPercent type(CProblem) :: HydraulicChoke2Plugged type(CProblem) :: HydraulicChoke2Fail type(CProblem) :: HydraulicChoke2Washout - integer :: HydraulicChoke2PluggedPercent type(CProblem) :: ManualChoke1Plugged type(CProblem) :: ManualChoke1Fail type(CProblem) :: ManualChoke1Washout - integer :: ManualChoke1PluggedPercent type(CProblem) :: ManualChoke2Plugged type(CProblem) :: ManualChoke2Fail type(CProblem) :: ManualChoke2Washout - integer :: ManualChoke2PluggedPercent type(CProblem) :: ChokePanelAirFail + + integer :: ManualChoke1PluggedPercent + integer :: HydraulicChoke2PluggedPercent + integer :: HydraulicChoke1PluggedPercent + integer :: ManualChoke2PluggedPercent end type ChokeProblemsType contains diff --git a/CSharp/Problems/CChokeProblemsVariables.i90 b/CSharp/Problems/CChokeProblemsVariables.i90 new file mode 100644 index 0000000..f520f48 --- /dev/null +++ b/CSharp/Problems/CChokeProblemsVariables.i90 @@ -0,0 +1,32 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CChokeProblemsVariables.f90" +module CChokeProblemsVariables + use CProblemDifinition + + implicit none + public + +! Input vars + type:: ChokeProblemsType + type(CProblem) :: HydraulicChoke1Plugged + type(CProblem) :: HydraulicChoke1Fail + type(CProblem) :: HydraulicChoke1Washout + type(CProblem) :: HydraulicChoke2Plugged + type(CProblem) :: HydraulicChoke2Fail + type(CProblem) :: HydraulicChoke2Washout + type(CProblem) :: ManualChoke1Plugged + type(CProblem) :: ManualChoke1Fail + type(CProblem) :: ManualChoke1Washout + type(CProblem) :: ManualChoke2Plugged + type(CProblem) :: ManualChoke2Fail + type(CProblem) :: ManualChoke2Washout + type(CProblem) :: ChokePanelAirFail + + integer :: ManualChoke1PluggedPercent + integer :: HydraulicChoke2PluggedPercent + integer :: HydraulicChoke1PluggedPercent + integer :: ManualChoke2PluggedPercent + end type ChokeProblemsType + + contains + +end module CChokeProblemsVariables diff --git a/CSharp/Problems/CDrillStemProblems.f90 b/CSharp/Problems/CDrillStemProblems.f90 index af847e0..04b17bf 100644 --- a/CSharp/Problems/CDrillStemProblems.f90 +++ b/CSharp/Problems/CDrillStemProblems.f90 @@ -3,6 +3,22 @@ module CDrillStemProblems implicit none public contains + subroutine DrillStemProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'DrillStemProblems',p) + call ProblemFromJson(p,"StringDragIncrease",data%problems%DrillStemProblems%StringDragIncrease) + call ProblemFromJson(p,"StringTorqueIncrease",data%problems%DrillStemProblems%StringTorqueIncrease) + call ProblemFromJson(p,"StringTorqueFluctuation",data%problems%DrillStemProblems%StringTorqueFluctuation) + + call json%get(p,'StringDragIncreaseTime',pval) + call json%get(pval,data%problems%DrillStemProblems%StringDragIncreaseTime) + call json%get(p,'StringTorqueIncreaseTime',pval) + call json%get(pval,data%problems%DrillStemProblems%StringTorqueIncreaseTime) + end subroutine + subroutine DrillStemProblemsToJson(parent) type(json_value),pointer :: parent type(json_core) :: json @@ -16,7 +32,7 @@ module CDrillStemProblems call ProblemToJson(p,"StringTorqueIncrease",data%problems%DrillStemProblems%StringTorqueIncrease) call ProblemToJson(p,"StringTorqueFluctuation",data%problems%DrillStemProblems%StringTorqueFluctuation) call json%add(p,"StringDragIncreaseTime",data%problems%DrillStemProblems%StringDragIncreaseTime) - call json%add(p,"StringTorqueIncreaseTime",data%problems%DrillStemProblems%StringTorqueIncreaseTime) + call json%add(p,"StringTorqueIncreaseTime",data%problems%DrillStemProblems%StringTorqueIncreaseTime) ! 3. add new node to parent call json%add(parent,p) end subroutine diff --git a/CSharp/Problems/CDrillStemProblems.i90 b/CSharp/Problems/CDrillStemProblems.i90 new file mode 100644 index 0000000..20c5f44 --- /dev/null +++ b/CSharp/Problems/CDrillStemProblems.i90 @@ -0,0 +1,99 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CDrillStemProblems.f90" +module CDrillStemProblems + use SimulationVariables + implicit none + public + contains + subroutine DrillStemProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'DrillStemProblems',p) + call ProblemFromJson(p,"StringDragIncrease",data%problems%DrillStemProblems%StringDragIncrease) + call ProblemFromJson(p,"StringTorqueIncrease",data%problems%DrillStemProblems%StringTorqueIncrease) + call ProblemFromJson(p,"StringTorqueFluctuation",data%problems%DrillStemProblems%StringTorqueFluctuation) + + call json%get(p,'StringDragIncreaseTime',pval) + call json%get(pval,data%problems%DrillStemProblems%StringDragIncreaseTime) + call json%get(p,'StringTorqueIncreaseTime',pval) + call json%get(pval,data%problems%DrillStemProblems%StringTorqueIncreaseTime) + end subroutine + + subroutine DrillStemProblemsToJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'DrillStemsProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"StringDragIncrease",data%problems%DrillStemProblems%StringDragIncrease) + call ProblemToJson(p,"StringTorqueIncrease",data%problems%DrillStemProblems%StringTorqueIncrease) + call ProblemToJson(p,"StringTorqueFluctuation",data%problems%DrillStemProblems%StringTorqueFluctuation) + call json%add(p,"StringDragIncreaseTime",data%problems%DrillStemProblems%StringDragIncreaseTime) + call json%add(p,"StringTorqueIncreaseTime",data%problems%DrillStemProblems%StringTorqueIncreaseTime) +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProcessDrillStemProblemsDueTime(time) + implicit none + integer :: time + if(data%problems%DrillStemProblems%StringDragIncrease%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%DrillStemProblems%StringDragIncrease, ChangeStringDragIncrease, time) + if(data%problems%DrillStemProblems%StringTorqueIncrease%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%DrillStemProblems%StringTorqueIncrease, ChangeStringTorqueIncrease, time) + if(data%problems%DrillStemProblems%StringTorqueFluctuation%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%DrillStemProblems%StringTorqueFluctuation, ChangeStringTorqueFluctuation, time) + end subroutine + + subroutine ProcessDrillStemProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + if(data%problems%DrillStemProblems%StringDragIncrease%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%DrillStemProblems%StringDragIncrease, ChangeStringDragIncrease, strokes) + if(data%problems%DrillStemProblems%StringTorqueIncrease%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%DrillStemProblems%StringTorqueIncrease, ChangeStringTorqueIncrease, strokes) + if(data%problems%DrillStemProblems%StringTorqueFluctuation%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%DrillStemProblems%StringTorqueFluctuation, ChangeStringTorqueFluctuation, strokes) + end subroutine + + subroutine ProcessDrillStemProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + if(data%problems%DrillStemProblems%StringDragIncrease%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%DrillStemProblems%StringDragIncrease, ChangeStringDragIncrease, volume) + if(data%problems%DrillStemProblems%StringTorqueIncrease%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%DrillStemProblems%StringTorqueIncrease, ChangeStringTorqueIncrease, volume) + if(data%problems%DrillStemProblems%StringTorqueFluctuation%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%DrillStemProblems%StringTorqueFluctuation, ChangeStringTorqueFluctuation, volume) + end subroutine + + subroutine ProcessDrillStemProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + if(data%problems%DrillStemProblems%StringDragIncrease%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%DrillStemProblems%StringDragIncrease, ChangeStringDragIncrease, distance) + if(data%problems%DrillStemProblems%StringTorqueIncrease%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%DrillStemProblems%StringTorqueIncrease, ChangeStringTorqueIncrease, distance) + if(data%problems%DrillStemProblems%StringTorqueFluctuation%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%DrillStemProblems%StringTorqueFluctuation, ChangeStringTorqueFluctuation, distance) + end subroutine + + + + subroutine ChangeStringDragIncrease(status) + implicit none + integer, intent (in) :: status +! if(associated(StringDragIncreasePtr)) call StringDragIncreasePtr(status) +!if(status == Clear_StatusType) print*,'On_StringDragIncrease_Clear' +!if(status == Executed_StatusType) print*,'On_StringDragIncrease_Execute' + endsubroutine + + subroutine ChangeStringTorqueIncrease(status) + implicit none + integer, intent (in) :: status +! if(associated(StringTorqueIncreasePtr)) call StringTorqueIncreasePtr(status) +!if(status == Clear_StatusType) print*,'On_StringTorqueIncrease_Clear' +!if(status == Executed_StatusType) print*,'On_StringTorqueIncrease_Execute' + endsubroutine + + subroutine ChangeStringTorqueFluctuation(status) + implicit none + integer, intent (in) :: status +! if(associated(StringTorqueFluctuationPtr)) call StringTorqueFluctuationPtr(status) +!if(status == Clear_StatusType) print*,'On_StringTorqueFluctuation_Clear' +!if(status == Executed_StatusType) print*,'On_StringTorqueFluctuation_Execute' + endsubroutine + +end module CDrillStemProblems diff --git a/CSharp/Problems/CDrillStemProblemsVariables.i90 b/CSharp/Problems/CDrillStemProblemsVariables.i90 new file mode 100644 index 0000000..2a331ad --- /dev/null +++ b/CSharp/Problems/CDrillStemProblemsVariables.i90 @@ -0,0 +1,18 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CDrillStemProblemsVariables.f90" +module CDrillStemProblemsVariables + use CProblemDifinition + implicit none + public + +! Input vars + type:: DrillStemProblemsType + type(CProblem) :: StringDragIncrease + type(CProblem) :: StringTorqueIncrease + type(CProblem) :: StringTorqueFluctuation + real(8) :: StringDragIncreaseTime + real(8) :: StringTorqueIncreaseTime + end type DrillStemProblemsType + + contains + +end module CDrillStemProblemsVariables diff --git a/CSharp/Problems/CGaugesProblems.f90 b/CSharp/Problems/CGaugesProblems.f90 index 32c7c7e..ac39407 100644 --- a/CSharp/Problems/CGaugesProblems.f90 +++ b/CSharp/Problems/CGaugesProblems.f90 @@ -2,7 +2,40 @@ module CGaugesProblems use SimulationVariables implicit none public - contains + contains + subroutine GaugesProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'GaugesProblems',p) + + call ProblemFromJson(p,"WeightIndicator",data%problems%GaugesProblems%WeightIndicator) + call ProblemFromJson(p,"RotaryRpm",data%problems%GaugesProblems%RotaryRpm) + call ProblemFromJson(p,"RotaryTorque",data%problems%GaugesProblems%RotaryTorque) + call ProblemFromJson(p,"StandPipePressure",data%problems%GaugesProblems%StandPipePressure) + call ProblemFromJson(p,"CasingPressure",data%problems%GaugesProblems%CasingPressure) + call ProblemFromJson(p,"Pump1Strokes",data%problems%GaugesProblems%Pump1Strokes) + call ProblemFromJson(p,"Pump2Strokes",data%problems%GaugesProblems%Pump2Strokes) + call ProblemFromJson(p,"ReturnLineTemperature",data%problems%GaugesProblems%ReturnLineTemperature) + call ProblemFromJson(p,"TripTank",data%problems%GaugesProblems%TripTank) + call ProblemFromJson(p,"PitGainLoss",data%problems%GaugesProblems%PitGainLoss) + call ProblemFromJson(p,"MudTankVolume",data%problems%GaugesProblems%MudTankVolume) + call ProblemFromJson(p,"ReturnMudFlow",data%problems%GaugesProblems%ReturnMudFlow) + call ProblemFromJson(p,"TorqueLimit",data%problems%GaugesProblems%TorqueLimit) + call ProblemFromJson(p,"PowerLimit",data%problems%GaugesProblems%PowerLimit) + call ProblemFromJson(p,"AccumulatorPressure",data%problems%GaugesProblems%AccumulatorPressure) + call ProblemFromJson(p,"ManifoldPressure",data%problems%GaugesProblems%ManifoldPressure) + call ProblemFromJson(p,"AnnularPressure",data%problems%GaugesProblems%AnnularPressure) + call ProblemFromJson(p,"RigAirPressure",data%problems%GaugesProblems%RigAirPressure) + call ProblemFromJson(p,"StandPipe1",data%problems%GaugesProblems%StandPipe1) + call ProblemFromJson(p,"StandPipe2",data%problems%GaugesProblems%StandPipe2) + call ProblemFromJson(p,"DrillPipePressure",data%problems%GaugesProblems%DrillPipePressure) + call ProblemFromJson(p,"ChokePosition",data%problems%GaugesProblems%ChokePosition) + call ProblemFromJson(p,"CasingPressure2",data%problems%GaugesProblems%CasingPressure2) + + end subroutine + subroutine GaugesProblemsToJson(parent) type(json_value),pointer :: parent diff --git a/CSharp/Problems/CGaugesProblems.i90 b/CSharp/Problems/CGaugesProblems.i90 new file mode 100644 index 0000000..0eacaf2 --- /dev/null +++ b/CSharp/Problems/CGaugesProblems.i90 @@ -0,0 +1,408 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CGaugesProblems.f90" +module CGaugesProblems + use SimulationVariables + implicit none + public + contains + subroutine GaugesProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'GaugesProblems',p) + + call ProblemFromJson(p,"WeightIndicator",data%problems%GaugesProblems%WeightIndicator) + call ProblemFromJson(p,"RotaryRpm",data%problems%GaugesProblems%RotaryRpm) + call ProblemFromJson(p,"RotaryTorque",data%problems%GaugesProblems%RotaryTorque) + call ProblemFromJson(p,"StandPipePressure",data%problems%GaugesProblems%StandPipePressure) + call ProblemFromJson(p,"CasingPressure",data%problems%GaugesProblems%CasingPressure) + call ProblemFromJson(p,"Pump1Strokes",data%problems%GaugesProblems%Pump1Strokes) + call ProblemFromJson(p,"Pump2Strokes",data%problems%GaugesProblems%Pump2Strokes) + call ProblemFromJson(p,"ReturnLineTemperature",data%problems%GaugesProblems%ReturnLineTemperature) + call ProblemFromJson(p,"TripTank",data%problems%GaugesProblems%TripTank) + call ProblemFromJson(p,"PitGainLoss",data%problems%GaugesProblems%PitGainLoss) + call ProblemFromJson(p,"MudTankVolume",data%problems%GaugesProblems%MudTankVolume) + call ProblemFromJson(p,"ReturnMudFlow",data%problems%GaugesProblems%ReturnMudFlow) + call ProblemFromJson(p,"TorqueLimit",data%problems%GaugesProblems%TorqueLimit) + call ProblemFromJson(p,"PowerLimit",data%problems%GaugesProblems%PowerLimit) + call ProblemFromJson(p,"AccumulatorPressure",data%problems%GaugesProblems%AccumulatorPressure) + call ProblemFromJson(p,"ManifoldPressure",data%problems%GaugesProblems%ManifoldPressure) + call ProblemFromJson(p,"AnnularPressure",data%problems%GaugesProblems%AnnularPressure) + call ProblemFromJson(p,"RigAirPressure",data%problems%GaugesProblems%RigAirPressure) + call ProblemFromJson(p,"StandPipe1",data%problems%GaugesProblems%StandPipe1) + call ProblemFromJson(p,"StandPipe2",data%problems%GaugesProblems%StandPipe2) + call ProblemFromJson(p,"DrillPipePressure",data%problems%GaugesProblems%DrillPipePressure) + call ProblemFromJson(p,"ChokePosition",data%problems%GaugesProblems%ChokePosition) + call ProblemFromJson(p,"CasingPressure2",data%problems%GaugesProblems%CasingPressure2) + + end subroutine + + subroutine GaugesProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'GaugesProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"WeightIndicator",data%problems%GaugesProblems%WeightIndicator) + call ProblemToJson(p,"RotaryRpm",data%problems%GaugesProblems%RotaryRpm) + call ProblemToJson(p,"RotaryTorque",data%problems%GaugesProblems%RotaryTorque) + call ProblemToJson(p,"StandPipePressure",data%problems%GaugesProblems%StandPipePressure) + call ProblemToJson(p,"CasingPressure",data%problems%GaugesProblems%CasingPressure) + call ProblemToJson(p,"Pump1Strokes",data%problems%GaugesProblems%Pump1Strokes) + call ProblemToJson(p,"Pump2Strokes",data%problems%GaugesProblems%Pump2Strokes) + call ProblemToJson(p,"ReturnLineTemperature",data%problems%GaugesProblems%ReturnLineTemperature) + call ProblemToJson(p,"TripTank",data%problems%GaugesProblems%TripTank) + call ProblemToJson(p,"PitGainLoss",data%problems%GaugesProblems%PitGainLoss) + call ProblemToJson(p,"MudTankVolume",data%problems%GaugesProblems%MudTankVolume) + call ProblemToJson(p,"ReturnMudFlow",data%problems%GaugesProblems%ReturnMudFlow) + call ProblemToJson(p,"TorqueLimit",data%problems%GaugesProblems%TorqueLimit) + call ProblemToJson(p,"PowerLimit",data%problems%GaugesProblems%PowerLimit) + call ProblemToJson(p,"AccumulatorPressure",data%problems%GaugesProblems%AccumulatorPressure) + call ProblemToJson(p,"ManifoldPressure",data%problems%GaugesProblems%ManifoldPressure) + call ProblemToJson(p,"AnnularPressure",data%problems%GaugesProblems%AnnularPressure) + call ProblemToJson(p,"RigAirPressure",data%problems%GaugesProblems%RigAirPressure) + call ProblemToJson(p,"StandPipe1",data%problems%GaugesProblems%StandPipe1) + call ProblemToJson(p,"StandPipe2",data%problems%GaugesProblems%StandPipe2) + call ProblemToJson(p,"DrillPipePressure",data%problems%GaugesProblems%DrillPipePressure) + call ProblemToJson(p,"ChokePosition",data%problems%GaugesProblems%ChokePosition) + call ProblemToJson(p,"CasingPressure2",data%problems%GaugesProblems%CasingPressure2) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProcessGaugesProblemsDueTime(time) + implicit none + integer :: time + if(data%problems%GaugesProblems%WeightIndicator%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%WeightIndicator, ChangeWeightIndicator, time) + if(data%problems%GaugesProblems%RotaryRpm%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%RotaryRpm, ChangeRotaryRpm, time) + if(data%problems%GaugesProblems%RotaryTorque%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%RotaryTorque, ChangeRotaryTorque, time) + if(data%problems%GaugesProblems%StandPipePressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%StandPipePressure, ChangeStandPipePressure, time) + if(data%problems%GaugesProblems%CasingPressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%CasingPressure, ChangeCasingPressure, time) + if(data%problems%GaugesProblems%Pump1Strokes%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%Pump1Strokes, ChangePump1Strokes, time) + if(data%problems%GaugesProblems%Pump2Strokes%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%Pump2Strokes, ChangePump2Strokes, time) + if(data%problems%GaugesProblems%ReturnLineTemperature%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%ReturnLineTemperature, ChangeReturnLineTemperature, time) + if(data%problems%GaugesProblems%TripTank%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%TripTank, ChangeTripTank, time) + if(data%problems%GaugesProblems%PitGainLoss%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%PitGainLoss, ChangePitGainLoss, time) + if(data%problems%GaugesProblems%MudTankVolume%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%MudTankVolume, ChangeMudTankVolume, time) + if(data%problems%GaugesProblems%ReturnMudFlow%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%ReturnMudFlow, ChangeReturnMudFlow, time) + if(data%problems%GaugesProblems%TorqueLimit%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%TorqueLimit, ChangeTorqueLimit, time) + if(data%problems%GaugesProblems%PowerLimit%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%PowerLimit, ChangePowerLimit, time) + if(data%problems%GaugesProblems%AccumulatorPressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%AccumulatorPressure, ChangeAccumulatorPressure, time) + if(data%problems%GaugesProblems%ManifoldPressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%ManifoldPressure, ChangeManifoldPressure, time) + if(data%problems%GaugesProblems%AnnularPressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%AnnularPressure, ChangeAnnularPressure, time) + if(data%problems%GaugesProblems%RigAirPressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%RigAirPressure, ChangeRigAirPressure, time) + if(data%problems%GaugesProblems%StandPipe1%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%StandPipe1, ChangeStandPipe1, time) + if(data%problems%GaugesProblems%StandPipe2%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%StandPipe2, ChangeStandPipe2, time) + if(data%problems%GaugesProblems%DrillPipePressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%DrillPipePressure, ChangeDrillPipePressure, time) + if(data%problems%GaugesProblems%ChokePosition%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%ChokePosition, ChangeChokePosition, time) + if(data%problems%GaugesProblems%CasingPressure2%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%CasingPressure2, ChangeCasingPressure2, time) + end subroutine + + subroutine ProcessGaugesProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + if(data%problems%GaugesProblems%WeightIndicator%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%WeightIndicator, ChangeWeightIndicator, strokes) + if(data%problems%GaugesProblems%RotaryRpm%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%RotaryRpm, ChangeRotaryRpm, strokes) + if(data%problems%GaugesProblems%RotaryTorque%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%RotaryTorque, ChangeRotaryTorque, strokes) + if(data%problems%GaugesProblems%StandPipePressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%StandPipePressure, ChangeStandPipePressure, strokes) + if(data%problems%GaugesProblems%CasingPressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%CasingPressure, ChangeCasingPressure, strokes) + if(data%problems%GaugesProblems%Pump1Strokes%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%Pump1Strokes, ChangePump1Strokes, strokes) + if(data%problems%GaugesProblems%Pump2Strokes%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%Pump2Strokes, ChangePump2Strokes, strokes) + if(data%problems%GaugesProblems%ReturnLineTemperature%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%ReturnLineTemperature, ChangeReturnLineTemperature, strokes) + if(data%problems%GaugesProblems%TripTank%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%TripTank, ChangeTripTank, strokes) + if(data%problems%GaugesProblems%PitGainLoss%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%PitGainLoss, ChangePitGainLoss, strokes) + if(data%problems%GaugesProblems%MudTankVolume%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%MudTankVolume, ChangeMudTankVolume, strokes) + if(data%problems%GaugesProblems%ReturnMudFlow%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%ReturnMudFlow, ChangeReturnMudFlow, strokes) + if(data%problems%GaugesProblems%TorqueLimit%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%TorqueLimit, ChangeTorqueLimit, strokes) + if(data%problems%GaugesProblems%PowerLimit%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%PowerLimit, ChangePowerLimit, strokes) + if(data%problems%GaugesProblems%AccumulatorPressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%AccumulatorPressure, ChangeAccumulatorPressure, strokes) + if(data%problems%GaugesProblems%ManifoldPressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%ManifoldPressure, ChangeManifoldPressure, strokes) + if(data%problems%GaugesProblems%AnnularPressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%AnnularPressure, ChangeAnnularPressure, strokes) + if(data%problems%GaugesProblems%RigAirPressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%RigAirPressure, ChangeRigAirPressure, strokes) + if(data%problems%GaugesProblems%StandPipe1%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%StandPipe1, ChangeStandPipe1, strokes) + if(data%problems%GaugesProblems%StandPipe2%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%StandPipe2, ChangeStandPipe2, strokes) + if(data%problems%GaugesProblems%DrillPipePressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%DrillPipePressure, ChangeDrillPipePressure, strokes) + if(data%problems%GaugesProblems%ChokePosition%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%ChokePosition, ChangeChokePosition, strokes) + if(data%problems%GaugesProblems%CasingPressure2%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%CasingPressure2, ChangeCasingPressure2, strokes) + end subroutine + + subroutine ProcessGaugesProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + if(data%problems%GaugesProblems%WeightIndicator%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%WeightIndicator, ChangeWeightIndicator, volume) + if(data%problems%GaugesProblems%RotaryRpm%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%RotaryRpm, ChangeRotaryRpm, volume) + if(data%problems%GaugesProblems%RotaryTorque%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%RotaryTorque, ChangeRotaryTorque, volume) + if(data%problems%GaugesProblems%StandPipePressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%StandPipePressure, ChangeStandPipePressure, volume) + if(data%problems%GaugesProblems%CasingPressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%CasingPressure, ChangeCasingPressure, volume) + if(data%problems%GaugesProblems%Pump1Strokes%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%Pump1Strokes, ChangePump1Strokes, volume) + if(data%problems%GaugesProblems%Pump2Strokes%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%Pump2Strokes, ChangePump2Strokes, volume) + if(data%problems%GaugesProblems%ReturnLineTemperature%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%ReturnLineTemperature, ChangeReturnLineTemperature, volume) + if(data%problems%GaugesProblems%TripTank%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%TripTank, ChangeTripTank, volume) + if(data%problems%GaugesProblems%PitGainLoss%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%PitGainLoss, ChangePitGainLoss, volume) + if(data%problems%GaugesProblems%MudTankVolume%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%MudTankVolume, ChangeMudTankVolume, volume) + if(data%problems%GaugesProblems%ReturnMudFlow%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%ReturnMudFlow, ChangeReturnMudFlow, volume) + if(data%problems%GaugesProblems%TorqueLimit%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%TorqueLimit, ChangeTorqueLimit, volume) + if(data%problems%GaugesProblems%PowerLimit%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%PowerLimit, ChangePowerLimit, volume) + if(data%problems%GaugesProblems%AccumulatorPressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%AccumulatorPressure, ChangeAccumulatorPressure, volume) + if(data%problems%GaugesProblems%ManifoldPressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%ManifoldPressure, ChangeManifoldPressure, volume) + if(data%problems%GaugesProblems%AnnularPressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%AnnularPressure, ChangeAnnularPressure, volume) + if(data%problems%GaugesProblems%RigAirPressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%RigAirPressure, ChangeRigAirPressure, volume) + if(data%problems%GaugesProblems%StandPipe1%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%StandPipe1, ChangeStandPipe1, volume) + if(data%problems%GaugesProblems%StandPipe2%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%StandPipe2, ChangeStandPipe2, volume) + if(data%problems%GaugesProblems%DrillPipePressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%DrillPipePressure, ChangeDrillPipePressure, volume) + if(data%problems%GaugesProblems%ChokePosition%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%ChokePosition, ChangeChokePosition, volume) + if(data%problems%GaugesProblems%CasingPressure2%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%CasingPressure2, ChangeCasingPressure2, volume) + end subroutine + + subroutine ProcessGaugesProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + if(data%problems%GaugesProblems%WeightIndicator%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%WeightIndicator, ChangeWeightIndicator, distance) + if(data%problems%GaugesProblems%RotaryRpm%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%RotaryRpm, ChangeRotaryRpm, distance) + if(data%problems%GaugesProblems%RotaryTorque%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%RotaryTorque, ChangeRotaryTorque, distance) + if(data%problems%GaugesProblems%StandPipePressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%StandPipePressure, ChangeStandPipePressure, distance) + if(data%problems%GaugesProblems%CasingPressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%CasingPressure, ChangeCasingPressure, distance) + if(data%problems%GaugesProblems%Pump1Strokes%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%Pump1Strokes, ChangePump1Strokes, distance) + if(data%problems%GaugesProblems%Pump2Strokes%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%Pump2Strokes, ChangePump2Strokes, distance) + if(data%problems%GaugesProblems%ReturnLineTemperature%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%ReturnLineTemperature, ChangeReturnLineTemperature, distance) + if(data%problems%GaugesProblems%TripTank%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%TripTank, ChangeTripTank, distance) + if(data%problems%GaugesProblems%PitGainLoss%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%PitGainLoss, ChangePitGainLoss, distance) + if(data%problems%GaugesProblems%MudTankVolume%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%MudTankVolume, ChangeMudTankVolume, distance) + if(data%problems%GaugesProblems%ReturnMudFlow%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%ReturnMudFlow, ChangeReturnMudFlow, distance) + if(data%problems%GaugesProblems%TorqueLimit%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%TorqueLimit, ChangeTorqueLimit, distance) + if(data%problems%GaugesProblems%PowerLimit%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%PowerLimit, ChangePowerLimit, distance) + if(data%problems%GaugesProblems%AccumulatorPressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%AccumulatorPressure, ChangeAccumulatorPressure, distance) + if(data%problems%GaugesProblems%ManifoldPressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%ManifoldPressure, ChangeManifoldPressure, distance) + if(data%problems%GaugesProblems%AnnularPressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%AnnularPressure, ChangeAnnularPressure, distance) + if(data%problems%GaugesProblems%RigAirPressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%RigAirPressure, ChangeRigAirPressure, distance) + if(data%problems%GaugesProblems%StandPipe1%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%StandPipe1, ChangeStandPipe1, distance) + if(data%problems%GaugesProblems%StandPipe2%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%StandPipe2, ChangeStandPipe2, distance) + if(data%problems%GaugesProblems%DrillPipePressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%DrillPipePressure, ChangeDrillPipePressure, distance) + if(data%problems%GaugesProblems%ChokePosition%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%ChokePosition, ChangeChokePosition, distance) + if(data%problems%GaugesProblems%CasingPressure2%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%CasingPressure2, ChangeCasingPressure2, distance) + end subroutine + + + + + + + + + + subroutine ChangeWeightIndicator(status) + use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(WeightIndicatorPtr)) call WeightIndicatorPtr(status) + if(status == Clear_StatusType) data%State%TD_General%WeightIndicatorMalf = 0 + if(status == Executed_StatusType) data%State%TD_General%WeightIndicatorMalf = 1 + endsubroutine + + subroutine ChangeRotaryRpm(status) + use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(RotaryRpmPtr)) call RotaryRpmPtr(status) + if(status == Clear_StatusType) data%State%RTable%RpmGaugeMalf = 0 + if(status == Executed_StatusType) data%State%RTable%RpmGaugeMalf = 1 + endsubroutine + + subroutine ChangeRotaryTorque(status) + use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(RotaryTorquePtr)) call RotaryTorquePtr(status) + if(status == Clear_StatusType) data%State%RTable%TorqueGaugeMalf = 0 + if(status == Executed_StatusType) data%State%RTable%TorqueGaugeMalf = 1 + endsubroutine + + subroutine ChangeStandPipePressure(status) + USE MudSystemVARIABLES +use SimulationVariables !@@@ + implicit none + integer, intent (in) :: status +! if(associated(StandPipePressurePtr)) call StandPipePressurePtr(status) + if(status == Clear_StatusType) data%State%MudSystem%StandPipePressure_DataDisplayMalf = 0 + if(status == Executed_StatusType) data%State%MudSystem%StandPipePressure_DataDisplayMalf = 1 + endsubroutine + + subroutine ChangeCasingPressure(status) + USE FricPressDropVarsModule + implicit none + integer, intent (in) :: status +! if(associated(CasingPressurePtr)) call CasingPressurePtr(status) + if(status == Clear_StatusType) data%State%FricPressDrop%CasingPressure_DataDisplayMalF = 0 + if(status == Executed_StatusType) data%State%FricPressDrop%CasingPressure_DataDisplayMalF = 1 + endsubroutine + + subroutine ChangePump1Strokes(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(Pump1StrokesPtr)) call Pump1StrokesPtr(status) + if(status == Clear_StatusType) data%State%Pump(1)%SPMGaugeMalf = 0 + if(status == Executed_StatusType) data%State%Pump(1)%SPMGaugeMalf = 1 + endsubroutine + + subroutine ChangePump2Strokes(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(Pump2StrokesPtr)) call Pump2StrokesPtr(status) + if(status == Clear_StatusType) data%State%Pump(2)%SPMGaugeMalf = 0 + if(status == Executed_StatusType) data%State%Pump(2)%SPMGaugeMalf = 1 + endsubroutine + + subroutine ChangeReturnLineTemperature(status) + implicit none + integer, intent (in) :: status +! if(associated(ReturnLineTemperaturePtr)) call ReturnLineTemperaturePtr(status) +!if(status == Clear_StatusType) print*,'On_ReturnLineTemperature_Clear' +!if(status == Executed_StatusType) print*,'On_ReturnLineTemperature_Execute' + endsubroutine + + subroutine ChangeTripTank(status) + USE MudSystemVARIABLES +use SimulationVariables !@@@ + implicit none + integer, intent (in) :: status +! if(associated(TripTankPtr)) call TripTankPtr(status) + if(status == Clear_StatusType) data%State%MudSystem%TripTankPressure_DataDisplayMalf = 0 + if(status == Executed_StatusType) data%State%MudSystem%TripTankPressure_DataDisplayMalf = 1 + endsubroutine + + subroutine ChangePitGainLoss(status) + USE MudSystemVARIABLES +use SimulationVariables !@@@ + implicit none + integer, intent (in) :: status +! if(associated(PitGainLossPtr)) call PitGainLossPtr(status) + if(status == Clear_StatusType) data%State%MudSystem%PitGainLossGaugeMalf = 0 + if(status == Executed_StatusType) data%State%MudSystem%PitGainLossGaugeMalf = 1 + endsubroutine + + subroutine ChangeMudTankVolume(status) + implicit none + integer, intent (in) :: status +! if(associated(MudTankVolumePtr)) call MudTankVolumePtr(status) +!if(status == Clear_StatusType) print*,'On_MudTankVolume_Clear' +!if(status == Executed_StatusType) print*,'On_MudTankVolume_Execute' + endsubroutine + + subroutine ChangeReturnMudFlow(status) + implicit none + integer, intent (in) :: status +! if(associated(ReturnMudFlowPtr)) call ReturnMudFlowPtr(status) +!if(status == Clear_StatusType) print*,'On_ReturnMudFlow_Clear' +!if(status == Executed_StatusType) print*,'On_ReturnMudFlow_Execute' + endsubroutine + + subroutine ChangeTorqueLimit(status) + use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(TorqueLimitPtr)) call TorqueLimitPtr(status) + if(status == Clear_StatusType) data%State%RTable%TorqueLimitGaugeMalf = 0 + if(status == Executed_StatusType) data%State%RTable%TorqueLimitGaugeMalf = 1 + endsubroutine + + subroutine ChangePowerLimit(status) + implicit none + integer, intent (in) :: status +! if(associated(PowerLimitPtr)) call PowerLimitPtr(status) +!if(status == Clear_StatusType) print*,'On_PowerLimit_Clear' +!if(status == Executed_StatusType) print*,'On_PowerLimit_Execute' + endsubroutine + + subroutine ChangeAccumulatorPressure(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(AccumulatorPressurePtr)) call AccumulatorPressurePtr(status) + if(status == Clear_StatusType) data%State%BopStackAcc%AccumulatorPressureGaugeMalf = 0 + if(status == Executed_StatusType) data%State%BopStackAcc%AccumulatorPressureGaugeMalf = 1 + endsubroutine + + subroutine ChangeManifoldPressure(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(ManifoldPressurePtr)) call ManifoldPressurePtr(status) + if(status == Clear_StatusType) data%State%BopStackAcc%ManifoldPressureGaugeMalf = 0 + if(status == Executed_StatusType) data%State%BopStackAcc%ManifoldPressureGaugeMalf = 1 + endsubroutine + + subroutine ChangeAnnularPressure(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(AnnularPressurePtr)) call AnnularPressurePtr(status) + if(status == Clear_StatusType) data%State%Annular%AnnularPressureGaugeMalf = 0 + if(status == Executed_StatusType) data%State%Annular%AnnularPressureGaugeMalf = 1 + endsubroutine + + subroutine ChangeRigAirPressure(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +! if(associated(RigAirPressurePtr)) call RigAirPressurePtr(status) + if(status == Clear_StatusType) data%State%BopStackAcc%AirSupplyPressureGaugeMalf = 0 + if(status == Executed_StatusType) data%State%BopStackAcc%AirSupplyPressureGaugeMalf = 1 + endsubroutine + + subroutine ChangeStandPipe1(status) + USE MudSystemVARIABLES +use SimulationVariables !@@@ + implicit none + integer, intent (in) :: status +! if(associated(StandPipe1Ptr)) call StandPipe1Ptr(status) + if(status == Clear_StatusType) data%State%MudSystem%StandPipeGauge1Malf = 0 + if(status == Executed_StatusType) data%State%MudSystem%StandPipeGauge1Malf = 1 + endsubroutine + + subroutine ChangeStandPipe2(status) + USE MudSystemVARIABLES +use SimulationVariables !@@@ + implicit none + integer, intent (in) :: status +! if(associated(StandPipe2Ptr)) call StandPipe2Ptr(status) + if(status == Clear_StatusType) data%State%MudSystem%StandPipeGauge2Malf = 0 + if(status == Executed_StatusType) data%State%MudSystem%StandPipeGauge2Malf = 1 + endsubroutine + + subroutine ChangeDrillPipePressure(status) + USE MudSystemVARIABLES +use SimulationVariables !@@@ + implicit none + integer, intent (in) :: status +! if(associated(DrillPipePressurePtr)) call DrillPipePressurePtr(status) + if(status == Clear_StatusType) data%State%MudSystem%DrillPipePressureMalf = 0 + if(status == Executed_StatusType) data%State%MudSystem%DrillPipePressureMalf = 1 + endsubroutine + + subroutine ChangeChokePosition(status) + USE CHOKEVARIABLES +use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(ChokePositionPtr)) call ChokePositionPtr(status) + if(status == Clear_StatusType) data%State%Choke%GaugeChokePositionMailf = 0 + if(status == Executed_StatusType) data%State%Choke%GaugeChokePositionMailf = 1 + endsubroutine + + subroutine ChangeCasingPressure2(status) + USE FricPressDropVarsModule + implicit none + integer, intent (in) :: status +! if(associated(CasingPressure2Ptr)) call CasingPressure2Ptr(status) + if(status == Clear_StatusType) data%State%FricPressDrop%CasingPressure_ChokeMalF = 0 + if(status == Executed_StatusType) data%State%FricPressDrop%CasingPressure_ChokeMalF = 1 + endsubroutine + +end module CGaugesProblems diff --git a/CSharp/Problems/CGaugesProblemsVariables.i90 b/CSharp/Problems/CGaugesProblemsVariables.i90 new file mode 100644 index 0000000..b7732a1 --- /dev/null +++ b/CSharp/Problems/CGaugesProblemsVariables.i90 @@ -0,0 +1,34 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CGaugesProblemsVariables.f90" +module CGaugesProblemsVariables + use CProblemDifinition + implicit none + public + type :: GaugesProblemsType + type(CProblem) :: WeightIndicator + type(CProblem) :: RotaryRpm + type(CProblem) :: RotaryTorque + type(CProblem) :: StandPipePressure + type(CProblem) :: CasingPressure + type(CProblem) :: Pump1Strokes + type(CProblem) :: Pump2Strokes + type(CProblem) :: ReturnLineTemperature + type(CProblem) :: TripTank + type(CProblem) :: PitGainLoss + type(CProblem) :: MudTankVolume + type(CProblem) :: ReturnMudFlow + type(CProblem) :: TorqueLimit + type(CProblem) :: PowerLimit + type(CProblem) :: AccumulatorPressure + type(CProblem) :: ManifoldPressure + type(CProblem) :: AnnularPressure + type(CProblem) :: RigAirPressure + type(CProblem) :: StandPipe1 + type(CProblem) :: StandPipe2 + type(CProblem) :: DrillPipePressure + type(CProblem) :: ChokePosition + type(CProblem) :: CasingPressure2 + end type GaugesProblemsType + + contains + +end module CGaugesProblemsVariables diff --git a/CSharp/Problems/CHoistingProblems.f90 b/CSharp/Problems/CHoistingProblems.f90 index 23dcadc..78264f1 100644 --- a/CSharp/Problems/CHoistingProblems.f90 +++ b/CSharp/Problems/CHoistingProblems.f90 @@ -3,6 +3,17 @@ module CHoistingProblems implicit none public contains + subroutine HoistingProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'HoistingProblems',p) + call ProblemFromJson(p,"MotorFail",data%problems%HoistingProblems%MotorFail) + call ProblemFromJson(p,"ClutchEngage",data%problems%HoistingProblems%ClutchEngage) + call ProblemFromJson(p,"ClutchDisengage",data%problems%HoistingProblems%ClutchDisengage) + end subroutine + subroutine HoistingProblemsToJson(parent) type(json_value),pointer :: parent diff --git a/CSharp/Problems/CHoistingProblems.i90 b/CSharp/Problems/CHoistingProblems.i90 new file mode 100644 index 0000000..79c7434 --- /dev/null +++ b/CSharp/Problems/CHoistingProblems.i90 @@ -0,0 +1,100 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CHoistingProblems.f90" +module CHoistingProblems + use SimulationVariables + implicit none + public + contains + subroutine HoistingProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'HoistingProblems',p) + call ProblemFromJson(p,"MotorFail",data%problems%HoistingProblems%MotorFail) + call ProblemFromJson(p,"ClutchEngage",data%problems%HoistingProblems%ClutchEngage) + call ProblemFromJson(p,"ClutchDisengage",data%problems%HoistingProblems%ClutchDisengage) + end subroutine + + subroutine HoistingProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'HoistingProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"MotorFail",data%problems%HoistingProblems%MotorFail) + call ProblemToJson(p,"ClutchEngage",data%problems%HoistingProblems%ClutchEngage) + call ProblemToJson(p,"ClutchDisengage",data%problems%HoistingProblems%ClutchDisengage) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProcessHoistingProblemsDueTime(time) + implicit none + integer :: time + if(data%problems%HoistingProblems%MotorFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%HoistingProblems%MotorFail, ChangeMotorFail, time) + if(data%problems%HoistingProblems%ClutchEngage%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%HoistingProblems%ClutchEngage, ChangeClutchEngage, time) + if(data%problems%HoistingProblems%ClutchDisengage%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%HoistingProblems%ClutchDisengage, ChangeClutchDisengage, time) + end subroutine + + subroutine ProcessHoistingProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + if(data%problems%HoistingProblems%MotorFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%HoistingProblems%MotorFail, ChangeMotorFail, strokes) + if(data%problems%HoistingProblems%ClutchEngage%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%HoistingProblems%ClutchEngage, ChangeClutchEngage, strokes) + if(data%problems%HoistingProblems%ClutchDisengage%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%HoistingProblems%ClutchDisengage, ChangeClutchDisengage, strokes) + end subroutine + + subroutine ProcessHoistingProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + if(data%problems%HoistingProblems%MotorFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%HoistingProblems%MotorFail, ChangeMotorFail, volume) + if(data%problems%HoistingProblems%ClutchEngage%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%HoistingProblems%ClutchEngage, ChangeClutchEngage, volume) + if(data%problems%HoistingProblems%ClutchDisengage%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%HoistingProblems%ClutchDisengage, ChangeClutchDisengage, volume) + end subroutine + + subroutine ProcessHoistingProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + if(data%problems%HoistingProblems%MotorFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%HoistingProblems%MotorFail, ChangeMotorFail, distance) + if(data%problems%HoistingProblems%ClutchEngage%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%HoistingProblems%ClutchEngage, ChangeClutchEngage, distance) + if(data%problems%HoistingProblems%ClutchDisengage%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%HoistingProblems%ClutchDisengage, ChangeClutchDisengage, distance) + end subroutine + + + + + + + subroutine ChangeMotorFail(status) + use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(MotorFailPtr)) call MotorFailPtr(status) + if(status == Clear_StatusType) data%State%Drawworks%MotorFaileMalf=0 + if(status == Executed_StatusType) data%State%Drawworks%MotorFaileMalf=1 + endsubroutine + + subroutine ChangeClutchEngage(status) + use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(ClutchEngagePtr)) call ClutchEngagePtr(status) + if(status == Clear_StatusType) data%State%Drawworks%ClutchEngageMalf=0 + if(status == Executed_StatusType) data%State%Drawworks%ClutchEngageMalf=1 + endsubroutine + + subroutine ChangeClutchDisengage(status) + use SimulationVariables !@ + implicit none + integer, intent (in) :: status +! if(associated(ClutchDisengagePtr)) call ClutchDisengagePtr(status) + if(status == Clear_StatusType) data%State%Drawworks%ClutchDisengageMalf=0 + if(status == Executed_StatusType) data%State%Drawworks%ClutchDisengageMalf=1 + endsubroutine + +end module CHoistingProblems diff --git a/CSharp/Problems/CHoistingProblemsVariables.i90 b/CSharp/Problems/CHoistingProblemsVariables.i90 new file mode 100644 index 0000000..b49070a --- /dev/null +++ b/CSharp/Problems/CHoistingProblemsVariables.i90 @@ -0,0 +1,18 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CHoistingProblemsVariables.f90" +module CHoistingProblemsVariables + use CProblemDifinition + implicit none + public + +! Input vars + type :: HoistingProblemsType + type(CProblem) :: MotorFail + type(CProblem) :: ClutchEngage + type(CProblem) :: ClutchDisengage + end type HoistingProblemsType + + + contains + + +end module CHoistingProblemsVariables diff --git a/CSharp/Problems/CKickProblems.f90 b/CSharp/Problems/CKickProblems.f90 index f6768cd..827c634 100644 --- a/CSharp/Problems/CKickProblems.f90 +++ b/CSharp/Problems/CKickProblems.f90 @@ -8,6 +8,25 @@ module CKickProblems ! integer :: Water_FluidType = 2 contains + subroutine KickProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'KickProblems',p) + call ProblemFromJson(p,"Kick",data%problems%KickProblems%Kick) + call json%get(p,'FluidType',pval) + call json%get(pval,data%problems%KickProblems%FluidType) + call json%get(p,'FlowRate',pval) + call json%get(pval,data%problems%KickProblems%FlowRate) + call json%get(p,'OverBalancePressure',pval) + call json%get(pval,data%problems%KickProblems%OverBalancePressure) + call json%get(p,'IsAutoMigrationRateSelected',pval) + call json%get(pval,data%problems%KickProblems%IsAutoMigrationRateSelected) + call json%get(p,'AutoMigrationRate',pval) + call json%get(pval,data%problems%KickProblems%AutoMigrationRate) + end subroutine + subroutine KickProblemsToJson(parent) type(json_value),pointer :: parent diff --git a/CSharp/Problems/CKickProblems.i90 b/CSharp/Problems/CKickProblems.i90 new file mode 100644 index 0000000..5f84be0 --- /dev/null +++ b/CSharp/Problems/CKickProblems.i90 @@ -0,0 +1,93 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CKickProblems.f90" +module CKickProblems + use SimulationVariables + implicit none + public +!constants +! integer :: Gas_FluidType = 0 +! integer :: Oil_FluidType = 1 +! integer :: Water_FluidType = 2 + + contains + subroutine KickProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'KickProblems',p) + call ProblemFromJson(p,"Kick",data%problems%KickProblems%Kick) + call json%get(p,'FluidType',pval) + call json%get(pval,data%problems%KickProblems%FluidType) + call json%get(p,'FlowRate',pval) + call json%get(pval,data%problems%KickProblems%FlowRate) + call json%get(p,'OverBalancePressure',pval) + call json%get(pval,data%problems%KickProblems%OverBalancePressure) + call json%get(p,'IsAutoMigrationRateSelected',pval) + call json%get(pval,data%problems%KickProblems%IsAutoMigrationRateSelected) + call json%get(p,'AutoMigrationRate',pval) + call json%get(pval,data%problems%KickProblems%AutoMigrationRate) + end subroutine + + subroutine KickProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'KickProblems') + + call ProblemToJson(p,"Kick",data%problems%KickProblems%Kick) + call json%add(p,"FluidType",data%problems%KickProblems%FluidType) + call json%add(p,"FlowRate",data%problems%KickProblems%FlowRate) + call json%add(p,"OverBalancePressure",data%problems%KickProblems%OverBalancePressure) + call json%add(p,"IsAutoMigrationRateSelected",data%problems%KickProblems%IsAutoMigrationRateSelected) + call json%add(p,"AutoMigrationRate",data%problems%KickProblems%AutoMigrationRate) ! 2. add member of data type to new node + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + + subroutine ProcessKickProblemsDueTime(time) + implicit none + integer :: time + + if(data%problems%KickProblems%Kick%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%KickProblems%Kick, ChangeKick, time) + + end subroutine + + subroutine ProcessKickProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + + if(data%problems%KickProblems%Kick%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%KickProblems%Kick, ChangeKick, strokes) + + end subroutine + + subroutine ProcessKickProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + + if(data%problems%KickProblems%Kick%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%KickProblems%Kick, ChangeKick, volume) + + end subroutine + + subroutine ProcessKickProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + + if(data%problems%KickProblems%Kick%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%KickProblems%Kick, ChangeKick, distance) + + end subroutine + + subroutine ChangeKick(status) + implicit none + integer, intent (in) :: status +! if(associated(data%problems%KickProblems%KickPtr)) call data%problems%KickProblems%KickPtr(status) +!if(status == Clear_StatusType) print*,'On_Kick_Clear' +!if(status == Executed_StatusType) print*,'On_Kick_Execute' + endsubroutine + + +end module CKickProblems diff --git a/CSharp/Problems/CKickProblemsVariables.i90 b/CSharp/Problems/CKickProblemsVariables.i90 new file mode 100644 index 0000000..6afaab2 --- /dev/null +++ b/CSharp/Problems/CKickProblemsVariables.i90 @@ -0,0 +1,19 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CKickProblemsVariables.f90" +module CKickProblemsVariables + use CProblemDifinition + implicit none + public + + + +! Input vars + type :: KickProblemsType + type(CProblem) :: Kick + integer :: FluidType + integer :: FlowRate + integer :: OverBalancePressure + logical :: IsAutoMigrationRateSelected + real(8) :: AutoMigrationRate + end type KickProblemsType + +end module CKickProblemsVariables diff --git a/CSharp/Problems/CLostProblems.f90 b/CSharp/Problems/CLostProblems.f90 index 6a155e4..4facef7 100644 --- a/CSharp/Problems/CLostProblems.f90 +++ b/CSharp/Problems/CLostProblems.f90 @@ -3,6 +3,17 @@ module CLostProblems implicit none public contains + subroutine LostProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'LostProblems',p) + call ProblemFromJson(p,"LostCirculation",data%problems%LostProblems%LostCirculation) + call json%get(p,'FlowRate',pval) + call json%get(pval,data%problems%LostProblems%FlowRate) + end subroutine + subroutine LostProblemsToJson(parent) type(json_value),pointer :: parent @@ -10,7 +21,7 @@ module CLostProblems type(json_value),pointer :: p ! 1. create new node - call json%create_object(p,'Configuration') + call json%create_object(p,'LostProblems') ! 2. add member of data type to new node call ProblemToJson(p,"LostCirculation",data%problems%LostProblems%LostCirculation) diff --git a/CSharp/Problems/CLostProblems.i90 b/CSharp/Problems/CLostProblems.i90 new file mode 100644 index 0000000..9b473a4 --- /dev/null +++ b/CSharp/Problems/CLostProblems.i90 @@ -0,0 +1,77 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CLostProblems.f90" +module CLostProblems + use SimulationVariables + implicit none + public + contains + subroutine LostProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,'LostProblems',p) + call ProblemFromJson(p,"LostCirculation",data%problems%LostProblems%LostCirculation) + call json%get(p,'FlowRate',pval) + call json%get(pval,data%problems%LostProblems%FlowRate) + end subroutine + + subroutine LostProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'LostProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"LostCirculation",data%problems%LostProblems%LostCirculation) + call json%add(p,"FlowRate",data%problems%LostProblems%FlowRate) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProcessLostProblemsDueTime(time) + implicit none + integer :: time + if(data%problems%LostProblems%LostCirculation%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%LostProblems%LostCirculation, ChangeLostCirculation, time) + end subroutine + + subroutine ProcessLostProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + + if(data%problems%LostProblems%LostCirculation%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%LostProblems%LostCirculation, ChangeLostCirculation, strokes) + + end subroutine + + subroutine ProcessLostProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + + if(data%problems%LostProblems%LostCirculation%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%LostProblems%LostCirculation, ChangeLostCirculation, volume) + + end subroutine + + subroutine ProcessLostProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + + if(data%problems%LostProblems%LostCirculation%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%LostProblems%LostCirculation, ChangeLostCirculation, distance) + + end subroutine + + + + + subroutine ChangeLostCirculation(status) + implicit none + integer, intent (in) :: status +! if(associated(LostCirculationPtr)) call LostCirculationPtr(status) +!if(status == Clear_StatusType) print*,'On_LostCirculation_Clear' +!if(status == Executed_StatusType) print*,'On_LostCirculation_Execute' + endsubroutine + + +end module CLostProblems diff --git a/CSharp/Problems/CLostProblemsVariables.f90 b/CSharp/Problems/CLostProblemsVariables.f90 index e023371..52dd6e0 100644 --- a/CSharp/Problems/CLostProblemsVariables.f90 +++ b/CSharp/Problems/CLostProblemsVariables.f90 @@ -9,9 +9,4 @@ module CLostProblemsVariables real(8) :: FlowRate end type LostProblemsType - ! procedure (ActionInteger), pointer :: LostCirculationPtr - - contains - - end module CLostProblemsVariables \ No newline at end of file diff --git a/CSharp/Problems/CLostProblemsVariables.i90 b/CSharp/Problems/CLostProblemsVariables.i90 new file mode 100644 index 0000000..101da79 --- /dev/null +++ b/CSharp/Problems/CLostProblemsVariables.i90 @@ -0,0 +1,13 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CLostProblemsVariables.f90" +module CLostProblemsVariables + use CProblemDifinition + implicit none + public + +! Input vars + type::LostProblemsType + type(CProblem) :: LostCirculation + real(8) :: FlowRate + end type LostProblemsType + +end module CLostProblemsVariables diff --git a/CSharp/Problems/CMudTreatmentProblems.f90 b/CSharp/Problems/CMudTreatmentProblems.f90 index dfe85a0..a833485 100644 --- a/CSharp/Problems/CMudTreatmentProblems.f90 +++ b/CSharp/Problems/CMudTreatmentProblems.f90 @@ -2,7 +2,19 @@ module CMudTreatmentProblems use SimulationVariables implicit none public - contains + contains + subroutine MudTreatmentProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'MudTreatmentProblems',p) + call ProblemFromJson(p,"Degasser",data%problems%MudTreatmentProblems%Degasser) + call ProblemFromJson(p,"ShaleShaker",data%problems%MudTreatmentProblems%ShaleShaker) + call ProblemFromJson(p,"Desander",data%problems%MudTreatmentProblems%Desander) + call ProblemFromJson(p,"Desilter",data%problems%MudTreatmentProblems%Desilter) + end subroutine + subroutine MudTreatmentProblemsToJson(parent) type(json_value),pointer :: parent diff --git a/CSharp/Problems/CMudTreatmentProblems.i90 b/CSharp/Problems/CMudTreatmentProblems.i90 new file mode 100644 index 0000000..90fca38 --- /dev/null +++ b/CSharp/Problems/CMudTreatmentProblems.i90 @@ -0,0 +1,121 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CMudTreatmentProblems.f90" +module CMudTreatmentProblems + use SimulationVariables + implicit none + public + contains + subroutine MudTreatmentProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'MudTreatmentProblems',p) + call ProblemFromJson(p,"Degasser",data%problems%MudTreatmentProblems%Degasser) + call ProblemFromJson(p,"ShaleShaker",data%problems%MudTreatmentProblems%ShaleShaker) + call ProblemFromJson(p,"Desander",data%problems%MudTreatmentProblems%Desander) + call ProblemFromJson(p,"Desilter",data%problems%MudTreatmentProblems%Desilter) + end subroutine + + subroutine MudTreatmentProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'MudTreatmentProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"Degasser",data%problems%MudTreatmentProblems%Degasser) + call ProblemToJson(p,"ShaleShaker",data%problems%MudTreatmentProblems%ShaleShaker) + call ProblemToJson(p,"Desander",data%problems%MudTreatmentProblems%Desander) + call ProblemToJson(p,"Desilter",data%problems%MudTreatmentProblems%Desilter) +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProcessMudTreatmentProblemsDueTime(time) + implicit none + integer :: time + + if(data%problems%MudTreatmentProblems%Degasser%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%MudTreatmentProblems%Degasser, ChangeDegasser, time) + if(data%problems%MudTreatmentProblems%ShaleShaker%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%MudTreatmentProblems%ShaleShaker, ChangeShaleShaker, time) + if(data%problems%MudTreatmentProblems%Desander%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%MudTreatmentProblems%Desander, ChangeDesander, time) + if(data%problems%MudTreatmentProblems%Desilter%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%MudTreatmentProblems%Desilter, ChangeDesilter, time) + + end subroutine + + + subroutine ProcessMudTreatmentProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + + if(data%problems%MudTreatmentProblems%Degasser%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%MudTreatmentProblems%Degasser, ChangeDegasser, strokes) + if(data%problems%MudTreatmentProblems%ShaleShaker%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%MudTreatmentProblems%ShaleShaker, ChangeShaleShaker, strokes) + if(data%problems%MudTreatmentProblems%Desander%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%MudTreatmentProblems%Desander, ChangeDesander, strokes) + if(data%problems%MudTreatmentProblems%Desilter%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%MudTreatmentProblems%Desilter, ChangeDesilter, strokes) + + end subroutine + + + subroutine ProcessMudTreatmentProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + + if(data%problems%MudTreatmentProblems%Degasser%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%MudTreatmentProblems%Degasser, ChangeDegasser, volume) + if(data%problems%MudTreatmentProblems%ShaleShaker%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%MudTreatmentProblems%ShaleShaker, ChangeShaleShaker, volume) + if(data%problems%MudTreatmentProblems%Desander%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%MudTreatmentProblems%Desander, ChangeDesander, volume) + if(data%problems%MudTreatmentProblems%Desilter%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%MudTreatmentProblems%Desilter, ChangeDesilter, volume) + + end subroutine + + subroutine ProcessMudTreatmentProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + + if(data%problems%MudTreatmentProblems%Degasser%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%MudTreatmentProblems%Degasser, ChangeDegasser, distance) + if(data%problems%MudTreatmentProblems%ShaleShaker%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%MudTreatmentProblems%ShaleShaker, ChangeShaleShaker, distance) + if(data%problems%MudTreatmentProblems%Desander%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%MudTreatmentProblems%Desander, ChangeDesander, distance) + if(data%problems%MudTreatmentProblems%Desilter%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%MudTreatmentProblems%Desilter, ChangeDesilter, distance) + + end subroutine + + + + + + + + subroutine ChangeDegasser(status) + implicit none + integer, intent (in) :: status +!if(associated(DegasserPtr)) call DegasserPtr(status) +!if(status == Clear_StatusType) print*,'On_Degasser_Clear' +!if(status == Executed_StatusType) print*,'On_Degasser_Execute' + endsubroutine + + subroutine ChangeShaleShaker(status) + implicit none + integer, intent (in) :: status +!if(associated(ShaleShakerPtr)) call ShaleShakerPtr(status) +!if(status == Clear_StatusType) print*,'On_ShaleShaker_Clear' +!if(status == Executed_StatusType) print*,'On_ShaleShaker_Execute' + endsubroutine + + subroutine ChangeDesander(status) + implicit none + integer, intent (in) :: status +!if(associated(DesanderPtr)) call DesanderPtr(status) +!if(status == Clear_StatusType) print*,'On_Desander_Clear' +!if(status == Executed_StatusType) print*,'On_Desander_Execute' + endsubroutine + + subroutine ChangeDesilter(status) + implicit none + integer, intent (in) :: status +!if(associated(DesilterPtr)) call DesilterPtr(status) +!if(status == Clear_StatusType) print*,'On_Desilter_Clear' +!if(status == Executed_StatusType) print*,'On_Desilter_Execute' + endsubroutine + +end module CMudTreatmentProblems diff --git a/CSharp/Problems/COtherProblems.f90 b/CSharp/Problems/COtherProblems.f90 index a762c9e..69001a4 100644 --- a/CSharp/Problems/COtherProblems.f90 +++ b/CSharp/Problems/COtherProblems.f90 @@ -3,6 +3,25 @@ module COtherProblems implicit none public contains + subroutine OtherProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'OtherProblems',p) + call ProblemFromJson(p,"RigAlarm",data%problems%OtherProblems%RigAlarm) + call ProblemFromJson(p,"RigWaterSupply",data%problems%OtherProblems%RigWaterSupply) + call ProblemFromJson(p,"RigAir",data%problems%OtherProblems%RigAir) + call ProblemFromJson(p,"Gen1",data%problems%OtherProblems%Gen1) + call ProblemFromJson(p,"Gen2",data%problems%OtherProblems%Gen2) + call ProblemFromJson(p,"Gen3",data%problems%OtherProblems%Gen3) + call ProblemFromJson(p,"Gen4",data%problems%OtherProblems%Gen4) + call ProblemFromJson(p,"Scr1",data%problems%OtherProblems%Scr1) + call ProblemFromJson(p,"Scr2",data%problems%OtherProblems%Scr2) + call ProblemFromJson(p,"Scr3",data%problems%OtherProblems%Scr3) + call ProblemFromJson(p,"Scr4",data%problems%OtherProblems%Scr4) + end subroutine + subroutine OtherProblemsToJson(parent) type(json_value),pointer :: parent diff --git a/CSharp/Problems/COtherProblems.i90 b/CSharp/Problems/COtherProblems.i90 new file mode 100644 index 0000000..b0413b9 --- /dev/null +++ b/CSharp/Problems/COtherProblems.i90 @@ -0,0 +1,215 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/COtherProblems.f90" +module COtherProblems + use SimulationVariables + implicit none + public + contains + subroutine OtherProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'OtherProblems',p) + call ProblemFromJson(p,"RigAlarm",data%problems%OtherProblems%RigAlarm) + call ProblemFromJson(p,"RigWaterSupply",data%problems%OtherProblems%RigWaterSupply) + call ProblemFromJson(p,"RigAir",data%problems%OtherProblems%RigAir) + call ProblemFromJson(p,"Gen1",data%problems%OtherProblems%Gen1) + call ProblemFromJson(p,"Gen2",data%problems%OtherProblems%Gen2) + call ProblemFromJson(p,"Gen3",data%problems%OtherProblems%Gen3) + call ProblemFromJson(p,"Gen4",data%problems%OtherProblems%Gen4) + call ProblemFromJson(p,"Scr1",data%problems%OtherProblems%Scr1) + call ProblemFromJson(p,"Scr2",data%problems%OtherProblems%Scr2) + call ProblemFromJson(p,"Scr3",data%problems%OtherProblems%Scr3) + call ProblemFromJson(p,"Scr4",data%problems%OtherProblems%Scr4) + end subroutine + + subroutine OtherProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'OtherProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"RigAlarm",data%problems%OtherProblems%RigAlarm) + call ProblemToJson(p,"RigWaterSupply",data%problems%OtherProblems%RigWaterSupply) + call ProblemToJson(p,"RigAir",data%problems%OtherProblems%RigAir) + call ProblemToJson(p,"Gen1",data%problems%OtherProblems%Gen1) + call ProblemToJson(p,"Gen2",data%problems%OtherProblems%Gen2) + call ProblemToJson(p,"Gen3",data%problems%OtherProblems%Gen3) + call ProblemToJson(p,"Gen4",data%problems%OtherProblems%Gen4) + call ProblemToJson(p,"Scr1",data%problems%OtherProblems%Scr1) + call ProblemToJson(p,"Scr2",data%problems%OtherProblems%Scr2) + call ProblemToJson(p,"Scr3",data%problems%OtherProblems%Scr3) + call ProblemToJson(p,"Scr4",data%problems%OtherProblems%Scr4) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProcessOtherProblemsDueTime(time) + implicit none + integer :: time + + if(data%problems%OtherProblems%RigAlarm%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%RigAlarm, ChangeRigAlarm, time) + if(data%problems%OtherProblems%RigWaterSupply%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%RigWaterSupply, ChangeRigWaterSupply, time) + if(data%problems%OtherProblems%RigAir%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%RigAir, ChangeRigAir, time) + if(data%problems%OtherProblems%Gen1%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Gen1, ChangeGen1, time) + if(data%problems%OtherProblems%Gen2%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Gen2, ChangeGen2, time) + if(data%problems%OtherProblems%Gen3%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Gen3, ChangeGen3, time) + if(data%problems%OtherProblems%Gen4%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Gen4, ChangeGen4, time) + if(data%problems%OtherProblems%Scr1%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Scr1, ChangeScr1, time) + if(data%problems%OtherProblems%Scr2%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Scr2, ChangeScr2, time) + if(data%problems%OtherProblems%Scr3%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Scr3, ChangeScr3, time) + if(data%problems%OtherProblems%Scr4%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%OtherProblems%Scr4, ChangeScr4, time) + + end subroutine + + subroutine ProcessOtherProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + + if(data%problems%OtherProblems%RigAlarm%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%RigAlarm, ChangeRigAlarm, strokes) + if(data%problems%OtherProblems%RigWaterSupply%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%RigWaterSupply, ChangeRigWaterSupply, strokes) + if(data%problems%OtherProblems%RigAir%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%RigAir, ChangeRigAir, strokes) + if(data%problems%OtherProblems%Gen1%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Gen1, ChangeGen1, strokes) + if(data%problems%OtherProblems%Gen2%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Gen2, ChangeGen2, strokes) + if(data%problems%OtherProblems%Gen3%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Gen3, ChangeGen3, strokes) + if(data%problems%OtherProblems%Gen4%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Gen4, ChangeGen4, strokes) + if(data%problems%OtherProblems%Scr1%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Scr1, ChangeScr1, strokes) + if(data%problems%OtherProblems%Scr2%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Scr2, ChangeScr2, strokes) + if(data%problems%OtherProblems%Scr3%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Scr3, ChangeScr3, strokes) + if(data%problems%OtherProblems%Scr4%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%OtherProblems%Scr4, ChangeScr4, strokes) + + end subroutine + + subroutine ProcessOtherProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + + if(data%problems%OtherProblems%RigAlarm%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%RigAlarm, ChangeRigAlarm, volume) + if(data%problems%OtherProblems%RigWaterSupply%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%RigWaterSupply, ChangeRigWaterSupply, volume) + if(data%problems%OtherProblems%RigAir%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%RigAir, ChangeRigAir, volume) + if(data%problems%OtherProblems%Gen1%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Gen1, ChangeGen1, volume) + if(data%problems%OtherProblems%Gen2%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Gen2, ChangeGen2, volume) + if(data%problems%OtherProblems%Gen3%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Gen3, ChangeGen3, volume) + if(data%problems%OtherProblems%Gen4%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Gen4, ChangeGen4, volume) + if(data%problems%OtherProblems%Scr1%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Scr1, ChangeScr1, volume) + if(data%problems%OtherProblems%Scr2%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Scr2, ChangeScr2, volume) + if(data%problems%OtherProblems%Scr3%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Scr3, ChangeScr3, volume) + if(data%problems%OtherProblems%Scr4%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%OtherProblems%Scr4, ChangeScr4, volume) + + end subroutine + + subroutine ProcessOtherProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + + if(data%problems%OtherProblems%RigAlarm%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%RigAlarm, ChangeRigAlarm, distance) + if(data%problems%OtherProblems%RigWaterSupply%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%RigWaterSupply, ChangeRigWaterSupply, distance) + if(data%problems%OtherProblems%RigAir%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%RigAir, ChangeRigAir, distance) + if(data%problems%OtherProblems%Gen1%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Gen1, ChangeGen1, distance) + if(data%problems%OtherProblems%Gen2%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Gen2, ChangeGen2, distance) + if(data%problems%OtherProblems%Gen3%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Gen3, ChangeGen3, distance) + if(data%problems%OtherProblems%Gen4%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Gen4, ChangeGen4, distance) + if(data%problems%OtherProblems%Scr1%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Scr1, ChangeScr1, distance) + if(data%problems%OtherProblems%Scr2%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Scr2, ChangeScr2, distance) + if(data%problems%OtherProblems%Scr3%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Scr3, ChangeScr3, distance) + if(data%problems%OtherProblems%Scr4%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%OtherProblems%Scr4, ChangeScr4, distance) + + end subroutine + + + subroutine ChangeRigAlarm(status) + implicit none + integer, intent (in) :: status +!if(associated(RigAlarmPtr)) call RigAlarmPtr(status) +!if(status == Clear_StatusType) print*,'On_RigAlarm_Clear' +!if(status == Executed_StatusType) print*,'On_RigAlarm_Execute' + endsubroutine + + subroutine ChangeRigWaterSupply(status) + implicit none + integer, intent (in) :: status +!if(associated(RigWaterSupplyPtr)) call RigWaterSupplyPtr(status) +!if(status == Clear_StatusType) print*,'On_RigWaterSupply_Clear' +!if(status == Executed_StatusType) print*,'On_RigWaterSupply_Execute' + endsubroutine + + subroutine ChangeRigAir(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +!if(associated(RigAirPtr)) call RigAirPtr(status) + if(status == Clear_StatusType) data%State%BopStackAcc%RigAirMalf = 0 + if(status == Executed_StatusType) data%State%BopStackAcc%RigAirMalf = 1 + endsubroutine + + subroutine ChangeGen1(status) + implicit none + integer, intent (in) :: status +!if(associated(Gen1Ptr)) call Gen1Ptr(status) +!if(status == Clear_StatusType) print*,'On_Gen1_Clear' +!if(status == Executed_StatusType) print*,'On_Gen1_Execute' + endsubroutine + + subroutine ChangeGen2(status) + implicit none + integer, intent (in) :: status +!if(associated(Gen2Ptr)) call Gen2Ptr(status) +!if(status == Clear_StatusType) print*,'On_Gen2_Clear' +!if(status == Executed_StatusType) print*,'On_Gen2_Execute' + endsubroutine + + subroutine ChangeGen3(status) + implicit none + integer, intent (in) :: status +!if(associated(Gen3Ptr)) call Gen3Ptr(status) +!if(status == Clear_StatusType) print*,'On_Gen3_Clear' +!if(status == Executed_StatusType) print*,'On_Gen3_Execute' + endsubroutine + + subroutine ChangeGen4(status) + implicit none + integer, intent (in) :: status +!if(associated(Gen4Ptr)) call Gen4Ptr(status) +!if(status == Clear_StatusType) print*,'On_Gen4_Clear' +!if(status == Executed_StatusType) print*,'On_Gen4_Execute' + endsubroutine + + subroutine ChangeScr1(status) + implicit none + integer, intent (in) :: status +!if(associated(Scr1Ptr)) call Scr1Ptr(status) +!if(status == Clear_StatusType) print*,'On_Scr1_Clear' +!if(status == Executed_StatusType) print*,'On_Scr1_Execute' + endsubroutine + + subroutine ChangeScr2(status) + implicit none + integer, intent (in) :: status +!if(associated(Scr2Ptr)) call Scr2Ptr(status) +!if(status == Clear_StatusType) print*,'On_Scr2_Clear' +!if(status == Executed_StatusType) print*,'On_Scr2_Execute' + endsubroutine + + subroutine ChangeScr3(status) + implicit none + integer, intent (in) :: status +!if(associated(Scr3Ptr)) call Scr3Ptr(status) +!if(status == Clear_StatusType) print*,'On_Scr3_Clear' +!if(status == Executed_StatusType) print*,'On_Scr3_Execute' + endsubroutine + + subroutine ChangeScr4(status) + implicit none + integer, intent (in) :: status +!if(associated(Scr4Ptr)) call Scr4Ptr(status) +!if(status == Clear_StatusType) print*,'On_Scr4_Clear' +!if(status == Executed_StatusType) print*,'On_Scr4_Execute' + endsubroutine + + +end module COtherProblems diff --git a/CSharp/Problems/COtherProblemsVariables.i90 b/CSharp/Problems/COtherProblemsVariables.i90 new file mode 100644 index 0000000..fbd39f8 --- /dev/null +++ b/CSharp/Problems/COtherProblemsVariables.i90 @@ -0,0 +1,36 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/COtherProblemsVariables.f90" +module COtherProblemsVariables + use CProblemDifinition + implicit none + public + +! Input vars + TYPE:: OtherProblemsType + type(CProblem) :: RigAlarm + type(CProblem) :: RigWaterSupply + type(CProblem) :: RigAir + type(CProblem) :: Gen1 + type(CProblem) :: Gen2 + type(CProblem) :: Gen3 + type(CProblem) :: Gen4 + type(CProblem) :: Scr1 + type(CProblem) :: Scr2 + type(CProblem) :: Scr3 + type(CProblem) :: Scr4 + end type OtherProblemsType + contains + + + + + + + + + + + + + + +end module COtherProblemsVariables diff --git a/CSharp/Problems/CProblemDifinition.f90 b/CSharp/Problems/CProblemDifinition.f90 index d8c9adf..b15a476 100644 --- a/CSharp/Problems/CProblemDifinition.f90 +++ b/CSharp/Problems/CProblemDifinition.f90 @@ -21,8 +21,29 @@ module CProblemDifinition real(8) :: DueValue end type CProblem - contains - + contains + + subroutine ProblemFromJson(parent,name,problem) + type(json_value),pointer :: parent + character(len=*)::name + type(CProblem)::problem + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,name,p) + + ! ! 2. add member of data type to new node + call json%get(p,'ProblemType',pval) + call json%get(pval,problem%ProblemType) + call json%get(p,'StatusType',pval) + call json%get(pval,problem%StatusType) + call json%get(p,'Value',pval) + call json%get(pval,problem%Value) + call json%get(p,'DueValue',pval) + call json%get(pval,problem%DueValue) + end subroutine + + subroutine ProblemToJson(parent,name,problem) type(json_value),pointer :: parent character(len=*)::name @@ -30,7 +51,6 @@ module CProblemDifinition type(json_core) :: json type(json_value),pointer :: p - ! 1. create new node call json%create_object(p,name) diff --git a/CSharp/Problems/CProblemDifinition.i90 b/CSharp/Problems/CProblemDifinition.i90 new file mode 100644 index 0000000..5407800 --- /dev/null +++ b/CSharp/Problems/CProblemDifinition.i90 @@ -0,0 +1,119 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CProblemDifinition.f90" +module CProblemDifinition + use json_module + use CIActionReference + implicit none + public + + integer, parameter :: Time_ProblemType = 0 + integer, parameter :: PumpStrokes_ProblemType = 1 + integer, parameter :: VolumePumped_ProblemType = 2 + integer, parameter :: DistanceDrilled_ProblemType = 3 + + integer, parameter :: Clear_StatusType = 0 + integer, parameter :: Now_StatusType = 1 + integer, parameter :: Later_StatusType = 2 + integer, parameter :: Executed_StatusType = 3 + + type, bind(c), public :: CProblem + integer :: ProblemType + integer :: StatusType + real(8) :: Value + real(8) :: DueValue + end type CProblem + + contains + + subroutine ProblemFromJson(parent,name,problem) + type(json_value),pointer :: parent + character(len=*)::name + type(CProblem)::problem + type(json_core) :: json + type(json_value),pointer :: p,pval + + call json%get(parent,name,p) + +! ! 2. add member of data type to new node + call json%get(p,'ProblemType',pval) + call json%get(pval,problem%ProblemType) + call json%get(p,'StatusType',pval) + call json%get(pval,problem%StatusType) + call json%get(p,'Value',pval) + call json%get(pval,problem%Value) + call json%get(p,'DueValue',pval) + call json%get(pval,problem%DueValue) + end subroutine + + + subroutine ProblemToJson(parent,name,problem) + type(json_value),pointer :: parent + character(len=*)::name + type(CProblem)::problem + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,name) + +! 2. add member of data type to new node + call json%add(p,"ProblemType",problem%ProblemType) + call json%add(p,"StatusType",problem%StatusType) + call json%add(p,"Value",problem%Value) + call json%add(p,"DueValue",problem%DueValue) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine Execute(problem, action) + type(CProblem), intent(inout) :: problem + procedure (ActionInteger), pointer, intent(in) :: action + problem%StatusType = Executed_StatusType + if(problem%StatusType == Executed_StatusType .and. associated(action)) call action(Executed_StatusType) + end subroutine + + + + subroutine ProcessDueTime(problem, action, time) + use CLog3 + implicit none + type(CProblem) :: problem + procedure (ActionInteger), pointer, intent(in) :: action + integer :: time + if(problem%ProblemType == Time_ProblemType .and. problem%StatusType /= Executed_StatusType .and. problem%StatusType /= Clear_StatusType) then + if(time >= int(problem%DueValue)) call Execute(problem, action) + end if + end subroutine + + subroutine ProcessDuePumpStrokes(problem, action, strokes) + implicit none + type(CProblem) :: problem + procedure (ActionInteger), pointer, intent(in) :: action + integer :: strokes + if(problem%ProblemType == PumpStrokes_ProblemType .and. problem%StatusType /= Executed_StatusType .and. problem%StatusType /= Clear_StatusType) then + if(strokes >= int(problem%DueValue)) call Execute(problem, action) + end if + end subroutine + + subroutine ProcessDueVolumePumped(problem, action, volume) + implicit none + type(CProblem) :: problem + procedure (ActionInteger), pointer, intent(in) :: action + real(8) :: volume + if(problem%ProblemType == VolumePumped_ProblemType .and. problem%StatusType /= Executed_StatusType .and. problem%StatusType /= Clear_StatusType) then + if(volume >= problem%DueValue) call Execute(problem, action) + end if + end subroutine + + subroutine ProcessDueDistanceDrilled(problem, action, distance) + implicit none + type(CProblem) :: problem + procedure (ActionInteger), pointer, intent(in) :: action + real(8) :: distance + if(problem%ProblemType == DistanceDrilled_ProblemType .and. problem%StatusType /= Executed_StatusType .and. problem%StatusType /= Clear_StatusType) then + if(distance >= problem%DueValue) call Execute(problem, action) + end if + end subroutine + + +end module CProblemDifinition diff --git a/CSharp/Problems/CPumpProblems.f90 b/CSharp/Problems/CPumpProblems.f90 index af567ac..5a3cb11 100644 --- a/CSharp/Problems/CPumpProblems.f90 +++ b/CSharp/Problems/CPumpProblems.f90 @@ -3,6 +3,20 @@ module CPumpProblems implicit none public contains + subroutine PumpProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'PumpProblems',p) + call ProblemFromJson(p,"Pump1PowerFail",data%problems%PumpProblems%Pump1PowerFail) + call ProblemFromJson(p,"Pump1BlowPopOffValve",data%problems%PumpProblems%Pump1BlowPopOffValve) + call ProblemFromJson(p,"Pump2PowerFail",data%problems%PumpProblems%Pump2PowerFail) + call ProblemFromJson(p,"Pump2BlowPopOffValve",data%problems%PumpProblems%Pump2BlowPopOffValve) + call ProblemFromJson(p,"CementPumpPowerFail",data%problems%PumpProblems%CementPumpPowerFail) + call ProblemFromJson(p,"CementPumpBlowPopOffValve",data%problems%PumpProblems%CementPumpBlowPopOffValve) + end subroutine + subroutine PumpProblemsToJson(parent) type(json_value),pointer :: parent diff --git a/CSharp/Problems/CPumpProblems.i90 b/CSharp/Problems/CPumpProblems.i90 new file mode 100644 index 0000000..2323575 --- /dev/null +++ b/CSharp/Problems/CPumpProblems.i90 @@ -0,0 +1,159 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CPumpProblems.f90" +module CPumpProblems + use SimulationVariables + implicit none + public + contains + subroutine PumpProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'PumpProblems',p) + call ProblemFromJson(p,"Pump1PowerFail",data%problems%PumpProblems%Pump1PowerFail) + call ProblemFromJson(p,"Pump1BlowPopOffValve",data%problems%PumpProblems%Pump1BlowPopOffValve) + call ProblemFromJson(p,"Pump2PowerFail",data%problems%PumpProblems%Pump2PowerFail) + call ProblemFromJson(p,"Pump2BlowPopOffValve",data%problems%PumpProblems%Pump2BlowPopOffValve) + call ProblemFromJson(p,"CementPumpPowerFail",data%problems%PumpProblems%CementPumpPowerFail) + call ProblemFromJson(p,"CementPumpBlowPopOffValve",data%problems%PumpProblems%CementPumpBlowPopOffValve) + end subroutine + + subroutine PumpProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'PumpProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"Pump1PowerFail",data%problems%PumpProblems%Pump1PowerFail) + call ProblemToJson(p,"Pump1BlowPopOffValve",data%problems%PumpProblems%Pump1BlowPopOffValve) + call ProblemToJson(p,"Pump2PowerFail",data%problems%PumpProblems%Pump2PowerFail) + call ProblemToJson(p,"Pump2BlowPopOffValve",data%problems%PumpProblems%Pump2BlowPopOffValve) + call ProblemToJson(p,"CementPumpPowerFail",data%problems%PumpProblems%CementPumpPowerFail) + call ProblemToJson(p,"CementPumpBlowPopOffValve",data%problems%PumpProblems%CementPumpBlowPopOffValve) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProcessPumpProblemsDueTime(time) + implicit none + integer :: time + + if(data%problems%PumpProblems%Pump1PowerFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%PumpProblems%Pump1PowerFail, ChangePump1PowerFail, time) + if(data%problems%PumpProblems%Pump1BlowPopOffValve%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%PumpProblems%Pump1BlowPopOffValve, ChangePump1BlowPopOffValve, time) + if(data%problems%PumpProblems%Pump2PowerFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%PumpProblems%Pump2PowerFail, ChangePump2PowerFail, time) + if(data%problems%PumpProblems%Pump2BlowPopOffValve%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%PumpProblems%Pump2BlowPopOffValve, ChangePump2BlowPopOffValve, time) + if(data%problems%PumpProblems%CementPumpPowerFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%PumpProblems%CementPumpPowerFail, ChangeCementPumpPowerFail, time) + if(data%problems%PumpProblems%CementPumpBlowPopOffValve%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%PumpProblems%CementPumpBlowPopOffValve, ChangeCementPumpBlowPopOffValve, time) + + end subroutine + + subroutine ProcessPumpProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + + if(data%problems%PumpProblems%Pump1PowerFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%PumpProblems%Pump1PowerFail, ChangePump1PowerFail, strokes) + if(data%problems%PumpProblems%Pump1BlowPopOffValve%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%PumpProblems%Pump1BlowPopOffValve, ChangePump1BlowPopOffValve, strokes) + if(data%problems%PumpProblems%Pump2PowerFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%PumpProblems%Pump2PowerFail, ChangePump2PowerFail, strokes) + if(data%problems%PumpProblems%Pump2BlowPopOffValve%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%PumpProblems%Pump2BlowPopOffValve, ChangePump2BlowPopOffValve, strokes) + if(data%problems%PumpProblems%CementPumpPowerFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%PumpProblems%CementPumpPowerFail, ChangeCementPumpPowerFail, strokes) + if(data%problems%PumpProblems%CementPumpBlowPopOffValve%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%PumpProblems%CementPumpBlowPopOffValve, ChangeCementPumpBlowPopOffValve, strokes) + + end subroutine + + subroutine ProcessPumpProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + + if(data%problems%PumpProblems%Pump1PowerFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%PumpProblems%Pump1PowerFail, ChangePump1PowerFail, volume) + if(data%problems%PumpProblems%Pump1BlowPopOffValve%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%PumpProblems%Pump1BlowPopOffValve, ChangePump1BlowPopOffValve, volume) + if(data%problems%PumpProblems%Pump2PowerFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%PumpProblems%Pump2PowerFail, ChangePump2PowerFail, volume) + if(data%problems%PumpProblems%Pump2BlowPopOffValve%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%PumpProblems%Pump2BlowPopOffValve, ChangePump2BlowPopOffValve, volume) + if(data%problems%PumpProblems%CementPumpPowerFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%PumpProblems%CementPumpPowerFail, ChangeCementPumpPowerFail, volume) + if(data%problems%PumpProblems%CementPumpBlowPopOffValve%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%PumpProblems%CementPumpBlowPopOffValve, ChangeCementPumpBlowPopOffValve, volume) + + end subroutine + + subroutine ProcessPumpProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + + if(data%problems%PumpProblems%Pump1PowerFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%PumpProblems%Pump1PowerFail, ChangePump1PowerFail, distance) + if(data%problems%PumpProblems%Pump1BlowPopOffValve%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%PumpProblems%Pump1BlowPopOffValve, ChangePump1BlowPopOffValve, distance) + if(data%problems%PumpProblems%Pump2PowerFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%PumpProblems%Pump2PowerFail, ChangePump2PowerFail, distance) + if(data%problems%PumpProblems%Pump2BlowPopOffValve%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%PumpProblems%Pump2BlowPopOffValve, ChangePump2BlowPopOffValve, distance) + if(data%problems%PumpProblems%CementPumpPowerFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%PumpProblems%CementPumpPowerFail, ChangeCementPumpPowerFail, distance) + if(data%problems%PumpProblems%CementPumpBlowPopOffValve%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%PumpProblems%CementPumpBlowPopOffValve, ChangeCementPumpBlowPopOffValve, distance) + + end subroutine + + + + + + + + + + + + subroutine ChangePump1PowerFail(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +!if(associated(Pump1PowerFailPtr)) call Pump1PowerFailPtr(status) + if(status == Clear_StatusType) data%State%Pump(1)%PowerFailMalf=0 + if(status == Executed_StatusType) data%State%Pump(1)%PowerFailMalf=1 + endsubroutine + + subroutine ChangePump1BlowPopOffValve(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +!if(associated(Pump1BlowPopOffValvePtr)) call Pump1BlowPopOffValvePtr(status) + if(status == Clear_StatusType) data%State%Pump(1)%BlowPopOffMalf=0 + if(status == Executed_StatusType) data%State%Pump(1)%BlowPopOffMalf=1 + endsubroutine + + subroutine ChangePump2PowerFail(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +!if(associated(Pump2PowerFailPtr)) call Pump2PowerFailPtr(status) + if(status == Clear_StatusType) data%State%Pump(2)%PowerFailMalf=0 + if(status == Executed_StatusType) data%State%Pump(2)%PowerFailMalf=1 + endsubroutine + + subroutine ChangePump2BlowPopOffValve(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +!if(associated(Pump2BlowPopOffValvePtr)) call Pump2BlowPopOffValvePtr(status) + if(status == Clear_StatusType) data%State%Pump(2)%BlowPopOffMalf=0 + if(status == Executed_StatusType) data%State%Pump(2)%BlowPopOffMalf=1 + endsubroutine + + subroutine ChangeCementPumpPowerFail(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +!if(associated(CementPumpPowerFailPtr)) call CementPumpPowerFailPtr(status) + if(status == Clear_StatusType) data%State%Pump(3)%PowerFailMalf=0 + if(status == Executed_StatusType) data%State%Pump(3)%PowerFailMalf=1 + endsubroutine + + subroutine ChangeCementPumpBlowPopOffValve(status) + use SimulationVariables + implicit none + integer, intent (in) :: status +!if(associated(CementPumpBlowPopOffValvePtr)) call CementPumpBlowPopOffValvePtr(status) + if(status == Clear_StatusType) data%State%Pump(3)%BlowPopOffMalf=0 + if(status == Executed_StatusType) data%State%Pump(3)%BlowPopOffMalf=1 + endsubroutine + + +end module CPumpProblems diff --git a/CSharp/Problems/CRotaryProblems.f90 b/CSharp/Problems/CRotaryProblems.f90 index 5d92c0e..3876986 100644 --- a/CSharp/Problems/CRotaryProblems.f90 +++ b/CSharp/Problems/CRotaryProblems.f90 @@ -3,6 +3,16 @@ module CRotaryProblems implicit none public contains + subroutine RotaryProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'RotaryProblems',p) + call ProblemFromJson(p,"MotorFail",data%problems%RotaryProblems%MotorFail) + call ProblemFromJson(p,"OverideTorqueLimit",data%problems%RotaryProblems%OverideTorqueLimit) + end subroutine + subroutine RotaryProblemsToJson(parent) type(json_value),pointer :: parent diff --git a/CSharp/Problems/CRotaryProblems.i90 b/CSharp/Problems/CRotaryProblems.i90 new file mode 100644 index 0000000..0fb4931 --- /dev/null +++ b/CSharp/Problems/CRotaryProblems.i90 @@ -0,0 +1,94 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CRotaryProblems.f90" +module CRotaryProblems + use SimulationVariables + implicit none + public + contains + subroutine RotaryProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + + call json%get(parent,'RotaryProblems',p) + call ProblemFromJson(p,"MotorFail",data%problems%RotaryProblems%MotorFail) + call ProblemFromJson(p,"OverideTorqueLimit",data%problems%RotaryProblems%OverideTorqueLimit) + end subroutine + + subroutine RotaryProblemsToJson(parent) + + type(json_value),pointer :: parent + type(json_core) :: json + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'RotaryProblems') + +! 2. add member of data type to new node + call ProblemToJson(p,"MotorFail",data%problems%RotaryProblems%MotorFail) + call ProblemToJson(p,"OverideTorqueLimit",data%problems%RotaryProblems%OverideTorqueLimit) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProcessRotaryProblemsDueTime(time) + implicit none + integer :: time + + if(data%problems%RotaryProblems%MotorFail%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%RotaryProblems%MotorFail, ChangeMotorFail, time) + if(data%problems%RotaryProblems%OverideTorqueLimit%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%RotaryProblems%OverideTorqueLimit, ChangeOverideTorqueLimit, time) + + end subroutine + + subroutine ProcessRotaryProblemsDuePumpStrokes(strokes) + implicit none + integer :: strokes + + if(data%problems%RotaryProblems%MotorFail%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%RotaryProblems%MotorFail, ChangeMotorFail, strokes) + if(data%problems%RotaryProblems%OverideTorqueLimit%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%RotaryProblems%OverideTorqueLimit, ChangeOverideTorqueLimit, strokes) + + end subroutine + + subroutine ProcessRotaryProblemsDueVolumePumped(volume) + implicit none + real(8) :: volume + + if(data%problems%RotaryProblems%MotorFail%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%RotaryProblems%MotorFail, ChangeMotorFail, volume) + if(data%problems%RotaryProblems%OverideTorqueLimit%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%RotaryProblems%OverideTorqueLimit, ChangeOverideTorqueLimit, volume) + + end subroutine + + subroutine ProcessRotaryProblemsDueDistanceDrilled(distance) + implicit none + real(8) :: distance + + if(data%problems%RotaryProblems%MotorFail%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%RotaryProblems%MotorFail, ChangeMotorFail, distance) + if(data%problems%RotaryProblems%OverideTorqueLimit%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%RotaryProblems%OverideTorqueLimit, ChangeOverideTorqueLimit, distance) + + end subroutine + + + + + + + + subroutine ChangeMotorFail(status) + use SimulationVariables !@ + implicit none + integer, intent (in) :: status +!if(associated(MotorFailPtr)) call MotorFailPtr(status) + if(status == Clear_StatusType) data%State%RTable%MotorFaileMalf=0 + if(status == Executed_StatusType) data%State%RTable%MotorFaileMalf=1 + endsubroutine + + subroutine ChangeOverideTorqueLimit(status) + use SimulationVariables !@ + implicit none + integer, intent (in) :: status +!if(associated(OverideTorqueLimitPtr)) call OverideTorqueLimitPtr(status) + if(status == Clear_StatusType) data%State%RTable%OverideTorqueLimitMalf=0 + if(status == Executed_StatusType) data%State%RTable%OverideTorqueLimitMalf=1 + endsubroutine + +end module CRotaryProblems diff --git a/Common/json-fortran/json_module.i90 b/Common/json-fortran/json_module.i90 new file mode 100644 index 0000000..c45fdda --- /dev/null +++ b/Common/json-fortran/json_module.i90 @@ -0,0 +1,96 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_module.F90" +!***************************************************************************************** +!> author: Jacob Williams +! license: BSD +! +! A Modern Fortran JSON (JavaScript Object Notation) API. +! +! This module provides access to [[json_value_module]] and +! [[json_file_module]]. For normal JSON-Fortran use, using this module +! is all that is necessary. +! +! Note that this module renames the kind definition variables from [[json_kinds]] +! from [`RK`, `IK`, `LK`, `CK`, and `CDK`] to [`json_RK`, `json_IK`, `json_LK`, +! `json_CK`, and `json_CDK`] so as to avoid namespace pollution with short +! variable names. +! +# 23 + +! +!### License +! * JSON-Fortran is released under a BSD-style license. +! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE) +! file for details. +! +!### History +! * Joseph A. Levin : March 2012 : Original [FSON](https://github.com/josephalevin/fson) +! code [retrieved on 12/2/2013]. +! * Jacob Williams : 2/8/2014 : Extensive modifications to the original FSON code. +! The original F95 code was split into four files: +! fson_path_m.f95, fson_string_m.f95, fson_value_m.f95, and fson.f95. +! The new code has been extensively updated, refactored and combined into this +! one module (json_module.f90). +! Various Fortran 2003/2008 features are now used +! (e.g., allocatable strings, newunit, generic, class, and abstract interface). +! * Development continues at: [Github](https://github.com/jacobwilliams/json-fortran) +! +!### See also +! * [json-fortran development site](https://github.com/jacobwilliams/json-fortran) +! * [json-fortran online documentation](https://jacobwilliams.github.io/json-fortran) +! * [JSON website](http://www.json.org/) +! * [JSON validator](http://jsonlint.com/) +! +!@note Originally JSON-Fortran was entirely contained within this module. + + module json_module + + use json_kinds, only: json_RK => RK, & + json_IK => IK, & + json_LK => LK, & + json_CK => CK, & + json_CDK => CDK +# 61 + + use json_parameters, only: json_unknown,& + json_null, & + json_object, & + json_array, & + json_logical,& + json_integer,& + json_real, & + json_double, & + json_string + use json_value_module + use json_file_module + + implicit none + + character(kind=json_CK,len=*),parameter,private :: version = '8.3.0' +!! JSON-Fortran version. +!! +!!@note This string should match the one in the `.VERSION` file (which is used +!! for the documentation generation.) + + public + + contains +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns the JSON-Fortran version string. + + function json_fortran_version() result(ver) + + implicit none + + character(len=:),allocatable :: ver !! JSON-Fortran version string + + ver = version + + end function json_fortran_version +!***************************************************************************************** + +!***************************************************************************************** + end module json_module +!***************************************************************************************** diff --git a/Common/json-fortran/json_value_module.i90 b/Common/json-fortran/json_value_module.i90 new file mode 100644 index 0000000..d471808 --- /dev/null +++ b/Common/json-fortran/json_value_module.i90 @@ -0,0 +1,11719 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" +!***************************************************************************************** +!> author: Jacob Williams +! license: BSD +! +! This module provides a low-level interface for manipulation of JSON data. +! The two public entities are [[json_value]], and [[json_core(type)]]. +! The [[json_file_module]] provides a higher-level interface to some +! of these routines. +! +!### License +! * JSON-Fortran is released under a BSD-style license. +! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE) +! file for details. + + module json_value_module + + use,intrinsic :: iso_fortran_env, only: iostat_end,error_unit,output_unit + use,intrinsic :: ieee_arithmetic + use json_kinds + use json_parameters + use json_string_utilities + + implicit none + + private + +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_macros.inc" 1 +! JSON-Fortran preprocessor macros. +! +! License +! JSON-Fortran is released under a BSD-style license. +! See the [LICENSE](https://github.com/jacobwilliams/json-fortran/blob/master/LICENSE) +! file for details. + +!********************************************************* +! File encoding preprocessor macro. +! +# 15 + +! don't ask for utf-8 file encoding unless using UCS4 +! this may let us use unformatted stream io to read in files more quickly +! even with unicode support turned on `inquire( ... encoding=FL_ENCODING)` +! may be able to detect json files in which each character is exactly one +! byte + + +!********************************************************* + +!********************************************************* +! This C preprocessor macro will take a procedure name as an +! input, and output either that same procedure name if the +! code is compiled without USE_UCS4 being defined or it will +! expand the procedure name to the original procedure name, +! followed by a comma and then the original procedure name +! with 'wrap_' prepended to it. This is suitable for creating +! overloaded interfaces that will accept UCS4 character actual +! arguments as well as DEFAULT/ASCII character arguments, +! based on whether or not ISO 10646 is supported and requested. +! +# 55 + + + +!********************************************************* +# 28 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + +!********************************************************* +!> +! If Unicode is not enabled, then +! JSON files are opened using access='STREAM' and +! form='UNFORMATTED'. This allows the file to +! be read faster. +! +# 38 + + logical,parameter :: use_unformatted_stream = .true. + +!********************************************************* + +!********************************************************* +!> +! If Unicode is not enabled, then +! JSON files are opened using access='STREAM' and +! form='UNFORMATTED'. This allows the file to +! be read faster. +! +# 52 + + character(kind=CDK,len=*),parameter :: access_spec = 'STREAM' + +!********************************************************* + +!********************************************************* +!> +! If Unicode is not enabled, then +! JSON files are opened using access='STREAM' and +! form='UNFORMATTED'. This allows the file to +! be read faster. +! +# 66 + + character(kind=CDK,len=*),parameter :: form_spec = 'UNFORMATTED' + +!********************************************************* + +!********************************************************* +!> +! Type used to construct the linked-list JSON structure. +! Normally, this should always be a pointer variable. +! This type should only be used by an instance of [[json_core(type)]]. +! +!### Example +! +! The following test program: +! +!````fortran +! program test +! use json_module +! implicit none +! type(json_core) :: json +! type(json_value),pointer :: p +! call json%create_object(p,'') !create the root +! call json%add(p,'year',1805) !add some data +! call json%add(p,'value',1.0_RK) !add some data +! call json%print(p,'test.json') !write it to a file +! call json%destroy(p) !cleanup +! end program test +!```` +! +! Produces the JSON file **test.json**: +! +!````json +! { +! "year": 1805, +! "value": 0.1E+1 +! } +!```` +! +!@warning Pointers of this type should only be allocated +! using the methods from [[json_core(type)]]. + + type,public :: json_value + +!force the constituents to be stored contiguously +![note: on Intel, the order of the variables below +! is significant to avoid the misaligned field warnings] + sequence + + private + +!for the linked list: + type(json_value),pointer :: previous => null() !! previous item in the list + type(json_value),pointer :: next => null() !! next item in the list + type(json_value),pointer :: parent => null() !! parent item of this + type(json_value),pointer :: children => null() !! first child item of this + type(json_value),pointer :: tail => null() !! last child item of this + + character(kind=CK,len=:),allocatable :: name !! variable name (unescaped) + + real(RK),allocatable :: dbl_value !! real data for this variable + logical(LK),allocatable :: log_value !! logical data for this variable + character(kind=CK,len=:),allocatable :: str_value !! string data for this variable +!! (unescaped) + integer(IK),allocatable :: int_value !! integer data for this variable + + integer(IK) :: var_type = json_unknown !! variable type + + integer(IK),private :: n_children = 0 !! number of children + + end type json_value +!********************************************************* + +!********************************************************* +!> +! To access the core routines for manipulation +! of [[json_value]] pointer variables. This class allows +! for thread safe use of the module. +! +!### Usage +!````fortran +! program test +! use json_module, wp=>json_RK +! implicit none +! type(json_core) :: json !<--have to declare this +! type(json_value),pointer :: p +! call json%create_object(p,'') !create the root +! call json%add(p,'year',1805) !add some data +! call json%add(p,'value',1.0_wp) !add some data +! call json%print(p,'test.json') !write it to a file +! call json%destroy(p) !cleanup +! end program test +!```` + type,public :: json_core + + private + + integer(IK) :: spaces_per_tab = 2 !! number of spaces for indenting + + logical(LK) :: compact_real = .true. !! to use the "compact" form of real +!! numbers for output + character(kind=CDK,len=:),allocatable :: real_fmt !! the format string to use +!! for converting real numbers to strings. +!! It can be set in [[json_initialize]], +!! and used in [[json_value_print]] +!! If not set, then `default_real_fmt` +!! is used instead. + + logical(LK) :: is_verbose = .false. !! if true, all exceptions are +!! immediately printed to console. + + logical(LK) :: stop_on_error = .false. !! if true, then the program is +!! stopped immediately when an +!! exception is raised. + + logical(LK) :: exception_thrown = .false. !! The error flag. Will be set to true +!! when an error is thrown in the class. +!! Many of the methods will check this +!! and return immediately if it is true. + character(kind=CK,len=:),allocatable :: err_message +!! the error message. +!! if `exception_thrown=False` then +!! this variable is not allocated. + + integer(IK) :: char_count = 0 !! character position in the current line + integer(IK) :: line_count = 1 !! lines read counter + integer(IK) :: pushed_index = 0 !! used when parsing lines in file + character(kind=CK,len=pushed_char_size) :: pushed_char = CK_'' !! used when parsing +!! lines in file + + integer(IK) :: ipos = 1 !! for allocatable strings: next character to read + + logical(LK) :: strict_type_checking = .false. !! if true, then no type conversions are done +!! in the `get` routines if the actual variable +!! type is different from the return type (for +!! example, integer to real). + + logical(LK) :: trailing_spaces_significant = .false. !! for name and path comparisons, if trailing +!! space is to be considered significant. + + logical(LK) :: case_sensitive_keys = .true. !! if name and path comparisons +!! are case sensitive. + + logical(LK) :: no_whitespace = .false. !! when printing a JSON string, don't include +!! non-significant spaces or line breaks. +!! If true, the entire structure will be +!! printed on one line. + + logical(LK) :: unescaped_strings = .true. !! If false, then the escaped +!! string is returned from [[json_get_string]] +!! and similar routines. If true [default], +!! then the string is returned unescaped. + + logical(LK) :: allow_comments = .true. !! if true, any comments will be ignored when +!! parsing a file. The comment tokens are defined +!! by the `comment_char` character variable. + character(kind=CK,len=:),allocatable :: comment_char !! comment tokens when +!! `allow_comments` is true. +!! Examples: '`!`' or '`#`'. +!! Default is `CK_'/!#'`. + + integer(IK) :: path_mode = 1_IK !! How the path strings are interpreted in the +!! `get_by_path` routines: +!! +!! * 1 -- Default mode (see [[json_get_by_path_default]]) +!! * 2 -- as RFC 6901 "JSON Pointer" paths +!! (see [[json_get_by_path_rfc6901]]) +!! * 3 -- JSONPath "bracket-notation" +!! see [[json_get_by_path_jsonpath_bracket]]) + + character(kind=CK,len=1) :: path_separator = dot !! The `path` separator to use +!! in the "default" mode for +!! the paths in the various +!! `get_by_path` routines. +!! Note: if `path_mode/=1` +!! then this is ignored. + + logical(LK) :: compress_vectors = .false. !! If true, then arrays of integers, +!! nulls, reals, & logicals are +!! printed all on one line. +!! [Note: `no_whitespace` will +!! override this option if necessary] + + logical(LK) :: allow_duplicate_keys = .true. !! If False, then after parsing, if any +!! duplicate keys are found, an error is +!! thrown. A call to [[json_value_validate]] +!! will also check for duplicates. If True +!! [default] then no special checks are done + + logical(LK) :: escape_solidus = .false. !! If True then the solidus "`/`" is always escaped +!! ("`\/`") when serializing JSON. +!! If False [default], then it is not escaped. +!! Note that this option does not affect parsing +!! (both escaped and unescaped versions are still +!! valid in all cases). + + integer(IK) :: null_to_real_mode = 2_IK !! if `strict_type_checking=false`: +!! +!! * 1 : an exception will be raised if +!! try to retrieve a `null` as a real. +!! * 2 : a `null` retrieved as a real +!! will return NaN. [default] +!! * 3 : a `null` retrieved as a real +!! will return 0.0. + + logical(LK) :: non_normals_to_null = .false. !! How to serialize NaN, Infinity, +!! and -Infinity real values: +!! +!! * If true : as JSON `null` values +!! * If false : as strings (e.g., "NaN", +!! "Infinity", "-Infinity") [default] + + logical(LK) :: use_quiet_nan = .true. !! if true [default], `null_to_real_mode=2` +!! and [[string_to_real]] will use +!! `ieee_quiet_nan` for NaN values. If false, +!! `ieee_signaling_nan` will be used. + + logical(LK) :: strict_integer_type_checking = .true. +!! * If false, when parsing JSON, if an integer numeric value +!! cannot be converted to an integer (`integer(IK)`), +!! then an attempt is then make to convert it +!! to a real (`real(RK)`). +!! * If true [default], an exception will be raised if an integer +!! value cannot be read when parsing JSON. + + integer :: ichunk = 0 !! index in `chunk` for [[pop_char]] +!! when `use_unformatted_stream=True` + integer :: filesize = 0 !! the file size when when `use_unformatted_stream=True` + character(kind=CK,len=:),allocatable :: chunk !! a chunk read from a stream file +!! when `use_unformatted_stream=True` + + contains + + private + +!> +! Return a child of a [[json_value]] structure. + generic,public :: get_child => json_value_get_child_by_index, & + json_value_get_child,& + json_value_get_child_by_name + procedure,private :: json_value_get_child_by_index + procedure,private :: json_value_get_child_by_name + procedure,private :: json_value_get_child + +!> +! Add objects to a linked list of [[json_value]]s. +! +!@note It might make more sense to call this `add_child`. + generic,public :: add => json_value_add_member, & + json_value_add_null, & + json_value_add_integer, & + json_value_add_integer_vec, & + + json_value_add_real32, & + json_value_add_real32_vec, & + + json_value_add_real, & + json_value_add_real_vec, & +# 326 + + json_value_add_logical, & + json_value_add_logical_vec, & + json_value_add_string, & + json_value_add_string_vec +# 336 + + + procedure,private :: json_value_add_member + procedure,private :: json_value_add_integer + procedure,private :: json_value_add_null + procedure,private :: json_value_add_integer_vec + + procedure,private :: json_value_add_real32 + procedure,private :: json_value_add_real32_vec + + procedure,private :: json_value_add_real + procedure,private :: json_value_add_real_vec +# 351 + + procedure,private :: json_value_add_logical + procedure,private :: json_value_add_logical_vec + procedure,private :: json_value_add_string + procedure,private :: json_value_add_string_vec +# 361 + + +!> +! These are like the `add` methods, except if a variable with the +! same path is already present, then its value is simply updated. +! Note that currently, these only work for scalar variables. +! These routines can also change the variable's type (but an error will be +! thrown if the existing variable is not a scalar). +! +!### See also +! * [[json_core(type):add_by_path]] - this one can be used to change +! arrays and objects to scalars if so desired. +! +!@note Unlike some routines, the `found` output is not optional, +! so it doesn't present exceptions from being thrown. +! +!@note These have been mostly supplanted by the [[json_core(type):add_by_path]] +! methods, which do a similar thing (and can be used for +! scalars and vectors, etc.) + generic,public :: update => json_update_logical,& + + json_update_real32,& + + json_update_real,& +# 387 + + + json_update_integer,& + json_update_string +# 394 + + procedure,private :: json_update_logical + + procedure,private :: json_update_real32 + + procedure,private :: json_update_real +# 402 + + procedure,private :: json_update_integer + procedure,private :: json_update_string +# 408 + + +!> +! Add variables to a [[json_value]] linked list +! by specifying their paths. +! +!### Example +! +!````fortran +! use, intrinsic :: iso_fortran_env, only: output_unit +! use json_module, wp=>json_RK +! type(json_core) :: json +! type(json_value) :: p +! call json%create_object(p,'root') ! create the root +! ! now add some variables using the paths: +! call json%add_by_path(p,'inputs.t', 0.0_wp ) +! call json%add_by_path(p,'inputs.x(1)', 100.0_wp) +! call json%add_by_path(p,'inputs.x(2)', 200.0_wp) +! call json%print(p) ! now print to console +!```` +! +!### Notes +! * This uses [[json_create_by_path]] +! +!### See also +! * The `json_core%update` methods. +! * [[json_create_by_path]] + + generic,public :: add_by_path => json_add_member_by_path,& + json_add_integer_by_path,& + + json_add_real32_by_path,& + + json_add_real_by_path,& +# 444 + + json_add_logical_by_path,& + json_add_string_by_path,& + json_add_integer_vec_by_path,& + + json_add_real32_vec_by_path,& + + json_add_real_vec_by_path,& +# 454 + + json_add_logical_vec_by_path,& + json_add_string_vec_by_path +# 462 + + procedure :: json_add_member_by_path + procedure :: json_add_integer_by_path + + procedure :: json_add_real32_by_path + + procedure :: json_add_real_by_path +# 471 + + procedure :: json_add_logical_by_path + procedure :: json_add_string_by_path + procedure :: json_add_integer_vec_by_path + + procedure :: json_add_real32_vec_by_path + + procedure :: json_add_real_vec_by_path +# 481 + + procedure :: json_add_logical_vec_by_path + procedure :: json_add_string_vec_by_path +# 489 + + +!> +! Create a [[json_value]] linked list using the +! path to the variables. Optionally return a +! pointer to the variable. +! +! (This will create a `null` variable) +! +!### See also +! * [[json_core(type):add_by_path]] + + generic,public :: create => json_create_by_path + procedure :: json_create_by_path + +!> +! Get data from a [[json_value]] linked list. +! +!@note There are two versions (e.g. [[json_get_integer]] and [[json_get_integer_by_path]]). +! The first one gets the value from the [[json_value]] passed into the routine, +! while the second one gets the value from the [[json_value]] found by parsing the +! path. The path version is split up into unicode and non-unicode versions. + + generic,public :: get => & + json_get_by_path, & + json_get_integer, json_get_integer_by_path, & + json_get_integer_vec, json_get_integer_vec_by_path, & + + json_get_real32, json_get_real32_by_path, & + json_get_real32_vec, json_get_real32_vec_by_path, & + + json_get_real, json_get_real_by_path, & + json_get_real_vec, json_get_real_vec_by_path, & +# 525 + + json_get_logical, json_get_logical_by_path, & + json_get_logical_vec, json_get_logical_vec_by_path, & + json_get_string, json_get_string_by_path, & + json_get_string_vec, json_get_string_vec_by_path, & + json_get_alloc_string_vec, json_get_alloc_string_vec_by_path,& + json_get_array, json_get_array_by_path + + procedure,private :: json_get_integer + procedure,private :: json_get_integer_vec + + procedure,private :: json_get_real32 + procedure,private :: json_get_real32_vec + + procedure,private :: json_get_real + procedure,private :: json_get_real_vec +# 544 + + procedure,private :: json_get_logical + procedure,private :: json_get_logical_vec + procedure,private :: json_get_string + procedure,private :: json_get_string_vec + procedure,private :: json_get_alloc_string_vec + procedure,private :: json_get_array + procedure,private :: json_get_by_path + procedure,private :: json_get_integer_by_path + procedure,private :: json_get_integer_vec_by_path + + procedure,private :: json_get_real32_by_path + procedure,private :: json_get_real32_vec_by_path + + procedure,private :: json_get_real_by_path + procedure,private :: json_get_real_vec_by_path +# 563 + + procedure,private :: json_get_logical_by_path + procedure,private :: json_get_logical_vec_by_path + procedure,private :: json_get_string_by_path + procedure,private :: json_get_string_vec_by_path + procedure,private :: json_get_array_by_path + procedure,private :: json_get_alloc_string_vec_by_path + procedure,private :: json_get_by_path_default + procedure,private :: json_get_by_path_rfc6901 + procedure,private :: json_get_by_path_jsonpath_bracket + +!> +! Print the [[json_value]] to an output unit or file. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value) :: p +! !... +! call json%print(p,'test.json') !this is [[json_print_to_filename]] +!```` + generic,public :: print => json_print_to_console,& + json_print_to_unit,& + json_print_to_filename + procedure :: json_print_to_console + procedure :: json_print_to_unit + procedure :: json_print_to_filename + +!> +! Destructor routine for a [[json_value]] pointer. +! This must be called explicitly if it is no longer needed, +! before it goes out of scope. Otherwise, a memory leak will result. +! +!### Example +! +! Destroy the [[json_value]] pointer before the variable goes out of scope: +!````fortran +! subroutine example1() +! type(json_core) :: json +! type(json_value),pointer :: p +! call json%create_object(p,'') +! call json%add(p,'year',2015) +! call json%print(p) +! call json%destroy(p) +! end subroutine example1 +!```` +! +! Note: it should NOT be called for a [[json_value]] pointer than has already been +! added to another [[json_value]] structure, since doing so may render the +! other structure invalid. Consider the following example: +!````fortran +! subroutine example2(p) +! type(json_core) :: json +! type(json_value),pointer,intent(out) :: p +! type(json_value),pointer :: q +! call json%create_object(p,'') +! call json%add(p,'year',2015) +! call json%create_object(q,'q') +! call json%add(q,'val',1) +! call json%add(p, q) !add q to p structure +! ! do NOT call json%destroy(q) here, because q is +! ! now part of the output structure p. p should be destroyed +! ! somewhere upstream by the caller of this routine. +! nullify(q) !OK, but not strictly necessary +! end subroutine example2 +!```` + generic,public :: destroy => json_value_destroy,destroy_json_core + procedure :: json_value_destroy + procedure :: destroy_json_core + +!> +! If the child variable is present, then remove it. + generic,public :: remove_if_present => json_value_remove_if_present + procedure :: json_value_remove_if_present + +!> +! Allocate a [[json_value]] pointer and make it a real variable. +! The pointer should not already be allocated. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: p +! call json%create_real(p,'value',1.0_RK) +!```` +! +!### Note +! * [[json_core(type):create_real]] is just an alias +! to this one for backward compatibility. + generic,public :: create_real => json_value_create_real + procedure :: json_value_create_real + + generic,public :: create_real => json_value_create_real32 + procedure :: json_value_create_real32 + +# 663 + + +!> +! This is equivalent to [[json_core(type):create_real]], +! and is here only for backward compatibility. + generic,public :: create_double => json_value_create_real + + generic,public :: create_double => json_value_create_real32 + +# 674 + + +!> +! Allocate a [[json_value]] pointer and make it an array variable. +! The pointer should not already be allocated. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: p +! call json%create_array(p,'arrayname') +!```` + generic,public :: create_array => json_value_create_array + procedure :: json_value_create_array + +!> +! Allocate a [[json_value]] pointer and make it an object variable. +! The pointer should not already be allocated. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: p +! call json%create_object(p,'objectname') +!```` +! +!@note The name is not significant for the root structure or an array element. +! In those cases, an empty string can be used. + generic,public :: create_object => json_value_create_object + procedure :: json_value_create_object + +!> +! Allocate a json_value pointer and make it a null variable. +! The pointer should not already be allocated. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: p +! call json%create_null(p,'value') +!```` + generic,public :: create_null => json_value_create_null + procedure :: json_value_create_null + +!> +! Allocate a json_value pointer and make it a string variable. +! The pointer should not already be allocated. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: p +! call json%create_string(p,'value','foobar') +!```` + generic,public :: create_string => json_value_create_string + procedure :: json_value_create_string + +!> +! Allocate a json_value pointer and make it an integer variable. +! The pointer should not already be allocated. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: p +! call json%create_integer(p,42,'value') +!```` + generic,public :: create_integer => json_value_create_integer + procedure :: json_value_create_integer + +!> +! Allocate a json_value pointer and make it a logical variable. +! The pointer should not already be allocated. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: p +! call json%create_logical(p,'value',.true.) +!```` + generic,public :: create_logical => json_value_create_logical + procedure :: json_value_create_logical + +!> +! Parse the JSON file and populate the [[json_value]] tree. + generic,public :: load => json_parse_file + procedure :: json_parse_file + +!> +! Print the [[json_value]] structure to an allocatable string + procedure,public :: serialize => json_value_to_string + +!> +! The same as `serialize`, but only here for backward compatibility + procedure,public :: print_to_string => json_value_to_string + +!> +! Parse the JSON string and populate the [[json_value]] tree. + generic,public :: deserialize => json_parse_string + procedure :: json_parse_string + +!> +! Same as `load` and `deserialize` but only here for backward compatibility. + generic,public :: parse => json_parse_file, & + json_parse_string + +!> +! Throw an exception. + generic,public :: throw_exception => json_throw_exception + procedure :: json_throw_exception + +!> +! Rename a [[json_value]] variable. + generic,public :: rename => json_value_rename,& + json_rename_by_path + procedure :: json_value_rename + procedure :: json_rename_by_path +# 802 + + +!> +! get info about a [[json_value]] + generic,public :: info => json_info, json_info_by_path + procedure :: json_info + procedure :: json_info_by_path + +!> +! get string info about a [[json_value]] + generic,public :: string_info => json_string_info + procedure :: json_string_info + +!> +! get matrix info about a [[json_value]] + generic,public :: matrix_info => json_matrix_info, json_matrix_info_by_path + procedure :: json_matrix_info + procedure :: json_matrix_info_by_path + +!> +! insert a new element after an existing one, +! updating the JSON structure accordingly + generic,public :: insert_after => json_value_insert_after, & + json_value_insert_after_child_by_index + procedure :: json_value_insert_after + procedure :: json_value_insert_after_child_by_index + +!> +! get the path to a JSON variable in a structure: + generic,public :: get_path => json_get_path + procedure :: json_get_path + +!> +! verify if a path is valid +! (i.e., a variable with this path exists in the file). + generic,public :: valid_path => json_valid_path + procedure :: json_valid_path + + procedure,public :: remove => json_value_remove !! Remove a [[json_value]] from a +!! linked-list structure. + procedure,public :: replace => json_value_replace !! Replace a [[json_value]] in a +!! linked-list structure. + procedure,public :: reverse => json_value_reverse !! Reverse the order of the children +!! of an array of object. + procedure,public :: check_for_errors => json_check_for_errors !! check for error and get error message + procedure,public :: clear_exceptions => json_clear_exceptions !! clear exceptions + procedure,public :: count => json_count !! count the number of children + procedure,public :: clone => json_clone !! clone a JSON structure (deep copy) + procedure,public :: failed => json_failed !! check for error + procedure,public :: get_parent => json_get_parent !! get pointer to json_value parent + procedure,public :: get_next => json_get_next !! get pointer to json_value next + procedure,public :: get_previous => json_get_previous !! get pointer to json_value previous + procedure,public :: get_tail => json_get_tail !! get pointer to json_value tail + procedure,public :: initialize => json_initialize !! to initialize some parsing parameters + procedure,public :: traverse => json_traverse !! to traverse all elements of a JSON +!! structure + procedure,public :: print_error_message => json_print_error_message !! simply routine to print error +!! messages + procedure,public :: swap => json_value_swap !! Swap two [[json_value]] pointers +!! in a structure (or two different +!! structures). + procedure,public :: is_child_of => json_value_is_child_of !! Check if a [[json_value]] is a +!! descendant of another. + procedure,public :: validate => json_value_validate !! Check that a [[json_value]] linked +!! list is valid (i.e., is properly +!! constructed). This may be useful +!! if it has been constructed externally. + procedure,public :: check_for_duplicate_keys & + => json_check_all_for_duplicate_keys !! Check entire JSON structure +!! for duplicate keys (recursively) + procedure,public :: check_children_for_duplicate_keys & + => json_check_children_for_duplicate_keys !! Check a `json_value` object's +!! children for duplicate keys + +!other private routines: + procedure :: name_equal + procedure :: name_strings_equal + procedure :: json_value_print + procedure :: string_to_int + procedure :: string_to_dble + procedure :: prepare_parser => json_prepare_parser + procedure :: parse_end => json_parse_end + procedure :: parse_value + procedure :: parse_number + procedure :: parse_string + procedure :: parse_for_chars + procedure :: parse_object + procedure :: parse_array + procedure :: annotate_invalid_json + procedure :: pop_char + procedure :: push_char + procedure :: get_current_line_from_file_stream + procedure,nopass :: get_current_line_from_file_sequential + procedure :: convert + procedure :: to_string + procedure :: to_logical + procedure :: to_integer + procedure :: to_real + procedure :: to_null + procedure :: to_object + procedure :: to_array + procedure,nopass :: json_value_clone_func + procedure :: is_vector => json_is_vector + + end type json_core +!********************************************************* + +!********************************************************* +!> +! Structure constructor to initialize a +! [[json_core(type)]] object +! +!### Example +! +!```fortran +! type(json_file) :: json_core +! json_core = json_core() +!``` + interface json_core + module procedure initialize_json_core + end interface +!********************************************************* + +!************************************************************************************* + abstract interface + + subroutine json_array_callback_func(json, element, i, count) +!! Array element callback function. Used by [[json_get_array]] + import :: json_value,json_core,IK + implicit none + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: element + integer(IK),intent(in) :: i !! index + integer(IK),intent(in) :: count !! size of array + end subroutine json_array_callback_func + + subroutine json_traverse_callback_func(json,p,finished) +!! Callback function used by [[json_traverse]] + import :: json_value,json_core,LK + implicit none + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + logical(LK),intent(out) :: finished !! set true to stop traversing + end subroutine json_traverse_callback_func + + end interface + public :: json_array_callback_func + public :: json_traverse_callback_func +!************************************************************************************* + + contains +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 4/17/2016 +! +! Destructor for the [[json_core(type)]] type. + + subroutine destroy_json_core(me) + + implicit none + + class(json_core),intent(out) :: me + + end subroutine destroy_json_core +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 4/26/2016 +! +! Function constructor for a [[json_core(type)]]. +! This is just a wrapper for [[json_initialize]]. +! +!@note [[initialize_json_core]], [[json_initialize]], +! [[initialize_json_core_in_file]], and [[initialize_json_file]] +! all have a similar interface. + + function initialize_json_core(& +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1 +! The dummy argument list for the various `initialize` subroutines. +! +! See also: json_initialize_argument.inc + +verbose,& +compact_reals,& +print_signs,& +real_format,& +spaces_per_tab,& +strict_type_checking,& +trailing_spaces_significant,& +case_sensitive_keys,& +no_whitespace,& +unescape_strings,& +comment_char,& +path_mode,& +path_separator,& +compress_vectors,& +allow_duplicate_keys,& +escape_solidus,& +stop_on_error,& +null_to_real_mode,& +non_normal_mode,& +use_quiet_nan, & +strict_integer_type_checking & +# 983 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + ) result(json_core_object) + + implicit none + + type(json_core) :: json_core_object +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_arguments.inc" 1 +! The argument list for the various `initialize` subroutines. +! +! See also: json_initialize_dummy_arguments.inc + +logical(LK),intent(in),optional :: verbose +!! mainly useful for debugging (default is false) +logical(LK),intent(in),optional :: compact_reals +!! to compact the real number strings for output (default is true) +logical(LK),intent(in),optional :: print_signs +!! always print numeric sign (default is false) +character(kind=CDK,len=*),intent(in),optional :: real_format +!! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES' +integer(IK),intent(in),optional :: spaces_per_tab +!! number of spaces per tab for indenting (default is 2) +logical(LK),intent(in),optional :: strict_type_checking +!! if true, no integer, double, or logical type +!! conversions are done for the `get` routines +!! (default is false). +logical(LK),intent(in),optional :: trailing_spaces_significant +!! for name and path comparisons, is trailing +!! space to be considered significant. +!! (default is false) +logical(LK),intent(in),optional :: case_sensitive_keys +!! for name and path comparisons, are they +!! case sensitive. (default is true) +logical(LK),intent(in),optional :: no_whitespace +!! if true, printing the JSON structure is +!! done without adding any non-significant +!! spaces or linebreaks (default is false) +logical(LK),intent(in),optional :: unescape_strings +!! If false, then the raw escaped +!! string is returned from [[json_get_string]] +!! and similar routines. If true [default], +!! then the string is returned unescaped. +character(kind=CK,len=*),intent(in),optional :: comment_char +!! If present, these characters are used +!! to denote comments in the JSON file, +!! which will be ignored if present. +!! Example: `!`, `#`, or `/!#`. Setting this +!! to a blank string disables the +!! ignoring of comments. (Default is `/!#`). +integer(IK),intent(in),optional :: path_mode +!! How the path strings are interpreted in the +!! `get_by_path` routines: +!! +!! * 1 : Default mode (see [[json_get_by_path_default]]) +!! * 2 : as RFC 6901 "JSON Pointer" paths +!! (see [[json_get_by_path_rfc6901]]) +!! * 3 : JSONPath "bracket-notation" +!! see [[json_get_by_path_jsonpath_bracket]]) +character(kind=CK,len=1),intent(in),optional :: path_separator +!! The `path` separator to use +!! in the "default" mode for +!! the paths in the various +!! `get_by_path` routines. +!! Example: `.` [default] or `%`. +!! Note: if `path_mode/=1` +!! then this is ignored. +logical(LK),intent(in),optional :: compress_vectors +!! If true, then arrays of integers, +!! nulls, doubles, and logicals are +!! printed all on one line. +!! [Note: `no_whitespace` will +!! override this option if necessary]. +!! (Default is False). +logical(LK),intent(in),optional :: allow_duplicate_keys +!! * If True [default] then no special checks +!! are done to check for duplicate keys. +!! * If False, then after parsing, if any duplicate +!! keys are found, an error is thrown. A call to +!! [[json_value_validate]] will also check for +!! duplicates. +logical(LK),intent(in),optional :: escape_solidus +!! * If True then the solidus "`/`" is always escaped +!! "`\/`" when serializing JSON +!! * If False [default], then it is not escaped. +!! +!! Note that this option does not affect parsing +!! (both escaped and unescaped are still valid in +!! all cases). +logical(LK),intent(in),optional :: stop_on_error +!! If an exception is raised, then immediately quit. +!! (Default is False). +integer(IK),intent(in),optional :: null_to_real_mode +!! if `strict_type_checking=false`: +!! +!! * 1 : an exception will be raised if +!! try to retrieve a `null` as a real. +!! * 2 : a `null` retrieved as a real +!! will return a NaN. [default] +!! * 3 : a `null` retrieved as a real +!! will return 0.0. +integer(IK),intent(in),optional :: non_normal_mode +!! How to serialize NaN, Infinity, and +!! -Infinity real values: +!! +!! * 1 : as strings (e.g., "NaN", +!! "Infinity", "-Infinity") [default] +!! * 2 : as JSON `null` values +logical(LK),intent(in),optional :: use_quiet_nan +!! * If true [default], `null_to_real_mode=2` +!! and [[string_to_real]] will use +!! `ieee_quiet_nan` for NaN values. +!! * If false, +!! `ieee_signaling_nan` will be used. +logical(LK),intent(in),optional :: strict_integer_type_checking +!! * If false, when parsing JSON, if an integer numeric value +!! cannot be converted to an integer (`integer(IK)`), +!! then an attempt is then make to convert it +!! to a real (`real(RK)`). +!! * If true, an exception will be raised if the integer +!! value cannot be read. +!! +!! (default is true) +# 989 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + call json_core_object%initialize(& +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1 +! The dummy argument list for the various `initialize` subroutines. +! +! See also: json_initialize_argument.inc + +verbose,& +compact_reals,& +print_signs,& +real_format,& +spaces_per_tab,& +strict_type_checking,& +trailing_spaces_significant,& +case_sensitive_keys,& +no_whitespace,& +unescape_strings,& +comment_char,& +path_mode,& +path_separator,& +compress_vectors,& +allow_duplicate_keys,& +escape_solidus,& +stop_on_error,& +null_to_real_mode,& +non_normal_mode,& +use_quiet_nan, & +strict_integer_type_checking & +# 992 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + ) + + end function initialize_json_core +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/4/2013 +! +! Initialize the [[json_core(type)]] instance. +! +! The routine may be called before any of the [[json_core(type)]] methods are used in +! order to specify certain parameters. If it is not called, then the defaults +! are used. This routine is also called internally by various routines. +! It can also be called to clear exceptions, or to reset some +! of the variables (note that only the arguments present are changed). +! +!### Modified +! * Izaak Beekman : 02/24/2015 +! +!@note [[initialize_json_core]], [[json_initialize]], +! [[initialize_json_core_in_file]], and [[initialize_json_file]] +! all have a similar interface. + + subroutine json_initialize(me,& +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_dummy_arguments.inc" 1 +! The dummy argument list for the various `initialize` subroutines. +! +! See also: json_initialize_argument.inc + +verbose,& +compact_reals,& +print_signs,& +real_format,& +spaces_per_tab,& +strict_type_checking,& +trailing_spaces_significant,& +case_sensitive_keys,& +no_whitespace,& +unescape_strings,& +comment_char,& +path_mode,& +path_separator,& +compress_vectors,& +allow_duplicate_keys,& +escape_solidus,& +stop_on_error,& +null_to_real_mode,& +non_normal_mode,& +use_quiet_nan, & +strict_integer_type_checking & +# 1018 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + ) + + implicit none + + class(json_core),intent(inout) :: me +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_initialize_arguments.inc" 1 +! The argument list for the various `initialize` subroutines. +! +! See also: json_initialize_dummy_arguments.inc + +logical(LK),intent(in),optional :: verbose +!! mainly useful for debugging (default is false) +logical(LK),intent(in),optional :: compact_reals +!! to compact the real number strings for output (default is true) +logical(LK),intent(in),optional :: print_signs +!! always print numeric sign (default is false) +character(kind=CDK,len=*),intent(in),optional :: real_format +!! Real number format: 'E' [default], '*', 'G', 'EN', or 'ES' +integer(IK),intent(in),optional :: spaces_per_tab +!! number of spaces per tab for indenting (default is 2) +logical(LK),intent(in),optional :: strict_type_checking +!! if true, no integer, double, or logical type +!! conversions are done for the `get` routines +!! (default is false). +logical(LK),intent(in),optional :: trailing_spaces_significant +!! for name and path comparisons, is trailing +!! space to be considered significant. +!! (default is false) +logical(LK),intent(in),optional :: case_sensitive_keys +!! for name and path comparisons, are they +!! case sensitive. (default is true) +logical(LK),intent(in),optional :: no_whitespace +!! if true, printing the JSON structure is +!! done without adding any non-significant +!! spaces or linebreaks (default is false) +logical(LK),intent(in),optional :: unescape_strings +!! If false, then the raw escaped +!! string is returned from [[json_get_string]] +!! and similar routines. If true [default], +!! then the string is returned unescaped. +character(kind=CK,len=*),intent(in),optional :: comment_char +!! If present, these characters are used +!! to denote comments in the JSON file, +!! which will be ignored if present. +!! Example: `!`, `#`, or `/!#`. Setting this +!! to a blank string disables the +!! ignoring of comments. (Default is `/!#`). +integer(IK),intent(in),optional :: path_mode +!! How the path strings are interpreted in the +!! `get_by_path` routines: +!! +!! * 1 : Default mode (see [[json_get_by_path_default]]) +!! * 2 : as RFC 6901 "JSON Pointer" paths +!! (see [[json_get_by_path_rfc6901]]) +!! * 3 : JSONPath "bracket-notation" +!! see [[json_get_by_path_jsonpath_bracket]]) +character(kind=CK,len=1),intent(in),optional :: path_separator +!! The `path` separator to use +!! in the "default" mode for +!! the paths in the various +!! `get_by_path` routines. +!! Example: `.` [default] or `%`. +!! Note: if `path_mode/=1` +!! then this is ignored. +logical(LK),intent(in),optional :: compress_vectors +!! If true, then arrays of integers, +!! nulls, doubles, and logicals are +!! printed all on one line. +!! [Note: `no_whitespace` will +!! override this option if necessary]. +!! (Default is False). +logical(LK),intent(in),optional :: allow_duplicate_keys +!! * If True [default] then no special checks +!! are done to check for duplicate keys. +!! * If False, then after parsing, if any duplicate +!! keys are found, an error is thrown. A call to +!! [[json_value_validate]] will also check for +!! duplicates. +logical(LK),intent(in),optional :: escape_solidus +!! * If True then the solidus "`/`" is always escaped +!! "`\/`" when serializing JSON +!! * If False [default], then it is not escaped. +!! +!! Note that this option does not affect parsing +!! (both escaped and unescaped are still valid in +!! all cases). +logical(LK),intent(in),optional :: stop_on_error +!! If an exception is raised, then immediately quit. +!! (Default is False). +integer(IK),intent(in),optional :: null_to_real_mode +!! if `strict_type_checking=false`: +!! +!! * 1 : an exception will be raised if +!! try to retrieve a `null` as a real. +!! * 2 : a `null` retrieved as a real +!! will return a NaN. [default] +!! * 3 : a `null` retrieved as a real +!! will return 0.0. +integer(IK),intent(in),optional :: non_normal_mode +!! How to serialize NaN, Infinity, and +!! -Infinity real values: +!! +!! * 1 : as strings (e.g., "NaN", +!! "Infinity", "-Infinity") [default] +!! * 2 : as JSON `null` values +logical(LK),intent(in),optional :: use_quiet_nan +!! * If true [default], `null_to_real_mode=2` +!! and [[string_to_real]] will use +!! `ieee_quiet_nan` for NaN values. +!! * If false, +!! `ieee_signaling_nan` will be used. +logical(LK),intent(in),optional :: strict_integer_type_checking +!! * If false, when parsing JSON, if an integer numeric value +!! cannot be converted to an integer (`integer(IK)`), +!! then an attempt is then make to convert it +!! to a real (`real(RK)`). +!! * If true, an exception will be raised if the integer +!! value cannot be read. +!! +!! (default is true) +# 1024 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + character(kind=CDK,len=10) :: w !! max string length + character(kind=CDK,len=10) :: d !! real precision digits + character(kind=CDK,len=10) :: e !! real exponent digits + character(kind=CDK,len=2) :: sgn !! sign flag: `ss` or `sp` + character(kind=CDK,len=2) :: rl_edit_desc !! `G`, `E`, `EN`, or `ES` + integer(IK) :: istat !! `iostat` flag for +!! write statements + logical(LK) :: sgn_prnt !! print sign flag + character(kind=CK,len=max_integer_str_len) :: istr !! for integer to +!! string conversion + +!reset exception to false: + call me%clear_exceptions() + +!Just in case, clear these global variables also: + me%pushed_index = 0 + me%pushed_char = CK_'' + me%char_count = 0 + me%line_count = 1 + me%ipos = 1 + if (use_unformatted_stream) then + me%filesize = 0 + me%ichunk = 0 + me%chunk = repeat(space, stream_chunk_size) ! default chunk size + end if + +# 1055 + + +!various optional inputs: + if (present(spaces_per_tab)) & + me%spaces_per_tab = spaces_per_tab + if (present(stop_on_error)) & + me%stop_on_error = stop_on_error + if (present(verbose)) & + me%is_verbose = verbose + if (present(strict_type_checking)) & + me%strict_type_checking = strict_type_checking + if (present(trailing_spaces_significant)) & + me%trailing_spaces_significant = trailing_spaces_significant + if (present(case_sensitive_keys)) & + me%case_sensitive_keys = case_sensitive_keys + if (present(no_whitespace)) & + me%no_whitespace = no_whitespace + if (present(unescape_strings)) & + me%unescaped_strings = unescape_strings + if (present(path_mode)) then + if (path_mode==1_IK .or. path_mode==2_IK .or. path_mode==3_IK) then + me%path_mode = path_mode + else + me%path_mode = 1_IK ! just to have a valid value + call me%throw_exception('Invalid path_mode.') + end if + end if + +! if we are allowing comments in the file: +! [an empty string disables comments] + if (present(comment_char)) then + me%allow_comments = comment_char/=CK_'' + me%comment_char = trim(adjustl(comment_char)) + end if + +! path separator: + if (present(path_separator)) then + me%path_separator = path_separator + end if + +! printing vectors in compressed form: + if (present(compress_vectors)) then + me%compress_vectors = compress_vectors + end if + +! checking for duplicate keys: + if (present(allow_duplicate_keys)) then + me%allow_duplicate_keys = allow_duplicate_keys + end if + +! if escaping the forward slash: + if (present(escape_solidus)) then + me%escape_solidus = escape_solidus + end if + +! how to handle null to read conversions: + if (present(null_to_real_mode)) then + select case (null_to_real_mode) + case(1_IK:3_IK) + me%null_to_real_mode = null_to_real_mode + case default + me%null_to_real_mode = 2_IK ! just to have a valid value + call integer_to_string(null_to_real_mode,int_fmt,istr) + call me%throw_exception('Invalid null_to_real_mode: '//istr) + end select + end if + +! how to handle NaN and Infinities: + if (present(non_normal_mode)) then + select case (non_normal_mode) + case(1_IK) ! use strings + me%non_normals_to_null = .false. + case(2_IK) ! use null + me%non_normals_to_null = .true. + case default + call integer_to_string(non_normal_mode,int_fmt,istr) + call me%throw_exception('Invalid non_normal_mode: '//istr) + end select + end if + + if (present(use_quiet_nan)) then + me%use_quiet_nan = use_quiet_nan + end if + + if (present(strict_integer_type_checking)) then + me%strict_integer_type_checking = strict_integer_type_checking + end if + +!Set the format for real numbers: +! [if not changing it, then it remains the same] + + if ( (.not. allocated(me%real_fmt)) .or. & ! if this hasn't been done yet + present(compact_reals) .or. & + present(print_signs) .or. & + present(real_format) ) then + +!allow the special case where real format is '*': +! [this overrides the other options] + if (present(real_format)) then + if (real_format==star) then + if (present(compact_reals)) then +! we will also allow for compact reals with +! '*' format, if both arguments are present. + me%compact_real = compact_reals + else + me%compact_real = .false. + end if + me%real_fmt = star + return + end if + end if + + if (present(compact_reals)) me%compact_real = compact_reals + +!set defaults + sgn_prnt = .false. + if ( present( print_signs) ) sgn_prnt = print_signs + if ( sgn_prnt ) then + sgn = 'sp' + else + sgn = 'ss' + end if + + rl_edit_desc = 'E' + if ( present( real_format ) ) then + select case ( real_format ) + case ('g','G','e','E','en','EN','es','ES') + rl_edit_desc = real_format + case default + call me%throw_exception('Invalid real format, "' // & + trim(real_format) // '", passed to json_initialize.'// & + new_line('a') // 'Acceptable formats are: "G", "E", "EN", and "ES".' ) + end select + end if + +! set the default output/input format for reals: + write(w,'(ss,I0)',iostat=istat) max_numeric_str_len + if (istat==0) write(d,'(ss,I0)',iostat=istat) real_precision + if (istat==0) write(e,'(ss,I0)',iostat=istat) real_exponent_digits + if (istat==0) then + me%real_fmt = '(' // sgn // ',' // trim(rl_edit_desc) //& + trim(w) // '.' // trim(d) // 'E' // trim(e) // ')' + else + me%real_fmt = '(' // sgn // ',' // trim(rl_edit_desc) // & + '27.17E4)' !just use this one (should never happen) + end if + + end if + + end subroutine json_initialize +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Returns true if `name` is equal to `p%name`, using the specified +! settings for case sensitivity and trailing whitespace. +! +!### History +! * 4/30/2016 : original version +! * 8/25/2017 : now just a wrapper for [[name_strings_equal]] + + function name_equal(json,p,name) result(is_equal) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),intent(in) :: p !! the json object + character(kind=CK,len=*),intent(in) :: name !! the name to check for + logical(LK) :: is_equal !! true if the string are +!! lexically equal + + if (allocated(p%name)) then +! call the low-level routines for the name strings: + is_equal = json%name_strings_equal(p%name,name) + else + is_equal = name == CK_'' ! check a blank name + end if + + end function name_equal +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 8/25/2017 +! +! Returns true if the name strings `name1` is equal to `name2`, using +! the specified settings for case sensitivity and trailing whitespace. + + function name_strings_equal(json,name1,name2) result(is_equal) + + implicit none + + class(json_core),intent(inout) :: json + character(kind=CK,len=*),intent(in) :: name1 !! the name to check + character(kind=CK,len=*),intent(in) :: name2 !! the name to check + logical(LK) :: is_equal !! true if the string are +!! lexically equal + +!must be the same length if we are treating +!trailing spaces as significant, so do a +!quick test of this first: + if (json%trailing_spaces_significant) then + is_equal = len(name1) == len(name2) + if (.not. is_equal) return + end if + + if (json%case_sensitive_keys) then + is_equal = name1 == name2 + else + is_equal = lowercase_string(name1) == lowercase_string(name2) + end if + + end function name_strings_equal +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 10/31/2015 +! +! Create a deep copy of a [[json_value]] linked-list structure. +! +!### Notes +! +! * If `from` has children, then they are also cloned. +! * The parent of `from` is not linked to `to`. +! * If `from` is an element of an array, then the previous and +! next entries are not cloned (only that element and it's children, if any). +! +!### Example +! +!````fortran +! program test +! use json_module +! implicit none +! type(json_core) :: json +! type(json_value),pointer :: j1, j2 +! call json%load('../files/inputs/test1.json',j1) +! call json%clone(j1,j2) !now have two independent copies +! call json%destroy(j1) !destroys j1, but j2 remains +! call json%print(j2,'j2.json') +! call json%destroy(j2) +! end program test +!```` + + subroutine json_clone(json,from,to) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: from !! this is the structure to clone + type(json_value),pointer :: to !! the clone is put here +!! (it must not already be associated) + +!call the main function: + call json%json_value_clone_func(from,to) + + end subroutine json_clone +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 10/31/2015 +! +! Recursive deep copy function called by [[json_clone]]. +! +!@note If new data is added to the [[json_value]] type, +! then this would need to be updated. + + recursive subroutine json_value_clone_func(from,to,parent,previous,tail) + + implicit none + + type(json_value),pointer :: from !! this is the structure to clone + type(json_value),pointer :: to !! the clone is put here (it +!! must not already be associated) + type(json_value),pointer,optional :: parent !! to%parent + type(json_value),pointer,optional :: previous !! to%previous + logical,optional :: tail !! if "to" is the tail of +!! its parent's children + + nullify(to) + + if (associated(from)) then + + allocate(to) + +!copy over the data variables: +! [note: the allocate() statements don't work here for the +! deferred-length characters in gfortran-4.9] + if (allocated(from%name)) to%name = from%name + if (allocated(from%dbl_value)) allocate(to%dbl_value,source=from%dbl_value) + if (allocated(from%log_value)) allocate(to%log_value,source=from%log_value) + if (allocated(from%str_value)) to%str_value = from%str_value + if (allocated(from%int_value)) allocate(to%int_value,source=from%int_value) + to%var_type = from%var_type + to%n_children = from%n_children + +! allocate and associate the pointers as necessary: + if (present(parent)) to%parent => parent + if (present(previous)) to%previous => previous + if (present(tail)) then + if (tail .and. associated(to%parent)) to%parent%tail => to + end if + + if (associated(from%next) .and. associated(to%parent)) then +! we only clone the next entry in an array +! if the parent has also been cloned + call json_value_clone_func(from = from%next,& + to = to%next,& + previous = to,& + parent = to%parent,& + tail = (.not. associated(from%next%next))) + end if + + if (associated(from%children)) then + call json_value_clone_func(from = from%children,& + to = to%children,& + parent = to,& + tail = (.not. associated(from%children%next))) + end if + + end if + + end subroutine json_value_clone_func +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Destroy the data within a [[json_value]], and reset type to `json_unknown`. + + pure subroutine destroy_json_data(d) + + implicit none + + type(json_value),intent(inout) :: d + + d%var_type = json_unknown + + if (allocated(d%log_value)) deallocate(d%log_value) + if (allocated(d%int_value)) deallocate(d%int_value) + if (allocated(d%dbl_value)) deallocate(d%dbl_value) + if (allocated(d%str_value)) deallocate(d%str_value) + + end subroutine destroy_json_data +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 2/13/2014 +! +! Returns information about a [[json_value]]. + + subroutine json_info(json,p,var_type,n_children,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + integer(IK),intent(out),optional :: var_type !! variable type + integer(IK),intent(out),optional :: n_children !! number of children + character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name + + if (.not. json%exception_thrown .and. associated(p)) then + + if (present(var_type)) var_type = p%var_type + if (present(n_children)) n_children = json%count(p) + if (present(name)) then + if (allocated(p%name)) then + name = p%name + else + name = CK_'' + end if + end if + + else ! error + + if (.not. json%exception_thrown) then + call json%throw_exception('Error in json_info: '//& + 'pointer is not associated.' ) + end if + if (present(var_type)) var_type = json_unknown + if (present(n_children)) n_children = 0 + if (present(name)) name = CK_'' + + end if + + end subroutine json_info +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/18/2016 +! +! Returns information about character strings returned from a [[json_value]]. + + subroutine json_string_info(json,p,ilen,max_str_len,found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + integer(IK),dimension(:),allocatable,intent(out),optional :: ilen !! if `p` is an array, this +!! is the actual length +!! of each character +!! string in the array. +!! if not an array, this +!! is returned unallocated. + integer(IK),intent(out),optional :: max_str_len !! The maximum length required to +!! hold the string representation returned +!! by a call to a `get` routine. If a scalar, +!! this is just the length of the scalar. If +!! a vector, this is the maximum length of +!! any element. + logical(LK),intent(out),optional :: found !! true if there were no errors. +!! if not present, an error will +!! throw an exception + + character(kind=CK,len=:),allocatable :: cval !! for getting values as strings. + logical(LK) :: initialized !! if the output array has been sized + logical(LK) :: get_max_len !! if we are returning the `max_str_len` + logical(LK) :: get_ilen !! if we are returning the `ilen` array + integer(IK) :: var_type !! variable type + + get_max_len = present(max_str_len) + get_ilen = present(ilen) + + if (.not. json%exception_thrown) then + + if (present(found)) found = .true. + initialized = .false. + + if (get_max_len) max_str_len = 0 + + select case (p%var_type) + + case (json_array) ! it's an array + +! call routine for each element + call json%get(p, array_callback=get_string_lengths) + + case default ! not an array + + if (json%strict_type_checking) then +! only allowing strings to be returned +! as strings, so we can check size directly + call json%info(p,var_type=var_type) + if (var_type==json_string) then + if (allocated(p%str_value) .and. get_max_len) & + max_str_len = len(p%str_value) + else +! it isn't a string, so there is no length + call json%throw_exception('Error in json_string_info: '//& + 'When strict_type_checking is true '//& + 'the variable must be a character string.',& + found) + end if + else +! in this case, we have to get the value +! as a string to know what size it is. + call json%get(p, value=cval) + if (.not. json%exception_thrown) then + if (allocated(cval) .and. get_max_len) & + max_str_len = len(cval) + end if + end if + + end select + + end if + + if (json%exception_thrown) then + if (present(found)) then + call json%clear_exceptions() + found = .false. + end if + if (get_max_len) max_str_len = 0 + if (get_ilen) then + if (allocated(ilen)) deallocate(ilen) + end if + end if + + contains + + subroutine get_string_lengths(json, element, i, count) + +!! callback function to call for each element in the array. + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: element + integer(IK),intent(in) :: i !! index + integer(IK),intent(in) :: count !! size of array + + character(kind=CK,len=:),allocatable :: cval + integer(IK) :: var_type + + if (json%exception_thrown) return + + if (.not. initialized) then + if (get_ilen) allocate(ilen(count)) + initialized = .true. + end if + + if (json%strict_type_checking) then +! only allowing strings to be returned +! as strings, so we can check size directly + call json%info(element,var_type=var_type) + if (var_type==json_string) then + if (allocated(element%str_value)) then + if (get_max_len) then + if (len(element%str_value)>max_str_len) & + max_str_len = len(element%str_value) + end if + if (get_ilen) ilen(i) = len(element%str_value) + else + if (get_ilen) ilen(i) = 0 + end if + else +! it isn't a string, so there is no length + call json%throw_exception('Error in json_string_info: '//& + 'When strict_type_checking is true '//& + 'the array must contain only '//& + 'character strings.',found) + end if + else +! in this case, we have to get the value +! as a string to know what size it is. + call json%get(element, value=cval) + if (json%exception_thrown) return + if (allocated(cval)) then + if (get_max_len) then + if (len(cval)>max_str_len) max_str_len = len(cval) + end if + if (get_ilen) ilen(i) = len(cval) + else + if (get_ilen) ilen(i) = 0 + end if + end if + + end subroutine get_string_lengths + + end subroutine json_string_info +!***************************************************************************************** + +!***************************************************************************************** +! +! Returns information about a [[json_value]], given the path. +! +!### See also +! * [[json_info]] +! +!@note If `found` is present, no exceptions will be thrown if an +! error occurs. Otherwise, an exception will be thrown if the +! variable is not found. + + subroutine json_info_by_path(json,p,path,found,var_type,n_children,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! a JSON linked list + character(kind=CK,len=*),intent(in) :: path !! path to the variable + logical(LK),intent(out),optional :: found !! true if it was found + integer(IK),intent(out),optional :: var_type !! variable type + integer(IK),intent(out),optional :: n_children !! number of children + character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name + + type(json_value),pointer :: p_var !! temporary pointer + logical(LK) :: ok !! if the variable was found +# 1629 + + + call json%get(p,path,p_var,found) + +!check if it was found: + if (present(found)) then + ok = found + else + ok = .not. json%exception_thrown + end if + + if (.not. ok) then + if (present(var_type)) var_type = json_unknown + if (present(n_children)) n_children = 0 + if (present(name)) name = CK_'' + else +!get info: + +# 1657 + + call json%info(p_var,var_type,n_children,name) + + + end if + + end subroutine json_info_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_info_by_path]] where "path" is kind=CDK. + + subroutine wrap_json_info_by_path(json,p,path,found,var_type,n_children,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! a JSON linked list + character(kind=CDK,len=*),intent(in) :: path !! path to the variable + logical(LK),intent(out),optional :: found !! true if it was found + integer(IK),intent(out),optional :: var_type !! variable type + integer(IK),intent(out),optional :: n_children !! number of children + character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name + + call json%info(p,to_unicode(path),found,var_type,n_children,name) + + end subroutine wrap_json_info_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 10/16/2015 +! +! Alternate version of [[json_info]] that returns matrix +! information about a [[json_value]]. +! +! A [[json_value]] is a valid rank 2 matrix if all of the following are true: +! +! * The var_type is *json_array* +! * Each child is also a *json_array*, each of which has the same number of elements +! * Each individual element has the same variable type (integer, logical, etc.) +! +! The idea here is that if it is a valid matrix, it can be interoperable with +! a Fortran rank 2 array of the same type. +! +!### Example +! +! The following example is an array with `var_type=json_integer`, +! `n_sets=3`, and `set_size=4` +! +!```json +! { +! "matrix": [ +! [1,2,3,4], +! [5,6,7,8], +! [9,10,11,12] +! ] +! } +!``` + + subroutine json_matrix_info(json,p,is_matrix,var_type,n_sets,set_size,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p !! a JSON linked list + logical(LK),intent(out) :: is_matrix !! true if it is a valid matrix + integer(IK),intent(out),optional :: var_type !! variable type of data in the matrix +!! (if all elements have the same type) + integer(IK),intent(out),optional :: n_sets !! number of data sets (i.e., matrix +!! rows if using row-major order) + integer(IK),intent(out),optional :: set_size !! size of each data set (i.e., matrix +!! cols if using row-major order) + character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name + + type(json_value),pointer :: p_row !! for getting a set + type(json_value),pointer :: p_element !! for getting an element in a set + integer(IK) :: vartype !! json variable type of `p` + integer(IK) :: row_vartype !! json variable type of a row + integer(IK) :: element_vartype !! json variable type of an element in a row + integer(IK) :: nr !! number of children of `p` + integer(IK) :: nc !! number of elements in first child of `p` + integer(IK) :: icount !! number of elements in a set + integer(IK) :: i !! counter + integer(IK) :: j !! counter +# 1745 + + +!get info about the variable: +# 1758 + + call json%info(p,vartype,nr,name) + + + is_matrix = (vartype==json_array) + + if (is_matrix) then + + main : do i=1,nr + + nullify(p_row) + call json%get_child(p,i,p_row) + if (.not. associated(p_row)) then + is_matrix = .false. + call json%throw_exception('Error in json_matrix_info: '//& + 'Malformed JSON linked list') + exit main + end if + call json%info(p_row,var_type=row_vartype,n_children=icount) + + if (row_vartype==json_array) then + if (i==1) nc = icount !number of columns in first row + if (icount==nc) then !make sure each row has the same number of columns +!see if all the variables in this row are the same type: + do j=1,icount + nullify(p_element) + call json%get_child(p_row,j,p_element) + if (.not. associated(p_element)) then + is_matrix = .false. + call json%throw_exception('Error in json_matrix_info: '//& + 'Malformed JSON linked list') + exit main + end if + call json%info(p_element,var_type=element_vartype) + if (i==1 .and. j==1) vartype = element_vartype !type of first element +!in the row + if (vartype/=element_vartype) then +!not all variables are the same time + is_matrix = .false. + exit main + end if + end do + else + is_matrix = .false. + exit main + end if + else + is_matrix = .false. + exit main + end if + + end do main + + end if + + if (is_matrix) then + if (present(var_type)) var_type = vartype + if (present(n_sets)) n_sets = nr + if (present(set_size)) set_size = nc + else + if (present(var_type)) var_type = json_unknown + if (present(n_sets)) n_sets = 0 + if (present(set_size)) set_size = 0 + end if + + end subroutine json_matrix_info +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns matrix information about a [[json_value]], given the path. +! +!### See also +! * [[json_matrix_info]] +! +!@note If `found` is present, no exceptions will be thrown if an +! error occurs. Otherwise, an exception will be thrown if the +! variable is not found. + + subroutine json_matrix_info_by_path(json,p,path,is_matrix,found,& + var_type,n_sets,set_size,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p !! a JSON linked list + character(kind=CK,len=*),intent(in) :: path !! path to the variable + logical(LK),intent(out) :: is_matrix !! true if it is a valid matrix + logical(LK),intent(out),optional :: found !! true if it was found + integer(IK),intent(out),optional :: var_type !! variable type of data in +!! the matrix (if all elements have +!! the same type) + integer(IK),intent(out),optional :: n_sets !! number of data sets (i.e., matrix +!! rows if using row-major order) + integer(IK),intent(out),optional :: set_size !! size of each data set (i.e., matrix +!! cols if using row-major order) + character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name + + type(json_value),pointer :: p_var + logical(LK) :: ok +# 1860 + + + call json%get(p,path,p_var,found) + +!check if it was found: + if (present(found)) then + ok = found + else + ok = .not. json%exception_thrown + end if + + if (.not. ok) then + if (present(var_type)) var_type = json_unknown + if (present(n_sets)) n_sets = 0 + if (present(set_size)) set_size = 0 + if (present(name)) name = CK_'' + else + +!get info about the variable: +# 1889 + + call json%matrix_info(p_var,is_matrix,var_type,n_sets,set_size,name) + + if (json%exception_thrown .and. present(found)) then + found = .false. + call json%clear_exceptions() + end if + end if + + end subroutine json_matrix_info_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_matrix_info_by_path]] where "path" is kind=CDK. + + subroutine wrap_json_matrix_info_by_path(json,p,path,is_matrix,found,& + var_type,n_sets,set_size,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p !! a JSON linked list + character(kind=CDK,len=*),intent(in) :: path !! path to the variable + logical(LK),intent(out) :: is_matrix !! true if it is a valid matrix + logical(LK),intent(out),optional :: found !! true if it was found + integer(IK),intent(out),optional :: var_type !! variable type of data in +!! the matrix (if all elements have +!! the same type) + integer(IK),intent(out),optional :: n_sets !! number of data sets (i.e., matrix +!! rows if using row-major order) + integer(IK),intent(out),optional :: set_size !! size of each data set (i.e., matrix +!! cols if using row-major order) + character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name + + call json%matrix_info(p,to_unicode(path),is_matrix,found,var_type,n_sets,set_size,name) + + end subroutine wrap_json_matrix_info_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 4/29/2016 +! +! Rename a [[json_value]]. + + subroutine json_value_rename(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + character(kind=CK,len=*),intent(in) :: name !! new variable name + + if (json%trailing_spaces_significant) then + p%name = name + else + p%name = trim(name) + end if + + end subroutine json_value_rename +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 4/29/2016 +! +! Alternate version of [[json_value_rename]], where `name` is kind=CDK. + + subroutine wrap_json_value_rename(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + character(kind=CDK,len=*),intent(in) :: name !! new variable name + + call json%rename(p,to_unicode(name)) + + end subroutine wrap_json_value_rename +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/4/2013 +! +! Clear exceptions in the [[json_core(type)]]. + + pure subroutine json_clear_exceptions(json) + + implicit none + + class(json_core),intent(inout) :: json + +!clear the flag and message: + json%exception_thrown = .false. + if (allocated(json%err_message)) deallocate(json%err_message) + + end subroutine json_clear_exceptions +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/4/2013 +! +! Throw an exception in the [[json_core(type)]]. +! This routine sets the error flag, and prevents any subsequent routine +! from doing anything, until [[json_clear_exceptions]] is called. +! +!@note If `is_verbose` is true, this will also print a +! traceback if the Intel compiler is used. +! +!@note If `stop_on_error` is true, then the program is stopped. + + subroutine json_throw_exception(json,msg,found) + + + use ifcore, only: tracebackqq + + + implicit none + + class(json_core),intent(inout) :: json + character(kind=CK,len=*),intent(in) :: msg !! the error message + logical(LK),intent(inout),optional :: found !! if the caller is handling the +!! exception with an optimal return +!! argument. If so, `json%stop_on_error` +!! is ignored. + + logical(LK) :: stop_on_error + + json%exception_thrown = .true. + json%err_message = trim(msg) + stop_on_error = json%stop_on_error .and. .not. present(found) + + if (stop_on_error) then + + +! for Intel, we raise a traceback and quit + call tracebackqq(string=trim(msg), user_exit_code=0) +# 2032 + + + elseif (json%is_verbose) then + + write(output_unit,'(A)') '***********************' + write(output_unit,'(A)') 'JSON-Fortran Exception: '//trim(msg) + +!#if defined __GFORTRAN__ +! call backtrace() ! (have to compile with -fbacktrace -fall-intrinsics flags) +!#endif + + + call tracebackqq(user_exit_code=-1) ! print a traceback and return + + + write(output_unit,'(A)') '***********************' + + end if + + end subroutine json_throw_exception +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_throw_exception]], where `msg` is kind=CDK. + + subroutine wrap_json_throw_exception(json,msg,found) + + implicit none + + class(json_core),intent(inout) :: json + character(kind=CDK,len=*),intent(in) :: msg !! the error message + logical(LK),intent(inout),optional :: found !! if the caller is handling the +!! exception with an optimal return +!! argument. If so, `json%stop_on_error` +!! is ignored. + + call json%throw_exception(to_unicode(msg),found) + + end subroutine wrap_json_throw_exception +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/4/2013 +! +! Retrieve error code from the [[json_core(type)]]. +! This should be called after `parse` to check for errors. +! If an error is thrown, before using the class again, [[json_initialize]] +! should be called to clean up before it is used again. +! +!### Example +! +!````fortran +! type(json_file) :: json +! logical :: status_ok +! character(kind=CK,len=:),allocatable :: error_msg +! call json%load(filename='myfile.json') +! call json%check_for_errors(status_ok, error_msg) +! if (.not. status_ok) then +! write(*,*) 'Error: '//error_msg +! call json%clear_exceptions() +! call json%destroy() +! end if +!```` +! +!### See also +! * [[json_failed]] +! * [[json_throw_exception]] + + subroutine json_check_for_errors(json,status_ok,error_msg) + + implicit none + + class(json_core),intent(in) :: json + logical(LK),intent(out),optional :: status_ok !! true if there were no errors + character(kind=CK,len=:),allocatable,intent(out),optional :: error_msg !! the error message. +!! (not allocated if +!! there were no errors) + +# 2114 + + + if (present(status_ok)) status_ok = .not. json%exception_thrown + + if (present(error_msg)) then + if (json%exception_thrown) then +! if an exception has been thrown, +! then this will always be allocated +! [see json_throw_exception] +# 2126 + + error_msg = json%err_message + + end if + end if + + end subroutine json_check_for_errors +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/5/2013 +! +! Logical function to indicate if an exception has been thrown in a [[json_core(type)]]. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: p +! logical :: status_ok +! character(len=:),allocatable :: error_msg +! call json%load(filename='myfile.json',p) +! if (json%failed()) then +! call json%check_for_errors(status_ok, error_msg) +! write(*,*) 'Error: '//error_msg +! call json%clear_exceptions() +! call json%destroy(p) +! end if +!```` +! +! Note that [[json_file]] contains a wrapper for this routine, which is used like: +!````fortran +! type(json_file) :: f +! logical :: status_ok +! character(len=:),allocatable :: error_msg +! call f%load(filename='myfile.json') +! if (f%failed()) then +! call f%check_for_errors(status_ok, error_msg) +! write(*,*) 'Error: '//error_msg +! call f%clear_exceptions() +! call f%destroy() +! end if +!```` +! +!### See also +! * [[json_check_for_errors]] + + pure function json_failed(json) result(failed) + + implicit none + + class(json_core),intent(in) :: json + logical(LK) :: failed !! will be true if an exception +!! has been thrown. + + failed = json%exception_thrown + + end function json_failed +!***************************************************************************************** + +!***************************************************************************************** +!> +! Allocate a [[json_value]] pointer variable. +! This should be called before adding data to it. +! +!### Example +! +!````fortran +! type(json_value),pointer :: var +! call json_value_create(var) +! call json%to_real(var,1.0_RK) +!```` +! +!### Notes +! 1. This routine does not check for exceptions. +! 2. The pointer should not already be allocated, or a memory leak will occur. + + subroutine json_value_create(p) + + implicit none + + type(json_value),pointer :: p + + nullify(p) + allocate(p) + + end subroutine json_value_create +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 1/22/2014 +! +! Destroy a [[json_value]] linked-list structure. +! +!@note The original FSON version of this +! routine was not properly freeing the memory. +! It was rewritten. +! +!@note This routine destroys this variable, it's children, and +! (if `destroy_next` is true) the subsequent elements in +! an object or array. It does not destroy the parent or +! previous elements. +! +!@Note There is some protection here to enable destruction of +! improperly-created linked lists. However, likely there +! are cases not handled. Use the [[json_value_validate]] +! method to validate a JSON structure that was manually +! created using [[json_value]] pointers. + + pure recursive subroutine json_value_destroy(json,p,destroy_next) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p !! variable to destroy + logical(LK),intent(in),optional :: destroy_next !! if true, then `p%next` +!! is also destroyed (default is true) + + logical(LK) :: des_next !! local copy of `destroy_next` +!! optional argument + type(json_value),pointer :: child !! for getting child elements + logical :: circular !! to check to malformed linked lists + + if (associated(p)) then + + if (present(destroy_next)) then + des_next = destroy_next + else + des_next = .true. + end if + + if (allocated(p%name)) deallocate(p%name) + + call destroy_json_data(p) + + if (associated(p%next)) then +! check for circular references: + if (associated(p, p%next)) nullify(p%next) + end if + + if (associated(p%children)) then + do while (p%n_children > 0) + child => p%children + if (associated(child)) then + p%children => p%children%next + p%n_children = p%n_children - 1 +! check children for circular references: + circular = (associated(p%children) .and. & + associated(p%children,child)) + call json%destroy(child,destroy_next=.false.) + if (circular) exit + else +! it is a malformed JSON object. But, we will +! press ahead with the destroy process, since +! otherwise, there would be no way to destroy it. + exit + end if + end do + nullify(p%children) + nullify(child) + end if + + if (associated(p%next) .and. des_next) call json%destroy(p%next) + + nullify(p%previous) + nullify(p%parent) + nullify(p%tail) + + if (associated(p)) deallocate(p) + nullify(p) + + end if + + end subroutine json_value_destroy +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 9/9/2014 +! +! Remove a [[json_value]] (and all its children) +! from a linked-list structure, preserving the rest of the structure. +! +!### Examples +! +! To extract an object from one JSON structure, and add it to another: +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: json1,json2,p +! logical :: found +! !create and populate json1 and json2 +! call json%get(json1,'name',p,found) ! get pointer to name element of json1 +! call json%remove(p,destroy=.false.) ! remove it from json1 (don't destroy) +! call json%add(json2,p) ! add it to json2 +!```` +! +! To remove an object from a JSON structure (and destroy it): +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: json1,p +! logical :: found +! !create and populate json1 +! call json%get(json1,'name',p,found) ! get pointer to name element of json1 +! call json%remove(p) ! remove and destroy it +!```` +! +!### History +! * Jacob Williams : 12/28/2014 : added destroy optional argument. +! * Jacob Williams : 12/04/2020 : bug fix. + + subroutine json_value_remove(json,p,destroy) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + logical(LK),intent(in),optional :: destroy !! Option to destroy `p` after it is removed: +!! +!! * If `destroy` is not present, it is also destroyed. +!! * If `destroy` is present and true, it is destroyed. +!! * If `destroy` is present and false, it is not destroyed. + + type(json_value),pointer :: parent !! pointer to parent + type(json_value),pointer :: previous !! pointer to previous + type(json_value),pointer :: next !! pointer to next + logical(LK) :: destroy_it !! if `p` should be destroyed + + if (associated(p)) then + +!optional input argument: + if (present(destroy)) then + destroy_it = destroy + else + destroy_it = .true. + end if + + if (associated(p%parent)) then + + parent => p%parent + + if (associated(p%next)) then + +!there are later items in the list: + next => p%next + + if (associated(p%previous)) then +!there are earlier items in the list + previous => p%previous + previous%next => next + next%previous => previous + else +!this is the first item in the list + parent%children => next + nullify(next%previous) + end if + + else + + if (associated(p%previous)) then +!there are earlier items in the list: + previous => p%previous + nullify(previous%next) + parent%tail => previous + else +!this is the only item in the list: + nullify(parent%children) + nullify(parent%tail) + end if + + end if + +! nullify all pointers to original structure: + nullify(p%next) + nullify(p%previous) + nullify(p%parent) + + parent%n_children = parent%n_children - 1 + + end if + + if (destroy_it) call json%destroy(p) + + end if + + end subroutine json_value_remove +!***************************************************************************************** + +!***************************************************************************************** +!> +! Replace `p1` with `p2` in a JSON structure. +! +!@note The replacement is done using an insert and remove +! See [[json_value_insert_after]] and [[json_value_remove]] +! for details. + + subroutine json_value_replace(json,p1,p2,destroy) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p1 !! the item to replace + type(json_value),pointer :: p2 !! item to take the place of `p1` + logical(LK),intent(in),optional :: destroy !! Should `p1` also be destroyed +!! (default is True). Normally, +!! this should be true to avoid +!! a memory leak. + + logical(LK) :: destroy_p1 !! if `p1` is to be destroyed + + if (present(destroy)) then + destroy_p1 = destroy + else + destroy_p1 = .true. ! default + end if + + call json%insert_after(p1,p2) + call json%remove(p1,destroy_p1) + + end subroutine json_value_replace +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 4/11/2017 +! +! Reverse the order of the children of an array or object. + + subroutine json_value_reverse(json,p) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + + type(json_value),pointer :: tmp !! temp variable for traversing the list + type(json_value),pointer :: current !! temp variable for traversing the list + integer(IK) :: var_type !! for getting the variable type + + if (associated(p)) then + + call json%info(p,var_type=var_type) + +! can only reverse objects or arrays + if (var_type==json_object .or. var_type==json_array) then + + nullify(tmp) + current => p%children + p%tail => current + +! Swap next and previous for all nodes: + do + if (.not. associated(current)) exit + tmp => current%previous + current%previous => current%next + current%next => tmp + current => current%previous + end do + + if (associated(tmp)) then + p%children => tmp%previous + end if + + end if + + end if + + end subroutine json_value_reverse +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 4/26/2016 +! +! Swap two elements in a JSON structure. +! All of the children are carried along as well. +! +!@note If both are not associated, then an error is thrown. +! +!@note The assumption here is that both variables are part of a valid +! [[json_value]] linked list (so the normal `parent`, `previous`, +! `next`, etc. pointers are properly associated if necessary). +! +!@warning This cannot be used to swap a parent/child pair, since that +! could lead to a circular linkage. An exception is thrown if +! this is tried. +! +!@warning There are also other situations where using this routine may +! produce a malformed JSON structure, such as moving an array +! element outside of an array. This is not checked for. +! +!@note If `p1` and `p2` have a common parent, it is always safe to swap them. + + subroutine json_value_swap(json,p1,p2) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p1 !! swap with `p2` + type(json_value),pointer :: p2 !! swap with `p1` + + logical :: same_parent !! if `p1` and `p2` have the same parent + logical :: first_last !! if `p1` and `p2` are the first,last or +!! last,first children of a common parent + logical :: adjacent !! if `p1` and `p2` are adjacent +!! elements in an array + type(json_value),pointer :: a !! temporary variable + type(json_value),pointer :: b !! temporary variable + + if (json%exception_thrown) return + +!both have to be associated: + if (associated(p1) .and. associated(p2)) then + +!simple check to make sure that they both +!aren't pointing to the same thing: + if (.not. associated(p1,p2)) then + +!we will not allow swapping an item with one of its descendants: + if (json%is_child_of(p1,p2) .or. json%is_child_of(p2,p1)) then + call json%throw_exception('Error in json_value_swap: '//& + 'cannot swap an item with one of its descendants') + else + + same_parent = ( associated(p1%parent) .and. & + associated(p2%parent) .and. & + associated(p1%parent,p2%parent) ) + if (same_parent) then + first_last = (associated(p1%parent%children,p1) .and. & + associated(p2%parent%tail,p2)) .or. & + (associated(p1%parent%tail,p1) .and. & + associated(p2%parent%children,p2)) + else + first_last = .false. + end if + +!first, we fix children,tail pointers: + + if (same_parent .and. first_last) then + +!this is all we have to do for the parent in this case: + call swap_pointers(p1%parent%children,p2%parent%tail) + + else if (same_parent .and. .not. first_last) then + + if (associated(p1%parent%children,p1)) then + p1%parent%children => p2 ! p1 is the first child of the parent + else if (associated(p1%parent%children,p2)) then + p1%parent%children => p1 ! p2 is the first child of the parent + end if + if (associated(p1%parent%tail,p1)) then + p1%parent%tail => p2 ! p1 is the last child of the parent + else if (associated(p1%parent%tail,p2)) then + p1%parent%tail => p1 ! p2 is the last child of the parent + end if + + else ! general case: different parents + + if (associated(p1%parent)) then + if (associated(p1%parent%children,p1)) p1%parent%children => p2 + if (associated(p1%parent%tail,p1)) p1%parent%tail => p2 + end if + if (associated(p2%parent)) then + if (associated(p2%parent%children,p2)) p2%parent%children => p1 + if (associated(p2%parent%tail,p2)) p2%parent%tail => p1 + end if + call swap_pointers(p1%parent, p2%parent) + + end if + +!now, have to fix previous,next pointers: + +!first, see if they are adjacent: + adjacent = associated(p1%next,p2) .or. & + associated(p2%next,p1) + if (associated(p2%next,p1)) then !p2,p1 + a => p2 + b => p1 + else !p1,p2 (or not adjacent) + a => p1 + b => p2 + end if + if (associated(a%previous)) a%previous%next => b + if (associated(b%next)) b%next%previous => a + + if (adjacent) then +!a comes before b in the original list + b%previous => a%previous + a%next => b%next + a%previous => b + b%next => a + else + if (associated(a%next)) a%next%previous => b + if (associated(b%previous)) b%previous%next => a + call swap_pointers(a%previous,b%previous) + call swap_pointers(a%next, b%next) + end if + + end if + + else + call json%throw_exception('Error in json_value_swap: '//& + 'both pointers must be associated') + end if + + end if + + contains + + pure subroutine swap_pointers(s1,s2) + + implicit none + + type(json_value),pointer,intent(inout) :: s1 + type(json_value),pointer,intent(inout) :: s2 + + type(json_value),pointer :: tmp !! temporary pointer + + if (.not. associated(s1,s2)) then + tmp => s1 + s1 => s2 + s2 => tmp + end if + + end subroutine swap_pointers + + end subroutine json_value_swap +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 4/28/2016 +! +! Returns True if `p2` is a descendant of `p1` +! (i.e, a child, or a child of child, etc.) + + function json_value_is_child_of(json,p1,p2) result(is_child_of) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p1 + type(json_value),pointer :: p2 + logical(LK) :: is_child_of + + is_child_of = .false. + + if (json%exception_thrown) return + + if (associated(p1) .and. associated(p2)) then + if (associated(p1%children)) then + call json%traverse(p1%children,is_child_of_callback) + end if + end if + + contains + + subroutine is_child_of_callback(json,p,finished) +!! Traverse until `p` is `p2`. + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + logical(LK),intent(out) :: finished + + is_child_of = associated(p,p2) + finished = is_child_of ! stop searching if found + + end subroutine is_child_of_callback + + end function json_value_is_child_of +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 5/2/2016 +! +! Validate a [[json_value]] linked list by checking to make sure +! all the pointers are properly associated, arrays and objects +! have the correct number of children, and the correct data is +! allocated for the variable types. +! +! It recursively traverses the entire structure and checks every element. +! +!### History +! * Jacob Williams, 8/26/2017 : added duplicate key check. +! +!@note It will return on the first error it encounters. +! +!@note This routine does not check or throw any exceptions. +! If `json` is currently in a state of exception, it will +! remain so after calling this routine. + + subroutine json_value_validate(json,p,is_valid,error_msg) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + logical(LK),intent(out) :: is_valid !! True if the structure is valid. + character(kind=CK,len=:),allocatable,intent(out) :: error_msg !! if not valid, this will contain +!! a description of the problem + + logical(LK) :: has_duplicate !! to check for duplicate keys + character(kind=CK,len=:),allocatable :: path !! path to duplicate key + logical(LK) :: status_ok !! to check for existing exception + character(kind=CK,len=:),allocatable :: exception_msg !! error message for an existing exception + character(kind=CK,len=:),allocatable :: exception_msg2 !! error message for a new exception + + if (associated(p)) then + + is_valid = .true. + call check_if_valid(p,require_parent=associated(p%parent)) + + if (is_valid .and. .not. json%allow_duplicate_keys) then +! if no errors so far, also check the +! entire structure for duplicate keys: + +! note: check_for_duplicate_keys does call routines +! that check and throw exceptions, so let's clear any +! first. (save message for later) + call json%check_for_errors(status_ok, exception_msg) + call json%clear_exceptions() + + call json%check_for_duplicate_keys(p,has_duplicate,path=path) + if (json%failed()) then +! if an exception was thrown during this call, +! then clear it but make that the error message +! returned by this routine. Normally this should +! never actually occur since we have already +! validated the structure. + call json%check_for_errors(is_valid, exception_msg2) + error_msg = exception_msg2 + call json%clear_exceptions() + is_valid = .false. + else + if (has_duplicate) then + error_msg = 'duplicate key found: '//path + is_valid = .false. + end if + end if + + if (.not. status_ok) then +! restore any existing exception if necessary + call json%throw_exception(exception_msg) + end if + +! cleanup: + if (allocated(path)) deallocate(path) + if (allocated(exception_msg)) deallocate(exception_msg) + if (allocated(exception_msg2)) deallocate(exception_msg2) + + end if + + else + error_msg = 'The pointer is not associated' + is_valid = .false. + end if + + contains + + recursive subroutine check_if_valid(p,require_parent) + + implicit none + + type(json_value),pointer,intent(in) :: p + logical,intent(in) :: require_parent !! the first one may be a root (so no parent), +!! but all descendants must have a parent. + + integer(IK) :: i !! counter + type(json_value),pointer :: element + type(json_value),pointer :: previous + + if (is_valid .and. associated(p)) then + +! data type: + select case (p%var_type) + case(json_null,json_object,json_array) + if (allocated(p%log_value) .or. allocated(p%int_value) .or. & + allocated(p%dbl_value) .or. allocated(p%str_value)) then + error_msg = 'incorrect data allocated for '//& + 'json_null, json_object, or json_array variable type' + is_valid = .false. + return + end if + case(json_logical) + if (.not. allocated(p%log_value)) then + error_msg = 'log_value should be allocated for json_logical variable type' + is_valid = .false. + return + else if (allocated(p%int_value) .or. & + allocated(p%dbl_value) .or. allocated(p%str_value)) then + error_msg = 'incorrect data allocated for json_logical variable type' + is_valid = .false. + return + end if + case(json_integer) + if (.not. allocated(p%int_value)) then + error_msg = 'int_value should be allocated for json_integer variable type' + is_valid = .false. + return + else if (allocated(p%log_value) .or. & + allocated(p%dbl_value) .or. allocated(p%str_value)) then + error_msg = 'incorrect data allocated for json_integer variable type' + is_valid = .false. + return + end if + case(json_real) + if (.not. allocated(p%dbl_value)) then + error_msg = 'dbl_value should be allocated for json_real variable type' + is_valid = .false. + return + else if (allocated(p%log_value) .or. allocated(p%int_value) .or. & + allocated(p%str_value)) then + error_msg = 'incorrect data allocated for json_real variable type' + is_valid = .false. + return + end if + case(json_string) + if (.not. allocated(p%str_value)) then + error_msg = 'str_value should be allocated for json_string variable type' + is_valid = .false. + return + else if (allocated(p%log_value) .or. allocated(p%int_value) .or. & + allocated(p%dbl_value)) then + error_msg = 'incorrect data allocated for json_string variable type' + is_valid = .false. + return + end if + case default + error_msg = 'invalid JSON variable type' + is_valid = .false. + return + end select + + if (require_parent .and. .not. associated(p%parent)) then + error_msg = 'parent pointer is not associated' + is_valid = .false. + return + end if + + if (.not. allocated(p%name)) then + if (associated(p%parent)) then + if (p%parent%var_type/=json_array) then + error_msg = 'JSON variable must have a name if not an '//& + 'array element or the root' + is_valid = .false. + return + end if + end if + end if + + if (associated(p%children) .neqv. associated(p%tail)) then + error_msg = 'both children and tail pointers must be associated' + is_valid = .false. + return + end if + +! now, check next one: + if (associated(p%next)) then + if (associated(p,p%next)) then + error_msg = 'circular linked list' + is_valid = .false. + return + else +! if it's an element in an +! array, then require a parent: + call check_if_valid(p%next,require_parent=.true.) + end if + end if + + if (associated(p%children)) then + + if (p%var_type/=json_array .and. p%var_type/=json_object) then + error_msg = 'only arrays and objects can have children' + is_valid = .false. + return + end if + +! first validate children pointers: + + previous => null() + element => p%children + do i = 1_IK, p%n_children + if (.not. associated(element%parent,p)) then + error_msg = 'child''s parent pointer not properly associated' + is_valid = .false. + return + end if + if (i==1 .and. associated(element%previous)) then + error_msg = 'first child shouldn''t have a previous' + is_valid = .false. + return + end if + if (i1) then + if (.not. associated(previous,element%previous)) then + error_msg = 'previous pointer not properly associated' + is_valid = .false. + return + end if + end if + if (i==p%n_children .and. & + .not. associated(element%parent%tail,element)) then + error_msg = 'parent''s tail pointer not properly associated' + is_valid = .false. + return + end if + if (i element + element => element%next + end if + end do + +!now check all the children: + call check_if_valid(p%children,require_parent=.true.) + + end if + + end if + + end subroutine check_if_valid + + end subroutine json_value_validate +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/6/2014 +! +! Given the path string, remove the variable +! from [[json_value]], if it exists. + + subroutine json_value_remove_if_present(json,p,path) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: path !! the path to the variable to remove + + type(json_value),pointer :: p_var + logical(LK) :: found + + call json%get(p,path,p_var,found) + if (found) call json%remove(p_var) + + end subroutine json_value_remove_if_present +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_remove_if_present]], where `path` is kind=CDK. + + subroutine wrap_json_value_remove_if_present(json,p,path) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: path + + call json%remove_if_present(p,to_unicode(path)) + + end subroutine wrap_json_value_remove_if_present +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/6/2014 +! +! Given the path string, if the variable is present, +! and is a scalar, then update its value. +! If it is not present, then create it and set its value. +! +!@note If the variable is not a scalar, an exception will be thrown. + + subroutine json_update_logical(json,p,path,val,found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: path !! path to the variable in the structure + logical(LK),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + + type(json_value),pointer :: p_var + integer(IK) :: var_type + + call json%get(p,path,p_var,found) + if (found) then + + call json%info(p_var,var_type) + select case (var_type) + case (json_null,json_logical,json_integer,json_real,json_string) + call json%to_logical(p_var,val) !update the value + case default + found = .false. + call json%throw_exception('Error in json_update_logical: '//& + 'the variable is not a scalar value',found) + end select + + else + call json%add_by_path(p,path,val) !add the new element + end if + + end subroutine json_update_logical +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_update_logical]], where `path` is kind=CDK. + + subroutine wrap_json_update_logical(json,p,path,val,found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: path !! path to the variable in the structure + logical(LK),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + + call json%update(p,to_unicode(path),val,found) + + end subroutine wrap_json_update_logical +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/6/2014 +! +! Given the path string, if the variable is present, +! and is a scalar, then update its value. +! If it is not present, then create it and set its value. +! +!@note If the variable is not a scalar, an exception will be thrown. + + subroutine json_update_real(json,p,path,val,found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: path !! path to the variable in the structure + real(RK),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + + type(json_value),pointer :: p_var + integer(IK) :: var_type + + call json%get(p,path,p_var,found) + if (found) then + + call json%info(p_var,var_type) + select case (var_type) + case (json_null,json_logical,json_integer,json_real,json_string) + call json%to_real(p_var,val) !update the value + case default + found = .false. + call json%throw_exception('Error in json_update_real: '//& + 'the variable is not a scalar value',found) + end select + + else + call json%add_by_path(p,path,val) !add the new element + end if + + end subroutine json_update_real +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_update_real]], where `path` is kind=CDK. + + subroutine wrap_json_update_real(json,p,path,val,found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: path !! path to the variable in the structure + real(RK),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + + call json%update(p,to_unicode(path),val,found) + + end subroutine wrap_json_update_real +!***************************************************************************************** + + +!***************************************************************************************** +!> +! Alternate version of [[json_update_real]], where `val` is `real32`. + + subroutine json_update_real32(json,p,path,val,found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: path !! path to the variable in the structure + real(real32),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + + call json%update(p,path,real(val,RK),found) + + end subroutine json_update_real32 +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_update_real32]], where `path` is kind=CDK. + + subroutine wrap_json_update_real32(json,p,path,val,found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: path !! path to the variable in the structure + real(real32),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + + call json%update(p,to_unicode(path),real(val,RK),found) + + end subroutine wrap_json_update_real32 +!***************************************************************************************** + + +# 3206 + + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/6/2014 +! +! Given the path string, if the variable is present, +! and is a scalar, then update its value. +! If it is not present, then create it and set its value. +! +!@note If the variable is not a scalar, an exception will be thrown. + + subroutine json_update_integer(json,p,path,val,found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: path !! path to the variable in the structure + integer(IK),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + + type(json_value),pointer :: p_var + integer(IK) :: var_type + + call json%get(p,path,p_var,found) + if (found) then + + call json%info(p_var,var_type) + select case (var_type) + case (json_null,json_logical,json_integer,json_real,json_string) + call json%to_integer(p_var,val) !update the value + case default + found = .false. + call json%throw_exception('Error in json_update_integer: '//& + 'the variable is not a scalar value',found) + end select + + else + call json%add_by_path(p,path,val) !add the new element + end if + + end subroutine json_update_integer +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_update_integer]], where `path` is kind=CDK. + + subroutine wrap_json_update_integer(json,p,path,val,found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: path !! path to the variable in the structure + integer(IK),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + + call json%update(p,to_unicode(path),val,found) + + end subroutine wrap_json_update_integer +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/6/2014 +! +! Given the path string, if the variable is present, +! and is a scalar, then update its value. +! If it is not present, then create it and set its value. +! +!@note If the variable is not a scalar, an exception will be thrown. + + subroutine json_update_string(json,p,path,val,found,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: path !! path to the variable in the structure + character(kind=CK,len=*),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` +!! (only used if `val` is present) + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` +!! (only used if `val` is present) +!! (note that ADJUSTL is done before TRIM) + + type(json_value),pointer :: p_var + integer(IK) :: var_type + + call json%get(p,path,p_var,found) + if (found) then + + call json%info(p_var,var_type) + select case (var_type) + case (json_null,json_logical,json_integer,json_real,json_string) + call json%to_string(p_var,val,trim_str=trim_str,adjustl_str=adjustl_str) ! update the value + case default + found = .false. + call json%throw_exception('Error in json_update_string: '//& + 'the variable is not a scalar value',found) + end select + + else + call json%add_by_path(p,path,val) !add the new element + end if + + end subroutine json_update_string +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_update_string]], where `path` and `value` are kind=CDK. + + subroutine wrap_json_update_string(json,p,path,val,found,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: path !! path to the variable in the structure + character(kind=CDK,len=*),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` +!! (only used if `val` is present) + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` +!! (only used if `val` is present) +!! (note that ADJUSTL is done before TRIM) + + call json%update(p,to_unicode(path),to_unicode(val),found,trim_str,adjustl_str) + + end subroutine wrap_json_update_string +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_update_string]], where `path` is kind=CDK. + + subroutine json_update_string_name_ascii(json,p,path,val,found,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: path !! path to the variable in the structure + character(kind=CK, len=*),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` +!! (only used if `val` is present) + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` +!! (only used if `val` is present) +!! (note that ADJUSTL is done before TRIM) + + call json%update(p,to_unicode(path),val,found,trim_str,adjustl_str) + + end subroutine json_update_string_name_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_update_string]], where `val` is kind=CDK. + + subroutine json_update_string_val_ascii(json,p,path,val,found,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK, len=*),intent(in) :: path !! path to the variable in the structure + character(kind=CDK,len=*),intent(in) :: val !! the new value + logical(LK),intent(out) :: found !! if the variable was found and was a scalar. + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` +!! (only used if `val` is present) + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` +!! (only used if `val` is present) +!! (note that ADJUSTL is done before TRIM) + + call json%update(p,path,to_unicode(val),found,trim_str,adjustl_str) + + end subroutine json_update_string_val_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> +! Adds `member` as a child of `p`. + + subroutine json_value_add_member(json,p,member) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p !! `p` must be a `json_object` +!! or a `json_array` + type(json_value),pointer :: member !! the child member +!! to add to `p` + + integer(IK) :: var_type !! variable type of `p` + + if (.not. json%exception_thrown) then + + if (associated(p)) then + + call json%info(p,var_type=var_type) + + select case (var_type) + case(json_object, json_array) + +! associate the parent + member%parent => p + +! add to linked list + if (associated(p%children)) then + p%tail%next => member + member%previous => p%tail + else + p%children => member + member%previous => null() !first in the list + end if + +! new member is now the last one in the list + p%tail => member + p%n_children = p%n_children + 1 + + case default + call json%throw_exception('Error in json_value_add_member: '//& + 'can only add child to object or array') + end select + + else + call json%throw_exception('Error in json_value_add_member: '//& + 'the pointer is not associated') + end if + + end if + + end subroutine json_value_add_member +!***************************************************************************************** + +!***************************************************************************************** +!> +! Inserts `element` after `p`, and updates the JSON structure accordingly. +! +!### Example +! +!````fortran +! program test +! use json_module +! implicit none +! logical(json_LK) :: found +! type(json_core) :: json +! type(json_value),pointer :: p,new,element +! call json%load(file='myfile.json', p=p) +! call json%get(p,'x(3)',element,found) ! get pointer to an array element in the file +! call json%create_integer(new,1,'') ! create a new element +! call json%insert_after(element,new) ! insert new element after x(3) +! call json%print(p,'myfile2.json') ! write it to a file +! call json%destroy(p) ! cleanup +! end program test +!```` +! +!### Details +! +! * This routine can be used to insert a new element (or set of elements) +! into an array or object at a specific index. +! See [[json_value_insert_after_child_by_index]] +! * Children and subsequent elements of `element` are carried along. +! * If the inserted elements are part of an existing list, then +! they are removed from that list. +! +!```` +! p +! [1] - [2] - [3] - [4] +! | +! [5] - [6] - [7] n=3 elements inserted +! element last +! +! Result is: +! +! [1] - [2] - [5] - [6] - [7] - [3] - [4] +! +!```` + + subroutine json_value_insert_after(json,p,element) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p !! a value from a JSON structure +!! (presumably, this is a child of +!! an object or array). + type(json_value),pointer :: element !! the element to insert after `p` + + type(json_value),pointer :: parent !! the parent of `p` + type(json_value),pointer :: next !! temp pointer for traversing structure + type(json_value),pointer :: last !! the last of the items being inserted + integer :: n !! number of items being inserted + + if (.not. json%exception_thrown) then + + parent => p%parent + +! set first parent of inserted list: + element%parent => parent + +! Count the number of inserted elements. +! and set their parents. + n = 1 ! initialize counter + next => element%next + last => element + do + if (.not. associated(next)) exit + n = n + 1 + next%parent => parent + last => next + next => next%next + end do + + if (associated(parent)) then +! update parent's child counter: + parent%n_children = parent%n_children + n +! if p is last of parents children then +! also have to update parent tail pointer: + if (associated(parent%tail,p)) then + parent%tail => last + end if + end if + + if (associated(element%previous)) then +! element is apparently part of an existing list, +! so have to update that as well. + if (associated(element%previous%parent)) then + element%previous%parent%n_children = & + element%previous%parent%n_children - n + element%previous%parent%tail => & + element%previous ! now the last one in the list + else +! this would be a memory leak if the previous entries +! are not otherwise being pointed too +! [throw an error in this case???] + end if +!remove element from the other list: + element%previous%next => null() + end if + element%previous => p + + if (associated(p%next)) then +! if there are any in the list after p: + last%next => p%next + last%next%previous => element + else + last%next => null() + end if + p%next => element + + end if + + end subroutine json_value_insert_after +!***************************************************************************************** + +!***************************************************************************************** +!> +! Inserts `element` after the `idx`-th child of `p`, +! and updates the JSON structure accordingly. This is just +! a wrapper for [[json_value_insert_after]]. + + subroutine json_value_insert_after_child_by_index(json,p,idx,element) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p !! a JSON object or array. + integer(IK),intent(in) :: idx !! the index of the child of `p` to +!! insert the new element after +!! (this is a 1-based Fortran +!! style array index) + type(json_value),pointer :: element !! the element to insert + + type(json_value),pointer :: tmp !! for getting the `idx`-th child of `p` + + if (.not. json%exception_thrown) then + +! get the idx-th child of p: + call json%get_child(p,idx,tmp) + +! call json_value_insert_after: + if (.not. json%exception_thrown) call json%insert_after(tmp,element) + + end if + + end subroutine json_value_insert_after_child_by_index +!***************************************************************************************** + +!***************************************************************************************** +!> +! Add a new member (`json_value` pointer) to a JSON structure, given the path. +! +!@warning If the path points to an existing variable in the structure, +! then this routine will destroy it and replace it with the +! new value. + + subroutine json_add_member_by_path(json,me,path,p,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + type(json_value),pointer,intent(in) :: p !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + type(json_value),pointer :: tmp + character(kind=CK,len=:),allocatable :: name !! name of the variable + + if ( .not. json%exception_thrown ) then + + if (.not. associated(p)) then + call json%throw_exception('Error in json_add_member_by_path:'//& + ' Input pointer p is not associated.',found) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + if ( present(was_created) ) was_created = .false. + else + +! return a pointer to the path (possibly creating it) + call json%create(me,path,tmp,found,was_created) + + if (.not. associated(tmp)) then + + call json%throw_exception('Error in json_add_member_by_path:'//& + ' Unable to resolve path: '//trim(path),found) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + + else + + call json%info(tmp,name=name) + +! replace it with the new one: + call json%replace(tmp,p,destroy=.true.) + call json%rename(p,name) + + end if + + end if + + else + if ( present(found) ) found = .false. + if ( present(was_created) ) was_created = .false. + end if + + end subroutine json_add_member_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper to [[json_add_member_by_path]] where "path" is kind=CDK. + + subroutine wrap_json_add_member_by_path(json,me,path,p,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + type(json_value),pointer,intent(in) :: p !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%json_add_member_by_path(me,to_unicode(path),p,found,was_created) + + end subroutine wrap_json_add_member_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Add an integer value to a [[json_value]], given the path. +! +!@warning If the path points to an existing variable in the structure, +! then this routine will destroy it and replace it with the +! new value. + + subroutine json_add_integer_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + integer(IK),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + type(json_value),pointer :: p + type(json_value),pointer :: tmp + character(kind=CK,len=:),allocatable :: name !! variable name + + if ( .not. json%exception_thrown ) then + + nullify(p) + +! return a pointer to the path (possibly creating it) +! If the variable had to be created, then +! it will be a json_null variable. + call json%create(me,path,p,found,was_created) + + if (.not. associated(p)) then + + call json%throw_exception('Error in json_add_integer_by_path:'//& + ' Unable to resolve path: '//trim(path),found) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + + else + +!NOTE: a new object is created, and the old one +! is replaced and destroyed. This is to +! prevent memory leaks if the type is +! being changed (for example, if an array +! is being replaced with a scalar). + + if (p%var_type==json_integer) then + p%int_value = value + else + call json%info(p,name=name) + call json%create_integer(tmp,value,name) + call json%replace(p,tmp,destroy=.true.) + end if + + end if + + else + if ( present(found) ) found = .false. + if ( present(was_created) ) was_created = .false. + end if + + end subroutine json_add_integer_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper to [[json_add_integer_by_path]] where "path" is kind=CDK. + + subroutine wrap_json_add_integer_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + integer(IK),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%json_add_integer_by_path(me,to_unicode(path),value,found,was_created) + + end subroutine wrap_json_add_integer_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Add an real value to a [[json_value]], given the path. +! +!@warning If the path points to an existing variable in the structure, +! then this routine will destroy it and replace it with the +! new value. + + subroutine json_add_real_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + real(RK),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + type(json_value),pointer :: p + type(json_value),pointer :: tmp + character(kind=CK,len=:),allocatable :: name !! variable name + + if ( .not. json%exception_thrown ) then + + nullify(p) + +! return a pointer to the path (possibly creating it) +! If the variable had to be created, then +! it will be a json_null variable. + call json%create(me,path,p,found,was_created) + + if (.not. associated(p)) then + + call json%throw_exception('Error in json_add_real_by_path:'//& + ' Unable to resolve path: '//trim(path),found) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + + else + +!NOTE: a new object is created, and the old one +! is replaced and destroyed. This is to +! prevent memory leaks if the type is +! being changed (for example, if an array +! is being replaced with a scalar). + + if (p%var_type==json_real) then + p%dbl_value = value + else + call json%info(p,name=name) + call json%create_real(tmp,value,name) + call json%replace(p,tmp,destroy=.true.) + end if + + end if + + else + if ( present(found) ) found = .false. + if ( present(was_created) ) was_created = .false. + end if + + end subroutine json_add_real_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper to [[json_add_real_by_path]] where "path" is kind=CDK. + + subroutine wrap_json_add_real_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + real(RK),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%json_add_real_by_path(me,to_unicode(path),value,found,was_created) + + end subroutine wrap_json_add_real_by_path +!***************************************************************************************** + + +!***************************************************************************************** +!> +! Alternate version of [[json_add_real_by_path]] where value=real32. + + subroutine json_add_real32_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + real(real32),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%add_by_path(me,path,real(value,RK),found,was_created) + + end subroutine json_add_real32_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper to [[json_add_real32_by_path]] where "path" is kind=CDK. + + subroutine wrap_json_add_real32_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + real(real32),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%add_by_path(me,to_unicode(path),real(value,RK),found,was_created) + + end subroutine wrap_json_add_real32_by_path +!***************************************************************************************** + + +# 3942 + + +!***************************************************************************************** +!> +! Add a logical value to a [[json_value]], given the path. +! +!@warning If the path points to an existing variable in the structure, +! then this routine will destroy it and replace it with the +! new value. + + subroutine json_add_logical_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + logical(LK),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + type(json_value),pointer :: p + type(json_value),pointer :: tmp + character(kind=CK,len=:),allocatable :: name !! variable name + + if ( .not. json%exception_thrown ) then + + nullify(p) + +! return a pointer to the path (possibly creating it) +! If the variable had to be created, then +! it will be a json_null variable. + call json%create(me,path,p,found,was_created) + + if (.not. associated(p)) then + + call json%throw_exception('Error in json_add_logical_by_path:'//& + ' Unable to resolve path: '//trim(path),found) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + + else + +!NOTE: a new object is created, and the old one +! is replaced and destroyed. This is to +! prevent memory leaks if the type is +! being changed (for example, if an array +! is being replaced with a scalar). + + if (p%var_type==json_logical) then + p%log_value = value + else + call json%info(p,name=name) + call json%create_logical(tmp,value,name) + call json%replace(p,tmp,destroy=.true.) + end if + + end if + + else + if ( present(found) ) found = .false. + if ( present(was_created) ) was_created = .false. + end if + + end subroutine json_add_logical_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper to [[json_add_logical_by_path]] where "path" is kind=CDK. + + subroutine wrap_json_add_logical_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + logical(LK),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%json_add_logical_by_path(me,to_unicode(path),value,found,was_created) + + end subroutine wrap_json_add_logical_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Add a string value to a [[json_value]], given the path. +! +!@warning If the path points to an existing variable in the structure, +! then this routine will destroy it and replace it with the +! new value. + + subroutine json_add_string_by_path(json,me,path,value,found,& + was_created,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + character(kind=CK,len=*),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element + + type(json_value),pointer :: p + type(json_value),pointer :: tmp + character(kind=CK,len=:),allocatable :: name !! variable name + + if ( .not. json%exception_thrown ) then + + nullify(p) + +! return a pointer to the path (possibly creating it) +! If the variable had to be created, then +! it will be a json_null variable. + call json%create(me,path,p,found,was_created) + + if (.not. associated(p)) then + + call json%throw_exception('Error in json_add_string_by_path:'//& + ' Unable to resolve path: '//trim(path),found) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + + else + +!NOTE: a new object is created, and the old one +! is replaced and destroyed. This is to +! prevent memory leaks if the type is +! being changed (for example, if an array +! is being replaced with a scalar). + + if (p%var_type==json_string) then + p%str_value = value + else + call json%info(p,name=name) + call json%create_string(tmp,value,name,trim_str,adjustl_str) + call json%replace(p,tmp,destroy=.true.) + end if + + end if + + else + if ( present(found) ) found = .false. + if ( present(was_created) ) was_created = .false. + end if + + end subroutine json_add_string_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper to [[json_add_string_by_path]] where "path" is kind=CDK. + + subroutine wrap_json_add_string_by_path(json,me,path,value,found,& + was_created,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + character(kind=CDK,len=*),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element + + call json%json_add_string_by_path(me,to_unicode(path),to_unicode(value),& + found,was_created,trim_str,adjustl_str) + + end subroutine wrap_json_add_string_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper for [[json_add_string_by_path]] where "path" is kind=CDK. + + subroutine json_add_string_by_path_path_ascii(json,me,path,value,found,& + was_created,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + character(kind=CK,len=*),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element + + call json%json_add_string_by_path(me,to_unicode(path),value,found,was_created,trim_str,adjustl_str) + + end subroutine json_add_string_by_path_path_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper for [[json_add_string_by_path]] where "value" is kind=CDK. + + subroutine json_add_string_by_path_value_ascii(json,me,path,value,found,& + was_created,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + character(kind=CDK,len=*),intent(in) :: value !! the value to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element + + call json%json_add_string_by_path(me,path,to_unicode(value),found,was_created,trim_str,adjustl_str) + + end subroutine json_add_string_by_path_value_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper to [[json_add_integer_by_path]] for adding an integer vector by path. + + subroutine json_add_integer_vec_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + integer(IK),dimension(:),intent(in) :: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + type(json_value),pointer :: p !! pointer to path (which may exist) + type(json_value),pointer :: var !! new variable that is created + integer(IK) :: i !! counter + character(kind=CK,len=:),allocatable :: name !! the variable name + logical(LK) :: p_found !! if the path was successfully found (or created) + + if ( .not. json%exception_thrown ) then + +!get a pointer to the variable +!(creating it if necessary) + call json%create(me,path,p,found=p_found) + if (p_found) then + call json%info(p,name=name) ! want to keep the existing name + call json%create_array(var,name) ! create a new array variable + call json%replace(p,var,destroy=.true.) ! replace p with this array (destroy p) +!populate each element of the array: + do i=1,size(value) + call json%add(var, CK_'', value(i)) + end do + end if + + else + if ( present(found) ) found = .false. + if ( present(was_created) ) was_created = .false. + end if + + end subroutine json_add_integer_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper for [[json_add_integer_vec_by_path]] where "path" is kind=CDK). + + subroutine wrap_json_add_integer_vec_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + integer(IK),dimension(:),intent(in) :: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%json_add_integer_vec_by_path(me,to_unicode(path),value,found,was_created) + + end subroutine wrap_json_add_integer_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper to [[json_add_logical_by_path]] for adding a logical vector by path. + + subroutine json_add_logical_vec_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + logical(LK),dimension(:),intent(in) :: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + type(json_value),pointer :: p !! pointer to path (which may exist) + type(json_value),pointer :: var !! new variable that is created + integer(IK) :: i !! counter + character(kind=CK,len=:),allocatable :: name !! the variable name + logical(LK) :: p_found !! if the path was successfully found (or created) + + if ( .not. json%exception_thrown ) then + +!get a pointer to the variable +!(creating it if necessary) + call json%create(me,path,p,found=p_found) + if (p_found) then + call json%info(p,name=name) ! want to keep the existing name + call json%create_array(var,name) ! create a new array variable + call json%replace(p,var,destroy=.true.) ! replace p with this array (destroy p) +!populate each element of the array: + do i=1,size(value) + call json%add(var, CK_'', value(i)) + end do + end if + + else + if ( present(found) ) found = .false. + if ( present(was_created) ) was_created = .false. + end if + + end subroutine json_add_logical_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper for [[json_add_logical_vec_by_path]] where "path" is kind=CDK). + + subroutine wrap_json_add_logical_vec_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + logical(LK),dimension(:),intent(in) :: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%json_add_logical_vec_by_path(me,to_unicode(path),value,found,was_created) + + end subroutine wrap_json_add_logical_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper to [[json_add_real_by_path]] for adding a real vector by path. + + subroutine json_add_real_vec_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + real(RK),dimension(:),intent(in) :: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + type(json_value),pointer :: p !! pointer to path (which may exist) + type(json_value),pointer :: var !! new variable that is created + integer(IK) :: i !! counter + character(kind=CK,len=:),allocatable :: name !! the variable name + logical(LK) :: p_found !! if the path was successfully found (or created) + + if ( .not. json%exception_thrown ) then + +!get a pointer to the variable +!(creating it if necessary) + call json%create(me,path,p,found=p_found) + if (p_found) then + call json%info(p,name=name) ! want to keep the existing name + call json%create_array(var,name) ! create a new array variable + call json%replace(p,var,destroy=.true.) ! replace p with this array (destroy p) +!populate each element of the array: + do i=1,size(value) + call json%add(var, CK_'', value(i)) + end do + end if + + else + if ( present(found) ) found = .false. + if ( present(was_created) ) was_created = .false. + end if + + end subroutine json_add_real_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper for [[json_add_real_vec_by_path]] where "path" is kind=CDK). + + subroutine wrap_json_add_real_vec_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + real(RK),dimension(:),intent(in) :: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%json_add_real_vec_by_path(me,to_unicode(path),value,found,was_created) + + end subroutine wrap_json_add_real_vec_by_path +!***************************************************************************************** + + +!***************************************************************************************** +!> +! Wrapper to [[json_add_real_by_path]] for adding a real vector by path. + + subroutine json_add_real32_vec_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + real(real32),dimension(:),intent(in) :: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%add_by_path(me,path,real(value,RK),found,was_created) + + end subroutine json_add_real32_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper for [[json_add_real32_vec_by_path]] where "path" is kind=CDK). + + subroutine wrap_json_add_real32_vec_by_path(json,me,path,value,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + real(real32),dimension(:),intent(in) :: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + + call json%add_by_path(me,to_unicode(path),real(value,RK),found,was_created) + + end subroutine wrap_json_add_real32_vec_by_path +!***************************************************************************************** + + +# 4445 + + +!***************************************************************************************** +!> +! Wrapper to [[json_add_string_by_path]] for adding a string vector by path. +! +!@note The `ilen` input can be used to specify the actual lengths of the +! the strings in the array. They must all be `<= len(value)`. + + subroutine json_add_string_vec_by_path(json,me,path,value,found,was_created,ilen,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + character(kind=CK,len=*),dimension(:),intent(in) :: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + integer(IK),dimension(:),intent(in),optional :: ilen !! the string lengths of each +!! element in `value`. If not present, +!! the full `len(value)` string is added +!! for each element. + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element + + type(json_value),pointer :: p !! pointer to path (which may exist) + type(json_value),pointer :: var !! new variable that is created + integer(IK) :: i !! counter + character(kind=CK,len=:),allocatable :: name !! the variable name + logical(LK) :: p_found !! if the path was successfully found (or created) + + if ( .not. json%exception_thrown ) then + +! validate ilen array if present: + if (present(ilen)) then + if (size(ilen)/=size(value)) then + call json%throw_exception('Error in json_add_string_vec_by_path: '//& + 'Invalid size of ilen input vector.',found) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + if (present(was_created)) was_created = .false. + return + else +! also have to validate the specified lengths. +! (must not be greater than input string length) + do i = 1, size(value) + if (ilen(i)>len(value)) then + call json%throw_exception('Error in json_add_string_vec_by_path: '//& + 'Invalid ilen element.',found) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + if (present(was_created)) was_created = .false. + return + end if + end do + end if + end if + +!get a pointer to the variable +!(creating it if necessary) + call json%create(me,path,p,found=p_found) + if (p_found) then + call json%info(p,name=name) ! want to keep the existing name + call json%create_array(var,name) ! create a new array variable + call json%replace(p,var,destroy=.true.) ! replace p with this array (destroy p) +!populate each element of the array: + do i=1,size(value) + if (present(ilen)) then + call json%add(var, CK_'', value(i)(1:ilen(i)), & + trim_str=trim_str, adjustl_str=adjustl_str) + else + call json%add(var, CK_'', value(i), & + trim_str=trim_str, adjustl_str=adjustl_str) + end if + end do + end if + + else + if ( present(found) ) found = .false. + if ( present(was_created) ) was_created = .false. + end if + + end subroutine json_add_string_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper for [[json_add_string_vec_by_path]] where "path" and "value" are kind=CDK). + + subroutine wrap_json_add_string_vec_by_path(json,me,path,value,& + found,was_created,ilen,& + trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + character(kind=CDK,len=*),dimension(:),intent(in):: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + integer(IK),dimension(:),intent(in),optional :: ilen !! the string lengths of each +!! element in `value`. If not present, +!! the full `len(value)` string is added +!! for each element. + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element + + call json%json_add_string_vec_by_path(me,to_unicode(path),to_unicode(value),& + found,was_created,ilen,trim_str,adjustl_str) + + end subroutine wrap_json_add_string_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper for [[json_add_string_vec_by_path]] where "value" is kind=CDK). + + subroutine json_add_string_vec_by_path_value_ascii(json,me,path,value,& + found,was_created,ilen,& + trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CK,len=*),intent(in) :: path !! the path to the variable + character(kind=CDK,len=*),dimension(:),intent(in):: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + integer(IK),dimension(:),intent(in),optional :: ilen !! the string lengths of each +!! element in `value`. If not present, +!! the full `len(value)` string is added +!! for each element. + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element + + call json%json_add_string_vec_by_path(me,path,to_unicode(value),& + found,was_created,ilen,trim_str,adjustl_str) + + end subroutine json_add_string_vec_by_path_value_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper for [[json_add_string_vec_by_path]] where "path" is kind=CDK). + + subroutine json_add_string_vec_by_path_path_ascii(json,me,path,value,& + found,was_created,ilen,& + trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me !! the JSON structure + character(kind=CDK,len=*),intent(in) :: path !! the path to the variable + character(kind=CK,len=*),dimension(:),intent(in) :: value !! the vector to add + logical(LK),intent(out),optional :: found !! if the variable was found + logical(LK),intent(out),optional :: was_created !! if the variable had to be created + integer(IK),dimension(:),intent(in),optional :: ilen !! the string lengths of each +!! element in `value`. If not present, +!! the full `len(value)` string is added +!! for each element. + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element + + call json%json_add_string_vec_by_path(me,to_unicode(path),value,& + found,was_created,ilen,trim_str,adjustl_str) + + end subroutine json_add_string_vec_by_path_path_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 1/19/2014 +! +! Add a real value child to the [[json_value]] variable. +! +!@note This routine is part of the public API that can be +! used to build a JSON structure using [[json_value]] pointers. + + subroutine json_value_add_real(json,p,name,val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name !! variable name + real(RK),intent(in) :: val !! real value + + type(json_value),pointer :: var + +!create the variable: + call json%create_real(var,val,name) + +!add it: + call json%add(p, var) + + end subroutine json_value_add_real +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_real]] where `name` is kind=CDK. + + subroutine wrap_json_value_add_real(json,p,name,val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name !! variable name + real(RK),intent(in) :: val !! real value + + call json%add(p, to_unicode(name), val) + + end subroutine wrap_json_value_add_real +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 1/20/2014 +! +! Add a real vector child to the [[json_value]] variable. +! +!@note This routine is part of the public API that can be +! used to build a JSON structure using [[json_value]] pointers. + + subroutine json_value_add_real_vec(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name + real(RK),dimension(:),intent(in) :: val + + type(json_value),pointer :: var + integer(IK) :: i !! counter + +!create the variable as an array: + call json%create_array(var,name) + +!populate the array: + do i=1,size(val) + call json%add(var, CK_'', val(i)) + end do + +!add it: + call json%add(p, var) + + end subroutine json_value_add_real_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_real_vec]] where `name` is kind=CDK. + + subroutine wrap_json_value_add_real_vec(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name + real(RK),dimension(:),intent(in) :: val + + call json%add(p, to_unicode(name), val) + + end subroutine wrap_json_value_add_real_vec +!***************************************************************************************** + + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_real]] where `val` is `real32`. + + subroutine json_value_add_real32(json,p,name,val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name !! variable name + real(real32),intent(in) :: val !! real value + + call json%add(p,name,real(val,RK)) + + end subroutine json_value_add_real32 +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_real32]] where `name` is kind=CDK. + + subroutine wrap_json_value_add_real32(json,p,name,val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name !! variable name + real(real32),intent(in) :: val !! real value + + call json%add(p, to_unicode(name), val) + + end subroutine wrap_json_value_add_real32 +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_real_vec]] where `val` is `real32`. + + subroutine json_value_add_real32_vec(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name + real(real32),dimension(:),intent(in) :: val + + call json%add(p,name,real(val,RK)) + + end subroutine json_value_add_real32_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_real32_vec]] where `name` is kind=CDK. + + subroutine wrap_json_value_add_real32_vec(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name + real(real32),dimension(:),intent(in) :: val + + call json%add(p, to_unicode(name), val) + + end subroutine wrap_json_value_add_real32_vec +!***************************************************************************************** + + +# 4868 + + +!***************************************************************************************** +!> +! Add a NULL value child to the [[json_value]] variable. +! +!@note This routine is part of the public API that can be +! used to build a JSON structure using [[json_value]] pointers. + + subroutine json_value_add_null(json, p, name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name + + type(json_value),pointer :: var + +!create the variable: + call json%create_null(var,name) + +!add it: + call json%add(p, var) + + end subroutine json_value_add_null +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_null]] where `name` is kind=CDK. + + subroutine wrap_json_value_add_null(json, p, name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name !! name of the variable + + call json%add(p, to_unicode(name)) + + end subroutine wrap_json_value_add_null +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 1/20/2014 +! +! Add an integer value child to the [[json_value]] variable. +! +!@note This routine is part of the public API that can be +! used to build a JSON structure using [[json_value]] pointers. + + subroutine json_value_add_integer(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name + integer(IK),intent(in) :: val + + type(json_value),pointer :: var + +!create the variable: + call json%create_integer(var,val,name) + +!add it: + call json%add(p, var) + + end subroutine json_value_add_integer +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_integer]] where `name` is kind=CDK. + + subroutine wrap_json_value_add_integer(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name !! name of the variable + integer(IK),intent(in) :: val !! value + + call json%add(p, to_unicode(name), val) + + end subroutine wrap_json_value_add_integer +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 1/20/2014 +! +! Add a integer vector child to the [[json_value]] variable. +! +!@note This routine is part of the public API that can be +! used to build a JSON structure using [[json_value]] pointers. + + subroutine json_value_add_integer_vec(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name !! name of the variable + integer(IK),dimension(:),intent(in) :: val !! value + + type(json_value),pointer :: var + integer(IK) :: i !! counter + +!create a variable as an array: + call json%create_array(var,name) + +!populate the array: + do i=1,size(val) + call json%add(var, CK_'', val(i)) + end do + +!add it: + call json%add(p, var) + + end subroutine json_value_add_integer_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_integer_vec]] where `name` is kind=CDK. + + subroutine wrap_json_value_add_integer_vec(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name !! name of the variable + integer(IK),dimension(:),intent(in) :: val !! value + + call json%add(p, to_unicode(name), val) + + end subroutine wrap_json_value_add_integer_vec +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 1/20/2014 +! +! Add a logical value child to the [[json_value]] variable. +! +!@note This routine is part of the public API that can be +! used to build a JSON structure using [[json_value]] pointers. + + subroutine json_value_add_logical(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name !! name of the variable + logical(LK),intent(in) :: val !! value + + type(json_value),pointer :: var + +!create the variable: + call json%create_logical(var,val,name) + +!add it: + call json%add(p, var) + + end subroutine json_value_add_logical +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_logical]] where `name` is kind=CDK. + + subroutine wrap_json_value_add_logical(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name !! name of the variable + logical(LK),intent(in) :: val !! value + + call json%add(p, to_unicode(name), val) + + end subroutine wrap_json_value_add_logical +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 1/20/2014 +! +! Add a logical vector child to the [[json_value]] variable. +! +!@note This routine is part of the public API that can be +! used to build a JSON structure using [[json_value]] pointers. + + subroutine json_value_add_logical_vec(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name !! name of the vector + logical(LK),dimension(:),intent(in) :: val !! value + + type(json_value),pointer :: var + integer(IK) :: i !! counter + +!create the variable as an array: + call json%create_array(var,name) + +!populate the array: + do i=1,size(val) + call json%add(var, CK_'', val(i)) + end do + +!add it: + call json%add(p, var) + + end subroutine json_value_add_logical_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_logical_vec]] where `name` is kind=CDK. + + subroutine wrap_json_value_add_logical_vec(json, p, name, val) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name !! name of the variable + logical(LK),dimension(:),intent(in) :: val !! value + + call json%add(p, to_unicode(name), val) + + end subroutine wrap_json_value_add_logical_vec +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 1/19/2014 +! +! Add a character string child to the [[json_value]] variable. +! +!@note This routine is part of the public API that can be +! used to build a JSON structure using [[json_value]] pointers. + + subroutine json_value_add_string(json, p, name, val, trim_str, adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name !! name of the variable + character(kind=CK,len=*),intent(in) :: val !! value + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` + + type(json_value),pointer :: var + +!create the variable: + call json%create_string(var,val,name,trim_str,adjustl_str) + +!add it: + call json%add(p, var) + + end subroutine json_value_add_string +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_string]] where `name` and `val` are kind=CDK. + + subroutine wrap_json_value_add_string(json, p, name, val, trim_str, adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name !! name of the variable + character(kind=CDK,len=*),intent(in) :: val !! value + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` + + call json%add(p, to_unicode(name), to_unicode(val), trim_str, adjustl_str) + + end subroutine wrap_json_value_add_string +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_string]] where `name` is kind=CDK. + + subroutine json_value_add_string_name_ascii(json, p, name, val, trim_str, adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name !! name of the variable + character(kind=CK, len=*),intent(in) :: val !! value + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` + + call json%add(p, to_unicode(name), val, trim_str, adjustl_str) + + end subroutine json_value_add_string_name_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_string]] where `val` is kind=CDK. + + subroutine json_value_add_string_val_ascii(json, p, name, val, trim_str, adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK, len=*),intent(in) :: name !! name of the variable + character(kind=CDK,len=*),intent(in) :: val !! value + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` + + call json%add(p, name, to_unicode(val), trim_str, adjustl_str) + + end subroutine json_value_add_string_val_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 1/19/2014 +! +! Add a character string vector child to the [[json_value]] variable. +! +!@note This routine is part of the public API that can be +! used to build a JSON structure using [[json_value]] pointers. + + subroutine json_value_add_string_vec(json, p, name, val, trim_str, adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name !! variable name + character(kind=CK,len=*),dimension(:),intent(in) :: val !! array of strings + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element + + type(json_value),pointer :: var + integer(IK) :: i !! counter + +!create the variable as an array: + call json%create_array(var,name) + +!populate the array: + do i=1,size(val) + call json%add(var, CK_'', val(i), trim_str, adjustl_str) + end do + +!add it: + call json%add(p, var) + + end subroutine json_value_add_string_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_string_vec]] where `name` and `val` are kind=CDK. + + subroutine wrap_json_value_add_string_vec(json, p, name, val, trim_str, adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name + character(kind=CDK,len=*),dimension(:),intent(in) :: val + logical(LK),intent(in),optional :: trim_str + logical(LK),intent(in),optional :: adjustl_str + + call json%add(p, to_unicode(name), to_unicode(val), trim_str, adjustl_str) + + end subroutine wrap_json_value_add_string_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_string_vec]] where `name` is kind=CDK. + + subroutine json_value_add_string_vec_name_ascii(json, p, name, val, trim_str, adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name + character(kind=CK, len=*),dimension(:),intent(in) :: val + logical(LK),intent(in),optional :: trim_str + logical(LK),intent(in),optional :: adjustl_str + + call json%add(p, to_unicode(name), val, trim_str, adjustl_str) + + end subroutine json_value_add_string_vec_name_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_add_string_vec]] where `val` is kind=CDK. + + subroutine json_value_add_string_vec_val_ascii(json, p, name, val, trim_str, adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK, len=*),intent(in) :: name + character(kind=CDK,len=*),dimension(:),intent(in) :: val + logical(LK),intent(in),optional :: trim_str + logical(LK),intent(in),optional :: adjustl_str + + call json%add(p, name, to_unicode(val), trim_str, adjustl_str) + + end subroutine json_value_add_string_vec_val_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> +! Count the number of children in the object or array. +! +!### History +! * JW : 1/4/2014 : Original routine removed. +! Now using `n_children` variable. +! Renamed from `json_value_count`. + + function json_count(json,p) result(count) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! this should normally be a `json_object` +!! or a `json_array`. For any other +!! variable type this will return 0. + integer(IK) :: count !! number of children in `p`. + + if (associated(p)) then + count = p%n_children + else + call json%throw_exception('Error in json_count: '//& + 'pointer is not associated.') + end if + + end function json_count +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 10/16/2015 +! +! Returns a pointer to the parent of a [[json_value]]. +! If there is no parent, then a `null()` pointer is returned. + + subroutine json_get_parent(json,p,parent) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! JSON object + type(json_value),pointer,intent(out) :: parent !! pointer to `parent` + + if (associated(p)) then + parent => p%parent + else + nullify(parent) + call json%throw_exception('Error in json_get_parent: '//& + 'pointer is not associated.') + end if + + end subroutine json_get_parent +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 10/31/2015 +! +! Returns a pointer to the next of a [[json_value]]. +! If there is no next, then a `null()` pointer is returned. + + subroutine json_get_next(json,p,next) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! JSON object + type(json_value),pointer,intent(out) :: next !! pointer to `next` + + if (associated(p)) then + next => p%next + else + nullify(next) + call json%throw_exception('Error in json_get_next: '//& + 'pointer is not associated.') + end if + + end subroutine json_get_next +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 10/31/2015 +! +! Returns a pointer to the previous of a [[json_value]]. +! If there is no previous, then a `null()` pointer is returned. + + subroutine json_get_previous(json,p,previous) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! JSON object + type(json_value),pointer,intent(out) :: previous !! pointer to `previous` + + if (associated(p)) then + previous => p%previous + else + nullify(previous) + call json%throw_exception('Error in json_get_previous: '//& + 'pointer is not associated.') + end if + + end subroutine json_get_previous +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 10/31/2015 +! +! Returns a pointer to the tail of a [[json_value]] +! (the last child of an array of object). +! If there is no tail, then a `null()` pointer is returned. + + subroutine json_get_tail(json,p,tail) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! JSON object + type(json_value),pointer,intent(out) :: tail !! pointer to `tail` + + if (associated(p)) then + tail => p%tail + else + nullify(tail) + call json%throw_exception('Error in json_get_tail: '//& + 'pointer is not associated.') + end if + + end subroutine json_get_tail +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns a child in the object or array given the index. + + subroutine json_value_get_child_by_index(json, p, idx, child, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! object or array JSON data + integer(IK),intent(in) :: idx !! index of the child +!! (this is a 1-based Fortran +!! style array index). + type(json_value),pointer :: child !! pointer to the child + logical(LK),intent(out),optional :: found !! true if the value was found +!! (if not present, an exception +!! will be thrown if it was not +!! found. If present and not +!! found, no exception will be +!! thrown). + + integer(IK) :: i !! counter + + nullify(child) + + if (.not. json%exception_thrown) then + + if (associated(p%children)) then + +! If getting first or last child, we can do this quickly. +! Otherwise, traverse the list. + if (idx==1) then + + child => p%children ! first one + + elseif (idx==p%n_children) then + + if (associated(p%tail)) then + child => p%tail ! last one + else + call json%throw_exception('Error in json_value_get_child_by_index:'//& + ' child%tail is not associated.',found) + end if + + elseif (idx<1 .or. idx>p%n_children) then + + call json%throw_exception('Error in json_value_get_child_by_index:'//& + ' idx is out of range.',found) + + else + +! if idx is closer to the end, we traverse the list backward from tail, +! otherwise we traverse it forward from children: + + if (p%n_children-idx < idx) then ! traverse backward + + child => p%tail + + do i = 1, p%n_children - idx + + if (associated(child%previous)) then + child => child%previous + else + call json%throw_exception('Error in json_value_get_child_by_index:'//& + ' child%previous is not associated.',found) + nullify(child) + exit + end if + + end do + + else ! traverse forward + + child => p%children + + do i = 1, idx - 1 + + if (associated(child%next)) then + child => child%next + else + call json%throw_exception('Error in json_value_get_child_by_index:'//& + ' child%next is not associated.',found) + nullify(child) + exit + end if + + end do + + end if + + end if + + else + + call json%throw_exception('Error in json_value_get_child_by_index:'//& + ' p%children is not associated.',found) + + end if + +! found output: + if (json%exception_thrown) then + if (present(found)) then + call json%clear_exceptions() + found = .false. + end if + else + if (present(found)) found = .true. + end if + + else + if (present(found)) found = .false. + end if + + end subroutine json_value_get_child_by_index +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns pointer to the first child of the object +! (or `null()` if it is not associated). + + subroutine json_value_get_child(json, p, child) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! object or array JSON data + type(json_value),pointer :: child !! pointer to the child + + if (associated(p)) then + child => p%children + else + nullify(child) + call json%throw_exception('Error in json_value_get_child: '//& + 'pointer is not associated.') + end if + + end subroutine json_value_get_child +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns a child in the object or array given the name string. +! +! The name search can be case-sensitive or not, and can have significant trailing +! whitespace or not, depending on the settings in the [[json_core(type)]] class. +! +!@note The `name` input is not a path, and is not parsed like it is in [[json_get_by_path]]. + + subroutine json_value_get_child_by_name(json, p, name, child, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + character(kind=CK,len=*),intent(in) :: name !! the name of a child of `p` + type(json_value),pointer :: child !! pointer to the child + logical(LK),intent(out),optional :: found !! true if the value was found +!! (if not present, an exception +!! will be thrown if it was not +!! found. If present and not +!! found, no exception will be +!! thrown). + + integer(IK) :: i,n_children + logical :: error + + nullify(child) + + if (.not. json%exception_thrown) then + + if (associated(p)) then + + error = .true. ! will be false if it is found + if (p%var_type==json_object) then + n_children = json%count(p) + child => p%children !start with first one + do i=1, n_children + if (.not. associated(child)) then + call json%throw_exception(& + 'Error in json_value_get_child_by_name: '//& + 'Malformed JSON linked list',found) + exit + end if + if (allocated(child%name)) then +!name string matching routine: + if (json%name_equal(child,name)) then + error = .false. + exit + end if + end if + child => child%next + end do + end if + + if (error) then +!did not find anything: + call json%throw_exception(& + 'Error in json_value_get_child_by_name: '//& + 'child variable '//trim(name)//' was not found.',found) + nullify(child) + end if + + else + call json%throw_exception(& + 'Error in json_value_get_child_by_name: '//& + 'pointer is not associated.',found) + end if + +! found output: + if (json%exception_thrown) then + if (present(found)) then + call json%clear_exceptions() + found = .false. + end if + else + if (present(found)) found = .true. + end if + + else + if (present(found)) found = .false. + end if + + end subroutine json_value_get_child_by_name +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 8/25/2017 +! +! Checks a JSON object for duplicate child names. +! +! It uses the specified settings for name matching (see [[name_strings_equal]]). +! +!@note This will only check for one duplicate, +! it will return the first one that it finds. + + subroutine json_check_children_for_duplicate_keys(json,p,has_duplicate,name,path) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! the object to search. If `p` is +!! not a `json_object`, then `has_duplicate` +!! will be false. + logical(LK),intent(out) :: has_duplicate !! true if there is at least +!! two children have duplicate +!! `name` values. + character(kind=CK,len=:),allocatable,intent(out),optional :: name !! the duplicate name +!! (unallocated if no +!! duplicate was found) + character(kind=CK,len=:),allocatable,intent(out),optional :: path !! the full path to the +!! duplicate name +!! (unallocated if no +!! duplicate was found) + + integer(IK) :: i !! counter + integer(IK) :: j !! counter + type(json_value),pointer :: child !! pointer to a child of `p` + integer(IK) :: n_children !! number of children of `p` + logical(LK) :: found !! flag for `get_child` + + type :: alloc_str +!! so we can have an array of allocatable strings + character(kind=CK,len=:),allocatable :: str !! name string + end type alloc_str + type(alloc_str),dimension(:),allocatable :: names !! array of all the +!! child name strings + +! initialize: + has_duplicate =.false. + + if (.not. json%exception_thrown) then + + if (associated(p)) then + + if (p%var_type==json_object) then + +! number of items to check: + n_children = json%count(p) + allocate(names(n_children)) + +! first get a list of all the name keys: + do i=1, n_children + call json%get_child(p,i,child,found) ! get by index + if (.not. found) then + call json%throw_exception(& + 'Error in json_check_children_for_duplicate_keys: '//& + 'Malformed JSON linked list') + exit + end if + if (allocated(child%name)) then + names(i)%str = child%name + else + call json%throw_exception(& + 'Error in json_check_children_for_duplicate_keys: '//& + 'Object child name is not allocated') + exit + end if + end do + + if (.not. json%exception_thrown) then +! now check the list for duplicates: + main: do i=1,n_children + do j=1,i-1 + if (json%name_strings_equal(names(i)%str,names(j)%str)) then + has_duplicate = .true. + if (present(name)) then + name = names(i)%str + end if + if (present(path)) then + call json%get_child(p,names(i)%str,child,found) ! get by name + if (found) then + call json%get_path(child,path,found) + if (.not. found) then +! should never happen since we know it is there + call json%throw_exception(& + 'Error in json_check_children_for_duplicate_keys: '//& + 'Could not get path') + end if + else +! should never happen since we know it is there + call json%throw_exception(& + 'Error in json_check_children_for_duplicate_keys: '//& + 'Could not get child: '//trim(names(i)%str)) + end if + end if + exit main + end if + end do + end do main + end if + +! cleanup + do i=1,n_children + if (allocated(names(i)%str)) deallocate(names(i)%str) + end do + if (allocated(names)) deallocate(names) + + end if + + end if + + end if + + end subroutine json_check_children_for_duplicate_keys +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 8/25/2017 +! +! Checks a JSON structure for duplicate child names. +! This one recursively traverses the entire structure +! (calling [[json_check_children_for_duplicate_keys]] +! recursively for each element). +! +!@note This will only check for one duplicate, +! it will return the first one that it finds. + + subroutine json_check_all_for_duplicate_keys(json,p,has_duplicate,name,path) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! the object to search. If `p` is +!! not a `json_object`, then `has_duplicate` +!! will be false. + logical(LK),intent(out) :: has_duplicate !! true if there is at least +!! one duplicate `name` key anywhere +!! in the structure. + character(kind=CK,len=:),allocatable,intent(out),optional :: name !! the duplicate name +!! (unallocated if no +!! duplicates were found) + character(kind=CK,len=:),allocatable,intent(out),optional :: path !! the full path to the +!! duplicate name +!! (unallocated if no +!! duplicate was found) + + has_duplicate = .false. + if (.not. json%exception_thrown) then + call json%traverse(p,duplicate_key_func) + end if + + contains + + subroutine duplicate_key_func(json,p,finished) + +!! Callback function to check each element +!! for duplicate child names. + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + logical(LK),intent(out) :: finished + +# 5854 + + call json%check_children_for_duplicate_keys(p,has_duplicate,name,path) + + + finished = has_duplicate .or. json%exception_thrown + + end subroutine duplicate_key_func + + end subroutine json_check_all_for_duplicate_keys +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_get_child_by_name]] where `name` is kind=CDK. + + subroutine wrap_json_value_get_child_by_name(json, p, name, child, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + character(kind=CDK,len=*),intent(in) :: name + type(json_value),pointer :: child + logical(LK),intent(out),optional :: found + + call json%get(p,to_unicode(name),child,found) + + end subroutine wrap_json_value_get_child_by_name +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 2/12/2014 +! +! Print the [[json_value]] structure to an allocatable string. + + subroutine json_value_to_string(json,p,str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + character(kind=CK,len=:),intent(out),allocatable :: str !! prints structure to this string + + integer(IK) :: iloc !! used to keep track of size of str +!! since it is being allocated in chunks. + + str = repeat(space, print_str_chunk_size) + iloc = 0_IK + call json%json_value_print(p, iunit=unit2str, str=str, iloc=iloc, indent=1_IK, colon=.true.) + +! trim the string if necessary: + if (len(str)>iloc) str = str(1:iloc) + + end subroutine json_value_to_string +!***************************************************************************************** + +!***************************************************************************************** +!> +! Print the [[json_value]] structure to the console (`output_unit`). +! +!### Note +! * Just a wrapper for [[json_print_to_unit]]. + + subroutine json_print_to_console(json,p) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + + call json%print(p,int(output_unit,IK)) + + end subroutine json_print_to_console +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 6/20/2014 +! +! Print the [[json_value]] structure to a file. + + subroutine json_print_to_unit(json,p,iunit) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + integer(IK),intent(in) :: iunit !! the file unit (the file must +!! already have been opened, can't be -1). + + character(kind=CK,len=:),allocatable :: dummy !! dummy for `str` argument +!! to [[json_value_print]] + integer(IK) :: idummy !! dummy for `iloc` argument +!! to [[json_value_print]] + + if (iunit/=unit2str) then + idummy = 0_IK + call json%json_value_print(p,iunit,str=dummy,iloc=idummy,indent=1_IK,colon=.true.) + else + call json%throw_exception('Error in json_print_to_unit: iunit must not be -1.') + end if + + end subroutine json_print_to_unit +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/23/2014 +! +! Print the [[json_value]] structure to a file. + + subroutine json_print_to_filename(json,p,filename) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + character(kind=CDK,len=*),intent(in) :: filename !! the filename to print to +!! (should not already be open) + + integer(IK) :: iunit !! file unit for `open` statement + integer(IK) :: istat !! `iostat` code for `open` statement + + open(newunit=iunit,file=filename,status='REPLACE',iostat=istat ) + if (istat==0) then + call json%print(p,iunit) + close(iunit,iostat=istat) + else + call json%throw_exception('Error in json_print_to_filename: could not open file: '//& + trim(filename)) + end if + + end subroutine json_print_to_filename +!***************************************************************************************** + +!***************************************************************************************** +!> +! Print the JSON structure to a string or a file. +! +!### Notes +! * This is an internal routine called by the various wrapper routines. +! * The reason the `str` argument is non-optional is because of a +! bug in v4.9 of the gfortran compiler. + + recursive subroutine json_value_print(json,p,iunit,str,indent,& + need_comma,colon,is_array_element,& + is_compressed_vector,iloc) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + integer(IK),intent(in) :: iunit !! file unit to write to (the +!! file is assumed to be open) + integer(IK),intent(in),optional :: indent !! indention level + logical(LK),intent(in),optional :: is_array_element !! if this is an array element + logical(LK),intent(in),optional :: need_comma !! if it needs a comma after it + logical(LK),intent(in),optional :: colon !! if the colon was just written + character(kind=CK,len=:),intent(inout),allocatable :: str +!! if `iunit==unit2str` (-1) then +!! the structure is printed to this +!! string rather than a file. This mode +!! is used by [[json_value_to_string]]. + integer(IK),intent(inout) :: iloc !! current index in `str`. should be set to 0 initially. +!! [only used when `str` is used.] + logical(LK),intent(in),optional :: is_compressed_vector !! if True, this is an element +!! from an array being printed +!! on one line [default is False] + + character(kind=CK,len=max_numeric_str_len) :: tmp !! for value to string conversions + character(kind=CK,len=:),allocatable :: s_indent !! the string of spaces for +!! indenting (see `tab` and `spaces`) + character(kind=CK,len=:),allocatable :: s !! the string appended to `str` + type(json_value),pointer :: element !! for getting children + integer(IK) :: tab !! number of `tabs` for indenting + integer(IK) :: spaces !! number of spaces for indenting + integer(IK) :: i !! counter + integer(IK) :: count !! number of children + logical(LK) :: print_comma !! if the comma will be printed after the value + logical(LK) :: write_file !! if we are writing to a file + logical(LK) :: write_string !! if we are writing to a string + logical(LK) :: is_array !! if this is an element in an array + logical(LK) :: is_vector !! if all elements of a vector +!! are scalars of the same type + character(kind=CK,len=:),allocatable :: str_escaped !! escaped version of +!! `name` or `str_value` + + if (.not. json%exception_thrown) then + + if (.not. associated(p)) then +! note: a null() pointer will trigger this error. +! However, if the pointer is undefined, then this will +! crash (if this wasn't here it would crash below when +! we try to access the contents) + call json%throw_exception('Error in json_value_print: '//& + 'the pointer is not associated') + return + end if + + if (present(is_compressed_vector)) then + is_vector = is_compressed_vector + else + is_vector = .false. + end if + +!whether to write a string or a file (one or the other): + write_string = (iunit==unit2str) + write_file = .not. write_string + +!if the comma will be printed after the value +! [comma not printed for the last elements] + if (present(need_comma)) then + print_comma = need_comma + else + print_comma = .false. + end if + +!number of "tabs" to indent: + if (present(indent) .and. .not. json%no_whitespace) then + tab = indent + else + tab = 0 + end if +!convert to number of spaces: + spaces = tab*json%spaces_per_tab + +!if this is an element in an array: + if (present(is_array_element)) then + is_array = is_array_element + else + is_array = .false. + end if + +!if the colon was the last thing written + if (present(colon)) then + s_indent = CK_'' + else + s_indent = repeat(space, spaces) + end if + + select case (p%var_type) + + case (json_object) + + count = json%count(p) + + if (count==0) then !special case for empty object + + s = s_indent//start_object//end_object + call write_it( comma=print_comma ) + + else + + s = s_indent//start_object + call write_it() + +!if an object is in an array, there is an extra tab: + if (is_array) then + if ( .not. json%no_whitespace) tab = tab+1 + spaces = tab*json%spaces_per_tab + end if + + nullify(element) + element => p%children + do i = 1, count + + if (.not. associated(element)) then + call json%throw_exception('Error in json_value_print: '//& + 'Malformed JSON linked list') + return + end if + +! print the name + if (allocated(element%name)) then + call escape_string(element%name,str_escaped,json%escape_solidus) + if (json%no_whitespace) then +!compact printing - no extra space + s = repeat(space, spaces)//quotation_mark//& + str_escaped//quotation_mark//colon_char + call write_it(advance=.false.) + else + s = repeat(space, spaces)//quotation_mark//& + str_escaped//quotation_mark//colon_char//space + call write_it(advance=.false.) + end if + else + call json%throw_exception('Error in json_value_print:'//& + ' element%name not allocated') + nullify(element) + return + end if + +! recursive print of the element + call json%json_value_print(element, iunit=iunit, indent=tab + 1_IK, & + need_comma=i element%next + + end do + +! [one fewer tab if it isn't an array element] + if (.not. is_array) then + s = repeat(space, max(0_IK,spaces-json%spaces_per_tab))//end_object + else + s = s_indent//end_object + end if + call write_it( comma=print_comma ) + nullify(element) + + end if + + case (json_array) + + count = json%count(p) + + if (count==0) then ! special case for empty array + + s = s_indent//start_array//end_array + call write_it( comma=print_comma ) + + else + +! if every child is the same type & a scalar: + is_vector = json%is_vector(p) + if (json%failed()) return + + s = s_indent//start_array + call write_it( advance=(.not. is_vector) ) + +!if an array is in an array, there is an extra tab: + if (is_array) then + if ( .not. json%no_whitespace) tab = tab+1 + spaces = tab*json%spaces_per_tab + end if + + nullify(element) + element => p%children + do i = 1, count + + if (.not. associated(element)) then + call json%throw_exception('Error in json_value_print: '//& + 'Malformed JSON linked list') + return + end if + +! recursive print of the element + if (is_vector) then + call json%json_value_print(element, iunit=iunit, indent=0_IK,& + need_comma=i element%next + + end do + +!indent the closing array character: + if (is_vector) then + s = end_array + call write_it( comma=print_comma ) + else + s = repeat(space, max(0_IK,spaces-json%spaces_per_tab))//end_array + call write_it( comma=print_comma ) + end if + nullify(element) + + end if + + case (json_null) + + s = s_indent//null_str + call write_it( comma=print_comma, & + advance=(.not. is_vector),& + space_after_comma=is_vector ) + + case (json_string) + + if (allocated(p%str_value)) then +! have to escape the string for printing: + call escape_string(p%str_value,str_escaped,json%escape_solidus) + s = s_indent//quotation_mark//str_escaped//quotation_mark + call write_it( comma=print_comma, & + advance=(.not. is_vector),& + space_after_comma=is_vector ) + else + call json%throw_exception('Error in json_value_print:'//& + ' p%value_string not allocated') + return + end if + + case (json_logical) + + if (p%log_value) then + s = s_indent//true_str + call write_it( comma=print_comma, & + advance=(.not. is_vector),& + space_after_comma=is_vector ) + else + s = s_indent//false_str + call write_it( comma=print_comma, & + advance=(.not. is_vector),& + space_after_comma=is_vector ) + end if + + case (json_integer) + + call integer_to_string(p%int_value,int_fmt,tmp) + + s = s_indent//trim(tmp) + call write_it( comma=print_comma, & + advance=(.not. is_vector),& + space_after_comma=is_vector ) + + case (json_real) + + if (allocated(json%real_fmt)) then + call real_to_string(p%dbl_value,json%real_fmt,json%compact_real,json%non_normals_to_null,tmp) + else +!use the default format (user has not called initialize() or specified one): + call real_to_string(p%dbl_value,default_real_fmt,json%compact_real,json%non_normals_to_null,tmp) + end if + + s = s_indent//trim(tmp) + call write_it( comma=print_comma, & + advance=(.not. is_vector),& + space_after_comma=is_vector ) + + case default + + call integer_to_string(p%var_type,int_fmt,tmp) + call json%throw_exception('Error in json_value_print: '//& + 'unknown data type: '//trim(tmp)) + + end select + + end if + + contains + + subroutine write_it(advance,comma,space_after_comma) + +!! write the string `s` to the file (or the output string) + + implicit none + + logical(LK),intent(in),optional :: advance !! to add line break or not + logical(LK),intent(in),optional :: comma !! print comma after the string + logical(LK),intent(in),optional :: space_after_comma !! print a space after the comma + + logical(LK) :: add_comma !! if a delimiter is to be added after string + logical(LK) :: add_line_break !! if a line break is to be added after string + logical(LK) :: add_space !! if a space is to be added after the comma + integer(IK) :: n !! length of actual string `s` appended to `str` + integer(IK) :: room_left !! number of characters left in `str` + integer(IK) :: n_chunks_to_add !! number of chunks to add to `str` for appending `s` + + if (present(comma)) then + add_comma = comma + else + add_comma = .false. !default is not to add comma + end if + if (json%no_whitespace) then + add_space = .false. + else + if (present(space_after_comma)) then + add_space = space_after_comma + else + add_space = .false. !default is not to add space + end if + end if + if (present(advance)) then + if (json%no_whitespace) then +! overrides input value: + add_line_break = .false. + else + add_line_break = advance + end if + else + add_line_break = .not. json%no_whitespace ! default is to advance if +! we are printing whitespace + end if + +! string to print: + if (add_comma) then + if (add_space) then + s = s // delimiter // space + else + s = s // delimiter + end if + end if + + if (write_file) then + + if (add_line_break) then + write(iunit,fmt='(A)') s + else + write(iunit,fmt='(A)',advance='NO') s + end if + + else !write string + + if (add_line_break) s = s // newline + + n = len(s) + room_left = len(str)-iloc + if (room_left < n) then +! need to add another chunk to fit this string: + n_chunks_to_add = max(1_IK, ceiling( real(len(s)-room_left,RK) / real(chunk_size,RK), IK ) ) + str = str // repeat(space, print_str_chunk_size*n_chunks_to_add) + end if +! append s to str: + str(iloc+1:iloc+n) = s + iloc = iloc + n + + end if + + end subroutine write_it + + end subroutine json_value_print +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns true if all the children are the same type (and a scalar). +! Note that integers and reals are considered the same type for this purpose. +! This routine is used for the `compress_vectors` option. + + function json_is_vector(json, p) result(is_vector) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + logical(LK) :: is_vector !! if all elements of a vector +!! are scalars of the same type + + integer(IK) :: var_type_prev !! for getting the variable type of children + integer(IK) :: var_type !! for getting the variable type of children + type(json_value),pointer :: element !! for getting children + integer(IK) :: i !! counter + integer(IK) :: count !! number of children + + integer(IK),parameter :: json_invalid = -1_IK !! to initialize the flag. an invalid value + integer(IK),parameter :: json_numeric = -2_IK !! indicates `json_integer` or `json_real` + + if (json%compress_vectors) then +! check to see if every child is the same type, +! and a scalar: + is_vector = .true. + var_type_prev = json_invalid + count = json%count(p) + element => p%children + do i = 1_IK, count + if (.not. associated(element)) then + call json%throw_exception('Error in json_is_vector: '//& + 'Malformed JSON linked list') + return + end if +! check variable type of all the children. +! They must all be the same, and a scalar. + call json%info(element,var_type=var_type) +! special check for numeric values: + if (var_type==json_integer .or. var_type==json_real) var_type = json_numeric + if (var_type==json_object .or. & + var_type==json_array .or. & + (i>1_IK .and. var_type/=var_type_prev)) then + is_vector = .false. + exit + end if + var_type_prev = var_type +! get the next child the list: + element => element%next + end do + else + is_vector = .false. + end if + + end function json_is_vector +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns true if the `path` is present in the `p` JSON structure. +! +!@note Just a wrapper for [[json_get_by_path]], so it uses the +! specified `path_mode` and other settings. + + function json_valid_path(json, p, path) result(found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! a JSON linked list + character(kind=CK,len=*),intent(in) :: path !! path to the variable + logical(LK) :: found !! true if it was found + + type(json_value),pointer :: tmp !! pointer to the variable specified by `path` + + call json%get(p, path, tmp, found) + + end function json_valid_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_valid_path]] where "path" is kind=CDK. + + function wrap_json_valid_path(json, p, path) result(found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! a JSON linked list + character(kind=CDK,len=*),intent(in) :: path !! path to the variable + logical(LK) :: found !! true if it was found + + found = json%valid_path(p, to_unicode(path)) + + end function wrap_json_valid_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns the [[json_value]] pointer given the path string. +! +! It uses one of three methods: +! +! * The original JSON-Fortran defaults +! * [RFC 6901](https://tools.ietf.org/html/rfc6901) +! * [JSONPath](http://goessner.net/articles/JsonPath/) "bracket-notation" + + subroutine json_get_by_path(json, me, path, p, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me !! a JSON linked list + character(kind=CK,len=*),intent(in) :: path !! path to the variable + type(json_value),pointer,intent(out) :: p !! pointer to the variable +!! specified by `path` + logical(LK),intent(out),optional :: found !! true if it was found + + character(kind=CK,len=max_integer_str_len),allocatable :: path_mode_str !! string version +!! of `json%path_mode` + + nullify(p) + + if (.not. json%exception_thrown) then + + select case (json%path_mode) + case(1_IK) + call json%json_get_by_path_default(me, path, p, found) + case(2_IK) + call json%json_get_by_path_rfc6901(me, path, p, found) + case(3_IK) + call json%json_get_by_path_jsonpath_bracket(me, path, p, found) + case default + call integer_to_string(json%path_mode,int_fmt,path_mode_str) + call json%throw_exception('Error in json_get_by_path: Unsupported path_mode: '//& + trim(path_mode_str)) + if (present(found)) found = .false. + end select + + if (present(found)) then + if (.not. found) call json%clear_exceptions() + end if + + else + if (present(found)) found = .false. + end if + + end subroutine json_get_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns the [[json_value]] pointer given the path string, +! If necessary, by creating the variables as needed. +! +! By default, the leaf node and any empty array elements +! are created as `json_null` values. +! +! It only works for `path_mode=1` or `path_mode=3`. +! An error will be thrown for `path_mode=2` (RFC 6901). +! +!### See also +! * [[json_get_by_path]] + + subroutine json_create_by_path(json,me,path,p,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me !! a JSON linked list + character(kind=CK,len=*),intent(in) :: path !! path to the variable + type(json_value),pointer,intent(out),optional :: p !! pointer to the variable +!! specify by `path` + logical(LK),intent(out),optional :: found !! true if there were no errors +!! (variable found or created) + logical(LK),intent(out),optional :: was_created !! true if it was actually created +!! (as opposed to already being there) + + type(json_value),pointer :: tmp + character(kind=CK,len=max_integer_str_len) :: path_mode_str !! string version +!! of `json%path_mode` + + if (present(p)) nullify(p) + + if (.not. json%exception_thrown) then + + select case (json%path_mode) + case(1_IK) + call json%json_get_by_path_default(me,path,tmp,found,& + create_it=.true.,& + was_created=was_created) + if (present(p)) p => tmp + case(3_IK) + call json%json_get_by_path_jsonpath_bracket(me,path,tmp,found,& + create_it=.true.,& + was_created=was_created) + if (present(p)) p => tmp + + case default + + if (json%path_mode==2_IK) then +! the problem here is there isn't really a way to disambiguate +! the array elements, so '/a/0' could be 'a(1)' or 'a.0'. + call json%throw_exception('Error in json_create_by_path: '//& + 'Create by path not supported in RFC 6901 path mode.') + else + call integer_to_string(json%path_mode,int_fmt,path_mode_str) + call json%throw_exception('Error in json_create_by_path: Unsupported path_mode: '//& + trim(path_mode_str)) + end if + if (present(found)) then + call json%clear_exceptions() + found = .false. + end if + if (present(was_created)) was_created = .false. + end select + + else + if (present(was_created)) was_created = .false. + if (present(found)) found = .false. + end if + + end subroutine json_create_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_create_by_path]] where "path" is kind=CDK. + + subroutine wrap_json_create_by_path(json,me,path,p,found,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me !! a JSON linked list + character(kind=CDK,len=*),intent(in) :: path !! path to the variable + type(json_value),pointer,intent(out),optional :: p !! pointer to the variable +!! specify by `path` + logical(LK),intent(out),optional :: found !! true if there were no errors +!! (variable found or created) + logical(LK),intent(out),optional :: was_created !! true if it was actually created +!! (as opposed to already being there) + + call json%create(me,to_unicode(path),p,found,was_created) + + end subroutine wrap_json_create_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Rename a [[json_value]], given the path. +! +!@note this is a wrapper for [[json_value_rename]]. + + subroutine json_rename_by_path(json, me, path, name, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path !! path to the variable to rename + character(kind=CK,len=*),intent(in) :: name !! the new name + logical(LK),intent(out),optional :: found !! if there were no errors + + type(json_value),pointer :: p + + if ( json%exception_thrown ) then + if ( present(found) ) found = .false. + return + end if + + nullify(p) + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in json_rename_by_path:'//& + ' Unable to resolve path: '//trim(path),found) + else + call json%rename(p,name) + nullify(p) + end if + + if (json%exception_thrown) then + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + else + if (present(found)) found = .true. + end if + + end subroutine json_rename_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_rename_by_path]], where "path" and "name" are kind=CDK + + subroutine wrap_json_rename_by_path(json, me, path, name, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CDK,len=*),intent(in) :: path + character(kind=CDK,len=*),intent(in) :: name + logical(LK),intent(out),optional :: found + + call json%rename(me,to_unicode(path),to_unicode(name),found) + + end subroutine wrap_json_rename_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_rename_by_path]], where "name" is kind=CDK + + subroutine json_rename_by_path_name_ascii(json, me, path, name, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + character(kind=CDK,len=*),intent(in) :: name + logical(LK),intent(out),optional :: found + + call json%rename(me,path,to_unicode(name),found) + + end subroutine json_rename_by_path_name_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_rename_by_path]], where "path" is kind=CDK + + subroutine json_rename_by_path_path_ascii(json, me, path, name, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CDK,len=*),intent(in) :: path + character(kind=CK,len=*),intent(in) :: name + logical(LK),intent(out),optional :: found + + call json%rename(me,to_unicode(path),name,found) + + end subroutine json_rename_by_path_path_ascii +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns the [[json_value]] pointer given the path string. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: dat,p +! logical :: found +! !... +! call json%initialize(path_mode=1) ! this is the default so not strictly necessary. +! call json%get(dat,'data(2).version',p,found) +!```` +! +!### Notes +! The syntax used here is a subset of the +! [http://goessner.net/articles/JsonPath/](JSONPath) "dot–notation". +! The following special characters are used to denote paths: +! +! * `$` - root +! * `@` - this +! * `.` - child object member (note this can be changed using `json%path_separator`) +! * `[]` or `()` - child array element (note that indices are 1-based) +! +! Thus, if any of these characters are present in the name key, +! this routine cannot be used to get the value. +! In that case, the `get_child` methods would need to be used. +! Or, the alternate [[json_get_by_path_rfc6901]] could be used. +! +!### See also +! * [[json_get_by_path_rfc6901]] +! * [[json_get_by_path_jsonpath_bracket]] +! +!@note The syntax is inherited from FSON, and is basically a subset +! of JSONPath "dot-notation", with the additional allowance of +! () for array elements. +! +!@note JSON `null` values are used here for unknown variables when `create_it` is True. +! So, it is possible that an existing null variable can be converted to another +! type (object or array) if a child is specified in the path. Doing it this way +! to avoid having to use another type (say `json_unknown`) that would have to be +! converted to null once all the variables have been created (user would have +! had to do this). +! +!@warning See (**) in code. I think we need to protect for memory leaks when +! changing the type of a variable that already exists. + + subroutine json_get_by_path_default(json,me,path,p,found,create_it,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me !! a JSON linked list + character(kind=CK,len=*),intent(in) :: path !! path to the variable + type(json_value),pointer,intent(out) :: p !! pointer to the variable +!! specify by `path` + logical(LK),intent(out),optional :: found !! true if it was found + logical(LK),intent(in),optional :: create_it !! if a variable is not present +!! in the path, then it is created. +!! the leaf node is returned as +!! a `null` json type and can be +!! changed by the caller. + logical(LK),intent(out),optional :: was_created !! if `create_it` is true, this +!! will be true if the variable +!! was actually created. Otherwise +!! it will be false. + + integer(IK) :: i !! counter of characters in `path` + integer(IK) :: length !! significant length of `path` + integer(IK) :: child_i !! index for getting children + character(kind=CK,len=1) :: c !! a character in the `path` + logical(LK) :: array !! flag when searching for array index in `path` + type(json_value),pointer :: tmp !! temp variables for getting child objects + logical(LK) :: child_found !! if the child value was found + logical(LK) :: create !! if the object is to be created + logical(LK) :: created !! if `create` is true, then this will be +!! true if the leaf object had to be created + integer(IK) :: j !! counter of children when creating object + logical(LK) :: status_ok !! integer to string conversion flag + + nullify(p) + + if (.not. json%exception_thrown) then + + if (present(create_it)) then + create = create_it + else + create = .false. + end if + +! default to assuming relative to me + p => me + + child_i = 1 + array = .false. + created = .false. + +!keep trailing space or not: + if (json%trailing_spaces_significant) then + length = len(path) + else + length = len_trim(path) + end if + + do i=1, length + + c = path(i:i) + + select case (c) + case (root) + +! root + do while (associated (p%parent)) + p => p%parent + end do + child_i = i + 1 + if (create) created = .false. ! should always exist + + case (this) + +! this + p => me + child_i = i + 1 + if (create) created = .false. ! should always exist + + case (start_array,start_array_alt) + +! start looking for the array element index + array = .true. + +! get child member from p + if (child_i < i) then + nullify(tmp) + if (create) then + +! Example: +! 'aaa.bbb(1)' +! -> and aaa is a null, need to make it an object +! +! What about the case: aaa.bbb(1)(3) ? +! Is that already handled? + + if (p%var_type==json_null) then ! (**) +! if p was also created, then we need to +! convert it into an object here: + p%var_type = json_object + end if + +! don't want to throw exceptions in this case + call json%get_child(p, path(child_i:i-1), tmp, child_found) + if (.not. child_found) then +! have to create this child +! [make it an array] + call json_value_create(tmp) + call json%to_array(tmp,path(child_i:i-1)) + call json%add(p,tmp) + created = .true. + else + created = .false. + end if + else +! call the normal way + call json%get_child(p, path(child_i:i-1), tmp) + end if + p => tmp + else + child_i = i + 1 ! say, '@(' + cycle + end if + if (.not. associated(p)) then + call json%throw_exception('Error in json_get_by_path_default:'//& + ' Error getting array element',found) + exit + end if + child_i = i + 1 + + case (end_array,end_array_alt) + + if (.not. array) then + call json%throw_exception('Error in json_get_by_path_default:'//& + ' Unexpected '//c,found) + exit + end if + array = .false. + call string_to_integer(path(child_i:i-1),child_i,status_ok) + if (.not. status_ok) then + call json%throw_exception('Error in json_get_by_path_default:'//& + ' Could not convert array index to integer: '//& + trim(path(child_i:i-1)),found) + exit + end if + + nullify(tmp) + if (create) then +! don't want to throw exceptions in this case + call json%get_child(p, child_i, tmp, child_found) + if (.not. child_found) then + + if (p%var_type==json_null) then ! (**) +! if p was also created, then we need to +! convert it into an array here: + p%var_type = json_array + end if + +! have to create this element +! [make it a null] +! (and any missing ones before it) + do j = 1, child_i + nullify(tmp) + call json%get_child(p, j, tmp, child_found) + if (.not. child_found) then + call json_value_create(tmp) + call json%to_null(tmp) ! array element doesn't need a name + call json%add(p,tmp) + if (j==child_i) created = .true. + else + if (j==child_i) created = .false. + end if + end do + + else + created = .false. + end if + + else +! call the normal way: + call json%get_child(p, child_i, tmp) + end if + + p => tmp + + child_i = i + 1 + + case default + + if (c==json%path_separator) then + +! get child member from p + if (child_i < i) then + nullify(tmp) + if (create) then + if (p%var_type==json_null) then ! (**) +! if p was also created, then we need to +! convert it into an object here: + p%var_type = json_object + end if + +! don't want to throw exceptions in this case + call json%get_child(p, path(child_i:i-1), tmp, child_found) + if (.not. child_found) then +! have to create this child +! [make it an object] + call json_value_create(tmp) + call json%to_object(tmp,path(child_i:i-1)) + call json%add(p,tmp) + created = .true. + else + created = .false. + end if + else +! call the normal way + call json%get_child(p, path(child_i:i-1), tmp) + end if + p => tmp + else + child_i = i + 1 ! say '$.', '@.', or ').' + cycle + end if + + if (.not. associated(p)) then + call json%throw_exception('Error in json_get_by_path_default:'//& + ' Error getting child member.',found) + exit + end if + + child_i = i + 1 + + end if + + end select + + end do + + if (json%exception_thrown) then + + if (present(found)) then + nullify(p) ! just in case + found = .false. + call json%clear_exceptions() + end if + + else + +! grab the last child if present in the path + if (child_i <= length) then + nullify(tmp) + if (create) then + if (p%var_type==json_null) then ! (**) +! if p was also created, then we need to +! convert it into an object here: + p%var_type = json_object + end if + + call json%get_child(p, path(child_i:i-1), tmp, child_found) + if (.not. child_found) then +! have to create this child +! (make it a null since it is the leaf) + call json_value_create(tmp) + call json%to_null(tmp,path(child_i:i-1)) + call json%add(p,tmp) + created = .true. + else + created = .false. + end if + else +! call the normal way + call json%get_child(p, path(child_i:i-1), tmp) + end if + p => tmp + else +! we already have p + if (create .and. created) then +! make leaf p a null, but only +! if it wasn't there + call json%to_null(p) + end if + end if + +! error checking + if (associated(p)) then + if (present(found)) found = .true. !everything seems to be ok + else + call json%throw_exception('Error in json_get_by_path_default:'//& + ' variable not found: '//trim(path),found) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + end if + + end if + +! if it had to be created: + if (present(was_created)) was_created = created + + else + if (present(found)) found = .false. + if (present(was_created)) was_created = .false. + end if + + end subroutine json_get_by_path_default +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 2/4/2017 +! +! Returns the [[json_value]] pointer given the path string, +! using the "JSON Pointer" path specification defined by RFC 6901. +! +! Note that trailing whitespace significance and case sensitivity +! are user-specified. To fully conform to the RFC 6901 standard, +! should probably set (via `initialize`): +! +! * `case_sensitive_keys = .true.` [this is the default setting] +! * `trailing_spaces_significant = .true.` [this is *not* the default setting] +! * `allow_duplicate_keys = .false.` [this is *not* the default setting] +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: dat,p +! logical :: found +! !... +! call json%initialize(path_mode=2) +! call json%get(dat,'/data/2/version',p,found) +!```` +! +!### See also +! * [[json_get_by_path_default]] +! * [[json_get_by_path_jsonpath_bracket]] +! +!### Reference +! * [JavaScript Object Notation (JSON) Pointer](https://tools.ietf.org/html/rfc6901) +! +!@note Not doing anything special about the `-` character to index an array. +! This is considered a normal error. +! +!@note Unlike in the default path mode, the array indices here are 0-based +! (in accordance with the RFC 6901 standard) +! +!@warning Not checking if the member that is referenced is unique. +! (according to the standard, evaluation of non-unique references +! should fail). Like [[json_get_by_path_default]], this one will just return +! the first instance it encounters. This might be changed in the future. +! +!@warning I think the standard indicates that the input paths should use +! escaped JSON strings (currently we are assuming they are not escaped). + + subroutine json_get_by_path_rfc6901(json, me, path, p, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me !! a JSON linked list + character(kind=CK,len=*),intent(in) :: path !! path to the variable +!! (an RFC 6901 "JSON Pointer") + type(json_value),pointer,intent(out) :: p !! pointer to the variable +!! specify by `path` + logical(LK),intent(out),optional :: found !! true if it was found + + character(kind=CK,len=:),allocatable :: token !! a token in the path (between the `/` characters) + integer(IK) :: i !! counter + integer(IK) :: islash_curr !! location of current '/' character in the path + integer(IK) :: islash_next !! location of next '/' character in the path + integer(IK) :: ilen !! length of `path` string + type(json_value),pointer :: tmp !! temporary variable for traversing the structure + integer(IK) :: ival !! integer array index value (0-based) + logical(LK) :: status_ok !! error flag + logical(LK) :: child_found !! for getting child values + + nullify(p) + + if (.not. json%exception_thrown) then + + p => me ! initialize + + if (path/=CK_'') then + + if (path(1:1)==slash) then ! the first character must be a slash + + islash_curr = 1 ! initialize current slash index + +!keep trailing space or not: + if (json%trailing_spaces_significant) then + ilen = len(path) + else + ilen = len_trim(path) + end if + + do + +! get the next token by finding the slashes +! +! 1 2 3 +! /abc/d/efg + + if (islash_curr==ilen) then +!the last token is an empty string + token = CK_'' + islash_next = 0 ! will signal to stop + else + +! . +! '/123/567/' + +! index in remaining string: + islash_next = index(path(islash_curr+1:ilen),slash) + if (islash_next<=0) then +!last token: + token = path(islash_curr+1:ilen) + else +! convert to actual index in path: + islash_next = islash_curr + index(path(islash_curr+1:ilen),slash) + if (islash_next>islash_curr+1) then + token = path(islash_curr+1:islash_next-1) + else +!empty token: + token = CK_'' + end if + end if + + end if + +! remove trailing spaces in the token here if necessary: + if (.not. json%trailing_spaces_significant) & + token = trim(token) + +! decode the token: + token = decode_rfc6901(token) + +! now, parse the token: + +! first see if there is a child with this name + call json%get_child(p,token,tmp,child_found) + if (child_found) then +! it was found + p => tmp + else +! No key with this name. +! Is it an integer? If so, +! it might be an array index. + status_ok = (len(token)>0) + if (status_ok) then + do i=1,len(token) +! It must only contain (0..9) characters +! (it must be unsigned) + if (scan(token(i:i),CK_'0123456789')<1) then + status_ok = .false. + exit + end if + end do + if (status_ok) then + if (len(token)>1 .and. token(1:1)==CK_'0') then +! leading zeros not allowed for some reason + status_ok = .false. + end if + end if + if (status_ok) then +! if we make it this far, it should be +! convertible to an integer, so do it. + call string_to_integer(token,ival,status_ok) + end if + end if + if (status_ok) then +! ival is an array index (0-based) + call json%get_child(p,ival+1_IK,tmp,child_found) + if (child_found) then + p => tmp + else +! not found + status_ok = .false. + end if + end if + if (.not. status_ok) then + call json%throw_exception('Error in json_get_by_path_rfc6901: '//& + 'invalid path specification: '//trim(path),found) + exit + end if + end if + + if (islash_next<=0) exit ! finished + +! set up for next token: + islash_curr = islash_next + + end do + + else + call json%throw_exception('Error in json_get_by_path_rfc6901: '//& + 'invalid path specification: '//trim(path),found) + end if + end if + + if (json%exception_thrown) then + nullify(p) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + else + if (present(found)) found = .true. + end if + + else + if (present(found)) found = .false. + end if + + end subroutine json_get_by_path_rfc6901 +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 9/2/2017 +! +! Returns the [[json_value]] pointer given the path string, +! using the "JSON Pointer" path specification defined by the +! JSONPath "bracket-notation". +! +! The first character `$` is optional, and signifies the root +! of the structure. If it is not present, then the first key +! is taken to be in the `me` object. +! +! Single or real quotes may be used. +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: dat,p +! logical :: found +! !... +! call json%initialize(path_mode=3) +! call json%get(dat,"$['store']['book'][1]['title']",p,found) +!```` +! +!### See also +! * [[json_get_by_path_default]] +! * [[json_get_by_path_rfc6901]] +! +!### Reference +! * [JSONPath](http://goessner.net/articles/JsonPath/) +! +!@note Uses 1-based array indices (same as [[json_get_by_path_default]], +! but unlike [[json_get_by_path_rfc6901]] which uses 0-based indices). +! +!@note When `create_it=True`, if the variable already exists and is a type +! that is not compatible with the usage in the `path`, then it is +! destroyed and replaced with what is specified in the `path`. Note that +! this applies the all variables in the path as it is created. Currently, +! this behavior is different from [[json_get_by_path_default]]. +! +!@note JSON `null` values are used here for unknown variables +! when `create_it` is True. +! +!@warning Note that if using single quotes, this routine cannot parse +! a key containing `']`. If using real quotes, this routine +! cannot parse a key containing `"]`. If the key contains both +! `']` and `"]`, there is no way to parse it using this routine. + + subroutine json_get_by_path_jsonpath_bracket(json,me,path,p,found,create_it,was_created) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me !! a JSON linked list + character(kind=CK,len=*),intent(in) :: path !! path to the variable +!! (using JSONPath +!! "bracket-notation") + type(json_value),pointer,intent(out) :: p !! pointer to the variable +!! specify by `path` + logical(LK),intent(out),optional :: found !! true if it was found + logical(LK),intent(in),optional :: create_it !! if a variable is not present +!! in the path, then it is created. +!! the leaf node is returned as +!! a `null` json type and can be +!! changed by the caller. + logical(LK),intent(out),optional :: was_created !! if `create_it` is true, this +!! will be true if the variable +!! was actually created. Otherwise +!! it will be false. + + character(kind=CK,len=:),allocatable :: token !! a token in the path +!! (between the `['']` or +!! `[]` characters) + integer(IK) :: istart !! location of current '[' +!! character in the path + integer(IK) :: iend !! location of current ']' +!! character in the path + integer(IK) :: ival !! integer array index value + logical(LK) :: status_ok !! error flag + type(json_value),pointer :: tmp !! temporary variable for +!! traversing the structure + integer(IK) :: i !! counter + integer(IK) :: ilen !! length of `path` string + logical(LK) :: real_quotes !! if the keys are enclosed in `"`, +!! rather than `'` tokens. + logical(LK) :: create !! if the object is to be created + logical(LK) :: created !! if `create` is true, then this will be +!! true if the leaf object had to be created + integer(IK) :: j !! counter of children when creating object + +!TODO instead of reallocating `token` all the time, just +! allocate a big size and keep track of the length, +! then just reallocate only if necessary. +! [would probably be inefficient if there was a very large token, +! and then a bunch of small ones... but for similarly-sized ones +! it should be way more efficient since it would avoid most +! reallocations.] + + nullify(p) + + if (.not. json%exception_thrown) then + + if (present(create_it)) then + create = create_it + else + create = .false. + end if + + p => me ! initialize + created = .false. + + if (path==CK_'') then + call json%throw_exception('Error in json_get_by_path_jsonpath_bracket: '//& + 'invalid path specification: '//trim(path),found) + else + + if (path(1:1)==root .or. path(1:1)==start_array) then ! the first character must be +! a `$` (root) or a `[` +! (element of `me`) + + if (path(1:1)==root) then +! go to the root + do while (associated (p%parent)) + p => p%parent + end do + if (create) created = .false. ! should always exist + end if + +!path length (don't need trailing spaces:) + ilen = len_trim(path) + + if (ilen>1) then + + istart = 2 ! initialize first '[' location index + + do + + if (istart>ilen) exit ! finished + +! must be the next start bracket: + if (path(istart:istart) /= start_array) then + call json%throw_exception(& + 'Error in json_get_by_path_jsonpath_bracket: '//& + 'expecting "[", found: "'//trim(path(istart:istart))//& + '" in path: '//trim(path),found) + exit + end if + +! get the next token by checking: +! +! * [''] -- is the token after istart a quote? +! if so, then search for the next `']` +! +! * [1] -- if not, then maybe it is a number, +! so search for the next `]` + +! verify length of remaining string + if (istart+2<=ilen) then + + real_quotes = path(istart+1:istart+1) == quotation_mark ! [" + + if (real_quotes .or. path(istart+1:istart+1)==single_quote) then ! [' + +! it might be a key value: ['abc'] + + istart = istart + 1 ! move counter to ' index + if (real_quotes) then + iend = istart + index(path(istart+1:ilen),& + quotation_mark//end_array) ! "] + else + iend = istart + index(path(istart+1:ilen),& + single_quote//end_array) ! '] + end if + if (iend>istart) then + +! istart iend +! | | +! ['p']['abcdefg'] + + if (iend>istart+1) then + token = path(istart+1:iend-1) + else + token = CK_'' ! blank string + end if +! remove trailing spaces in +! the token here if necessary: + if (.not. json%trailing_spaces_significant) & + token = trim(token) + + if (create) then +! have a token, create it if necessary + +! we need to convert it into an object here +! (e.g., if p was also just created) +! and destroy its data to prevent a memory leak + call json%convert(p,json_object) + +! don't want to throw exceptions in this case + call json%get_child(p,token,tmp,status_ok) + if (.not. status_ok) then +! have to create this child +! [make it a null since we don't +! know what it is yet] + call json_value_create(tmp) + call json%to_null(tmp,token) + call json%add(p,tmp) + status_ok = .true. + created = .true. + else +! it was already there. + created = .false. + end if + else +! have a token, see if it is valid: + call json%get_child(p,token,tmp,status_ok) + end if + + if (status_ok) then +! it was found + p => tmp + else + call json%throw_exception(& + 'Error in json_get_by_path_jsonpath_bracket: '//& + 'invalid token found: "'//token//& + '" in path: '//trim(path),found) + exit + end if + iend = iend + 1 ! move counter to ] index + else + call json%throw_exception(& + 'Error in json_get_by_path_jsonpath_bracket: '//& + 'invalid path: '//trim(path),found) + exit + end if + + else + +! it might be an integer value: [123] + + iend = istart + index(path(istart+1:ilen),end_array) ! ] + if (iend>istart+1) then + +! this should be an integer: + token = path(istart+1:iend-1) + +! verify that there are no spaces or other +! characters in the string: + status_ok = .true. + do i=1,len(token) +! It must only contain (0..9) characters +! (it must be unsigned) + if (scan(token(i:i),CK_'0123456789')<1) then + status_ok = .false. + exit + end if + end do + if (status_ok) then + call string_to_integer(token,ival,status_ok) + if (status_ok) status_ok = ival>0 ! assuming 1-based array indices + end if + + if (status_ok) then + +! have a valid integer to use as an index +! see if this element is really there: + call json%get_child(p,ival,tmp,status_ok) + + if (create .and. .not. status_ok) then + +! have to create it: + + if (.not.(p%var_type==json_object .or. p%var_type==json_array)) then +! we need to convert it into an array here +! (e.g., if p was also just created) +! and destroy its data to prevent a memory leak + call json%convert(p,json_array) + end if + +! have to create this element +! [make it a null] +! (and any missing ones before it) + do j = 1, ival + nullify(tmp) + call json%get_child(p, j, tmp, status_ok) + if (.not. status_ok) then + call json_value_create(tmp) + call json%to_null(tmp) ! array element doesn't need a name + call json%add(p,tmp) + if (j==ival) created = .true. + else + if (j==ival) created = .false. + end if + end do + status_ok = .true. + + else + created = .false. + end if + + if (status_ok) then +! found it + p => tmp + else +! not found + call json%throw_exception(& + 'Error in json_get_by_path_jsonpath_bracket: '//& + 'invalid array index found: "'//token//& + '" in path: '//trim(path),found) + exit + end if + else + call json%throw_exception(& + 'Error in json_get_by_path_jsonpath_bracket: '//& + 'invalid token: "'//token//& + '" in path: '//trim(path),found) + exit + end if + + else + call json%throw_exception(& + 'Error in json_get_by_path_jsonpath_bracket: '//& + 'invalid path: '//trim(path),found) + exit + end if + + end if + + else + call json%throw_exception(& + 'Error in json_get_by_path_jsonpath_bracket: '//& + 'invalid path: '//trim(path),found) + exit + end if + +! set up for next token: + istart = iend + 1 + + end do + + end if + + else + call json%throw_exception(& + 'Error in json_get_by_path_jsonpath_bracket: '//& + 'expecting "'//root//'", found: "'//path(1:1)//& + '" in path: '//trim(path),found) + end if + + end if + + if (json%exception_thrown) then + nullify(p) + if (present(found)) then + found = .false. + call json%clear_exceptions() + end if + else + if (present(found)) found = .true. + end if + +! if it had to be created: + if (present(was_created)) was_created = created + + else + if (present(found)) found = .false. + if (present(was_created)) was_created = .false. + end if + + end subroutine json_get_by_path_jsonpath_bracket +!***************************************************************************************** + +!***************************************************************************************** +!> +! Convert an existing JSON variable `p` to a different variable type. +! The existing variable (and its children) is destroyed. It is replaced +! in the structure by a new variable of type `var_type` +! (which can be a `json_null`, `json_object` or `json_array`). +! +!@note This is an internal routine used when creating variables by path. + + subroutine convert(json,p,var_type) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p !! the variable to convert + integer(IK),intent(in) :: var_type !! the variable type to convert `p` to + + type(json_value),pointer :: tmp !! temporary variable + character(kind=CK,len=:),allocatable :: name !! the name of a JSON variable + + logical :: convert_it !! if `p` needs to be converted + + convert_it = p%var_type /= var_type + + if (convert_it) then + + call json%info(p,name=name) ! get existing name + + select case (var_type) + case(json_object) + call json%create_object(tmp,name) + case(json_array) + call json%create_array(tmp,name) + case(json_null) + call json%create_null(tmp,name) + case default + call json%throw_exception('Error in convert: invalid var_type value.') + return + end select + + call json%replace(p,tmp,destroy=.true.) + p => tmp + nullify(tmp) + + end if + + end subroutine convert +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_by_path]] where "path" is kind=CDK. + + subroutine wrap_json_get_by_path(json, me, path, p, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CDK,len=*),intent(in) :: path + type(json_value),pointer,intent(out) :: p + logical(LK),intent(out),optional :: found + + call json%get(me, to_unicode(path), p, found) + + end subroutine wrap_json_get_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Returns the path to a JSON object that is part +! of a linked list structure. +! +! The path returned would be suitable for input to +! [[json_get_by_path]] and related routines. +! +!@note If an error occurs (which in this case means a malformed +! JSON structure) then an exception will be thrown, unless +! `found` is present, which will be set to `false`. `path` +! will be a blank string. +! +!@note If `json%path_mode/=1`, then the `use_alt_array_tokens` +! and `path_sep` inputs are ignored if present. +! +!@note [http://goessner.net/articles/JsonPath/](JSONPath) (`path_mode=3`) +! does not specify whether or not the keys should be escaped (this routine +! assumes not, as does http://jsonpath.com). +! Also, we are using Fortran-style 1-based array indices, +! not 0-based, to agree with the assumption in `path_mode=1` + + subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! a JSON linked list object + character(kind=CK,len=:),allocatable,intent(out) :: path !! path to the variable + logical(LK),intent(out),optional :: found !! true if there were no problems + logical(LK),intent(in),optional :: use_alt_array_tokens !! if true, then '()' are used for array elements +!! otherwise, '[]' are used [default] +!! (only used if `path_mode=1`) + character(kind=CK,len=1),intent(in),optional :: path_sep !! character to use for path separator +!! (otherwise use `json%path_separator`) +!! (only used if `path_mode=1`) + + character(kind=CK,len=:),allocatable :: name !! variable name + character(kind=CK,len=:),allocatable :: parent_name !! variable's parent name + character(kind=CK,len=max_integer_str_len) :: istr !! for integer to string conversion +!! (array indices) + type(json_value),pointer :: tmp !! for traversing the structure + type(json_value),pointer :: element !! for traversing the structure + integer(IK) :: var_type !! JSON variable type flag + integer(IK) :: i !! counter + integer(IK) :: n_children !! number of children for parent + logical(LK) :: use_brackets !! to use '[]' characters for arrays + logical(LK) :: parent_is_root !! if the parent is the root + character(kind=CK,len=1) :: array_start !! for `path_mode=1`, the character to start arrays + character(kind=CK,len=1) :: array_end !! for `path_mode=1`, the character to end arrays + logical :: consecutive_arrays !! check for array of array case + integer(IK) :: parents_parent_var_type !! `var_type` for parent's parent + +!optional input: + if (present(use_alt_array_tokens)) then + use_brackets = .not. use_alt_array_tokens + else + use_brackets = .true. + end if + + if (json%path_mode==1_IK) then + if (use_brackets) then + array_start = start_array + array_end = end_array + else + array_start = start_array_alt + array_end = end_array_alt + end if + end if + +! initialize: + consecutive_arrays = .false. + + if (associated(p)) then + +!traverse the structure via parents up to the root + tmp => p + do + + if (.not. associated(tmp)) exit !finished + +!get info about the current variable: + call json%info(tmp,name=name) + if (json%path_mode==2_IK) then + name = encode_rfc6901(name) + end if + +! if tmp a child of an object, or an element of an array + if (associated(tmp%parent)) then + +!get info about the parent: + call json%info(tmp%parent,var_type=var_type,& + n_children=n_children,name=parent_name) + if (json%path_mode==2_IK) then + parent_name = encode_rfc6901(parent_name) + end if + if (associated(tmp%parent%parent)) then + call json%info(tmp%parent%parent,var_type=parents_parent_var_type) + consecutive_arrays = parents_parent_var_type == json_array .and. & + var_type == json_array + else + consecutive_arrays = .false. + end if + + select case (var_type) + case (json_array) + +!get array index of this element: + element => tmp%parent%children + do i = 1, n_children + if (.not. associated(element)) then + call json%throw_exception('Error in json_get_path: '//& + 'malformed JSON structure. ',found) + exit + end if + if (associated(element,tmp)) then + exit + else + element => element%next + end if + if (i==n_children) then ! it wasn't found (should never happen) + call json%throw_exception('Error in json_get_path: '//& + 'malformed JSON structure. ',found) + exit + end if + end do + select case(json%path_mode) + case(3_IK) +! JSONPath "bracket-notation" +! example: `$['key'][1]` +! [note: this uses 1-based indices] + call integer_to_string(i,int_fmt,istr) + if (consecutive_arrays) then + call add_to_path(start_array//trim(adjustl(istr))//end_array,CK_'') + else + call add_to_path(start_array//single_quote//parent_name//& + single_quote//end_array//& + start_array//trim(adjustl(istr))//end_array,CK_'') + end if + case(2_IK) +! rfc6901 +! Example: '/key/0' + call integer_to_string(i-1_IK,int_fmt,istr) ! 0-based index + if (consecutive_arrays) then + call add_to_path(trim(adjustl(istr))) + else + call add_to_path(parent_name//slash//trim(adjustl(istr))) + end if + case(1_IK) +! default +! Example: `key[1]` + call integer_to_string(i,int_fmt,istr) + if (consecutive_arrays) then + call add_to_path(array_start//trim(adjustl(istr))//array_end,path_sep) + else + call add_to_path(parent_name//array_start//& + trim(adjustl(istr))//array_end,path_sep) + end if + end select + + if (.not. consecutive_arrays) tmp => tmp%parent ! already added parent name + + case (json_object) + + if (.not. consecutive_arrays) then +! idea is not to print the array name if +! it was already printed with the array + +!process parent on the next pass + select case(json%path_mode) + case(3_IK) + call add_to_path(start_array//single_quote//name//& + single_quote//end_array,CK_'') + case default + call add_to_path(name,path_sep) + end select + + end if + + case default + + call json%throw_exception('Error in json_get_path: '//& + 'malformed JSON structure. '//& + 'A variable that is not an object '//& + 'or array should not have a child.',found) + exit + + end select + + else +!the last one: + select case(json%path_mode) + case(3_IK) + call add_to_path(start_array//single_quote//name//& + single_quote//end_array,CK_'') + case default + call add_to_path(name,path_sep) + end select + end if + + if (associated(tmp%parent)) then +!check if the parent is the root: + parent_is_root = (.not. associated(tmp%parent%parent)) + if (parent_is_root) exit + end if + +!go to parent: + tmp => tmp%parent + + end do + + else + call json%throw_exception('Error in json_get_path: '//& + 'input pointer is not associated',found) + end if + +!for errors, return blank string: + if (json%exception_thrown .or. .not. allocated(path)) then + path = CK_'' + else + select case (json%path_mode) + case(3_IK) +! add the outer level object identifier: + path = root//path + case(2_IK) +! add the root slash: + path = slash//path + end select + end if + +!optional output: + if (present(found)) then + if (json%exception_thrown) then + found = .false. + call json%clear_exceptions() + else + found = .true. + end if + end if + + contains + + subroutine add_to_path(str,path_sep) +!! prepend the string to the path + implicit none + character(kind=CK,len=*),intent(in) :: str !! string to prepend to `path` + character(kind=CK,len=*),intent(in),optional :: path_sep +!! path separator (default is '.'). +!! (ignored if `json%path_mode/=1`) + + select case (json%path_mode) + case(3_IK) +! in this case, the options are ignored + if (.not. allocated(path)) then + path = str + else + path = str//path + end if + case(2_IK) +! in this case, the options are ignored + if (.not. allocated(path)) then + path = str + else + path = str//slash//path + end if + case(1_IK) +! default path format + if (.not. allocated(path)) then + path = str + else +! shouldn't add the path_sep for cases like x[1][2] +! [if current is an array element, and the previous was +! also an array element] so check for that here: + if (.not. ( str(len(str):len(str))==array_end .and. & + path(1:1)==array_start )) then + if (present(path_sep)) then +! use user specified: + path = str//path_sep//path + else +! use the default: + path = str//json%path_separator//path + end if + else + path = str//path + end if + end if + end select + + end subroutine add_to_path + + end subroutine json_get_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Wrapper for [[json_get_path]] where "path" and "path_sep" are kind=CDK. + + subroutine wrap_json_get_path(json, p, path, found, use_alt_array_tokens, path_sep) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p !! a JSON linked list object + character(kind=CDK,len=:),allocatable,intent(out) :: path !! path to the variable + logical(LK),intent(out),optional :: found !! true if there were no problems + logical(LK),intent(in),optional :: use_alt_array_tokens !! if true, then '()' are used +!! for array elements otherwise, +!! '[]' are used [default] + character(kind=CDK,len=1),intent(in),optional :: path_sep !! character to use for path +!! separator (default is '.') + + character(kind=CK,len=:),allocatable :: ck_path !! path to the variable + +! call the main routine: + if (present(path_sep)) then + call json%get_path(p,ck_path,found,use_alt_array_tokens,to_unicode(path_sep)) + else + call json%get_path(p,ck_path,found,use_alt_array_tokens) + end if + +! from unicode: + path = ck_path + + end subroutine wrap_json_get_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Convert a string into an integer. +! +!@note Replacement for the `parse_integer` function in the original code. + + function string_to_int(json,str) result(ival) + + implicit none + + class(json_core),intent(inout) :: json + character(kind=CK,len=*),intent(in) :: str !! a string + integer(IK) :: ival !! `str` converted to an integer + + logical(LK) :: status_ok !! error flag for [[string_to_integer]] + +! call the core routine: + call string_to_integer(str,ival,status_ok) + + if (.not. status_ok) then + ival = 0 + call json%throw_exception('Error in string_to_int: '//& + 'string cannot be converted to an integer: '//& + trim(str)) + end if + + end function string_to_int +!***************************************************************************************** + +!***************************************************************************************** +!> +! Convert a string into a `real(RK)` value. + + function string_to_dble(json,str) result(rval) + + implicit none + + class(json_core),intent(inout) :: json + character(kind=CK,len=*),intent(in) :: str !! a string + real(RK) :: rval !! `str` converted to a `real(RK)` + + logical(LK) :: status_ok !! error flag for [[string_to_real]] + + call string_to_real(str,json%use_quiet_nan,rval,status_ok) + + if (.not. status_ok) then !if there was an error + rval = 0.0_RK + call json%throw_exception('Error in string_to_dble: '//& + 'string cannot be converted to a real: '//& + trim(str)) + end if + + end function string_to_dble +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get an integer value from a [[json_value]]. + + subroutine json_get_integer(json, me, value) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + integer(IK),intent(out) :: value !! the integer value + + logical(LK) :: status_ok !! for [[string_to_integer]] + + value = 0_IK + if ( json%exception_thrown ) return + + if (me%var_type == json_integer) then + value = me%int_value + else + if (json%strict_type_checking) then + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_integer:'//& + ' Unable to resolve value to integer: '//me%name) + else + call json%throw_exception('Error in json_get_integer:'//& + ' Unable to resolve value to integer') + end if + else +!type conversions + select case(me%var_type) + case (json_real) + value = int(me%dbl_value, IK) + case (json_logical) + if (me%log_value) then + value = 1_IK + else + value = 0_IK + end if + case (json_string) + call string_to_integer(me%str_value,value,status_ok) + if (.not. status_ok) then + value = 0_IK + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_integer:'//& + ' Unable to convert string value to integer: '//& + me%name//' = '//trim(me%str_value)) + else + call json%throw_exception('Error in json_get_integer:'//& + ' Unable to convert string value to integer: '//& + trim(me%str_value)) + end if + end if + case default + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_integer:'//& + ' Unable to resolve value to integer: '//me%name) + else + call json%throw_exception('Error in json_get_integer:'//& + ' Unable to resolve value to integer') + end if + end select + end if + end if + + end subroutine json_get_integer +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get an integer value from a [[json_value]], given the path string. + + subroutine json_get_integer_by_path(json, me, path, value, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + integer(IK),intent(out) :: value + logical(LK),intent(out),optional :: found + integer(IK),intent(in),optional :: default !! default value if not found + + integer(IK),parameter :: default_if_not_specified = 0_IK + character(kind=CK,len=*),parameter :: routine = CK_'json_get_integer_by_path' + +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_get_scalar_by_path.inc" 1 + type(json_value),pointer :: p + + if (present(default)) then + value = default + else + value = default_if_not_specified + end if + + if ( json%exception_thrown ) then + call flag_not_found(found) + return + end if + + nullify(p) + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in '//routine//':'//& + ' Unable to resolve path: '// trim(path),found) + else + call json%get(p,value) + end if + + if ( json%exception_thrown ) then + if ( present(found) .or. present(default)) then + call flag_not_found(found) + if (present(default)) value = default + call json%clear_exceptions() + end if + else + if ( present(found) ) found = .true. + end if +# 8210 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + end subroutine json_get_integer_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_integer_by_path]], where "path" is kind=CDK. + + subroutine wrap_json_get_integer_by_path(json, me, path, value, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CDK,len=*),intent(in) :: path + integer(IK),intent(out) :: value + logical(LK),intent(out),optional :: found + integer(IK),intent(in),optional :: default !! default value if not found + + call json%get(me, to_unicode(path), value, found, default) + + end subroutine wrap_json_get_integer_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 5/14/2014 +! +! Get an integer vector from a [[json_value]]. + + subroutine json_get_integer_vec(json, me, vec) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + integer(IK),dimension(:),allocatable,intent(out) :: vec + + logical(LK) :: initialized + + if ( json%exception_thrown ) return + +! check for 0-length arrays first: + select case (me%var_type) + case (json_array) + if (json%count(me)==0) then + allocate(vec(0)) + return + end if + end select + + initialized = .false. + +!the callback function is called for each element of the array: + call json%get(me, array_callback=get_int_from_array) + + if (json%exception_thrown .and. allocated(vec)) deallocate(vec) + + contains + + subroutine get_int_from_array(json, element, i, count) + +!! callback function for integer + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: element + integer(IK),intent(in) :: i !! index + integer(IK),intent(in) :: count !! size of array + +!size the output array: + if (.not. initialized) then + allocate(vec(count)) + initialized = .true. + end if + +!populate the elements: + call json%get(element, value=vec(i)) + + end subroutine get_int_from_array + + end subroutine json_get_integer_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! If `found` is present, set it it false. + + subroutine flag_not_found(found) + + implicit none + + logical(LK),intent(out),optional :: found + + if (present(found)) found = .false. + + end subroutine flag_not_found +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get an integer vector from a [[json_value]], given the path string. + + subroutine json_get_integer_vec_by_path(json, me, path, vec, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + integer(IK),dimension(:),allocatable,intent(out) :: vec + logical(LK),intent(out),optional :: found + integer(IK),dimension(:),intent(in),optional :: default !! default value if not found + + character(kind=CK,len=*),parameter :: routine = CK_'json_get_integer_vec_by_path' + +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_get_vec_by_path.inc" 1 + type(json_value),pointer :: p + + if ( json%exception_thrown ) then + if (present(default)) vec = default + call flag_not_found(found) + return + end if + + nullify(p) + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in '//routine//':'//& + ' Unable to resolve path: '// trim(path),found) + else + call json%get(p,vec) + end if + + if ( json%exception_thrown ) then + if ( present(found) .or. present(default)) then + call flag_not_found(found) + if (present(default)) vec = default + call json%clear_exceptions() + end if + else + if ( present(found) ) found = .true. + end if +# 8328 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + end subroutine json_get_integer_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_integer_vec_by_path]], where "path" is kind=CDK + + subroutine wrap_json_get_integer_vec_by_path(json, me, path, vec, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + character(kind=CDK,len=*),intent(in) :: path + integer(IK),dimension(:),allocatable,intent(out) :: vec + logical(LK),intent(out),optional :: found + integer(IK),dimension(:),intent(in),optional :: default !! default value if not found + + call json%get(me,path=to_unicode(path),vec=vec,found=found,default=default) + + end subroutine wrap_json_get_integer_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get a real value from a [[json_value]]. + + subroutine json_get_real(json, me, value) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + real(RK),intent(out) :: value + + logical(LK) :: status_ok !! for [[string_to_real]] + + value = 0.0_RK + if ( json%exception_thrown ) return + + if (me%var_type == json_real) then + value = me%dbl_value + else + if (json%strict_type_checking) then + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_real:'//& + ' Unable to resolve value to real: '//me%name) + else + call json%throw_exception('Error in json_get_real:'//& + ' Unable to resolve value to real') + end if + else +!type conversions + select case (me%var_type) + case (json_integer) + value = real(me%int_value, RK) + case (json_logical) + if (me%log_value) then + value = 1.0_RK + else + value = 0.0_RK + end if + case (json_string) + call string_to_real(me%str_value,json%use_quiet_nan,value,status_ok) + if (.not. status_ok) then + value = 0.0_RK + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_real:'//& + ' Unable to convert string value to real: '//& + me%name//' = '//trim(me%str_value)) + else + call json%throw_exception('Error in json_get_real:'//& + ' Unable to convert string value to real: '//& + trim(me%str_value)) + end if + end if + case (json_null) + if (ieee_support_nan(value) .and. json%null_to_real_mode/=1_IK) then + select case (json%null_to_real_mode) + case(2_IK) + if (json%use_quiet_nan) then + value = ieee_value(value,ieee_quiet_nan) + else + value = ieee_value(value,ieee_signaling_nan) + end if + case(3_IK) + value = 0.0_RK + end select + else + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_real:'//& + ' Cannot convert null to NaN: '//me%name) + else + call json%throw_exception('Error in json_get_real:'//& + ' Cannot convert null to NaN') + end if + end if + case default + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_real:'//& + ' Unable to resolve value to real: '//me%name) + else + call json%throw_exception('Error in json_get_real:'//& + ' Unable to resolve value to real') + end if + end select + end if + end if + + end subroutine json_get_real +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get a real value from a [[json_value]], given the path. + + subroutine json_get_real_by_path(json, me, path, value, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + character(kind=CK,len=*),intent(in) :: path + real(RK),intent(out) :: value + logical(LK),intent(out),optional :: found + real(RK),intent(in),optional :: default !! default value if not found + + real(RK),parameter :: default_if_not_specified = 0.0_RK + character(kind=CK,len=*),parameter :: routine = CK_'json_get_real_by_path' + +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_get_scalar_by_path.inc" 1 + type(json_value),pointer :: p + + if (present(default)) then + value = default + else + value = default_if_not_specified + end if + + if ( json%exception_thrown ) then + call flag_not_found(found) + return + end if + + nullify(p) + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in '//routine//':'//& + ' Unable to resolve path: '// trim(path),found) + else + call json%get(p,value) + end if + + if ( json%exception_thrown ) then + if ( present(found) .or. present(default)) then + call flag_not_found(found) + if (present(default)) value = default + call json%clear_exceptions() + end if + else + if ( present(found) ) found = .true. + end if +# 8460 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + end subroutine json_get_real_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_real_by_path]], where "path" is kind=CDK + + subroutine wrap_json_get_real_by_path(json, me, path, value, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + character(kind=CDK,len=*),intent(in) :: path + real(RK),intent(out) :: value + logical(LK),intent(out),optional :: found + real(RK),intent(in),optional :: default !! default value if not found + + call json%get(me,to_unicode(path),value,found,default) + + end subroutine wrap_json_get_real_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 5/14/2014 +! +! Get a real vector from a [[json_value]]. + + subroutine json_get_real_vec(json, me, vec) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + real(RK),dimension(:),allocatable,intent(out) :: vec + + logical(LK) :: initialized + + if ( json%exception_thrown ) return + +! check for 0-length arrays first: + select case (me%var_type) + case (json_array) + if (json%count(me)==0) then + allocate(vec(0)) + return + end if + end select + + initialized = .false. + +!the callback function is called for each element of the array: + call json%get(me, array_callback=get_real_from_array) + + if (json%exception_thrown .and. allocated(vec)) deallocate(vec) + + contains + + subroutine get_real_from_array(json, element, i, count) + +!! callback function for real + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: element + integer(IK),intent(in) :: i !! index + integer(IK),intent(in) :: count !! size of array + +!size the output array: + if (.not. initialized) then + allocate(vec(count)) + initialized = .true. + end if + +!populate the elements: + call json%get(element, value=vec(i)) + + end subroutine get_real_from_array + + end subroutine json_get_real_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get a real vector from a [[json_value]], given the path. + + subroutine json_get_real_vec_by_path(json, me, path, vec, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + real(RK),dimension(:),allocatable,intent(out) :: vec + logical(LK),intent(out),optional :: found + real(RK),dimension(:),intent(in),optional :: default !! default value if not found + + character(kind=CK,len=*),parameter :: routine = CK_'json_get_real_vec_by_path' + +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_get_vec_by_path.inc" 1 + type(json_value),pointer :: p + + if ( json%exception_thrown ) then + if (present(default)) vec = default + call flag_not_found(found) + return + end if + + nullify(p) + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in '//routine//':'//& + ' Unable to resolve path: '// trim(path),found) + else + call json%get(p,vec) + end if + + if ( json%exception_thrown ) then + if ( present(found) .or. present(default)) then + call flag_not_found(found) + if (present(default)) vec = default + call json%clear_exceptions() + end if + else + if ( present(found) ) found = .true. + end if +# 8563 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + end subroutine json_get_real_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_real_vec_by_path]], where "path" is kind=CDK + + subroutine wrap_json_get_real_vec_by_path(json, me, path, vec, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + character(kind=CDK,len=*),intent(in) :: path + real(RK),dimension(:),allocatable,intent(out) :: vec + logical(LK),intent(out),optional :: found + real(RK),dimension(:),intent(in),optional :: default !! default value if not found + + call json%get(me, to_unicode(path), vec, found, default) + + end subroutine wrap_json_get_real_vec_by_path +!***************************************************************************************** + + +!***************************************************************************************** +!> +! Alternate version of [[json_get_real]] where value=real32. + + subroutine json_get_real32(json, me, value) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + real(real32),intent(out) :: value + + real(RK) :: tmp + + call json%get(me, tmp) + value = real(tmp,real32) + + end subroutine json_get_real32 +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_real_by_path]] where value=real32. + + subroutine json_get_real32_by_path(json, me, path, value, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + character(kind=CK,len=*),intent(in) :: path + real(real32),intent(out) :: value + logical(LK),intent(out),optional :: found + real(real32),intent(in),optional :: default !! default value if not found + + real(RK) :: tmp + real(RK) :: tmp_default + + if (present(default)) then + tmp_default = real(default,RK) + call json%get(me, path, tmp, found, tmp_default) + else + call json%get(me, path, tmp, found) + end if + + value = real(tmp,real32) + + end subroutine json_get_real32_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_real32_by_path]], where "path" is kind=CDK + + subroutine wrap_json_get_real32_by_path(json, me, path, value, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + character(kind=CDK,len=*),intent(in) :: path + real(real32),intent(out) :: value + logical(LK),intent(out),optional :: found + real(real32),intent(in),optional :: default !! default value if not found + + call json%get(me,to_unicode(path),value,found,default) + + end subroutine wrap_json_get_real32_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_real_vec]] where `vec` is `real32`. + + subroutine json_get_real32_vec(json, me, vec) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + real(real32),dimension(:),allocatable,intent(out) :: vec + + real(RK),dimension(:),allocatable :: tmp + + call json%get(me, tmp) + if (allocated(tmp)) vec = real(tmp,real32) + + end subroutine json_get_real32_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_real_vec_by_path]] where `vec` is `real32`. + + subroutine json_get_real32_vec_by_path(json, me, path, vec, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + real(real32),dimension(:),allocatable,intent(out) :: vec + logical(LK),intent(out),optional :: found + real(real32),dimension(:),intent(in),optional :: default !! default value if not found + + real(RK),dimension(:),allocatable :: tmp + real(RK),dimension(:),allocatable :: tmp_default + + if (present(default)) then + tmp_default = real(default,RK) + call json%get(me, path, tmp, found, tmp_default) + else + call json%get(me, path, tmp, found) + end if + + if (allocated(tmp)) vec = real(tmp,real32) + + end subroutine json_get_real32_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_real32_vec_by_path]], where "path" is kind=CDK + + subroutine wrap_json_get_real32_vec_by_path(json, me, path, vec, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: me + character(kind=CDK,len=*),intent(in) :: path + real(real32),dimension(:),allocatable,intent(out) :: vec + logical(LK),intent(out),optional :: found + real(real32),dimension(:),intent(in),optional :: default !! default value if not found + + call json%get(me, to_unicode(path), vec, found, default) + + end subroutine wrap_json_get_real32_vec_by_path +!***************************************************************************************** + + +# 8855 + + +!***************************************************************************************** +!> +! Get a logical value from a [[json_value]]. +! +!### Note +! If `strict_type_checking` is False, then the following assumptions are made: +! +! * For integers: a value > 0 is True +! * For reals: a value > 0 is True +! * For strings: 'true' is True, and everything else is false. [case sensitive match] + + subroutine json_get_logical(json, me, value) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + logical(LK),intent(out) :: value + + value = .false. + if ( json%exception_thrown ) return + + if (me%var_type == json_logical) then + value = me%log_value + else + if (json%strict_type_checking) then + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_logical: '//& + 'Unable to resolve value to logical: '//& + me%name) + else + call json%throw_exception('Error in json_get_logical: '//& + 'Unable to resolve value to logical') + end if + else +!type conversions + select case (me%var_type) + case (json_integer) + value = (me%int_value > 0_IK) + case (json_real) + value = (me%dbl_value > 0.0_RK) + case (json_string) + value = (me%str_value == true_str) + case default + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_logical: '//& + 'Unable to resolve value to logical: '//& + me%name) + else + call json%throw_exception('Error in json_get_logical: '//& + 'Unable to resolve value to logical') + end if + end select + end if + end if + + end subroutine json_get_logical +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get a logical value from a [[json_value]], given the path. + + subroutine json_get_logical_by_path(json, me, path, value, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + logical(LK),intent(out) :: value + logical(LK),intent(out),optional :: found + logical(LK),intent(in),optional :: default !! default value if not found + + logical(LK),parameter :: default_if_not_specified = .false. + character(kind=CK,len=*),parameter :: routine = CK_'json_get_logical_by_path' + +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_get_scalar_by_path.inc" 1 + type(json_value),pointer :: p + + if (present(default)) then + value = default + else + value = default_if_not_specified + end if + + if ( json%exception_thrown ) then + call flag_not_found(found) + return + end if + + nullify(p) + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in '//routine//':'//& + ' Unable to resolve path: '// trim(path),found) + else + call json%get(p,value) + end if + + if ( json%exception_thrown ) then + if ( present(found) .or. present(default)) then + call flag_not_found(found) + if (present(default)) value = default + call json%clear_exceptions() + end if + else + if ( present(found) ) found = .true. + end if +# 8935 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + end subroutine json_get_logical_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_logical_by_path]], where "path" is kind=CDK + + subroutine wrap_json_get_logical_by_path(json, me, path, value, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CDK,len=*),intent(in) :: path + logical(LK),intent(out) :: value + logical(LK),intent(out),optional :: found + logical(LK),intent(in),optional :: default !! default value if not found + + call json%get(me,to_unicode(path),value,found,default) + + end subroutine wrap_json_get_logical_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 5/14/2014 +! +! Get a logical vector from [[json_value]]. + + subroutine json_get_logical_vec(json, me, vec) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + logical(LK),dimension(:),allocatable,intent(out) :: vec + + logical(LK) :: initialized + + if ( json%exception_thrown ) return + +! check for 0-length arrays first: + select case (me%var_type) + case (json_array) + if (json%count(me)==0) then + allocate(vec(0)) + return + end if + end select + + initialized = .false. + +!the callback function is called for each element of the array: + call json%get(me, array_callback=get_logical_from_array) + + if (json%exception_thrown .and. allocated(vec)) deallocate(vec) + + contains + + subroutine get_logical_from_array(json, element, i, count) + +!! callback function for logical + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: element + integer(IK),intent(in) :: i !! index + integer(IK),intent(in) :: count !! size of array + +!size the output array: + if (.not. initialized) then + allocate(vec(count)) + initialized = .true. + end if + +!populate the elements: + call json%get(element, value=vec(i)) + + end subroutine get_logical_from_array + + end subroutine json_get_logical_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get a logical vector from a [[json_value]], given the path. + + subroutine json_get_logical_vec_by_path(json, me, path, vec, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + logical(LK),dimension(:),allocatable,intent(out) :: vec + logical(LK),intent(out),optional :: found + logical(LK),dimension(:),intent(in),optional :: default + + character(kind=CK,len=*),parameter :: routine = CK_'json_get_logical_vec_by_path' + +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_get_vec_by_path.inc" 1 + type(json_value),pointer :: p + + if ( json%exception_thrown ) then + if (present(default)) vec = default + call flag_not_found(found) + return + end if + + nullify(p) + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in '//routine//':'//& + ' Unable to resolve path: '// trim(path),found) + else + call json%get(p,vec) + end if + + if ( json%exception_thrown ) then + if ( present(found) .or. present(default)) then + call flag_not_found(found) + if (present(default)) vec = default + call json%clear_exceptions() + end if + else + if ( present(found) ) found = .true. + end if +# 9038 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + end subroutine json_get_logical_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_logical_vec_by_path]], where "path" is kind=CDK + + subroutine wrap_json_get_logical_vec_by_path(json, me, path, vec, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CDK,len=*),intent(in) :: path + logical(LK),dimension(:),allocatable,intent(out) :: vec + logical(LK),intent(out),optional :: found + logical(LK),dimension(:),intent(in),optional :: default + + call json%get(me,to_unicode(path),vec,found,default) + + end subroutine wrap_json_get_logical_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get a character string from a [[json_value]]. + + subroutine json_get_string(json, me, value) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=:),allocatable,intent(out) :: value + + value = CK_'' + if (.not. json%exception_thrown) then + + if (me%var_type == json_string) then + + if (allocated(me%str_value)) then + if (json%unescaped_strings) then +! default: it is stored already unescaped: + value = me%str_value + else +! return the escaped version: + call escape_string(me%str_value, value, json%escape_solidus) + end if + else + call json%throw_exception('Error in json_get_string: '//& + 'me%str_value not allocated') + end if + + else + + if (json%strict_type_checking) then + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_string:'//& + ' Unable to resolve value to string: '//me%name) + else + call json%throw_exception('Error in json_get_string:'//& + ' Unable to resolve value to string') + end if + else + + select case (me%var_type) + + case (json_integer) + + if (allocated(me%int_value)) then + value = repeat(space, max_integer_str_len) + call integer_to_string(me%int_value,int_fmt,value) + value = trim(value) + else + call json%throw_exception('Error in json_get_string: '//& + 'me%int_value not allocated') + end if + + case (json_real) + + if (allocated(me%dbl_value)) then + value = repeat(space, max_numeric_str_len) + call real_to_string(me%dbl_value,json%real_fmt,& + json%non_normals_to_null,& + json%compact_real,value) + value = trim(value) + else + call json%throw_exception('Error in json_get_string: '//& + 'me%int_value not allocated') + end if + + case (json_logical) + + if (allocated(me%log_value)) then + if (me%log_value) then + value = true_str + else + value = false_str + end if + else + call json%throw_exception('Error in json_get_string: '//& + 'me%log_value not allocated') + end if + + case (json_null) + + value = null_str + + case default + if (allocated(me%name)) then + call json%throw_exception('Error in json_get_string: '//& + 'Unable to resolve value to characters: '//& + me%name) + else + call json%throw_exception('Error in json_get_string: '//& + 'Unable to resolve value to characters') + end if + end select + + end if + end if + + end if + + end subroutine json_get_string +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get a character string from a [[json_value]], given the path. + + subroutine json_get_string_by_path(json, me, path, value, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + character(kind=CK,len=:),allocatable,intent(out) :: value + logical(LK),intent(out),optional :: found + character(kind=CK,len=*),intent(in),optional :: default + + character(kind=CK,len=*),parameter :: default_if_not_specified = CK_'' + character(kind=CK,len=*),parameter :: routine = CK_'json_get_string_by_path' + +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_get_scalar_by_path.inc" 1 + type(json_value),pointer :: p + + if (present(default)) then + value = default + else + value = default_if_not_specified + end if + + if ( json%exception_thrown ) then + call flag_not_found(found) + return + end if + + nullify(p) + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in '//routine//':'//& + ' Unable to resolve path: '// trim(path),found) + else + call json%get(p,value) + end if + + if ( json%exception_thrown ) then + if ( present(found) .or. present(default)) then + call flag_not_found(found) + if (present(default)) value = default + call json%clear_exceptions() + end if + else + if ( present(found) ) found = .true. + end if +# 9185 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + end subroutine json_get_string_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_string_by_path]], where "path" is kind=CDK + + subroutine wrap_json_get_string_by_path(json, me, path, value, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CDK,len=*),intent(in) :: path + character(kind=CK,len=:),allocatable,intent(out) :: value + logical(LK),intent(out),optional :: found + character(kind=CK,len=*),intent(in),optional :: default + + call json%get(me,to_unicode(path),value,found,default) + + end subroutine wrap_json_get_string_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 5/14/2014 +! +! Get a string vector from a [[json_value(type)]]. + + subroutine json_get_string_vec(json, me, vec) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),dimension(:),allocatable,intent(out) :: vec + + logical(LK) :: initialized + + if ( json%exception_thrown ) return + +! check for 0-length arrays first: + select case (me%var_type) + case (json_array) + if (json%count(me)==0) then + allocate(vec(0)) + return + end if + end select + + initialized = .false. + +!the callback function is called for each element of the array: + call json%get(me, array_callback=get_chars_from_array) + + if (json%exception_thrown .and. allocated(vec)) deallocate(vec) + + contains + + subroutine get_chars_from_array(json, element, i, count) + +!! callback function for chars + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: element + integer(IK),intent(in) :: i !! index + integer(IK),intent(in) :: count !! size of array + + character(kind=CK,len=:),allocatable :: cval + +!size the output array: + if (.not. initialized) then + allocate(vec(count)) + initialized = .true. + end if + +!populate the elements: + call json%get(element, value=cval) + if (allocated(cval)) then + vec(i) = cval + deallocate(cval) + else + vec(i) = CK_'' + end if + + end subroutine get_chars_from_array + + end subroutine json_get_string_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get a string vector from a [[json_value(type)]], given the path. + + subroutine json_get_string_vec_by_path(json, me, path, vec, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + character(kind=CK,len=*),dimension(:),allocatable,intent(out) :: vec + logical(LK),intent(out),optional :: found + character(kind=CK,len=*),dimension(:),intent(in),optional :: default + + character(kind=CK,len=*),parameter :: routine = CK_'json_get_string_vec_by_path' + +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_get_vec_by_path.inc" 1 + type(json_value),pointer :: p + + if ( json%exception_thrown ) then + if (present(default)) vec = default + call flag_not_found(found) + return + end if + + nullify(p) + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in '//routine//':'//& + ' Unable to resolve path: '// trim(path),found) + else + call json%get(p,vec) + end if + + if ( json%exception_thrown ) then + if ( present(found) .or. present(default)) then + call flag_not_found(found) + if (present(default)) vec = default + call json%clear_exceptions() + end if + else + if ( present(found) ) found = .true. + end if +# 9296 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + end subroutine json_get_string_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_string_vec_by_path]], where "path" is kind=CDK + + subroutine wrap_json_get_string_vec_by_path(json, me, path, vec, found, default) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CDK,len=*),intent(in) :: path + character(kind=CK,len=*),dimension(:),allocatable,intent(out) :: vec + logical(LK),intent(out),optional :: found + character(kind=CK,len=*),dimension(:),intent(in),optional :: default + + call json%get(me,to_unicode(path),vec,found,default) + + end subroutine wrap_json_get_string_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 12/16/2016 +! +! Get a string vector from a [[json_value(type)]]. This is an alternate +! version of [[json_get_string_vec]]. This one returns an allocatable +! length character (where the string length is the maximum length of +! any element in the array). It also returns an integer array of the +! actual sizes of the strings in the JSON structure. +! +!@note This is somewhat inefficient since it does +! cycle through the array twice. +! +!@warning The allocation of `vec` doesn't work with +! gfortran 4.9 or 5 due to compiler bugs + + subroutine json_get_alloc_string_vec(json, me, vec, ilen) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=:),dimension(:),allocatable,intent(out) :: vec + integer(IK),dimension(:),allocatable,intent(out) :: ilen !! the actual length +!! of each character +!! string in the array + + logical(LK) :: initialized !! if the output array has been sized + integer(IK) :: max_len !! the length of the longest string in the array + + if ( json%exception_thrown ) return + +! check for 0-length arrays first: + select case (me%var_type) + case (json_array) + if (json%count(me)==0) then + allocate(character(kind=CK,len=0) :: vec(0)) + allocate(ilen(0)) + return + end if + end select + + initialized = .false. + + call json%string_info(me,ilen=ilen,max_str_len=max_len) + if (.not. json%exception_thrown) then +! now get each string using the callback function: + call json%get(me, array_callback=get_chars_from_array) + end if + + if (json%exception_thrown) then + if (allocated(vec)) deallocate(vec) + if (allocated(ilen)) deallocate(ilen) + end if + + contains + + subroutine get_chars_from_array(json, element, i, count) + +!! callback function for chars + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: element + integer(IK),intent(in) :: i !! index + integer(IK),intent(in) :: count !! size of array + + character(kind=CK,len=:),allocatable :: cval !! for getting string + +!size the output array: + if (.not. initialized) then +! string length long enough to hold the longest one +! Note that this doesn't work with gfortran 4.9 or 5. + allocate( character(kind=CK,len=max_len) :: vec(count) ) + initialized = .true. + end if + +!populate the elements: + call json%get(element, value=cval) + if (allocated(cval)) then + vec(i) = cval + ilen(i) = len(cval) ! return the actual length + deallocate(cval) + else + vec(i) = CK_'' + ilen(i) = 0 + end if + + end subroutine get_chars_from_array + + end subroutine json_get_alloc_string_vec +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_alloc_string_vec]] where input is the path. +! +! This is an alternate version of [[json_get_string_vec_by_path]]. +! This one returns an allocatable length character (where the string +! length is the maximum length of any element in the array). It also +! returns an integer array of the actual sizes of the strings in the +! JSON structure. +! +!@note An alternative to using this routine is to use [[json_get_array]] with +! a callback function that gets the string from each element and populates +! a user-defined string type. +! +!@note If the `default` argument is used, and `default_ilen` is not present, +! then `ilen` will just be returned as the length of the `default` dummy +! argument (all elements with the same length). + + subroutine json_get_alloc_string_vec_by_path(json,me,path,vec,ilen,found,default,default_ilen) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + character(kind=CK,len=:),dimension(:),allocatable,intent(out) :: vec + integer(IK),dimension(:),allocatable,intent(out) :: ilen !! the actual length +!! of each character +!! string in the array + logical(LK),intent(out),optional :: found + character(kind=CK,len=*),dimension(:),intent(in),optional :: default + integer(IK),dimension(:),intent(in),optional :: default_ilen !! the actual +!! length of `default` + + character(kind=CK,len=*),parameter :: routine = CK_'json_get_alloc_string_vec_by_path' + +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_get_vec_by_path_alloc.inc" 1 + type(json_value),pointer :: p + + if ( json%exception_thrown ) then + if (present(default)) then + vec = default + if (present(default_ilen)) then + ilen = default_ilen + else + allocate(ilen(size(default))) + ilen = len(default) + end if + end if + call flag_not_found(found) + return + end if + + nullify(p) + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in '//routine//':'//& + ' Unable to resolve path: '// trim(path),found) + else + call json%get(p,vec,ilen) + end if + + if ( json%exception_thrown ) then + if ( present(found) .or. present(default)) then + call flag_not_found(found) + if (present(default)) then + vec = default + if (present(default_ilen)) then + ilen = default_ilen + else + allocate(ilen(size(default))) + ilen = len(default) + end if + end if + call json%clear_exceptions() + end if + else + if ( present(found) ) found = .true. + end if +# 9451 "/mnt/c/Projects/VSIM/SimulationCore2/Common/json-fortran/json_value_module.F90" 2 + + end subroutine json_get_alloc_string_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_alloc_string_vec_by_path]], where "path" is kind=CDK + + subroutine wrap_json_get_alloc_string_vec_by_path(json,me,path,vec,ilen,found,default,default_ilen) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CDK,len=*),intent(in) :: path + character(kind=CK,len=:),dimension(:),allocatable,intent(out) :: vec + integer(IK),dimension(:),allocatable,intent(out) :: ilen !! the actual length +!! of each character +!! string in the array + logical(LK),intent(out),optional :: found + character(kind=CK,len=*),dimension(:),intent(in),optional :: default + integer(IK),dimension(:),intent(in),optional :: default_ilen !! the actual +!! length of `default` + + call json%get(me,to_unicode(path),vec,ilen,found,default,default_ilen) + + end subroutine wrap_json_get_alloc_string_vec_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! This routine calls the user-supplied [[json_array_callback_func]] +! subroutine for each element in the array. +! +!@note For integer, real, logical, and character arrays, +! higher-level routines are provided (see `get` methods), so +! this routine does not have to be used for those cases. + + recursive subroutine json_get_array(json, me, array_callback) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + procedure(json_array_callback_func) :: array_callback + + type(json_value),pointer :: element !! temp variable for getting elements + integer(IK) :: i !! counter + integer(IK) :: count !! number of elements in the array + + if ( json%exception_thrown ) return + + select case (me%var_type) + case (json_array) + count = json%count(me) + element => me%children + do i = 1, count ! callback for each child + if (.not. associated(element)) then + call json%throw_exception('Error in json_get_array: '//& + 'Malformed JSON linked list') + return + end if + call array_callback(json, element, i, count) + if (json%exception_thrown) exit + element => element%next + end do + case default + call json%throw_exception('Error in json_get_array:'//& + ' Resolved value is not an array ') + end select + + end subroutine json_get_array +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 4/28/2016 +! +! Traverse a JSON structure. +! This routine calls the user-specified [[json_traverse_callback_func]] +! for each element of the structure. + + subroutine json_traverse(json,p,traverse_callback) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: p + procedure(json_traverse_callback_func) :: traverse_callback + + logical(LK) :: finished !! can be used to stop the process + + if (.not. json%exception_thrown) call traverse(p) + + contains + + recursive subroutine traverse(p) + +!! recursive [[json_value]] traversal. + + implicit none + + type(json_value),pointer,intent(in) :: p + + type(json_value),pointer :: element !! a child element + integer(IK) :: i !! counter + integer(IK) :: icount !! number of children + + if (json%exception_thrown) return + call traverse_callback(json,p,finished) ! first call for this object + if (finished) return + +!for arrays and objects, have to also call for all children: + if (p%var_type==json_array .or. p%var_type==json_object) then + + icount = json%count(p) ! number of children + if (icount>0) then + element => p%children ! first one + do i = 1, icount ! call for each child + if (.not. associated(element)) then + call json%throw_exception('Error in json_traverse: '//& + 'Malformed JSON linked list') + return + end if + call traverse(element) + if (finished .or. json%exception_thrown) exit + element => element%next + end do + end if + nullify(element) + + end if + + end subroutine traverse + + end subroutine json_traverse +!***************************************************************************************** + +!***************************************************************************************** +!> +! This routine calls the user-supplied array_callback subroutine +! for each element in the array (specified by the path). + + recursive subroutine json_get_array_by_path(json, me, path, array_callback, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CK,len=*),intent(in) :: path + procedure(json_array_callback_func) :: array_callback + logical(LK),intent(out),optional :: found + + type(json_value),pointer :: p + + if ( json%exception_thrown ) then + if ( present(found) ) found = .false. + return + end if + + nullify(p) + +! resolve the path to the value + call json%get(me=me, path=path, p=p) + + if (.not. associated(p)) then + call json%throw_exception('Error in json_get_array:'//& + ' Unable to resolve path: '//trim(path),found) + else + call json%get(me=p,array_callback=array_callback) + nullify(p) + end if + if ( json%exception_thrown ) then + if ( present(found) ) then + found = .false. + call json%clear_exceptions() + end if + else + if ( present(found) ) found = .true. + end if + + end subroutine json_get_array_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_get_array_by_path]], where "path" is kind=CDK + + recursive subroutine wrap_json_get_array_by_path(json, me, path, array_callback, found) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer,intent(in) :: me + character(kind=CDK,len=*),intent(in) :: path + procedure(json_array_callback_func) :: array_callback + logical(LK),intent(out),optional :: found + + call json%get(me, to_unicode(path), array_callback, found) + + end subroutine wrap_json_get_array_by_path +!***************************************************************************************** + +!***************************************************************************************** +!> +! Internal routine to be called before parsing JSON. +! Currently, all this does it allocate the `comment_char` if none was specified. + + subroutine json_prepare_parser(json) + + implicit none + + class(json_core),intent(inout) :: json + + if (json%allow_comments .and. .not. allocated(json%comment_char)) then +! comments are enabled, but user hasn't set the comment char, +! so in this case use the default: + json%comment_char = CK_'/!#' + end if + + end subroutine json_prepare_parser +!***************************************************************************************** + +!***************************************************************************************** +!> +! Parse the JSON file and populate the [[json_value]] tree. +! +!### Inputs +! +! The inputs can be: +! +! * `file` & `unit` : the specified unit is used to read JSON from file. +! [note if unit is already open, then the filename is ignored] +! * `file` : JSON is read from file using internal unit number +! +!### Example +! +!````fortran +! type(json_core) :: json +! type(json_value),pointer :: p +! call json%load(file='myfile.json', p=p) +!```` +! +!### History +! * Jacob Williams : 01/13/2015 : added read from string option. +! * Izaak Beekman : 03/08/2015 : moved read from string to separate +! subroutine, and error annotation to separate subroutine. +! +!@note When calling this routine, any exceptions thrown from previous +! calls will automatically be cleared. + + subroutine json_parse_file(json, file, p, unit) + + implicit none + + class(json_core),intent(inout) :: json + character(kind=CDK,len=*),intent(in) :: file !! JSON file name + type(json_value),pointer :: p !! output structure + integer(IK),intent(in),optional :: unit !! file unit number (/= 0) + + integer(IK) :: iunit !! file unit actually used + integer(IK) :: istat !! iostat flag + logical(LK) :: is_open !! if the file is already open + logical(LK) :: has_duplicate !! if checking for duplicate keys + character(kind=CK,len=:),allocatable :: path !! path to any duplicate key + +! clear any exceptions and initialize: + call json%initialize() + call json%prepare_parser() + + if ( present(unit) ) then + + if (unit==0) then + call json%throw_exception('Error in json_parse_file: unit number must not be 0.') + return + end if + + iunit = unit + +! check to see if the file is already open +! if it is, then use it, otherwise open the file with the name given. + inquire(unit=iunit, opened=is_open, iostat=istat) + if (istat==0 .and. .not. is_open) then +! open the file + open ( unit = iunit, & + file = file, & + status = 'OLD', & + action = 'READ', & + form = form_spec, & + access = access_spec, & + iostat = istat & + ) + else +! if the file is already open, then we need to make sure +! that it is open with the correct form/access/etc... + end if + + else + +! open the file with a new unit number: + open ( newunit = iunit, & + file = file, & + status = 'OLD', & + action = 'READ', & + form = form_spec, & + access = access_spec, & + iostat = istat & + ) + + end if + + if (istat==0) then + + if (use_unformatted_stream) then +! save the file size to be read: + inquire(unit=iunit, size=json%filesize, iostat=istat) + end if + +! create the value and associate the pointer + call json_value_create(p) + +! Note: the name of the root json_value doesn't really matter, +! but we'll allocate something here just in case. + p%name = trim(file) !use the file name + +! parse as a value + call json%parse_value(unit=iunit, str=CK_'', value=p) + call json%parse_end(unit=iunit, str=CK_'') + +! check for errors: + if (json%exception_thrown) then + call json%annotate_invalid_json(iunit,CK_'') + else + if (.not. json%allow_duplicate_keys) then + call json%check_for_duplicate_keys(p,has_duplicate,path=path) + if (.not. json%exception_thrown) then + if (has_duplicate) then + call json%throw_exception('Error in json_parse_file: '//& + 'Duplicate key found: '//path) + end if + end if + end if + end if + +! close the file: + close(unit=iunit, iostat=istat) + + else + + call json%throw_exception('Error in json_parse_file: Error opening file: '//trim(file)) + nullify(p) + + end if + + end subroutine json_parse_file +!***************************************************************************************** + +!***************************************************************************************** +!> +! Parse the JSON string and populate the [[json_value]] tree. +! +!### See also +! * [[json_parse_file]] + + subroutine json_parse_string(json, p, str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p !! output structure + character(kind=CK,len=*),intent(in) :: str !! string with JSON data + + integer(IK),parameter :: iunit = 0 !! indicates that json data will be read from buffer + + logical(LK) :: has_duplicate !! if checking for duplicate keys + character(kind=CK,len=:),allocatable :: path !! path to any duplicate key + +! clear any exceptions and initialize: + call json%initialize() + call json%prepare_parser() + +! create the value and associate the pointer + call json_value_create(p) + +! Note: the name of the root json_value doesn't really matter, +! but we'll allocate something here just in case. + p%name = CK_'' + +! parse as a value + call json%parse_value(unit=iunit, str=str, value=p) + call json%parse_end(unit=iunit, str=str) + + if (json%exception_thrown) then + call json%annotate_invalid_json(iunit,str) + else + if (.not. json%allow_duplicate_keys) then + call json%check_for_duplicate_keys(p,has_duplicate,path=path) + if (.not. json%exception_thrown) then + if (has_duplicate) then + call json%throw_exception('Error in json_parse_string: '//& + 'Duplicate key found: '//path) + end if + end if + end if + end if + + end subroutine json_parse_string +!***************************************************************************************** + +!***************************************************************************************** +!> +! An error checking routine to call after a file (or string) has been parsed. +! It will throw an exception if there are any other non-whitespace characters +! in the file. + + subroutine json_parse_end(json, unit, str) + + implicit none + + class(json_core),intent(inout) :: json + integer(IK),intent(in) :: unit !! file unit number + character(kind=CK,len=*),intent(in) :: str !! string containing JSON +!! data (only used if `unit=0`) + + logical(LK) :: eof !! end-of-file flag + character(kind=CK,len=1) :: c !! character read from file +!! (or string) by [[pop_char]] + +! first check for exceptions: + if (json%exception_thrown) return + +! pop the next non whitespace character off the file + call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., & + skip_comments=json%allow_comments, popped=c) + + if (.not. eof) then + call json%throw_exception('Error in json_parse_end:'//& + ' Unexpected character found after parsing value. "'//& + c//'"') + end if + + end subroutine json_parse_end +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_parse_string]], where `str` is kind=CDK. + + subroutine wrap_json_parse_string(json, p, str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p !! output structure + character(kind=CDK,len=*),intent(in) :: str !! string with JSON data + + call json%deserialize(p,to_unicode(str)) + + end subroutine wrap_json_parse_string +!***************************************************************************************** + +!***************************************************************************************** +!> +! Generate a warning message if there was an error parsing a JSON +! file or string. + + subroutine annotate_invalid_json(json,iunit,str) + + implicit none + + class(json_core),intent(inout) :: json + integer(IK),intent(in) :: iunit !! file unit number + character(kind=CK,len=*),intent(in) :: str !! string with JSON data + + character(kind=CK,len=:),allocatable :: line !! line containing the error + character(kind=CK,len=:),allocatable :: arrow_str !! arrow string that points +!! to the current character + character(kind=CK,len=max_integer_str_len) :: line_str !! current line number string + character(kind=CK,len=max_integer_str_len) :: char_str !! current character count string + integer(IK) :: i !! line number counter + integer(IK) :: i_nl_prev !! index of previous newline character + integer(IK) :: i_nl !! index of current newline character + +! If there was an error reading the file, then +! print the line where the error occurred: + if (json%exception_thrown) then + +!the counters for the current line and the last character read: + call integer_to_string(json%line_count, int_fmt, line_str) + call integer_to_string(json%char_count, int_fmt, char_str) + +!draw the arrow string that points to the current character: + arrow_str = repeat('-',max( 0_IK, json%char_count - 1_IK) )//'^' + + if (json%line_count>0 .and. json%char_count>0) then + + if (iunit/=0) then + + if (use_unformatted_stream) then + call json%get_current_line_from_file_stream(iunit,line) + else + call json%get_current_line_from_file_sequential(iunit,line) + end if + + else + +!get the current line from the string: +! [this is done by counting the newline characters] + i_nl_prev = 0 !index of previous newline character + i_nl = 2 !just in case line_count = 0 + do i=1,json%line_count + i_nl = index(str(i_nl_prev+1:),newline) + if (i_nl==0) then !last line - no newline character + i_nl = len(str)+1 + exit + end if + i_nl = i_nl + i_nl_prev !index of current newline character + i_nl_prev = i_nl !update for next iteration + end do + line = str(i_nl_prev+1 : i_nl-1) !extract current line + + end if + + else +!in this case, it was an empty line or file + line = CK_'' + end if + +! add a newline for the error display if necessary: + line = trim(line) + if (len(line)>0) then + i = len(line) + if (line(i:i)/=newline) line = line//newline + else + line = line//newline + end if + +!create the error message: + if (allocated(json%err_message)) then + json%err_message = json%err_message//newline + else + json%err_message = '' + end if + json%err_message = json%err_message//& + 'line: '//trim(adjustl(line_str))//', '//& + 'character: '//trim(adjustl(char_str))//newline//& + line//arrow_str + + if (allocated(line)) deallocate(line) + + end if + + end subroutine annotate_invalid_json +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Rewind the file to the beginning of the current line, and return this line. +! The file is assumed to be opened. +! This is the SEQUENTIAL version (see also [[get_current_line_from_file_stream]]). + + subroutine get_current_line_from_file_sequential(iunit,line) + + implicit none + + integer(IK),intent(in) :: iunit !! file unit number + character(kind=CK,len=:),allocatable,intent(out) :: line !! current line + + character(kind=CK,len=seq_chunk_size) :: chunk !! for reading line in chunks + integer(IK) :: istat !! iostat flag + integer(IK) :: isize !! number of characters read in read statement + +!initialize: + line = CK_'' + +!rewind to beginning of the current record: + backspace(iunit, iostat=istat) + +!loop to read in all the characters in the current record. +![the line is read in chunks until the end of the line is reached] + if (istat==0) then + do + isize = 0 + read(iunit,fmt='(A)',advance='NO',size=isize,iostat=istat) chunk + if (istat==0) then + line = line//chunk + else + if (isize>0 .and. isize<=seq_chunk_size) line = line//chunk(1:isize) + exit + end if + end do + end if + + end subroutine get_current_line_from_file_sequential +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Rewind the file to the beginning of the current line, and return this line. +! The file is assumed to be opened. +! This is the STREAM version (see also [[get_current_line_from_file_sequential]]). + + subroutine get_current_line_from_file_stream(json,iunit,line) + + implicit none + + class(json_core),intent(inout) :: json + integer(IK),intent(in) :: iunit !! file unit number + character(kind=CK,len=:),allocatable,intent(out) :: line !! current line + + integer(IK) :: istart !! start position of current line + integer(IK) :: iend !! end position of current line + integer(IK) :: ios !! file read `iostat` code + character(kind=CK,len=1) :: c !! a character read from the file + logical :: done !! flag to exit the loop + + istart = json%ipos + do + if (istart<=1) then + istart = 1 + exit + end if + read(iunit,pos=istart,iostat=ios) c + done = ios /= 0_IK + if (.not. done) done = c==newline + if (done) then + if (istart/=1) istart = istart - 1 + exit + end if + istart = istart-1 !rewind until the beginning of the line + end do + iend = json%ipos + do + read(iunit,pos=iend,iostat=ios) c + if (IS_IOSTAT_END(ios)) then +! account for end of file without linebreak + iend=iend-1 + exit + end if + if (c==newline .or. ios/=0) exit + iend=iend+1 + end do + allocate( character(kind=CK,len=iend-istart+1) :: line ) + read(iunit,pos=istart,iostat=ios) line + + end subroutine get_current_line_from_file_stream +!***************************************************************************************** + +!***************************************************************************************** +!> +! Core parsing routine. + + recursive subroutine parse_value(json, unit, str, value) + + implicit none + + class(json_core),intent(inout) :: json + integer(IK),intent(in) :: unit !! file unit number + character(kind=CK,len=*),intent(in) :: str !! string containing JSON +!! data (only used if `unit=0`) + type(json_value),pointer :: value !! JSON data that is extracted + + logical(LK) :: eof !! end-of-file flag + character(kind=CK,len=1) :: c !! character read from file +!! (or string) by [[pop_char]] +# 10121 + + + if (.not. json%exception_thrown) then + +!the routine is being called incorrectly. + if (.not. associated(value)) then + call json%throw_exception('Error in parse_value: value pointer not associated.') + return + end if + +! pop the next non whitespace character off the file + call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., & + skip_comments=json%allow_comments, popped=c) + + if (eof) then + return + else + + select case (c) + + case (start_object) + +! start object + call json%to_object(value) !allocate class + call json%parse_object(unit, str, value) + + case (start_array) + +! start array + call json%to_array(value) !allocate class + call json%parse_array(unit, str, value) + + case (end_array) + +! end an empty array + call json%push_char(c) + if (associated(value)) then + deallocate(value) + nullify(value) + end if + + case (quotation_mark) + +! string + call json%to_string(value) !allocate class + + select case (value%var_type) + case (json_string) +# 10175 + + call json%parse_string(unit,str,value%str_value) + + end select + + case (CK_'t') !true_str(1:1) gfortran bug work around + +!true + call json%parse_for_chars(unit, str, true_str(2:)) +!allocate class and set value: + if (.not. json%exception_thrown) call json%to_logical(value,.true.) + + case (CK_'f') !false_str(1:1) gfortran bug work around + +!false + call json%parse_for_chars(unit, str, false_str(2:)) +!allocate class and set value: + if (.not. json%exception_thrown) call json%to_logical(value,.false.) + + case (CK_'n') !null_str(1:1) gfortran bug work around + +!null + call json%parse_for_chars(unit, str, null_str(2:)) + if (.not. json%exception_thrown) call json%to_null(value) ! allocate class + + case(CK_'-', CK_'0': CK_'9', CK_'.', CK_'+') + + call json%push_char(c) + call json%parse_number(unit, str, value) + + case default + + call json%throw_exception('Error in parse_value:'//& + ' Unexpected character while parsing value. "'//& + c//'"') + + end select + end if + + end if + + end subroutine parse_value +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Allocate a [[json_value]] pointer and make it a logical(LK) variable. +! The pointer should not already be allocated. +! +!### Example +!````fortran +! type(json_value),pointer :: p +! type(json_core) :: json +! call json%create_logical(p,'value',.true.) +!```` + + subroutine json_value_create_logical(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + logical(LK),intent(in) :: val !! variable value + character(kind=CK,len=*),intent(in) :: name !! variable name + + call json_value_create(p) + call json%to_logical(p,val,name) + + end subroutine json_value_create_logical +!***************************************************************************************** + +!***************************************************************************************** +!> author: Izaak Beekman +! +! Wrapper for [[json_value_create_logical]] so `create_logical` method can +! be called with name of character kind 'DEFAULT' or 'ISO_10646' + + subroutine wrap_json_value_create_logical(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + logical(LK),intent(in) :: val + character(kind=CDK,len=*),intent(in) :: name + + call json%create_logical(p,val,to_unicode(name)) + + end subroutine wrap_json_value_create_logical +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Allocate a [[json_value]] pointer and make it an integer(IK) variable. +! The pointer should not already be allocated. +! +!### Example +!````fortran +! type(json_value),pointer :: p +! type(json_core) :: json +! call json%create_integer(p,'value',1) +!```` + + subroutine json_value_create_integer(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + integer(IK),intent(in) :: val + character(kind=CK,len=*),intent(in) :: name + + call json_value_create(p) + call json%to_integer(p,val,name) + + end subroutine json_value_create_integer +!***************************************************************************************** + +!***************************************************************************************** +!> author: Izaak Beekman +! +! A wrapper procedure for [[json_value_create_integer]] so that `create_integer` +! method may be called with either a 'DEFAULT' or 'ISO_10646' character kind +! `name` actual argument. + + subroutine wrap_json_value_create_integer(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + integer(IK),intent(in) :: val + character(kind=CDK,len=*),intent(in) :: name + + call json%create_integer(p,val,to_unicode(name)) + + end subroutine wrap_json_value_create_integer +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Allocate a [[json_value]] pointer and make it a real(RK) variable. +! The pointer should not already be allocated. +! +!### Example +!````fortran +! type(json_value),pointer :: p +! type(json_core) :: json +! call json%create_real(p,'value',1.0_RK) +!```` + + subroutine json_value_create_real(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + real(RK),intent(in) :: val + character(kind=CK,len=*),intent(in) :: name + + call json_value_create(p) + call json%to_real(p,val,name) + + end subroutine json_value_create_real +!***************************************************************************************** + +!***************************************************************************************** +!> author: Izaak Beekman +! +! A wrapper for [[json_value_create_real]] so that `create_real` method +! may be called with an actual argument corresponding to the dummy argument, +! `name` that may be of 'DEFAULT' or 'ISO_10646' character kind. + + subroutine wrap_json_value_create_real(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + real(RK),intent(in) :: val + character(kind=CDK,len=*),intent(in) :: name + + call json%create_real(p,val,to_unicode(name)) + + end subroutine wrap_json_value_create_real +!***************************************************************************************** + + +!***************************************************************************************** +!> +! Alternate version of [[json_value_create_real]] where val=real32. +! +!@note The value is converted into a `real(RK)` variable internally. + + subroutine json_value_create_real32(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + real(real32),intent(in) :: val + character(kind=CK,len=*),intent(in) :: name + + call json%create_real(p,real(val,RK),name) + + end subroutine json_value_create_real32 +!***************************************************************************************** + +!***************************************************************************************** +!> +! Alternate version of [[json_value_create_real32]] where "name" is kind(CDK). + + subroutine wrap_json_value_create_real32(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + real(real32),intent(in) :: val + character(kind=CDK,len=*),intent(in) :: name + + call json%create_real(p,val,to_unicode(name)) + + end subroutine wrap_json_value_create_real32 +!***************************************************************************************** + + +# 10443 + + +!***************************************************************************************** +!> author: Jacob Williams +! +! Allocate a json_value pointer and make it a string variable. +! The pointer should not already be allocated. +! +!### Example +!````fortran +! type(json_value),pointer :: p +! type(json_core) :: json +! call json%create_string(p,'value','hello') +!```` + + subroutine json_value_create_string(json,p,val,name,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: val + character(kind=CK,len=*),intent(in) :: name + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` + + call json_value_create(p) + call json%to_string(p,val,name,trim_str,adjustl_str) + + end subroutine json_value_create_string +!***************************************************************************************** + +!***************************************************************************************** +!> author: Izaak Beekman +! +! Wrap [[json_value_create_string]] so that `create_string` method may be called +! with actual character string arguments for `name` and `val` that are BOTH of +! 'DEFAULT' or 'ISO_10646' character kind. + + subroutine wrap_json_value_create_string(json,p,val,name,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: val + character(kind=CDK,len=*),intent(in) :: name + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` + + call json%create_string(p,to_unicode(val),to_unicode(name),trim_str,adjustl_str) + + end subroutine wrap_json_value_create_string +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Allocate a json_value pointer and make it a null variable. +! The pointer should not already be allocated. +! +!### Example +!````fortran +! type(json_value),pointer :: p +! type(json_core) :: json +! call json%create_null(p,'value') +!```` + + subroutine json_value_create_null(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name + + call json_value_create(p) + call json%to_null(p,name) + + end subroutine json_value_create_null +!***************************************************************************************** + +!***************************************************************************************** +!> author: Izaak Beekman +! +! Wrap [[json_value_create_null]] so that `create_null` method may be called with +! an actual argument corresponding to the dummy argument `name` that is either +! of 'DEFAULT' or 'ISO_10646' character kind. + + subroutine wrap_json_value_create_null(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name + + call json%create_null(p,to_unicode(name)) + + end subroutine wrap_json_value_create_null +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Allocate a [[json_value]] pointer and make it an object variable. +! The pointer should not already be allocated. +! +!### Example +!````fortran +! type(json_value),pointer :: p +! type(json_core) :: json +! call json%create_object(p,'objectname') +!```` +! +!@note The name is not significant for the root structure or an array element. +! In those cases, an empty string can be used. + + subroutine json_value_create_object(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name + + call json_value_create(p) + call json%to_object(p,name) + + end subroutine json_value_create_object +!***************************************************************************************** + +!***************************************************************************************** +!> author: Izaak Beekman +! +! Wrap [[json_value_create_object]] so that `create_object` method may be called +! with an actual argument corresponding to the dummy argument `name` that is of +! either 'DEFAULT' or 'ISO_10646' character kind. + + subroutine wrap_json_value_create_object(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name + + call json%create_object(p,to_unicode(name)) + + end subroutine wrap_json_value_create_object +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Allocate a [[json_value]] pointer and make it an array variable. +! The pointer should not already be allocated. +! +!### Example +!````fortran +! type(json_value),pointer :: p +! type(json_core) :: json +! call json%create_array(p,'arrayname') +!```` + + subroutine json_value_create_array(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in) :: name + + call json_value_create(p) + call json%to_array(p,name) + + end subroutine json_value_create_array +!***************************************************************************************** + +!***************************************************************************************** +!> author: Izaak Beekman +! +! A wrapper for [[json_value_create_array]] so that `create_array` method may be +! called with an actual argument, corresponding to the dummy argument `name`, +! that is either of 'DEFAULT' or 'ISO_10646' character kind. + + subroutine wrap_json_value_create_array(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CDK,len=*),intent(in) :: name + + call json%create_array(p,to_unicode(name)) + + end subroutine wrap_json_value_create_array +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Change the [[json_value]] variable to a logical. + + subroutine to_logical(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + logical(LK),intent(in),optional :: val !! if the value is also to be set +!! (if not present, then .false. is used). + character(kind=CK,len=*),intent(in),optional :: name !! if the name is also to be changed. + +!set type and value: + call destroy_json_data(p) + p%var_type = json_logical + allocate(p%log_value) + if (present(val)) then + p%log_value = val + else + p%log_value = .false. !default value + end if + +!name: + if (present(name)) call json%rename(p,name) + + end subroutine to_logical +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Change the [[json_value]] variable to an integer. + + subroutine to_integer(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + integer(IK),intent(in),optional :: val !! if the value is also to be set +!! (if not present, then 0 is used). + character(kind=CK,len=*),intent(in),optional :: name !! if the name is also to be changed. + +!set type and value: + call destroy_json_data(p) + p%var_type = json_integer + allocate(p%int_value) + if (present(val)) then + p%int_value = val + else + p%int_value = 0_IK !default value + end if + +!name: + if (present(name)) call json%rename(p,name) + + end subroutine to_integer +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Change the [[json_value]] variable to a real. + + subroutine to_real(json,p,val,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + real(RK),intent(in),optional :: val !! if the value is also to be set +!! (if not present, then 0.0_rk is used). + character(kind=CK,len=*),intent(in),optional :: name !! if the name is also to be changed. + +!set type and value: + call destroy_json_data(p) + p%var_type = json_real + allocate(p%dbl_value) + if (present(val)) then + p%dbl_value = val + else + p%dbl_value = 0.0_RK !default value + end if + +!name: + if (present(name)) call json%rename(p,name) + + end subroutine to_real +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Change the [[json_value]] variable to a string. +! +!### Modified +! * Izaak Beekman : 02/24/2015 + + subroutine to_string(json,p,val,name,trim_str,adjustl_str) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in),optional :: val !! if the value is also to be set +!! (if not present, then '' is used). + character(kind=CK,len=*),intent(in),optional :: name !! if the name is also to be changed. + logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for the `val` +!! (only used if `val` is present) + logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for the `val` +!! (only used if `val` is present) +!! (note that ADJUSTL is done before TRIM) + + character(kind=CK,len=:),allocatable :: str !! temp string for `trim()` and/or `adjustl()` + logical :: trim_string !! if the string is to be trimmed + logical :: adjustl_string !! if the string is to be adjusted left + +!set type and value: + call destroy_json_data(p) + p%var_type = json_string + if (present(val)) then + + if (present(trim_str)) then + trim_string = trim_str + else + trim_string = .false. + end if + if (present(adjustl_str)) then + adjustl_string = adjustl_str + else + adjustl_string = .false. + end if + + if (trim_string .or. adjustl_string) then + str = val + if (adjustl_string) str = adjustl(str) + if (trim_string) str = trim(str) + p%str_value = str + else + p%str_value = val + end if + + else + p%str_value = CK_'' ! default value + end if + +!name: + if (present(name)) call json%rename(p,name) + + end subroutine to_string +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Change the [[json_value]] variable to a null. + + subroutine to_null(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in),optional :: name !! if the name is also to be changed. + +!set type and value: + call destroy_json_data(p) + p%var_type = json_null + +!name: + if (present(name)) call json%rename(p,name) + + end subroutine to_null +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Change the [[json_value]] variable to an object. + + subroutine to_object(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in),optional :: name !! if the name is also to be changed. + +!set type and value: + call destroy_json_data(p) + p%var_type = json_object + +!name: + if (present(name)) call json%rename(p,name) + + end subroutine to_object +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Change the [[json_value]] variable to an array. + + subroutine to_array(json,p,name) + + implicit none + + class(json_core),intent(inout) :: json + type(json_value),pointer :: p + character(kind=CK,len=*),intent(in),optional :: name !! if the name is also to be changed. + +!set type and value: + call destroy_json_data(p) + p%var_type = json_array + +!name: + if (present(name)) call json%rename(p,name) + + end subroutine to_array +!***************************************************************************************** + +!***************************************************************************************** +!> +! Core parsing routine. + + recursive subroutine parse_object(json, unit, str, parent) + + implicit none + + class(json_core),intent(inout) :: json + integer(IK),intent(in) :: unit !! file unit number (if parsing from a file) + character(kind=CK,len=*),intent(in) :: str !! JSON string (if parsing from a string) + type(json_value),pointer :: parent !! the parsed object will be added as a child of this + + type(json_value),pointer :: pair !! temp variable + logical(LK) :: eof !! end of file flag + character(kind=CK,len=1) :: c !! character returned by [[pop_char]] +# 10885 + + + if (.not. json%exception_thrown) then + +!the routine is being called incorrectly. + if (.not. associated(parent)) then + call json%throw_exception('Error in parse_object: parent pointer not associated.') + end if + + nullify(pair) !probably not necessary + +! pair name + call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., & + skip_comments=json%allow_comments, popped=c) + if (eof) then + call json%throw_exception('Error in parse_object:'//& + ' Unexpected end of file while parsing start of object.') + return + else if (end_object == c) then +! end of an empty object + return + else if (quotation_mark == c) then + call json_value_create(pair) +# 10912 + + call json%parse_string(unit,str,pair%name) + + if (json%exception_thrown) then + call json%destroy(pair) + return + end if + else + call json%throw_exception('Error in parse_object: Expecting string: "'//c//'"') + return + end if + +! pair value + call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., & + skip_comments=json%allow_comments, popped=c) + if (eof) then + call json%destroy(pair) + call json%throw_exception('Error in parse_object:'//& + ' Unexpected end of file while parsing object member.') + return + else if (colon_char == c) then +! parse the value + call json%parse_value(unit, str, pair) + if (json%exception_thrown) then + call json%destroy(pair) + return + else + call json%add(parent, pair) + end if + else + call json%destroy(pair) + call json%throw_exception('Error in parse_object:'//& + ' Expecting : and then a value: '//c) + return + end if + +! another possible pair + call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., & + skip_comments=json%allow_comments, popped=c) + if (eof) then + call json%throw_exception('Error in parse_object: '//& + 'End of file encountered when parsing an object') + return + else if (delimiter == c) then +! read the next member + call json%parse_object(unit = unit, str=str, parent = parent) + else if (end_object == c) then +! end of object + return + else + call json%throw_exception('Error in parse_object: Expecting end of object: '//c) + return + end if + + end if + + end subroutine parse_object +!***************************************************************************************** + +!***************************************************************************************** +!> +! Core parsing routine. + + recursive subroutine parse_array(json, unit, str, array) + + implicit none + + class(json_core),intent(inout) :: json + integer(IK),intent(in) :: unit !! file unit number (if parsing from a file) + character(kind=CK,len=*),intent(in) :: str !! JSON string (if parsing from a string) + type(json_value),pointer :: array + + type(json_value),pointer :: element !! temp variable for array element + logical(LK) :: eof !! end of file flag + character(kind=CK,len=1) :: c !! character returned by [[pop_char]] + + do + + if (json%exception_thrown) exit + +! try to parse an element value + nullify(element) + call json_value_create(element) + call json%parse_value(unit, str, element) + if (json%exception_thrown) then + if (associated(element)) call json%destroy(element) + exit + end if + +! parse value will deallocate an empty array value + if (associated(element)) call json%add(array, element) + +! popped the next character + call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., & + skip_comments=json%allow_comments, popped=c) + + if (eof) then +! The file ended before array was finished: + call json%throw_exception('Error in parse_array: '//& + 'End of file encountered when parsing an array.') + exit + else if (delimiter == c) then +! parse the next element + cycle + else if (end_array == c) then +! end of array + exit + else + call json%throw_exception('Error in parse_array: '//& + 'Unexpected character encountered when parsing array.') + exit + end if + + end do + + end subroutine parse_array +!***************************************************************************************** + +!***************************************************************************************** +!> +! Parses a string while reading a JSON file. +! +!### History +! * Jacob Williams : 6/16/2014 : Added hex validation. +! * Jacob Williams : 12/3/2015 : Fixed some bugs. +! * Jacob Williams : 8/23/2015 : `string` is now returned unescaped. +! * Jacob Williams : 7/21/2018 : moved hex validate to [[unescape_string]]. + + subroutine parse_string(json, unit, str, string) + + implicit none + + class(json_core),intent(inout) :: json + integer(IK),intent(in) :: unit !! file unit number (if +!! parsing from a file) + character(kind=CK,len=*),intent(in) :: str !! JSON string (if parsing +!! from a string) + character(kind=CK,len=:),allocatable,intent(out) :: string !! the string (unescaped +!! if necessary) + + logical(LK) :: eof !! end of file flag + logical(LK) :: escape !! for escape string parsing + character(kind=CK,len=1) :: c !! character returned by [[pop_char]] + integer(IK) :: ip !! index to put next character, +!! to speed up by reducing the number +!! of character string reallocations. + character(kind=CK,len=:),allocatable :: error_message !! for string unescaping + +!at least return a blank string if there is a problem: + string = blank_chunk + + if (.not. json%exception_thrown) then + +!initialize: + escape = .false. + ip = 1 + + do + +!get the next character from the file: + call json%pop_char(unit, str=str, eof=eof, skip_ws=.false., popped=c) + + if (eof) then + + call json%throw_exception('Error in parse_string: Expecting end of string') + return + + else if (c==quotation_mark .and. .not. escape) then !end of string + + exit + + else + +!if the string is not big enough, then add another chunk: + if (ip>len(string)) string = string // blank_chunk + +!append to string: + string(ip:ip) = c + ip = ip + 1 + +! check for escape character, so we don't +! exit prematurely if escaping a quotation +! character: + if (escape) then + escape = .false. + else + escape = (c==backslash) + end if + + end if + + end do + +!trim the string if necessary: + if (ip +! Core parsing routine. +! +! This is used to verify the strings `true`, `false`, and `null` during parsing. + + subroutine parse_for_chars(json, unit, str, chars) + + implicit none + + class(json_core),intent(inout) :: json + integer(IK),intent(in) :: unit !! file unit number (if parsing from a file) + character(kind=CK,len=*),intent(in) :: str !! JSON string (if parsing from a string) + character(kind=CK,len=*),intent(in) :: chars !! the string to check for. + + integer(IK) :: i !! counter + integer(IK) :: length !! trimmed length of `chars` + logical(LK) :: eof !! end of file flag + character(kind=CK,len=1) :: c !! character returned by [[pop_char]] + + if (.not. json%exception_thrown) then + + length = len_trim(chars) + + do i = 1, length + call json%pop_char(unit, str=str, eof=eof, skip_ws=.false., popped=c) + if (eof) then + call json%throw_exception('Error in parse_for_chars:'//& + ' Unexpected end of file while parsing.') + return + else if (c /= chars(i:i)) then + call json%throw_exception('Error in parse_for_chars:'//& + ' Unexpected character: "'//c//'" (expecting "'//& + chars(i:i)//'")') + return + end if + end do + + end if + + end subroutine parse_for_chars +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! date: 1/20/2014 +! +! Read a numerical value from the file (or string). +! The routine will determine if it is an integer or a real, and +! allocate the type accordingly. +! +!@note Complete rewrite of the original FSON routine, which had some problems. + + subroutine parse_number(json, unit, str, value) + + implicit none + + class(json_core),intent(inout) :: json + integer(IK),intent(in) :: unit !! file unit number (if parsing from a file) + character(kind=CK,len=*),intent(in) :: str !! JSON string (if parsing from a string) + type(json_value),pointer :: value + + character(kind=CK,len=:),allocatable :: tmp !! temp string + character(kind=CK,len=:),allocatable :: saved_err_message !! temp error message for +!! string to int conversion + character(kind=CK,len=1) :: c !! character returned by [[pop_char]] + logical(LK) :: eof !! end of file flag + real(RK) :: rval !! real value + integer(IK) :: ival !! integer value + logical(LK) :: first !! first character + logical(LK) :: is_integer !! it is an integer + integer(IK) :: ip !! index to put next character +!! [to speed up by reducing the number +!! of character string reallocations] + + if (.not. json%exception_thrown) then + + tmp = blank_chunk + ip = 1 + first = .true. + is_integer = .true. !assume it may be an integer, unless otherwise determined + +!read one character at a time and accumulate the string: + do + +!get the next character: + call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., popped=c) + + select case (c) + case(CK_'-',CK_'+') !note: allowing a '+' as the first character here. + + if (is_integer .and. (.not. first)) is_integer = .false. + +!add it to the string: +!tmp = tmp // c !...original + if (ip>len(tmp)) tmp = tmp // blank_chunk + tmp(ip:ip) = c + ip = ip + 1 + + case(CK_'.',CK_'E',CK_'e',CK_'D',CK_'d') !can be present in real numbers + + if (is_integer) is_integer = .false. + +!add it to the string: +!tmp = tmp // c !...original + if (ip>len(tmp)) tmp = tmp // blank_chunk + tmp(ip:ip) = c + ip = ip + 1 + + case(CK_'0':CK_'9') !valid characters for numbers + +!add it to the string: +!tmp = tmp // c !...original + if (ip>len(tmp)) tmp = tmp // blank_chunk + tmp(ip:ip) = c + ip = ip + 1 + + case default + +!push back the last character read: + call json%push_char(c) + +!string to value: + if (is_integer) then +! it is an integer: + ival = json%string_to_int(tmp) + + if (json%exception_thrown .and. .not. json%strict_integer_type_checking) then +! if it couldn't be converted to an integer, +! then try to convert it to a real value and see if that works + + saved_err_message = json%err_message ! keep the original error message + call json%clear_exceptions() ! clear exceptions + rval = json%string_to_dble(tmp) + if (json%exception_thrown) then +! restore original error message and continue + json%err_message = saved_err_message + call json%to_integer(value,ival) ! just so we have something + else +! in this case, we return a real + call json%to_real(value,rval) + end if + + else + call json%to_integer(value,ival) + end if + + else +! it is a real: + rval = json%string_to_dble(tmp) + call json%to_real(value,rval) + end if + + exit !finished + + end select + + if (first) first = .false. + + end do + +!cleanup: + if (allocated(tmp)) deallocate(tmp) + + end if + + end subroutine parse_number +!***************************************************************************************** + +!***************************************************************************************** +!> +! Get the next character from the file (or string). +! +!### See also +! * [[push_char]] +! +!@note This routine ignores non-printing ASCII characters +! (`iachar<=31`) that are in strings. + + subroutine pop_char(json,unit,str,skip_ws,skip_comments,eof,popped) + + implicit none + + class(json_core),intent(inout) :: json + integer(IK),intent(in) :: unit !! file unit number (if parsing +!! from a file) + character(kind=CK,len=*),intent(in) :: str !! JSON string (if parsing from a +!! string) -- only used if `unit=0` + logical(LK),intent(in),optional :: skip_ws !! to ignore whitespace [default False] + logical(LK),intent(in),optional :: skip_comments !! to ignore comment lines [default False] + logical(LK),intent(out) :: eof !! true if the end of the file has +!! been reached. + character(kind=CK,len=1),intent(out) :: popped !! the popped character returned + + integer(IK) :: ios !! `iostat` flag + integer(IK) :: str_len !! length of `str` + character(kind=CK,len=1) :: c !! a character read from the file (or string) + logical(LK) :: ignore !! if whitespace is to be ignored + logical(LK) :: ignore_comments !! if comment lines are to be ignored + logical(LK) :: parsing_comment !! if we are in the process +!! of parsing a comment line + + if (.not. json%exception_thrown) then + + eof = .false. + if (.not. present(skip_ws)) then + ignore = .false. + else + ignore = skip_ws + end if + parsing_comment = .false. + if (.not. present(skip_comments)) then + ignore_comments = .false. + else + ignore_comments = skip_comments + end if + + do + + if (json%pushed_index > 0) then + +! there is a character pushed back on, most likely +! from the number parsing. Note: this can only occur if +! reading from a file when use_unformatted_stream=.false. + c = json%pushed_char(json%pushed_index:json%pushed_index) + json%pushed_index = json%pushed_index - 1 + + else + + if (unit/=0) then !read from the file + +!read the next character: + if (use_unformatted_stream) then + +! in this case, we read the file in chunks. +! if we already have the character we need, +! then get it from the chunk. Otherwise, +! read in another chunk. + if (json%ichunk<1) then +! read in a chunk: + json%ichunk = 0 + if (json%filesizelen(json%chunk)) then +! check this just in case + ios = IOSTAT_END + else +! get the next character from the chunk: + c = json%chunk(json%ichunk:json%ichunk) + if (json%ichunk==len(json%chunk)) then + json%ichunk = 0 ! reset for next chunk + end if + end if + + else +! a formatted read: + read(unit=unit,fmt='(A1)',advance='NO',iostat=ios) c + end if + json%ipos = json%ipos + 1 + + else !read from the string + + str_len = len(str) !length of the string + if (json%ipos<=str_len) then + c = str(json%ipos:json%ipos) + ios = 0 + else + ios = IOSTAT_END !end of the string + end if + json%ipos = json%ipos + 1 + + end if + + json%char_count = json%char_count + 1 !character count in the current line + + if (IS_IOSTAT_END(ios)) then !end of file + +! no character to return + json%char_count = 0 + eof = .true. + popped = space ! just to set a value + exit + + else if (IS_IOSTAT_EOR(ios) .or. c==newline) then !end of record + + json%char_count = 0 + json%line_count = json%line_count + 1 + if (ignore_comments) parsing_comment = .false. ! done parsing this comment line + cycle + + end if + + end if + + if (ignore_comments .and. (parsing_comment .or. scan(c,json%comment_char,kind=IK)>0_IK) ) then + +! skipping the comment + parsing_comment = .true. + cycle + + else if (any(c == control_chars)) then + +! non printing ascii characters + cycle + + else if (ignore .and. c == space) then + +! ignoring whitespace + cycle + + else + +! return the character + popped = c + exit + + end if + + end do + + end if + + end subroutine pop_char +!***************************************************************************************** + +!***************************************************************************************** +!> +! Core routine. +! +!### See also +! * [[pop_char]] +! +!### History +! * Jacob Williams : 5/3/2015 : replaced original version of this routine. + + subroutine push_char(json,c) + + implicit none + + class(json_core),intent(inout) :: json + character(kind=CK,len=1),intent(in) :: c !! to character to push + + character(kind=CK,len=max_numeric_str_len) :: istr !! for error printing + + if (.not. json%exception_thrown) then + + if (use_unformatted_stream) then + +!in this case, c is ignored, and we just +!decrement the stream position counter: + json%ipos = json%ipos - 1 + json%ichunk = json%ichunk - 1 + + else + + json%pushed_index = json%pushed_index + 1 + + if (json%pushed_index>0 .and. json%pushed_index<=len(json%pushed_char)) then + json%pushed_char(json%pushed_index:json%pushed_index) = c + else + call integer_to_string(json%pushed_index,int_fmt,istr) + call json%throw_exception('Error in push_char: '//& + 'invalid valid of pushed_index: '//trim(istr)) + end if + + end if + +!character count in the current line + json%char_count = json%char_count - 1 + + end if + + end subroutine push_char +!***************************************************************************************** + +!***************************************************************************************** +!> author: Jacob Williams +! +! Print any error message, and then clear the exceptions. +! +!@note This routine is used by the unit tests. +! It was originally in json_example.f90, and was +! moved here 2/26/2015 by Izaak Beekman. + + subroutine json_print_error_message(json,io_unit) + + implicit none + + class(json_core),intent(inout) :: json + integer, intent(in), optional :: io_unit !! unit number for +!! printing error message + + character(kind=CK,len=:),allocatable :: error_msg !! error message + logical :: status_ok !! false if there were any errors thrown + +!get error message: + call json%check_for_errors(status_ok, error_msg) + +!print it if there is one: + if (.not. status_ok) then + if (present(io_unit)) then + write(io_unit,'(A)') error_msg + else + write(output_unit,'(A)') error_msg + end if + deallocate(error_msg) + call json%clear_exceptions() + end if + + end subroutine json_print_error_message +!***************************************************************************************** + +!***************************************************************************************** + end module json_value_module +!***************************************************************************************** diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3105a5c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM ubuntu:latest +COPY /SimulationCore2 /app/SimulationCore2 +COPY /config-remote.json /app/config-remote.json +CMD ['./SimulationCore2', 'config-remote.json'] \ No newline at end of file diff --git a/Equipments/BopStack/ANNULAR.f90 b/Equipments/BopStack/ANNULAR.f90 index 108b30b..faef276 100644 --- a/Equipments/BopStack/ANNULAR.f90 +++ b/Equipments/BopStack/ANNULAR.f90 @@ -16,7 +16,7 @@ SUBROUTINE ANNULAR_SUB1 data%State%RAM(1)%SuccessionCounter = data%State%RAM(1)%SuccessionCounter + 1 - if (data%EquipmentControl%BopControlPanel%AnnularValve == 1.0 .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if (data%Equipments%BopControlPanel%AnnularValve == 1.0 .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then if (data%State%BopStackInput%AnnularCloseLedMine == LedOn) then RETURN @@ -38,9 +38,9 @@ SUBROUTINE ANNULAR_SUB1 data%State%RAM(1)%First_CloseTimecheck= 1 - data%EquipmentControl%BopControlPanel%AnnularOpenLED = LedOff + data%Equipments%BopControlPanel%AnnularOpenLED = LedOff data%State%BopStackInput%AnnularOpenLedMine = LedOff - data%EquipmentControl%BopControlPanel%AnnularCloseLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%AnnularCloseLED = LedOn !LedBlinking data%State%RAM(1)%FourwayValve = 1 @@ -70,7 +70,7 @@ SUBROUTINE ANNULAR_SUB1 if (data%State%Annular%finished_Annular==1) then data%State%Annular%AnnularLeverOld=-1.0 else - data%State%Annular%AnnularLeverOld=data%EquipmentControl%BopControlPanel%AnnularValve + data%State%Annular%AnnularLeverOld=data%Equipments%BopControlPanel%AnnularValve endif data%State%Annular%finished_Annular=0 data%State%Annular%AnnularIsClosing = .true. @@ -85,7 +85,7 @@ SUBROUTINE ANNULAR_SUB1 endif - if (data%EquipmentControl%BopControlPanel%AnnularValve == -1.0 .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1 ) then + if (data%Equipments%BopControlPanel%AnnularValve == -1.0 .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 ) then if (data%State%BopStackInput%AnnularOpenLedMine == LedOn) then RETURN @@ -111,9 +111,9 @@ SUBROUTINE ANNULAR_SUB1 data%State%RAM(1)%First_OpenTimecheck= 1 - data%EquipmentControl%BopControlPanel%AnnularCloseLED = LedOff !new + data%Equipments%BopControlPanel%AnnularCloseLED = LedOff !new data%State%BopStackInput%AnnularCloseLedMine = LedOff !new - data%EquipmentControl%BopControlPanel%AnnularOpenLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%AnnularOpenLED = LedOn !LedBlinking data%State%RAM(1)%FourwayValve = 1 @@ -150,7 +150,7 @@ SUBROUTINE ANNULAR_SUB1 if (data%State%Annular%finished_Annular==1) then data%State%Annular%AnnularLeverOld=1.0 else - data%State%Annular%AnnularLeverOld=data%EquipmentControl%BopControlPanel%AnnularValve + data%State%Annular%AnnularLeverOld=data%Equipments%BopControlPanel%AnnularValve endif data%State%Annular%finished_Annular=0 data%State%Annular%AnnularIsOpening = .true. @@ -220,7 +220,7 @@ SUBROUTINE ANNULAR_SUB2 ! CALL CPU_TIME(Annular_StartTime) - if (data%EquipmentControl%BopControlPanel%AnnularValve == 1.0 .and. data%State%Annular%AnnularLeverOld == -1.0 .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if (data%Equipments%BopControlPanel%AnnularValve == 1.0 .and. data%State%Annular%AnnularLeverOld == -1.0 .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then if ( data%State%RAM(1)%First_CloseTimecheck == 0 ) then @@ -238,9 +238,9 @@ SUBROUTINE ANNULAR_SUB2 if ( data%State%RAM(1)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then !return - data%EquipmentControl%BopControlPanel%AnnularOpenLED = LedOff + data%Equipments%BopControlPanel%AnnularOpenLED = LedOff data%State%BopStackInput%AnnularOpenLedMine = LedOff - data%EquipmentControl%BopControlPanel%AnnularCloseLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%AnnularCloseLED = LedOn !LedBlinking data%State%RAM(1)%FourwayValve = 1 @@ -261,7 +261,7 @@ SUBROUTINE ANNULAR_SUB2 data%State%Annular%Annular_closed=0 !Annular_closed_withPossibility= Annular_closed * TD_BOPConnectionPossibility(1) data%State%AnnularComputational%p_annular=data%State%AnnularComputational%pa_annular - data%State%Annular%AnnularLeverOld = data%EquipmentControl%BopControlPanel%AnnularValve + data%State%Annular%AnnularLeverOld = data%Equipments%BopControlPanel%AnnularValve CALL OpenAnnular data%State%Annular%Annular_Situation_forTD= 0 ! open - for TD code @@ -281,7 +281,7 @@ SUBROUTINE ANNULAR_SUB2 endif - if (data%EquipmentControl%BopControlPanel%AnnularValve == -1.0 .and. data%State%Annular%AnnularLeverOld == 1.0 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1 ) then + if (data%Equipments%BopControlPanel%AnnularValve == -1.0 .and. data%State%Annular%AnnularLeverOld == 1.0 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 ) then !CasingPressure : PressureGauges(2) *****temp conditionssssss @@ -300,9 +300,9 @@ SUBROUTINE ANNULAR_SUB2 if ( data%State%RAM(1)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then !return - data%EquipmentControl%BopControlPanel%AnnularCloseLED = LedOff + data%Equipments%BopControlPanel%AnnularCloseLED = LedOff data%State%BopStackInput%AnnularCloseLedMine= LedOff - data%EquipmentControl%BopControlPanel%AnnularOpenLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%AnnularOpenLED = LedOn !LedBlinking data%State%RAM(1)%FourwayValve = 1 @@ -325,7 +325,7 @@ SUBROUTINE ANNULAR_SUB2 data%State%Annular%Annular_closed=0 !Annular_closed_withPossibility= Annular_closed * TD_BOPConnectionPossibility(1) data%State%AnnularComputational%p_annular=data%State%AnnularComputational%pa_annular - data%State%Annular%AnnularLeverOld = data%EquipmentControl%BopControlPanel%AnnularValve + data%State%Annular%AnnularLeverOld = data%Equipments%BopControlPanel%AnnularValve CALL OpenAnnular data%State%Annular%Annular_Situation_forTD= 0 ! open - for TD code diff --git a/Equipments/BopStack/ANNULAR.i90 b/Equipments/BopStack/ANNULAR.i90 new file mode 100644 index 0000000..f8e1ad8 --- /dev/null +++ b/Equipments/BopStack/ANNULAR.i90 @@ -0,0 +1,430 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/ANNULAR.f90" +SUBROUTINE ANNULAR_SUB1 + use SimulationVariables + use CBopControlPanel + use SimulationVariables + use PressureDisplayVARIABLESModule + USE CEquipmentsConstants + USE CBopStackVariables + + implicit none + +!write(*,*) 'checkpoint 1' +!===================================================================== +! ANNULAR PREVENTER- BOP CAMERON Type U 5000 +! START CONDITIONS FOR ANNULAR PREVENTER +!===================================================================== + + data%State%RAM(1)%SuccessionCounter = data%State%RAM(1)%SuccessionCounter + 1 + + if (data%Equipments%BopControlPanel%AnnularValve == 1.0 .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + + if (data%State%BopStackInput%AnnularCloseLedMine == LedOn) then + RETURN + end if + + + if ( data%State%RAM(1)%SuccessionCounter /= data%State%RAM(1)%SuccessionCounterOld+1 ) then + data%State%RAM(1)%SuccessionCounter = 0 ! also in starup + data%State%RAM(1)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(1)%SuccessionCounterOld= data%State%RAM(1)%SuccessionCounter + endif + + + + if ( data%State%RAM(1)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%State%RAM(1)%First_CloseTimecheck= 1 + + data%Equipments%BopControlPanel%AnnularOpenLED = LedOff + data%State%BopStackInput%AnnularOpenLedMine = LedOff + data%Equipments%BopControlPanel%AnnularCloseLED = LedOn !LedBlinking + + data%State%RAM(1)%FourwayValve = 1 + + endif + + endif + + + if (data%State%RAM(1)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure .and. data%State%Annular%Pannular_reg>data%State%AnnularComputational%AnnularMovingPressure) then ! 1: Open , 0: Close + + + data%State%RAM(1)%FourwayValve = 0 + + + + data%State%Annular%Annular_closed=0 +!Annular_closed_withPossibility= Annular_closed * TD_BOPConnectionPossibility(1) + data%State%RAM(1)%vdis_tot=0 + data%State%RAM(1)%vdis_bottles=0. + data%State%RAM(1)%fvr_air=0. + data%State%RAM(1)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(1)%Qzero=70 + data%State%RAM(1)%Q=data%State%RAM(1)%Qzero + data%State%RAM(1)%flow=70 + data%State%Annular%tolAnnular=0.0018 + if (data%State%Annular%finished_Annular==1) then + data%State%Annular%AnnularLeverOld=-1.0 + else + data%State%Annular%AnnularLeverOld=data%Equipments%BopControlPanel%AnnularValve + endif + data%State%Annular%finished_Annular=0 + data%State%Annular%AnnularIsClosing = .true. + data%State%Annular%AnnularIsOpening = .false. + + data%State%RAM(2)%bop_type = 3 +!AbopAnnular=963.1 !(in^2) + data%State%Annular%AbopAnnular=(data%Configuration%BopStack%AnnularPreventerClose*231.)/((data%State%Annular%IDAnnularBase-data%State%Annular%ODDrillpipe_inAnnularBase)/2.) ! 231 in^3 = 1 gal + data%State%Annular%NeededVolumeAnnular=data%State%Annular%AbopAnnular*(data%State%Annular%IDAnnularBase-max(data%State%Annular%ODDrillpipe_inAnnular,data%State%Annular%ODDrillpipe_inAnnularBase))/(2.*231) !=17.98 galon for IDAnnularBase=13 5/8 , ODDrillpipe_inAnnularBase=5 +!WRITE(*,*) 'a)NeededVolumeAnnular=' , NeededVolumeAnnular +!write(*,*) 'close 1' + endif + + + if (data%Equipments%BopControlPanel%AnnularValve == -1.0 .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 ) then + + if (data%State%BopStackInput%AnnularOpenLedMine == LedOn) then + RETURN + end if + +!CasingPressure : PressureGauges(2) *****temp conditionssssss + +!note: (AnnularSealingPressure) is only for opening while well is pressurised + + + if ( data%State%RAM(1)%SuccessionCounter /= data%State%RAM(1)%SuccessionCounterOld+1 ) then + data%State%RAM(1)%SuccessionCounter = 0 ! also in starup + data%State%RAM(1)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(1)%SuccessionCounterOld= data%State%RAM(1)%SuccessionCounter + endif + + + + if ( data%State%RAM(1)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%State%RAM(1)%First_OpenTimecheck= 1 + + data%Equipments%BopControlPanel%AnnularCloseLED = LedOff !new + data%State%BopStackInput%AnnularCloseLedMine = LedOff !new + data%Equipments%BopControlPanel%AnnularOpenLED = LedOn !LedBlinking + + data%State%RAM(1)%FourwayValve = 1 + + endif + + endif + + + + + + if (data%State%RAM(1)%FourwayValve == 1 .and. data%State%Annular%Pannular_reg>data%State%AnnularComputational%AnnularMovingPressure .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure & + .and. (data%State%Annular%Annular_closed==0 .or. (data%State%Annular%Annular_closed==1 .and. data%State%PressureDisplay%PressureGauges(2) <=100.0) .or. (data%State%Annular%Annular_closed==1 .and. data%State%PressureDisplay%PressureGauges(2)>100.0 .and. data%State%Annular%Pannular_reg>=data%State%AnnularComputational%AnnularSealingPressure))) then ! 1: Open , 0: Close +!write(*,*) 'open 2' + + data%State%RAM(1)%FourwayValve = 0 + + + + data%State%Annular%Annular_closed=0 +!Annular_closed_withPossibility= Annular_closed * TD_BOPConnectionPossibility(1) + data%State%RAM(1)%vdis_tot=0 + data%State%RAM(1)%vdis_bottles=0. + data%State%RAM(1)%fvr_air=0. + data%State%RAM(1)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(1)%Qzero=70 + data%State%RAM(1)%Q=data%State%RAM(1)%Qzero + data%State%RAM(1)%flow=70 + data%State%Annular%tolAnnular=0.0018 + + + + if (data%State%Annular%finished_Annular==1) then + data%State%Annular%AnnularLeverOld=1.0 + else + data%State%Annular%AnnularLeverOld=data%Equipments%BopControlPanel%AnnularValve + endif + data%State%Annular%finished_Annular=0 + data%State%Annular%AnnularIsOpening = .true. + data%State%Annular%AnnularIsClosing = .false. + + +!if (AnnularOpenLed == LedOn) then +! RETURN +!end if + + + + data%State%RAM(1)%bop_type = 3 +!AbopAnnular=758.48 !(in^2) + data%State%Annular%AbopAnnular=(data%Configuration%BopStack%AnnularPreventerOpen*231)/((data%State%Annular%IDAnnularBase-max(data%State%Annular%ODDrillpipe_inAnnular,data%State%Annular%ODDrillpipe_inAnnularBase))/2.) + data%State%Annular%NeededVolumeAnnular=data%State%Annular%AbopAnnular*(data%State%Annular%IDAnnularBase-data%State%Annular%ODDrillpipe_inAnnular)/(2.*231) !=14.16 galon for IDAnnularBase=13 5/8 , ODDrillpipe_inAnnular=5 +!write(*,*) 'open 1' + + endif + +!===================================================================== + +if (data%State%Annular%AnnularIsOpening .or. data%State%Annular%AnnularIsClosing .or. data%State%RAM(1)%Bottles_Charged_MalfActive) then + CALL ANNULAR_SUB2 +end if + + + + + END SUBROUTINE ANNULAR_SUB1 + + + + + + + + + + + + + + +SUBROUTINE ANNULAR_SUB2 + use SimulationVariables + use PressureDisplayVARIABLESModule + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants + USE CBopStackVariables +! use CSimulationVariables + + implicit none + + + data%State%Annular%FirstSet= 0 + data%State%AnnularComputational%RamsFirstSet= 0 + + +! loop5: do while (finished_Annular==0) + +!write(*,*) 'checkpoint 2' + + + data%State%RAM(1)%SuccessionCounter = data%State%RAM(1)%SuccessionCounter + 1 + +! CALL CPU_TIME(Annular_StartTime) + + if (data%Equipments%BopControlPanel%AnnularValve == 1.0 .and. data%State%Annular%AnnularLeverOld == -1.0 .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + if ( data%State%RAM(1)%First_CloseTimecheck == 0 ) then + + + + if ( data%State%RAM(1)%SuccessionCounter /= data%State%RAM(1)%SuccessionCounterOld+1 ) then + data%State%RAM(1)%SuccessionCounter = 0 ! also in starup + data%State%RAM(1)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(1)%SuccessionCounterOld= data%State%RAM(1)%SuccessionCounter + endif + + + + if ( data%State%RAM(1)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%Equipments%BopControlPanel%AnnularOpenLED = LedOff + data%State%BopStackInput%AnnularOpenLedMine = LedOff + data%Equipments%BopControlPanel%AnnularCloseLED = LedOn !LedBlinking + + data%State%RAM(1)%FourwayValve = 1 + + endif + + endif +!write(*,*) 'chekkk 1' + + endif + + + if (data%State%RAM(1)%FourwayValve == 1 .and. data%State%Annular%Pannular_reg>data%State%AnnularComputational%AnnularMovingPressure .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then +!write(*,*) 'close 4' + + data%State%RAM(1)%FourwayValve = 0 + + + data%State%Annular%Annular_closed=0 +!Annular_closed_withPossibility= Annular_closed * TD_BOPConnectionPossibility(1) + data%State%AnnularComputational%p_annular=data%State%AnnularComputational%pa_annular + data%State%Annular%AnnularLeverOld = data%Equipments%BopControlPanel%AnnularValve + + CALL OpenAnnular + data%State%Annular%Annular_Situation_forTD= 0 ! open - for TD code + data%State%RAM(1)%bop_type = 3 +!AbopAnnular=963.1 !(in^2) + data%State%Annular%AbopAnnular=(data%Configuration%BopStack%AnnularPreventerClose*231)/((data%State%Annular%IDAnnularBase-data%State%Annular%ODDrillpipe_inAnnularBase)/2.) +!write(*,*) 'NeededVolumeShearRams1=',NeededVolumeShearRams + data%State%Annular%NeededVolumeAnnular=data%State%Annular%AbopAnnular*(data%State%Annular%IDAnnular-max(data%State%Annular%ODDrillpipe_inAnnular,data%State%Annular%ODDrillpipe_inAnnularBase))/(2*231.) +! write(*,*) 'NeededVolumeAnnular=',NeededVolumeAnnular + + data%State%RAM(1)%vdis_bottles=0. + data%State%RAM(1)%fvr_air=0. + data%State%RAM(1)%vdis_elecp=0. + data%State%Annular%AnnularIsClosing = .true. + data%State%Annular%AnnularIsOpening = .false. +!write(*,*) 'close 2' + + endif + + if (data%Equipments%BopControlPanel%AnnularValve == -1.0 .and. data%State%Annular%AnnularLeverOld == 1.0 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure .and. data%State%Annular%AnnularFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 ) then + +!CasingPressure : PressureGauges(2) *****temp conditionssssss + +!note: (AnnularSealingPressure) is only for opening while well is pressurised + + if ( data%State%RAM(1)%First_OpenTimecheck == 0 ) then + + if ( data%State%RAM(1)%SuccessionCounter /= data%State%RAM(1)%SuccessionCounterOld+1 ) then + data%State%RAM(1)%SuccessionCounter = 0 ! also in starup + data%State%RAM(1)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(1)%SuccessionCounterOld= data%State%RAM(1)%SuccessionCounter + endif + + if ( data%State%RAM(1)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%Equipments%BopControlPanel%AnnularCloseLED = LedOff + data%State%BopStackInput%AnnularCloseLedMine= LedOff + data%Equipments%BopControlPanel%AnnularOpenLED = LedOn !LedBlinking + + data%State%RAM(1)%FourwayValve = 1 + + endif + + endif +!write(*,*) 'chekkk 2' + + endif + + + + if (data%State%RAM(1)%FourwayValve == 1 .and. data%State%Annular%Pannular_reg>data%State%AnnularComputational%AnnularMovingPressure & + .and. (data%State%Annular%Annular_closed==0 .or. (data%State%Annular%Annular_closed==1 .and. data%State%PressureDisplay%PressureGauges(2) <=100.0) .or. (data%State%Annular%Annular_closed==1 .and. data%State%PressureDisplay%PressureGauges(2)>100.0 .and. data%State%Annular%Pannular_reg>=data%State%AnnularComputational%AnnularSealingPressure))) then +!write(*,*) 'open 4' + + data%State%RAM(1)%FourwayValve = 0 + + + data%State%Annular%Annular_closed=0 +!Annular_closed_withPossibility= Annular_closed * TD_BOPConnectionPossibility(1) + data%State%AnnularComputational%p_annular=data%State%AnnularComputational%pa_annular + data%State%Annular%AnnularLeverOld = data%Equipments%BopControlPanel%AnnularValve + + CALL OpenAnnular + data%State%Annular%Annular_Situation_forTD= 0 ! open - for TD code + data%State%RAM(1)%bop_type = 3 +!AbopAnnular=758.48 !(in^2) + data%State%Annular%AbopAnnular=(data%Configuration%BopStack%AnnularPreventerOpen*231)/((data%State%Annular%IDAnnularBase-data%State%Annular%ODDrillpipe_inAnnularBase)/2.) + data%State%Annular%NeededVolumeAnnular=data%State%Annular%AbopAnnular*(data%State%Annular%IDAnnularBase-data%State%Annular%IDAnnular)/(2*231.) + data%State%RAM(1)%vdis_bottles=0. + data%State%RAM(1)%fvr_air=0. + data%State%RAM(1)%vdis_elecp=0. + + data%State%Annular%AnnularIsOpening = .true. + data%State%Annular%AnnularIsClosing = .false. + +!write(*,*) 'open 2' + + endif + + + + data%State%RAM(1)%First_CloseTimecheck = 0 + data%State%RAM(1)%First_OpenTimecheck = 0 + + data%State%RAM(1)%time=data%State%RAM(1)%time+data%State%RamLine%DeltaT_BOP !overal time (s) + + + + + +!=================================================== +! BOP +!=================================================== +if (data%State%Annular%Annular_closed==0) then !bop closing +!write(*,*) 'AnnularIsClosing,AnnularIsOpening' , AnnularIsClosing,AnnularIsOpening + call bop_codeAnnular(1) !ramtype=4 1=RNUMBER +endif !bop is closing +!================================================================ +if (data%State%Annular%Annular_closed==1) then + data%State%RAM(1)%Q=0 +!p_bop=pram_reg + data%State%AnnularComputational%p_annular=data%State%AnnularComputational%pa_annular +endif + +data%State%RAM(1)%timecounter_ram=data%State%RAM(1)%timecounter_ram+1 + + + + + +! MiddleRamsStatus = IDshearBop +! UpperRamsStatus = IDPipeRam1 +! LowerRamsStatus = IDPipeRam2 +! AnnularStatus = IDAnnular +! AccumulatorPressureGauge = p_acc +! ManifoldPressureGauge= pram_reg +! AnnularPressureGauge=Pannular_reg +! +! +! +! WRITE(60,60) data%State%RAM(1)%time,data%State%RAM(1)%Q,data%State%RAM(1)%vdis_tot,p_acc, & +! pram_reg,Pannular_reg,data%State%RAM(1)%p_bop,IDshearBop, & +! IDPipeRam1,IDPipeRam2,IDAnnular +!60 FORMAT(11(f18.5)) + + +! call sleepqq(100) + + +!CALL CPU_TIME(Annular_EndTime) +! +! +!data%State%Pump(1)%INT_CPU_TIME=IDINT((Annular_EndTime-Annular_StartTime)*1000.) +!data%State%Pump(1)%Dt_ref=IDINT(DeltaT_BOP*1000.) +! +!call sleepqq(data%State%Pump(1)%Dt_ref-data%State%Pump(1)%INT_CPU_TIME) + + + + + +if (data%State%Annular%Annular_closed==1) then +! if ((MiddleRamsValve==1. .and. MiddleRamsFailureMalf==0) .or. (MiddleRamsValve==-1.0 .and. MiddleRamsFailureMalf==0) .or. (LowerRamsValve==1. .and. LowerRamsFailureMalf==0) .or. (LowerRamsValve==-1.0 .and. LowerRamsFailureMalf==0) .or. (UpperRamsValve==1. .and. UpperRamsFailureMalf==0) .or. (UpperRamsValve==-1.0 .and. UpperRamsFailureMalf==0) .or. ChokeLineValve==1. .or. ChokeLineValve==-1.0 .or. KillLineValve==1. .or. KillLineValve==-1.0) then + data%State%Annular%finished_Annular=1 +! endif +endif + +! if (IsStopped == .true.) return + + +! end do loop5 !while finished_Annular==0 + + + + + + if ( data%State%Annular%finished_Annular==1 .and. data%State%RAM(1)%Bottles_Charged_MalfActive==.true.) then + call bop_codeAnnular(1) !ramtype=4 1=RNUMBER +! call sleepqq(100) + endif + +END SUBROUTINE ANNULAR_SUB2 diff --git a/Equipments/BopStack/BOP.f90 b/Equipments/BopStack/BOP.f90 index 176b5c2..ea2bd1b 100644 --- a/Equipments/BopStack/BOP.f90 +++ b/Equipments/BopStack/BOP.f90 @@ -19,7 +19,7 @@ module BOP write(*,*) 'BOP_timeCounter=' , data%State%BopStackInput%BOP_timeCounter - data%EquipmentControl%BopControlPanel%AirSupplyPressureGauge= (1 - data%State%BopStackAcc%AirSupplyPressureGaugeMalf)* (1 - data%State%BopStackAcc%RigAirMalf) *120. !psi + data%Equipments%BopControlPanel%AirSupplyPressureGauge= (1 - data%State%BopStackAcc%AirSupplyPressureGaugeMalf)* (1 - data%State%BopStackAcc%RigAirMalf) *120. !psi if (data%State%BopStackAcc%pram_reg < 2300.) then @@ -104,17 +104,17 @@ module BOP !===================================================================== ! BYPASS POSITION !===================================================================== - if(data%EquipmentControl%BopControlPanel%ByePassValve == -1.0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if(data%Equipments%BopControlPanel%ByePassValve == -1.0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then data%State%BopStackAcc%ByPassOld= -1.0 !write(*,*) 'ByePassValve to -1' ,ByePassValve - elseif(data%EquipmentControl%BopControlPanel%ByePassValve == 1.0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + elseif(data%Equipments%BopControlPanel%ByePassValve == 1.0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then data%State%BopStackAcc%ByPassOld= 1.0 !write(*,*) 'ByePassValve to 1=' ,ByePassValve endif !write(*,*) 'ByePassValve,ByPassOld=' ,ByePassValve,ByPassOld !===================================================================== !WRITE(*,*) 'AnnularRegulatorSetControl====' , AnnularRegulatorSetControl - data%State%Annular%Pannular_regset=min(data%EquipmentControl%BopControlPanel%AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously + data%State%Annular%Pannular_regset=min(data%Equipments%BopControlPanel%AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously if (data%State%Annular%Annular_closed==1) then if (data%State%Annular%FirstSet==1) then ! code start data%State%Annular%Pannular_reg= data%State%Annular%Pannular_regset @@ -141,9 +141,9 @@ module BOP !=================================================================== if (data%State%Annular%FirstSet== 1) then !new= (1 - AnnularPressureGaugeMalf) * min(AnnularRegulatorSetControl,1700.) - CALL data%State%AnnularComputational%Pannular_regDelay%AddToFirst( (1 - data%State%Annular%AnnularPressureGaugeMalf) * min(data%EquipmentControl%BopControlPanel%AnnularRegulatorSetControl,1700.) ) + CALL data%State%AnnularComputational%Pannular_regDelay%AddToFirst( (1 - data%State%Annular%AnnularPressureGaugeMalf) * min(data%Equipments%BopControlPanel%AnnularRegulatorSetControl,1700.) ) CALL data%State%AnnularComputational%Pannular_regDelay%Remove(data%State%AnnularComputational%Pannular_regDelay%Length()) - data%EquipmentControl%BopControlPanel%AnnularPressureGauge= data%State%AnnularComputational%Pannular_regDelay%Last() + data%Equipments%BopControlPanel%AnnularPressureGauge= data%State%AnnularComputational%Pannular_regDelay%Last() !AnnularPressureGauge= (1 - AnnularPressureGaugeMalf) * min(AnnularRegulatorSetControl,1700.) !write(*,*) 'set 1' , AnnularPressureGauge else !FirstSet== 0 @@ -151,7 +151,7 @@ module BOP CALL data%State%AnnularComputational%Pannular_regDelay%AddToFirst( (1 - data%State%Annular%AnnularPressureGaugeMalf) * data%State%Annular%Pannular_reg) CALL data%State%AnnularComputational%Pannular_regDelay%Remove(data%State%AnnularComputational%Pannular_regDelay%Length()) - data%EquipmentControl%BopControlPanel%AnnularPressureGauge= data%State%AnnularComputational%Pannular_regDelay%Last() + data%Equipments%BopControlPanel%AnnularPressureGauge= data%State%AnnularComputational%Pannular_regDelay%Last() !AnnularPressureGauge= (1 - AnnularPressureGaugeMalf) * Pannular_reg !write(*,*) 'set 0' , AnnularPressureGauge endif @@ -284,12 +284,12 @@ module BOP endif - data%EquipmentControl%BopControlPanel%MiddleRamsStatus = data%State%ShearRAM%IDshearBop - data%EquipmentControl%BopControlPanel%UpperRamsStatus = data%State%PipeRam1%ID - data%EquipmentControl%BopControlPanel%LowerRamsStatus = data%State%PipeRam2%ID - data%EquipmentControl%BopControlPanel%AnnularStatus = data%State%Annular%IDAnnular - data%EquipmentControl%BopControlPanel%AccumulatorPressureGauge = (1 - data%State%BopStackAcc%AccumulatorPressureGaugeMalf) * data%State%RamLine%P_ACC - data%EquipmentControl%BopControlPanel%ManifoldPressureGauge= (1 - data%State%BopStackAcc%ManifoldPressureGaugeMalf) * data%State%BopStackAcc%pram_reg + data%Equipments%BopControlPanel%MiddleRamsStatus = data%State%ShearRAM%IDshearBop + data%Equipments%BopControlPanel%UpperRamsStatus = data%State%PipeRam1%ID + data%Equipments%BopControlPanel%LowerRamsStatus = data%State%PipeRam2%ID + data%Equipments%BopControlPanel%AnnularStatus = data%State%Annular%IDAnnular + data%Equipments%BopControlPanel%AccumulatorPressureGauge = (1 - data%State%BopStackAcc%AccumulatorPressureGaugeMalf) * data%State%RamLine%P_ACC + data%Equipments%BopControlPanel%ManifoldPressureGauge= (1 - data%State%BopStackAcc%ManifoldPressureGaugeMalf) * data%State%BopStackAcc%pram_reg !AnnularPressureGauge=Pannular_reg ! ! WRITE(60,60) data%State%RAM(2)%time,data%State%RAM(2)%Q,data%State%RAM(2)%vdis_tot,p_acc, & diff --git a/Equipments/BopStack/BOP.i90 b/Equipments/BopStack/BOP.i90 new file mode 100644 index 0000000..5fb042d --- /dev/null +++ b/Equipments/BopStack/BOP.i90 @@ -0,0 +1,305 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/BOP.f90" +module BOP + contains + + subroutine BopStack_Init + call BOP_StartUp + end subroutine BopStack_Init + + subroutine BopStack_Step + use SimulationVariables + use CBopControlPanel + use BopVariables + use SimulationVariables !@ +! USE CEquipmentsConstants + use CSounds + implicit none + + + data%State%BopStackInput%BOP_timeCounter= data%State%BopStackInput%BOP_timeCounter + 1 + + write(*,*) 'BOP_timeCounter=' , data%State%BopStackInput%BOP_timeCounter + + data%Equipments%BopControlPanel%AirSupplyPressureGauge= (1 - data%State%BopStackAcc%AirSupplyPressureGaugeMalf)* (1 - data%State%BopStackAcc%RigAirMalf) *120. !psi + + + if (data%State%BopStackAcc%pram_reg < 2300.) then + data%State%ShearRAM%ShearIsNotAllowed= 1 + else + data%State%ShearRAM%ShearIsNotAllowed= 0 + endif + +!write(*,*) 'ShearIsNotAllowed=' , ShearIsNotAllowed + + +!TD_AnnularFillingFinal ! (0.0 to 1.0) percentage filled by tool joint + + +!====================================================================== +! MAIN BODY OF PROGRAM +! PURPOSE: BOP Control +!====================================================================== + + +!=== Instantaneous Pipe Diameters in Each Ram (Input from TD Module):== + data%State%Annular%ODDrillpipe_inAnnular= data%State%TD_BOP%AnnularPreventerDiam * 12.0 ! ft to inch + data%State%PipeRam1%ODDrillpipe_in= data%State%TD_BOP%UpperRamDiam * 12.0 + data%State%ShearRAM%ODDrillpipe_inShearRam= data%State%TD_BOP%BlindRamDiam * 12.0 + data%State%PipeRam2%ODDrillpipe_in= data%State%TD_BOP%LowerRamDiam * 12.0 + + + +!IDshearBopFinal +!IDPipeRam1Final +!IDPipeRam2Final +!IDAnnularFinal + + data%State%ShearRAM%OpenArea_shearBop= PI*(data%State%ShearRAM%IDshearBopFinal**2-data%State%ShearRAM%ODDrillpipe_inShearRam**2)/4.0d0 !D(in), AREA(in^2) + data%State%ShearRAM%OpenArea_PipeRam1= PI*(data%State%ShearRAM%IDPipeRam1Final**2-data%State%PipeRam1%ODDrillpipe_in**2)/4.0d0 !D(in), AREA(in^2) + data%State%ShearRAM%OpenArea_PipeRam2= PI*(data%State%ShearRAM%IDPipeRam2Final**2-data%State%PipeRam2%ODDrillpipe_in**2)/4.0d0 !D(in), AREA(in^2) + data%State%ShearRAM%OpenArea_Annular= PI*(data%State%ShearRAM%IDAnnularFinal**2-data%State%Annular%ODDrillpipe_inAnnular**2)/4.0d0 !D(in), AREA(in^2) + + data%State%ShearRAM%MinimumOpenArea_InBOP= min(data%State%ShearRAM%OpenArea_shearBop,data%State%ShearRAM%OpenArea_PipeRam1,data%State%ShearRAM%OpenArea_PipeRam2,data%State%ShearRAM%OpenArea_Annular) + +!TD_BOPConnectionPossibility(j) = 0 or 1 + +!!!AnnularPreventerDiam = TD_BOPConnectionPossibility(1) >> used in Annular code +!!!UpperRamDiam = TD_BOPConnectionPossibility(2) >> used in PipeRam1 code +!!!BlindRamDiam = TD_BOPConnectionPossibility(3) >> used in ShearRam code +!!!LowerRamDiam = TD_BOPConnectionPossibility(4) >> used in PipeRam2 code + +!===================================================================== +!============SEALING PRESSURES TO BE SET IN ANNULAR REGULATOR========== + data%State%AnnularComputational%WellBorePressure=5000. + if (data%State%Annular%ODDrillpipe_inAnnular>0.) then + if (data%State%Annular%ODDrillpipe_inAnnular>0. .and. data%State%Annular%ODDrillpipe_inAnnular<=1.99) then + data%State%AnnularComputational%acoef=-0.2673 + data%State%AnnularComputational%Bcoef=994.3 + data%State%AnnularComputational%const=77 + elseif (data%State%Annular%ODDrillpipe_inAnnular>1.99 .and. data%State%Annular%ODDrillpipe_inAnnular<=2.375) then + data%State%AnnularComputational%acoef=-0.2539 + data%State%AnnularComputational%Bcoef=994.3 + data%State%AnnularComputational%const=73.15 + elseif (data%State%Annular%ODDrillpipe_inAnnular>2.375 .and. data%State%Annular%ODDrillpipe_inAnnular<=2.875) then + data%State%AnnularComputational%acoef=-0.2005 + data%State%AnnularComputational%Bcoef=745.9 + data%State%AnnularComputational%const=57.75 + elseif (data%State%Annular%ODDrillpipe_inAnnular>2.875 .and. data%State%Annular%ODDrillpipe_inAnnular<=3.5) then + data%State%AnnularComputational%acoef=-0.1871 + data%State%AnnularComputational%Bcoef=696.1 + data%State%AnnularComputational%const=53.9 + elseif (data%State%Annular%ODDrillpipe_inAnnular>3.5 .and. data%State%Annular%ODDrillpipe_inAnnular<=5) then + data%State%AnnularComputational%acoef=-0.1733 + data%State%AnnularComputational%Bcoef=647 + data%State%AnnularComputational%const=50 + elseif (data%State%Annular%ODDrillpipe_inAnnular>5 .and. data%State%Annular%ODDrillpipe_inAnnular<=10) then + data%State%AnnularComputational%acoef=-0.1604 + data%State%AnnularComputational%Bcoef=596.7 + data%State%AnnularComputational%const=46.2 + endif + data%State%AnnularComputational%AnnularSealingPressure= max((data%State%AnnularComputational%acoef*data%State%AnnularComputational%WellBorePressure+data%State%AnnularComputational%Bcoef), data%State%AnnularComputational%const) !(psi) + else !CSO(COMPLETE SHUT OFF) ODDrillpipe_inAnnular=0 + data%State%AnnularComputational%AnnularSealingPressure= 1150. !(psi) + endif + +!===================================================================== +! BYPASS POSITION +!===================================================================== + if(data%Equipments%BopControlPanel%ByePassValve == -1.0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + data%State%BopStackAcc%ByPassOld= -1.0 +!write(*,*) 'ByePassValve to -1' ,ByePassValve + elseif(data%Equipments%BopControlPanel%ByePassValve == 1.0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + data%State%BopStackAcc%ByPassOld= 1.0 +!write(*,*) 'ByePassValve to 1=' ,ByePassValve + endif +!write(*,*) 'ByePassValve,ByPassOld=' ,ByePassValve,ByPassOld +!===================================================================== +!WRITE(*,*) 'AnnularRegulatorSetControl====' , AnnularRegulatorSetControl + data%State%Annular%Pannular_regset=min(data%Equipments%BopControlPanel%AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously + if (data%State%Annular%Annular_closed==1) then + if (data%State%Annular%FirstSet==1) then ! code start + data%State%Annular%Pannular_reg= data%State%Annular%Pannular_regset + endif + + if (data%State%Annular%FirstSet==0) then ! durig run, but annular is not closing or opening + data%State%Annular%Pannular_reg= min(data%State%RamLine%P_ACC,data%State%Annular%Pannular_regset) + endif + endif + +!=================================================================== +! Annular Preventer Pressure Rise On Tooljoint +!=================================================================== + if ( data%State%Annular%Annular_Situation_forTD == 1 .and. data%State%TD_BOP%AnnularFillingFinal==0.0 ) then ! Annular_Situation_forTD= 1 ! closed - for TD code + data%State%AnnularComputational%AnnPressureRise= .true. + elseif ( data%State%Annular%Annular_Situation_forTD == 0 ) then + data%State%AnnularComputational%AnnPressureRise= .false. + endif + + if (data%State%AnnularComputational%AnnPressureRise == .true.) then + data%State%Annular%Pannular_reg= data%State%Annular%Pannular_reg + 200. * data%State%TD_BOP%AnnularFillingFinal ! 200 psi pressure rise when 100% of AnnPreventer is filled by tool joint +!TD_AnnularFillingFinal ! (0.0 to 1.0) percentage filled by tool joint + endif +!=================================================================== + if (data%State%Annular%FirstSet== 1) then +!new= (1 - AnnularPressureGaugeMalf) * min(AnnularRegulatorSetControl,1700.) + CALL data%State%AnnularComputational%Pannular_regDelay%AddToFirst( (1 - data%State%Annular%AnnularPressureGaugeMalf) * min(data%Equipments%BopControlPanel%AnnularRegulatorSetControl,1700.) ) + CALL data%State%AnnularComputational%Pannular_regDelay%Remove(data%State%AnnularComputational%Pannular_regDelay%Length()) + data%Equipments%BopControlPanel%AnnularPressureGauge= data%State%AnnularComputational%Pannular_regDelay%Last() +!AnnularPressureGauge= (1 - AnnularPressureGaugeMalf) * min(AnnularRegulatorSetControl,1700.) +!write(*,*) 'set 1' , AnnularPressureGauge + else !FirstSet== 0 +!new= (1 - AnnularPressureGaugeMalf) * Pannular_reg + + CALL data%State%AnnularComputational%Pannular_regDelay%AddToFirst( (1 - data%State%Annular%AnnularPressureGaugeMalf) * data%State%Annular%Pannular_reg) + CALL data%State%AnnularComputational%Pannular_regDelay%Remove(data%State%AnnularComputational%Pannular_regDelay%Length()) + data%Equipments%BopControlPanel%AnnularPressureGauge= data%State%AnnularComputational%Pannular_regDelay%Last() +!AnnularPressureGauge= (1 - AnnularPressureGaugeMalf) * Pannular_reg +!write(*,*) 'set 0' , AnnularPressureGauge + endif + +!=================================================== +! AIR OPERATED PUMP CODE- START +!=================================================== + if (data%State%RamLine%P_ACCdata%State%Pumps%AIR_OFF .and. data%State%RamLine%AIRP_SWITCH==1) then + data%State%RamLine%AIRP_SWITCH=0 + call SetSoundKoomeyAirPump(data%State%RamLine%AIRP_SWITCH) + endif + + if (data%State%RamLine%P_ACCdata%State%Pumps%ELECTRIC_OFF .and. data%State%RamLine%ELECP_SWITCH==1) then + data%State%RamLine%ELECP_SWITCH=0 + endif + +!write(*,*) 'airp_switch,elecp_switch=' , airp_switch,elecp_switch +!================CHARGING BOTTLES======================= + if (data%State%RamLine%AIRP_SWITCH==1 .or. data%State%RamLine%ELECP_SWITCH==1) then + if (data%State%Annular%Annular_closed==1 .and. data%State%RamLine%ShearBop_closed==1 .and. data%State%PipeRam1%closed==1 .and. data%State%PipeRam2%closed==1 .and. data%State%ChokeLine%closed==1 .and. data%State%KillLine%closed==1) then + call pumps_charge_bottle() +! increases volume and pressure in the bottles + if (data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_ChargedPressure) then + data%State%RamLine%P_ACC=data%State%BopStackAcc%acc_ChargedPressure + if (data%State%Annular%AnnularLeakMalf== 0) then +!finished_Annular=1 + data%State%RAM(1)%Bottles_Charged_MalfActive= .false. + else + data%State%Annular%finished_Annular=0 + data%State%RAM(1)%Bottles_Charged_MalfActive= .true. +!fvr=fvr-2.5 + endif + if (data%State%PipeRam1%UpperRamsLeakMalf== 0) then +!finished_pipe1=1 + data%State%RAM(2)%Bottles_Charged_MalfActive= .false. + else + data%State%PipeRam1%finished=0 + data%State%RAM(2)%Bottles_Charged_MalfActive= .true. +!fvr=fvr-2.5 + endif + + if (data%State%PipeRam2%LowerRamsLeakMalf== 0) then +!finished_pipe2=1 + data%State%RAM(3)%Bottles_Charged_MalfActive= .false. + else + data%State%PipeRam2%finished=0 + data%State%RAM(3)%Bottles_Charged_MalfActive= .true. +!fvr=fvr-2.5 + endif + if (data%State%ShearRAM%MiddleRamsLeakMalf== 0) then +!finished_shear=1 + data%State%RAM(4)%Bottles_Charged_MalfActive= .false. + else + data%State%RamLine%FINISHED_shear=0 + data%State%RAM(4)%Bottles_Charged_MalfActive= .true. +!fvr=fvr-2.5 + endif + + data%State%KillLine%finished=1 + data%State%ChokeLine%finished=1 + + + if (data%State%Annular%AnnularLeakMalf== 0 .and. data%State%PipeRam1%UpperRamsLeakMalf== 0 .and. data%State%PipeRam2%LowerRamsLeakMalf== 0 .and. data%State%ShearRAM%MiddleRamsLeakMalf== 0) then + data%State%RamLine%ELECP_SWITCH=0 + data%State%RamLine%AIRP_SWITCH=0 + endif + endif + endif + endif + +!======================================================= + if (data%State%RamLine%ELECP_SWITCH==1 .and. data%State%BopStackAcc%AccPupmsFailMalf==0) then !on position + data%State%Pumps%DELTAV_ELECP=data%State%Pumps%QELECTRIC*data%State%RamLine%DeltaT_BOP/60. !QELECTRIC_PUMP(gpm), deltav_elecp(gal), DeltaT_BOP(0.1 sec) + data%State%Pumps%SoundKoomeyElectric= .True. + else + data%State%Pumps%DELTAV_ELECP=0 + data%State%Pumps%SoundKoomeyElectric= .false. + endif + +!call SetSoundKoomeyElectricPump(SoundKoomeyElectricPump) + if (data%State%RamLine%AIRP_SWITCH==1 .and. data%State%BopStackAcc%AccPupmsFailMalf==0) then !on position + call airpump_code() !ramtype=2 + end if ! if (airp_switch==1) then !on position + + +!===============AIR OPERATED PUMP CODE- END================ + if (data%State%RamLine%ShearBop_closed==1 .and. data%State%PipeRam1%closed==1 .and. data%State%PipeRam2%closed==1 .and. data%State%ChokeLine%closed==1 .and. data%State%KillLine%closed==1) then + +!write(*,*) ' All Rams are closed' + + if(data%State%BopStackAcc%ByPassOld== -1.0) then ! (OPEN POSITION) +!old=pram_reg +!new=p_acc- MAXVAL(data%State%RAM%loss_before) +!difference= new-old + data%State%BopStackAcc%PressureDifference= data%State%RamLine%P_ACC- MAXVAL(data%State%RAM%loss_before) - data%State%BopStackAcc%pram_reg + if (ABS(data%State%BopStackAcc%PressureDifference) > BaseDifferenceP) then !BaseDifferenceP= 300. psi + data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%pram_reg + (data%State%BopStackAcc%PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20. + else + data%State%BopStackAcc%pram_reg= data%State%RamLine%P_ACC- MAXVAL(data%State%RAM%loss_before) ! mishe khate paeen ye shart gozasht ke pacc=3000 shod, in adad dige kam nashe + endif + + elseif (data%State%BopStackAcc%ByPassOld== 1.0) then ! (CLOSE POSITION) +!pram_reg= prams_regset +!if (RamsFirstSet==1) then +!write(*,*) 'bypass CLOSE POSITION' +!old=pram_reg +!new=prams_regset +!difference= new-old + data%State%BopStackAcc%PressureDifference= data%State%BopStackAcc%PRAMS_REGSET - data%State%BopStackAcc%pram_reg +!write(*,*) 'PressureDifference, prams_regset , pram_reg=' , PressureDifference, prams_regset , pram_reg + + if (ABS(data%State%BopStackAcc%PressureDifference) > BaseDifferenceP) then !BaseDifferenceP= 200. ! psi in starup + data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%pram_reg + (data%State%BopStackAcc%PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20. in startup + else + data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%PRAMS_REGSET + endif +!write(*,*) 'pram_reg=' , pram_reg + +!endif ! if (RamsFirstSet==1) then + endif + + + endif + + data%Equipments%BopControlPanel%MiddleRamsStatus = data%State%ShearRAM%IDshearBop + data%Equipments%BopControlPanel%UpperRamsStatus = data%State%PipeRam1%ID + data%Equipments%BopControlPanel%LowerRamsStatus = data%State%PipeRam2%ID + data%Equipments%BopControlPanel%AnnularStatus = data%State%Annular%IDAnnular + data%Equipments%BopControlPanel%AccumulatorPressureGauge = (1 - data%State%BopStackAcc%AccumulatorPressureGaugeMalf) * data%State%RamLine%P_ACC + data%Equipments%BopControlPanel%ManifoldPressureGauge= (1 - data%State%BopStackAcc%ManifoldPressureGaugeMalf) * data%State%BopStackAcc%pram_reg +!AnnularPressureGauge=Pannular_reg +! +! WRITE(60,60) data%State%RAM(2)%time,data%State%RAM(2)%Q,data%State%RAM(2)%vdis_tot,p_acc, & +! pram_reg,Pannular_reg,data%State%RAM(2)%p_bop,IDshearBop, & +! IDPipeRam1,IDPipeRam2,IDAnnular +!60 FORMAT(11(f18.5)) +!WRITE(*,*) 'IDAnnular=' , IDAnnular +!write(*,*) 'elecp_switch=' , elecp_switch +!call sleepqq(100) + end subroutine BopStack_Step + +end module BOP diff --git a/Equipments/BopStack/BOPstartup.f90 b/Equipments/BopStack/BOPstartup.f90 index 3388c11..7da843a 100644 --- a/Equipments/BopStack/BOPstartup.f90 +++ b/Equipments/BopStack/BOPstartup.f90 @@ -232,18 +232,18 @@ data%State%RAM%vdis_elecp=0 data%State%RAM%timecounter_ram=0 data%State%RAM%Q=0 data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%PRAMS_REGSET !psi !RamsReglatorSet -data%State%Annular%Pannular_reg=min(data%EquipmentControl%BopControlPanel%AnnularRegulatorSetControl,1700.) +data%State%Annular%Pannular_reg=min(data%Equipments%BopControlPanel%AnnularRegulatorSetControl,1700.) -data%EquipmentControl%BopControlPanel%MiddleRamsStatus= data%State%ShearRAM%IDshearBop -data%EquipmentControl%BopControlPanel%UpperRamsStatus= data%State%PipeRam1%ID -data%EquipmentControl%BopControlPanel%LowerRamsStatus= data%State%PipeRam2%ID -data%EquipmentControl%BopControlPanel%AnnularStatus = data%State%Annular%IDAnnular +data%Equipments%BopControlPanel%MiddleRamsStatus= data%State%ShearRAM%IDshearBop +data%Equipments%BopControlPanel%UpperRamsStatus= data%State%PipeRam1%ID +data%Equipments%BopControlPanel%LowerRamsStatus= data%State%PipeRam2%ID +data%Equipments%BopControlPanel%AnnularStatus = data%State%Annular%IDAnnular -data%EquipmentControl%BopControlPanel%AccumulatorPressureGauge = data%State%RamLine%P_ACC +data%Equipments%BopControlPanel%AccumulatorPressureGauge = data%State%RamLine%P_ACC data%State%RAM%time=0 @@ -260,47 +260,47 @@ data%State%RAM%time=0 !60 FORMAT(11(f18.5)) - data%EquipmentControl%BopControlPanel%MiddleRamsOpenLED = LedOn + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOn data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOn - data%EquipmentControl%BopControlPanel%MiddleRamsCloseLED = LedOff + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOff data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOff data%State%RamLine%ShearRamIsOpening = .false. data%State%RamLine%ShearRamIsClosing = .false. - data%EquipmentControl%BopControlPanel%UpperRamsOpenLED = LedOn + data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOn data%State%BopStackInput%UpperRamsOpenLEDMine = LedOn - data%EquipmentControl%BopControlPanel%UpperRamsCloseLED = LedOff + data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOff data%State%BopStackInput%UpperRamsCloseLEDMine = LedOff data%State%PipeRam1%IsOpening = .false. data%State%PipeRam1%IsClosing = .false. - data%EquipmentControl%BopControlPanel%LowerRamsOpenLED = LedOn + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOn data%State%BopStackInput%LowerRamsOpenLEDMine = LedOn - data%EquipmentControl%BopControlPanel%LowerRamsCloseLED = LedOff + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOff data%State%BopStackInput%LowerRamsCloseLEDMine = LedOff data%State%PipeRam2%IsOpening = .false. data%State%PipeRam2%IsClosing = .false. - data%EquipmentControl%BopControlPanel%ChokeLineOpenLED = LedOff + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOff data%State%BopStackInput%ChokeLineOpenLEDMine = LedOff - data%EquipmentControl%BopControlPanel%ChokeLineCloseLED = LedOn + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOn data%State%BopStackInput%ChokeLineCloseLEDMine = LedOn data%State%ChokeLine%IsOpening = .false. data%State%ChokeLine%IsClosing = .false. - data%EquipmentControl%BopControlPanel%KillLineOpenLED = LedOff + data%Equipments%BopControlPanel%KillLineOpenLED = LedOff data%State%BopStackInput%KillLineOpenLedMine = LedOff - data%EquipmentControl%BopControlPanel%KillLineCloseLED = LedOn + data%Equipments%BopControlPanel%KillLineCloseLED = LedOn data%State%BopStackInput%KillLineCloseLedMine = LedOn data%State%KillLine%IsOpening = .false. data%State%KillLine%IsClosing = .false. - data%EquipmentControl%BopControlPanel%AnnularOpenLED = LedOn + data%Equipments%BopControlPanel%AnnularOpenLED = LedOn data%State%BopStackInput%AnnularOpenLedMine = LedOn - data%EquipmentControl%BopControlPanel%AnnularCloseLED = LedOff + data%Equipments%BopControlPanel%AnnularCloseLED = LedOff data%State%BopStackInput%AnnularCloseLedMine = LedOff data%State%Annular%AnnularIsOpening = .false. @@ -309,14 +309,14 @@ data%State%RAM%time=0 data%State%Annular%FirstSet=1 data%State%AnnularComputational%RamsFirstSet=1 - data%EquipmentControl%BopControlPanel%ManifoldPressureGauge=data%State%BopStackAcc%PRAMS_REGSET !RamsReglatorSet - data%EquipmentControl%BopControlPanel%AnnularPressureGauge= (1 - data%State%Annular%AnnularPressureGaugeMalf) * min(data%EquipmentControl%BopControlPanel%AnnularRegulatorSetControl,1700.) + data%Equipments%BopControlPanel%ManifoldPressureGauge=data%State%BopStackAcc%PRAMS_REGSET !RamsReglatorSet + data%Equipments%BopControlPanel%AnnularPressureGauge= (1 - data%State%Annular%AnnularPressureGaugeMalf) * min(data%Equipments%BopControlPanel%AnnularRegulatorSetControl,1700.) data%State%AnnularComputational%PannularTimeStepDelay = int(1./data%State%RamLine%DeltaT_BOP) ! 1/0.1 : for 1 sec delay in AnnRegulator shot time DO i = 1 , data%State%AnnularComputational%PannularTimeStepDelay - CALL data%State%AnnularComputational%Pannular_regDelay%AddToFirst(data%EquipmentControl%BopControlPanel%AnnularPressureGauge) + CALL data%State%AnnularComputational%Pannular_regDelay%AddToFirst(data%Equipments%BopControlPanel%AnnularPressureGauge) END DO diff --git a/Equipments/BopStack/BOPstartup.i90 b/Equipments/BopStack/BOPstartup.i90 new file mode 100644 index 0000000..1335086 --- /dev/null +++ b/Equipments/BopStack/BOPstartup.i90 @@ -0,0 +1,326 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/BOPstartup.f90" + +SUBROUTINE BOP_StartUp() +use SimulationVariables +USE CAccumulatorVariables +USE CBopStackVariables +use CBopControlPanel + use SimulationVariables +USE CEquipmentsConstants +implicit none + +integer i + + +!UpperRamsFailureMalf=0 +!AnnularFailureMalf=0 +!LowerRamsFailureMalf=0 +!MiddleRamsFailureMalf=0 +!UpperRamsLeakMalf=0 +!LowerRamsLeakMalf=0 +!MiddleRamsLeakMalf=0 +!AnnularLeakMalf=0 +!AccPupmsFailMalf=0 +!AirSupplyPressureGauge=0 +!======================= SETTING VARIABLES + +data%State%BopStackInput%BOP_timeCounter= 0 + +!============== FOR MANIFOLD VALVES CODE===================== +CALL OpenAnnular +CALL OpenUpperRams +CALL OpenMiddleRams +CALL CloseKillLine +CALL CloseChokeLine +CALL OpenLowerRams + +data%State%Annular%Annular_Situation_forTD= 0 ! open - for TD code +data%State%RamLine%ShearBop_Situation_forTD= 0 ! open - for TD code +data%State%PipeRam1%Situation_forTD= 0 ! open - for TD code +data%State%PipeRam2%Situation_forTD= 0 ! open - for TD code +!====================================================================== + +CALL LOSS_INPUTS() +! +!OPEN(50,FILE='AIRPUMP_OUTPUTS.DAT') +!OPEN(60,FILE='RAMS_OUTPUTS.DAT') +!====================================================================== +! GET INPUTS +!====================================================================== + +data%State%RAM%SuccessionCounter = 0 +data%State%RAM%SuccessionCounterOld = 0 + +data%State%RAM%First_CloseTimecheck= 0 +data%State%RAM%First_OpenTimecheck= 0 + + + +data%State%BopStackAcc%Cumulative_AirVolume= 0.0 + + +data%State%BopStackAcc%BOTTLE_CAPACITY=10 !(GALON) +data%State%BopStackAcc%NOBOTTLES=data%Configuration%Accumulator%NumberOfBottels + + + + + + + +!fvr_tot=40 !(GALON) IN CHARGED POSITION +data%State%BopStackAcc%PRAMS_REGSET=1500 !RamsReglatorSet !=1500 DEFAULT regulator set pressure (PSI) +data%State%BopStackAcc%acc_ChargedPressure=3000 !charged(PSI) +data%State%BopStackAcc%acc_MinPressure=data%Configuration%Accumulator%AccumulatorMinimumOperatingPressure !1200 !discharged(PSI) +!acc_precharge=1000 + + +data%State%BopStackAcc%FVR_TOT=(-2451*(data%State%BopStackAcc%acc_ChargedPressure**(-0.8202))+8.435)*data%State%BopStackAcc%NOBOTTLES ! IT IS WRRITEN FOR PRECHARGE 1000 PSI FROM ITS CURVE + +!write(*,*) 'fvr_tot=',fvr_tot + +!ELECTRIC_PUMPON=2800 +data%State%Pumps%ELECTRIC_ON=data%Configuration%Accumulator%StartPressure +!ELECTRIC_PUMPOFF=acc_ChargedPressure !=3000 psi +data%State%Pumps%ELECTRIC_OFF=data%Configuration%Accumulator%StopPressure +!QELECTRIC_PUMP=12 !(gpm) +data%State%Pumps%QELECTRIC=data%Configuration%Accumulator%ElectricPumpOutput + + + +!AIR_PUMPON=2600 +data%State%Pumps%AIR_ON=data%Configuration%Accumulator%StartPressure2 +!AIR_PUMPOFF=2900 +data%State%Pumps%AIR_OFF=data%Configuration%Accumulator%StopPressure2 + + + +data%State%RAM%tol=0.0037 !%=(2700-2600)/2700 +data%State%RAM%tolzero=data%State%RAM%tol + +data%State%Annular%tolAnnular=0.0018 !=(2900-2895)/2900 +data%State%Annular%tolzeroAnnular=data%State%Annular%tolAnnular +!======================OTHER INPUTS(CONSTANTS)=========================== +data%State%ShearRAM%PA=300 !(PSI) +data%State%ShearRAM%P_SHEAR=1200 !(PSI) +!p_shear=2423.1 !(PSI) +data%State%ShearRAM%PB=data%State%ShearRAM%P_SHEAR-data%State%ShearRAM%PA +data%State%AnnularComputational%pa_annular=100 !(psi) + + + + +data%State%Annular%IDAnnularBase=13.625 !(inch) +data%State%Annular%IDAnnular=data%State%Annular%IDAnnularBase +data%State%Annular%ODDrillpipe_inAnnularBase=5. ! so 18 gal is for complete closing of annular +data%State%Annular%ODDrillpipe_inAnnular=5. ! initial +data%State%AnnularComputational%AnnularMovingPressure=360. !(psi) +data%State%ShearRAM%IDAnnularFinal= data%State%Annular%IDAnnular + + +data%State%ShearRAM%IDshearBopBase=13.625 !(inch) +data%State%ShearRAM%IDshearBop=data%State%ShearRAM%IDshearBopBase +data%State%ShearRAM%ODDrillpipe_inShearRamBase=5 !initial +data%State%ShearRAM%ODDrillpipe_inShearRam=5 !initial +data%State%ShearRAM%IDshearBopFinal= data%State%ShearRAM%IDshearBop + +data%State%PipeRam1%IDBase=13.625 !(inch) +data%State%PipeRam1%ID=data%State%PipeRam1%IDBase +data%State%PipeRam1%ODDrillpipe_inBase=5 !initial +data%State%PipeRam1%ODDrillpipe_in=5 !initial +data%State%ShearRAM%IDPipeRam1Final= data%State%PipeRam1%ID + + +data%State%PipeRam2%ID=data%State%PipeRam1%IDBase !(inch) +data%State%PipeRam2%ODDrillpipe_inBase=5 !initial +data%State%PipeRam2%ODDrillpipe_in=5 !initial +data%State%ShearRAM%IDPipeRam2Final= data%State%PipeRam2%ID + +data%State%ChokeLine%IDBase=8.6 !(inch) +data%State%ChokeLine%ID=data%State%ChokeLine%IDBase +data%State%ChokeLine%ODDrillpipe_inBase=5 +data%State%ChokeLine%ODDrillpipe_in=5 + +data%State%KillLine%IDBase=8.6 !(inch) +data%State%KillLine%ID=data%State%KillLine%IDBase +data%State%KillLine%ODDrillpipe_inBase=5 +data%State%KillLine%ODDrillpipe_in=5 + + +!va=4 !(liter) +!vb=8 !(liter) + +!cv=2; !flow coefficinet of regulator + +data%State%ShearRAM%RAM_COURSE=320.2 !milimeter +data%State%ShearRAM%H_REGRAM=0 !(m)<<<<<<<<<<<<<<<<<<<<<<<< +data%State%ShearRAM%H_ShearRamBop=(data%Configuration%BopStack%GroundLevel-data%Configuration%BopStack%BlindRamHeight)*0.3048 ! foot to meter +data%State%PipeRam1%H=(data%Configuration%BopStack%GroundLevel-data%Configuration%BopStack%UpperRamHeight)*0.3048 ! foot to meter +data%State%PipeRam2%H_Bop=(data%Configuration%BopStack%GroundLevel-data%Configuration%BopStack%LowerRamHeight)*0.3048 ! foot to meter +data%State%Annular%H_AnnularBop=(data%Configuration%BopStack%GroundLevel-data%Configuration%BopStack%AnnularPreventerHeight)*0.3048 ! foot to meter +data%State%ChokeLine%H_Bop=(data%Configuration%BopStack%GroundLevel-data%Configuration%BopStack%KillHeight)*0.3048 ! foot to meter +data%State%KillLine%H_Bop=(data%Configuration%BopStack%GroundLevel-data%Configuration%BopStack%KillHeight)*0.3048 ! foot to meter + + +data%State%RamLine%P_ACC=data%State%BopStackAcc%acc_ChargedPressure +data%State%RAM%vdis_bottles=0 !initial discharged volume +data%State%RamLine%FVR=data%State%BopStackAcc%FVR_TOT +data%State%RAMS%minloss=0. + +!======================AIRPUMP INPUTS(CONSTANTS)=========================== + +data%State%RAM%FVR_AIR=0 +data%State%Pumps%P_AIRP=0 + +data%State%RamLine%BA1=1003; data%State%RamLine%BA2=.03375; data%State%RamLine%BA3=4.014; data%State%RamLine%BA4=.2458 +data%State%RamLine%BBA1 =31.8; data%State%RamLine%BBA2 =-725.7 ; data%State%RamLine%BBA3 =4154 + +data%State%Pumps%Qiter=7 !(gpm) + +! Q=0.0003585; true + + +data%State%RamLine%DeltaT_BOP=0.1 !second +data%State%Pumps%TOL_AIR=.08 + +data%State%Pumps%alpha_Qair=0 +data%State%Pumps%alpha_timeair=0 +data%State%Pumps%alpha_paccair=data%State%RamLine%P_ACC +data%State%Pumps%alpha_pairp=data%State%RamLine%P_ACC +data%State%Pumps%alpha_diffpair=0 +data%State%Pumps%alpha_lossesair=0 +data%State%Pumps%alpha_fvrair=0 + +data%State%RamLine%counter_airp=1 + +!======================BOP INPUTS(CONSTANTS)=========================== + + if (data%Configuration%Accumulator%PrechargePressure == 1400.) then + data%State%RamLine%B1=1396; data%State%RamLine%B2=0.17; data%State%RamLine%B3=3.873; data%State%RamLine%B4=1.101 + elseif (data%Configuration%Accumulator%PrechargePressure == 2000.) then + data%State%RamLine%B1=1980; data%State%RamLine%B2=0.1237; data%State%RamLine%B3=15.69; data%State%RamLine%B4=1.029 + elseif (data%Configuration%Accumulator%PrechargePressure == 600.) then + data%State%RamLine%B1=591.9; data%State%RamLine%B2=0.1968; data%State%RamLine%B3=2.887; data%State%RamLine%B4=0.9757 + else !(PrechargePressure == 1000.) then ! this is for precharge=1000 psi + data%State%RamLine%B1=993.7; data%State%RamLine%B2=0.164; data%State%RamLine%B3=5.492; data%State%RamLine%B4=0.9796 + endif + +data%State%BopStackAcc%ByPassOld= 1.0 + +data%State%RAM%p_bop=data%State%ShearRAM%PA +data%State%AnnularComputational%p_annular=data%State%AnnularComputational%pa_annular +!Q=0.0055; !initial flow rate (m^3/s) +data%State%RAM%flow=60 !(gpm) initial value +data%State%RAM%Qzero=70 !for DP code, increasing Q after shear +data%State%RAM%vdis_tot=0 +data%State%RamLine%AIRP_SWITCH=0 !off position +data%State%RamLine%ELECP_SWITCH=0 !off position +data%State%RamLine%ShearBop_closed=1 +data%State%PipeRam1%closed=1 +data%State%PipeRam2%closed=1 +data%State%ChokeLine%closed=1 +data%State%KillLine%closed=1 +data%State%Annular%Annular_closed=1 +data%State%RamLine%FINISHED_shear=0 +data%State%PipeRam1%finished=0 +data%State%PipeRam2%finished=0 +data%State%ChokeLine%finished=0 +data%State%KillLine%finished=0 +data%State%Annular%finished_Annular=0 +data%State%Pumps%DELTAV_ELECP=0 +data%State%RAM%vdis_elecp=0 +!================================================================== +data%State%RAM%timecounter_ram=0 +data%State%RAM%Q=0 +data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%PRAMS_REGSET !psi !RamsReglatorSet +data%State%Annular%Pannular_reg=min(data%Equipments%BopControlPanel%AnnularRegulatorSetControl,1700.) + + + + +data%Equipments%BopControlPanel%MiddleRamsStatus= data%State%ShearRAM%IDshearBop +data%Equipments%BopControlPanel%UpperRamsStatus= data%State%PipeRam1%ID +data%Equipments%BopControlPanel%LowerRamsStatus= data%State%PipeRam2%ID +data%Equipments%BopControlPanel%AnnularStatus = data%State%Annular%IDAnnular + + +data%Equipments%BopControlPanel%AccumulatorPressureGauge = data%State%RamLine%P_ACC + + +data%State%RAM%time=0 + +! WRITE(60,10) ' Overal Time','Q Ram Line','Vdis Ram Line','P Accumulator','Preg Ram Line','Preg Annular',' P BOP','ID Shear Ram', & +! 'ID Pipe Ram1','ID Pipe Ram2','ID Annular' +!10 FORMAT(11(A18)) +! +! +! +! WRITE(60,60) data%State%RAM(2)%time,data%State%RAM(2)%Q,data%State%RAM(2)%vdis_tot,p_acc, & +! pram_reg,Pannular_reg,data%State%RAM(2)%p_bop,IDshearBop, & +! IDPipeRam1,IDPipeRam2,IDAnnular +!60 FORMAT(11(f18.5)) + + + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOn + data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOn + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOff + data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOff + data%State%RamLine%ShearRamIsOpening = .false. + data%State%RamLine%ShearRamIsClosing = .false. + + data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOn + data%State%BopStackInput%UpperRamsOpenLEDMine = LedOn + data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOff + data%State%BopStackInput%UpperRamsCloseLEDMine = LedOff + data%State%PipeRam1%IsOpening = .false. + data%State%PipeRam1%IsClosing = .false. + + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOn + data%State%BopStackInput%LowerRamsOpenLEDMine = LedOn + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOff + data%State%BopStackInput%LowerRamsCloseLEDMine = LedOff + data%State%PipeRam2%IsOpening = .false. + data%State%PipeRam2%IsClosing = .false. + + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOff + data%State%BopStackInput%ChokeLineOpenLEDMine = LedOff + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOn + data%State%BopStackInput%ChokeLineCloseLEDMine = LedOn + data%State%ChokeLine%IsOpening = .false. + data%State%ChokeLine%IsClosing = .false. + + + data%Equipments%BopControlPanel%KillLineOpenLED = LedOff + data%State%BopStackInput%KillLineOpenLedMine = LedOff + data%Equipments%BopControlPanel%KillLineCloseLED = LedOn + data%State%BopStackInput%KillLineCloseLedMine = LedOn + data%State%KillLine%IsOpening = .false. + data%State%KillLine%IsClosing = .false. + + + data%Equipments%BopControlPanel%AnnularOpenLED = LedOn + data%State%BopStackInput%AnnularOpenLedMine = LedOn + + data%Equipments%BopControlPanel%AnnularCloseLED = LedOff + data%State%BopStackInput%AnnularCloseLedMine = LedOff + + data%State%Annular%AnnularIsOpening = .false. + data%State%Annular%AnnularIsClosing = .false. + + + data%State%Annular%FirstSet=1 + data%State%AnnularComputational%RamsFirstSet=1 + data%Equipments%BopControlPanel%ManifoldPressureGauge=data%State%BopStackAcc%PRAMS_REGSET !RamsReglatorSet + data%Equipments%BopControlPanel%AnnularPressureGauge= (1 - data%State%Annular%AnnularPressureGaugeMalf) * min(data%Equipments%BopControlPanel%AnnularRegulatorSetControl,1700.) + + +data%State%AnnularComputational%PannularTimeStepDelay = int(1./data%State%RamLine%DeltaT_BOP) ! 1/0.1 : for 1 sec delay in AnnRegulator shot time + + DO i = 1 , data%State%AnnularComputational%PannularTimeStepDelay + CALL data%State%AnnularComputational%Pannular_regDelay%AddToFirst(data%Equipments%BopControlPanel%AnnularPressureGauge) + END DO + + + + end + diff --git a/Equipments/BopStack/BlindRamsMain.i90 b/Equipments/BopStack/BlindRamsMain.i90 new file mode 100644 index 0000000..8a464a6 --- /dev/null +++ b/Equipments/BopStack/BlindRamsMain.i90 @@ -0,0 +1,89 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/BlindRamsMain.f90" +module BlindRamsMain + implicit none + public + contains + +! subroutine BlindRams_Setup() +! ! use CSimulationVariables +! implicit none +! call OnSimulationInitialization%Add(BlindRams_Init) +! call OnSimulationStop%Add(BlindRams_Init) +! call OnBlindRamsStep%Add(BlindRams_Step) +! call OnBlindRamsOutput%Add(BlindRams_Output) +! call OnBlindRamsMain%Add(BlindRamsMainBody) +! end subroutine + +! subroutine BlindRams_Init +! implicit none +! end subroutine BlindRams_Init + + subroutine BlindRams_Step + use SimulationVariables + implicit none + if (data%State%RamLine%FINISHED_shear/=0) then + call SHEAR_RAMS + if (data%State%RamLine%ShearRamIsOpening .or. data%State%RamLine%ShearRamIsClosing .or. data%State%RAM(4)%Bottles_Charged_MalfActive) then + data%State%Annular%FirstSet= 0 + data%State%AnnularComputational%RamsFirstSet= 0 + if(data%State%RamLine%FINISHED_shear==0) then + call SHEAR_RAMS_SUB !only body of loop2 + if (data%State%RamLine%FINISHED_shear/=0 .and. data%State%RamLine%FINISHED_shear==1 .and. data%State%RAM(4)%Bottles_Charged_MalfActive==.true.) then + call bop_code(1,data%State%ShearRAM%H_ShearRamBop,4) + endif + endif + endif + else + call SHEAR_RAMS_SUB + if (data%State%RamLine%FINISHED_shear/=0 .and. data%State%RamLine%FINISHED_shear==1 .and. data%State%RAM(4)%Bottles_Charged_MalfActive==.true.) then + call bop_code(1,data%State%ShearRAM%H_ShearRamBop,4) + endif + endif + + end subroutine BlindRams_Step + +! subroutine BlindRams_Output +! implicit none +! end subroutine BlindRams_Output + +! subroutine BlindRamsMainBody +! USE ifport +! USE ifmt +! ! use CSimulationVariables +! ! USE BOP + +! implicit none + +! INTEGER :: ShearRamDuration +! integer,dimension(8) :: ShearRamStartTime , ShearRamEndTime + + +! ! CALL BOP_StartUp() +! loop1: DO + +! CALL DATE_AND_TIME(values=ShearRamStartTime) + + +! CALL SHEAR_RAMS + +! CALL DATE_AND_TIME(values=ShearRamEndTime) + +! ShearRamDuration = 3600000 * (ShearRamEndTime(5) - ShearRamStartTime(5)) + 60000 * (ShearRamEndTime(6) - ShearRamStartTime(6)) + 1000 * (ShearRamEndTime(7) - ShearRamStartTime(7)) + (ShearRamEndTime(8) - ShearRamStartTime(8)) + +! if (ShearRamDuration < 100) then +! call sleepqq(100 - ShearRamDuration) +! ELSE +! WRITE (*,*) 'ShearRam BOP run duration exceeded 100 ms and =', ShearRamDuration +! end if + + +! IF (IsStopped==.true.) THEN +! EXIT loop1 +! ENDIF + + +! ENDDO loop1 + +! end subroutine BlindRamsMainBody + +end module BlindRamsMain diff --git a/Equipments/BopStack/CHOKE_LINE.f90 b/Equipments/BopStack/CHOKE_LINE.f90 index a70122c..d36a9a4 100644 --- a/Equipments/BopStack/CHOKE_LINE.f90 +++ b/Equipments/BopStack/CHOKE_LINE.f90 @@ -19,7 +19,7 @@ SUBROUTINE CHOKE_LINE data%State%RAM(5)%SuccessionCounter = data%State%RAM(5)%SuccessionCounter + 1 - if (data%EquipmentControl%BopControlPanel%ChokeLineValve == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + if (data%Equipments%BopControlPanel%ChokeLineValve == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then if ( data%State%RAM(5)%SuccessionCounter /= data%State%RAM(5)%SuccessionCounterOld+1 ) then data%State%RAM(5)%SuccessionCounter = 0 ! also in starup @@ -55,20 +55,20 @@ SUBROUTINE CHOKE_LINE if (data%State%ChokeLine%finished==1) then data%State%ChokeLine%LeverOld= 1.0 else - data%State%ChokeLine%LeverOld=data%EquipmentControl%BopControlPanel%ChokeLineValve + data%State%ChokeLine%LeverOld=data%Equipments%BopControlPanel%ChokeLineValve endif data%State%ChokeLine%finished=0 data%State%ChokeLine%IsOpening = .true. - data%EquipmentControl%BopControlPanel%ChokeLineCloseLED = LedOff + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOff data%State%BopStackInput%ChokeLineCloseLEDMine = LedOff - data%EquipmentControl%BopControlPanel%ChokeLineOpenLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOn !LedBlinking data%State%RAM(5)%bop_type = 3 !AbopChokeLine=196.67 data%State%ChokeLine%Abop=(data%Configuration%BopStack%ChokeClose*231)/((data%State%ChokeLine%IDBase-data%State%ChokeLine%ODDrillpipe_inBase)/2.) data%State%ChokeLine%NeededVolume=data%State%ChokeLine%Abop*(data%State%ChokeLine%IDBase-max(data%State%ChokeLine%ODDrillpipe_in,data%State%ChokeLine%ODDrillpipe_inBase))/(2.*231) !1.5 galon for each BOP endif - if (data%EquipmentControl%BopControlPanel%ChokeLineValve == 1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + if (data%Equipments%BopControlPanel%ChokeLineValve == 1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then if ( data%State%RAM(5)%SuccessionCounter /= data%State%RAM(5)%SuccessionCounterOld+1 ) then @@ -107,7 +107,7 @@ SUBROUTINE CHOKE_LINE if (data%State%ChokeLine%finished==1) then data%State%ChokeLine%LeverOld= -1.0 else - data%State%ChokeLine%LeverOld=data%EquipmentControl%BopControlPanel%ChokeLineValve + data%State%ChokeLine%LeverOld=data%Equipments%BopControlPanel%ChokeLineValve endif data%State%ChokeLine%finished=0 data%State%ChokeLine%IsClosing = .true. @@ -117,11 +117,11 @@ SUBROUTINE CHOKE_LINE ! RETURN !end if - data%EquipmentControl%BopControlPanel%ChokeLineCloseLED = LedOff !new + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOff !new data%State%BopStackInput%ChokeLineCloseLEDMine = LedOff !new - data%EquipmentControl%BopControlPanel%ChokeLineCloseLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOn !LedBlinking data%State%RAM(5)%bop_type = 3 !AbopChokeLine=196.67 data%State%ChokeLine%Abop=(data%Configuration%BopStack%ChokeOpen*231)/((data%State%ChokeLine%IDBase-data%State%ChokeLine%ODDrillpipe_inBase)/2.) @@ -170,7 +170,7 @@ SUBROUTINE CHOKE_LINE_SUB data%State%RAM(5)%SuccessionCounter = data%State%RAM(5)%SuccessionCounter + 1 - if (data%EquipmentControl%BopControlPanel%ChokeLineValve == 1.0 .and. data%State%ChokeLine%LeverOld == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + if (data%Equipments%BopControlPanel%ChokeLineValve == 1.0 .and. data%State%ChokeLine%LeverOld == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then if ( data%State%RAM(5)%First_CloseTimecheck == 0 ) then @@ -195,10 +195,10 @@ SUBROUTINE CHOKE_LINE_SUB data%State%ChokeLine%closed=0 data%State%RAM(5)%p_bop=data%State%ShearRAM%PA - data%State%ChokeLine%LeverOld = data%EquipmentControl%BopControlPanel%ChokeLineValve - data%EquipmentControl%BopControlPanel%ChokeLineOpenLED = LedOff + data%State%ChokeLine%LeverOld = data%Equipments%BopControlPanel%ChokeLineValve + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOff data%State%BopStackInput%ChokeLineOpenLEDMine = LedOff - data%EquipmentControl%BopControlPanel%ChokeLineCloseLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOn !LedBlinking CALL OpenChokeLine data%State%RAM(5)%bop_type = 3 !AbopChokeLine=196.67 @@ -212,7 +212,7 @@ SUBROUTINE CHOKE_LINE_SUB data%State%ChokeLine%IsOpening = .false. endif - if (data%EquipmentControl%BopControlPanel%ChokeLineValve == -1.0 .and. data%State%ChokeLine%LeverOld == 1.0 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if (data%Equipments%BopControlPanel%ChokeLineValve == -1.0 .and. data%State%ChokeLine%LeverOld == 1.0 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then if ( data%State%RAM(5)%First_OpenTimecheck == 0 ) then @@ -234,10 +234,10 @@ SUBROUTINE CHOKE_LINE_SUB data%State%ChokeLine%closed=0 data%State%RAM(5)%p_bop=data%State%ShearRAM%PA - data%State%ChokeLine%LeverOld = data%EquipmentControl%BopControlPanel%ChokeLineValve - data%EquipmentControl%BopControlPanel%ChokeLineCloseLED = LedOff + data%State%ChokeLine%LeverOld = data%Equipments%BopControlPanel%ChokeLineValve + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOff data%State%BopStackInput%ChokeLineCloseLEDMine = LedOff - data%EquipmentControl%BopControlPanel%ChokeLineOpenLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOn !LedBlinking CALL OpenChokeLine data%State%RAM(5)%bop_type = 3 !AbopChokeLine=196.67 diff --git a/Equipments/BopStack/CHOKE_LINE.i90 b/Equipments/BopStack/CHOKE_LINE.i90 new file mode 100644 index 0000000..854ce58 --- /dev/null +++ b/Equipments/BopStack/CHOKE_LINE.i90 @@ -0,0 +1,311 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/CHOKE_LINE.f90" + + +SUBROUTINE CHOKE_LINE + use SimulationVariables + USE CAccumulatorVariables + USE CBopStackVariables + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants + + implicit none + + +!===================================================================== +! CHOKE LINE 1- BOP CAMERON Type U 5000 +! START CONDITIONS FOR CHOKE LINE 1 +!===================================================================== + + data%State%RAM(5)%SuccessionCounter = data%State%RAM(5)%SuccessionCounter + 1 + + + if (data%Equipments%BopControlPanel%ChokeLineValve == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + + if ( data%State%RAM(5)%SuccessionCounter /= data%State%RAM(5)%SuccessionCounterOld+1 ) then + data%State%RAM(5)%SuccessionCounter = 0 ! also in starup + data%State%RAM(5)%SuccessionCounterOld = 0 ! also in starup + return + else + data%State%RAM(5)%SuccessionCounterOld= data%State%RAM(5)%SuccessionCounter + endif + + + if ( data%State%RAM(5)%SuccessionCounter < int(2.5/data%State%RamLine%DeltaT_BOP) ) then + return + endif + + data%State%RAM(5)%First_CloseTimecheck= 1 + + + + + if (data%State%BopStackInput%ChokeLineOpenLEDMine == LedOn) then + RETURN + end if + data%State%ChokeLine%closed=0 + data%State%RAM(5)%vdis_tot=0 + data%State%RAM(5)%vdis_bottles=0. + data%State%RAM(5)%fvr_air=0. + data%State%RAM(5)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(5)%Qzero=70 + data%State%RAM(5)%Q=data%State%RAM(5)%Qzero + data%State%RAM(5)%flow=70 + data%State%RAM(5)%tol=0.0037 + if (data%State%ChokeLine%finished==1) then + data%State%ChokeLine%LeverOld= 1.0 + else + data%State%ChokeLine%LeverOld=data%Equipments%BopControlPanel%ChokeLineValve + endif + data%State%ChokeLine%finished=0 + data%State%ChokeLine%IsOpening = .true. + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOff + data%State%BopStackInput%ChokeLineCloseLEDMine = LedOff + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOn !LedBlinking + data%State%RAM(5)%bop_type = 3 +!AbopChokeLine=196.67 + data%State%ChokeLine%Abop=(data%Configuration%BopStack%ChokeClose*231)/((data%State%ChokeLine%IDBase-data%State%ChokeLine%ODDrillpipe_inBase)/2.) + data%State%ChokeLine%NeededVolume=data%State%ChokeLine%Abop*(data%State%ChokeLine%IDBase-max(data%State%ChokeLine%ODDrillpipe_in,data%State%ChokeLine%ODDrillpipe_inBase))/(2.*231) !1.5 galon for each BOP + endif + + if (data%Equipments%BopControlPanel%ChokeLineValve == 1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + + + if ( data%State%RAM(5)%SuccessionCounter /= data%State%RAM(5)%SuccessionCounterOld+1 ) then + data%State%RAM(5)%SuccessionCounter = 0 ! also in starup + data%State%RAM(5)%SuccessionCounterOld = 0 ! also in starup + return + else + data%State%RAM(5)%SuccessionCounterOld= data%State%RAM(5)%SuccessionCounter + endif + + + if ( data%State%RAM(5)%SuccessionCounter < int(2.5/data%State%RamLine%DeltaT_BOP) ) then + return + endif + + data%State%RAM(5)%First_OpenTimecheck= 1 + + + + if (data%State%BopStackInput%ChokeLineCloseLEDMine == LedOn) then + RETURN + end if + data%State%ChokeLine%closed=0 + data%State%RAM(5)%vdis_tot=0 + data%State%RAM(5)%vdis_bottles=0. + data%State%RAM(5)%fvr_air=0. + data%State%RAM(5)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(5)%Qzero=70 + data%State%RAM(5)%Q=data%State%RAM(5)%Qzero + data%State%RAM(5)%flow=70 + data%State%RAM(5)%tol=0.0037 + + + + if (data%State%ChokeLine%finished==1) then + data%State%ChokeLine%LeverOld= -1.0 + else + data%State%ChokeLine%LeverOld=data%Equipments%BopControlPanel%ChokeLineValve + endif + data%State%ChokeLine%finished=0 + data%State%ChokeLine%IsClosing = .true. + + +!if (ChokeLineCloseLED == LedOn) then +! RETURN +!end if + + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOff !new + data%State%BopStackInput%ChokeLineCloseLEDMine = LedOff !new + + + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOn !LedBlinking + data%State%RAM(5)%bop_type = 3 +!AbopChokeLine=196.67 + data%State%ChokeLine%Abop=(data%Configuration%BopStack%ChokeOpen*231)/((data%State%ChokeLine%IDBase-data%State%ChokeLine%ODDrillpipe_inBase)/2.) + data%State%ChokeLine%NeededVolume=data%State%ChokeLine%Abop*(data%State%ChokeLine%IDBase-max(data%State%ChokeLine%ODDrillpipe_in,data%State%ChokeLine%ODDrillpipe_inBase))/(2.*231) !1.5 galon for each BOP + endif + + +!===================================================================== + +! if (ChokeLineIsOpening .or. ChokeLineIsClosing) then +! CALL CHOKE_LINE_SUB +! end if + + + END SUBROUTINE CHOKE_LINE + + + + + + + + + + + + +SUBROUTINE CHOKE_LINE_SUB + + use SimulationVariables + USE CAccumulatorVariables + USE CBopStackVariables + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants +! use CSimulationVariables + implicit none + + +! FirstSet= 0 +! RamsFirstSet= 0 + +! loop5: do while (finished_ChokeLine==0) + + + data%State%RAM(5)%SuccessionCounter = data%State%RAM(5)%SuccessionCounter + 1 + + + if (data%Equipments%BopControlPanel%ChokeLineValve == 1.0 .and. data%State%ChokeLine%LeverOld == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + + if ( data%State%RAM(5)%First_CloseTimecheck == 0 ) then + + + if ( data%State%RAM(5)%SuccessionCounter /= data%State%RAM(5)%SuccessionCounterOld+1 ) then + data%State%RAM(5)%SuccessionCounter = 0 ! also in starup + data%State%RAM(5)%SuccessionCounterOld = 0 ! also in starup + return + else + data%State%RAM(5)%SuccessionCounterOld= data%State%RAM(5)%SuccessionCounter + endif + + + + if ( data%State%RAM(5)%SuccessionCounter < int(2.5/data%State%RamLine%DeltaT_BOP) ) then + return + endif + + endif + + + + data%State%ChokeLine%closed=0 + data%State%RAM(5)%p_bop=data%State%ShearRAM%PA + data%State%ChokeLine%LeverOld = data%Equipments%BopControlPanel%ChokeLineValve + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOff + data%State%BopStackInput%ChokeLineOpenLEDMine = LedOff + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOn !LedBlinking + CALL OpenChokeLine + data%State%RAM(5)%bop_type = 3 +!AbopChokeLine=196.67 + data%State%ChokeLine%Abop=(data%Configuration%BopStack%ChokeClose*231)/((data%State%ChokeLine%IDBase-data%State%ChokeLine%ODDrillpipe_inBase)/2.) + data%State%ChokeLine%NeededVolume=data%State%ChokeLine%Abop*(data%State%ChokeLine%ID-max(data%State%ChokeLine%ODDrillpipe_in,data%State%ChokeLine%ODDrillpipe_inBase))/(2.*231) + + data%State%RAM(5)%vdis_bottles=0. + data%State%RAM(5)%fvr_air=0. + data%State%RAM(5)%vdis_elecp=0. + data%State%ChokeLine%IsClosing = .true. + data%State%ChokeLine%IsOpening = .false. + endif + + if (data%Equipments%BopControlPanel%ChokeLineValve == -1.0 .and. data%State%ChokeLine%LeverOld == 1.0 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + + if ( data%State%RAM(5)%First_OpenTimecheck == 0 ) then + + if ( data%State%RAM(5)%SuccessionCounter /= data%State%RAM(5)%SuccessionCounterOld+1 ) then + data%State%RAM(5)%SuccessionCounter = 0 ! also in starup + data%State%RAM(5)%SuccessionCounterOld = 0 ! also in starup + return + else + data%State%RAM(5)%SuccessionCounterOld= data%State%RAM(5)%SuccessionCounter + endif + + if ( data%State%RAM(5)%SuccessionCounter < int(2.5/data%State%RamLine%DeltaT_BOP) ) then + return + endif + + endif + + + + data%State%ChokeLine%closed=0 + data%State%RAM(5)%p_bop=data%State%ShearRAM%PA + data%State%ChokeLine%LeverOld = data%Equipments%BopControlPanel%ChokeLineValve + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOff + data%State%BopStackInput%ChokeLineCloseLEDMine = LedOff + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOn !LedBlinking + CALL OpenChokeLine + data%State%RAM(5)%bop_type = 3 +!AbopChokeLine=196.67 + data%State%ChokeLine%Abop=(data%Configuration%BopStack%ChokeOpen*231)/((data%State%ChokeLine%IDBase-data%State%ChokeLine%ODDrillpipe_inBase)/2.) + data%State%ChokeLine%NeededVolume=data%State%ChokeLine%Abop*(data%State%ChokeLine%IDBase-data%State%ChokeLine%ID)/(2.*231) + data%State%RAM(5)%vdis_bottles=0. + data%State%RAM(5)%fvr_air=0. + data%State%RAM(5)%vdis_elecp=0. + + data%State%ChokeLine%IsOpening = .true. + data%State%ChokeLine%IsClosing = .false. + endif + + + data%State%RAM(5)%First_CloseTimecheck = 0 + data%State%RAM(5)%First_OpenTimecheck = 0 + + + data%State%RAM(5)%time=data%State%RAM(5)%time+data%State%RamLine%DeltaT_BOP !overal time (s) + + + +!=================================================== +! BOP +!=================================================== +if (data%State%ChokeLine%closed==0) then !bop closing + call bop_code(4,data%State%ChokeLine%H_Bop,5) !ramtype=4 5=RNUMBER +endif !bop is closing +!================================================================ +if (data%State%ChokeLine%closed==1) then + data%State%RAM(5)%Q=0 +!p_bop=pram_reg + data%State%RAM(5)%p_bop=data%State%ShearRAM%PA + data%State%RAMS%minloss(5,17)=0. !RNUMBER=5 +endif + +data%State%RAM(5)%timecounter_ram=data%State%RAM(5)%timecounter_ram+1 + + + + + +! MiddleRamsStatus = IDshearBop +! UpperRamsStatus = IDPipeRam1 +! LowerRamsStatus = IDPipeRam2 +! AnnularStatus = IDAnnular +! AccumulatorPressureGauge = p_acc +! ManifoldPressureGauge= pram_reg +! AnnularPressureGauge=Pannular_reg +! +! +! +! WRITE(60,60) data%State%RAM(5)%time,data%State%RAM(5)%Q,data%State%RAM(5)%vdis_tot,p_acc, & +! pram_reg,Pannular_reg,data%State%RAM(5)%p_bop,IDshearBop, & +! IDPipeRam1,IDPipeRam2,IDAnnular +!60 FORMAT(11(f18.5)) + + +! call sleepqq(100) + if (data%State%ChokeLine%closed==1) then +! if ((UpperRamsValve==1. .and. UpperRamsFailureMalf==0) .or. (UpperRamsValve==-1.0 .and. UpperRamsFailureMalf==0) .or. (MiddleRamsValve==1. .and. MiddleRamsFailureMalf==0) .or. (MiddleRamsValve==-1.0 .and. MiddleRamsFailureMalf==0) .or. (LowerRamsValve==1. .and. LowerRamsFailureMalf==0) .or. (LowerRamsValve==-1.0 .and. LowerRamsFailureMalf==0) .or. (AnnularValve==1. .and. AnnularFailureMalf==0) .or. (AnnularValve==-1.0 .and. AnnularFailureMalf==0) .or. KillLineValve==1. .or. KillLineValve==-1.0) then + data%State%ChokeLine%finished=1 +! endif +endif + +! if (IsStopped == .true.) return + +! end do loop5 !while finished_ChokeLine==0 + +END SUBROUTINE CHOKE_LINE_SUB diff --git a/Equipments/BopStack/ChokeLineMain.i90 b/Equipments/BopStack/ChokeLineMain.i90 new file mode 100644 index 0000000..3c948bd --- /dev/null +++ b/Equipments/BopStack/ChokeLineMain.i90 @@ -0,0 +1,83 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/ChokeLineMain.f90" +module ChokeLineMain + implicit none + public + contains + +! subroutine ChokeLine_Setup() +! ! use CSimulationVariables +! implicit none +! call OnSimulationInitialization%Add(ChokeLine_Init) +! call OnSimulationStop%Add(ChokeLine_Init) +! call OnChokeLineStep%Add(ChokeLine_Step) +! call OnChokeLineOutput%Add(ChokeLine_Output) +! call OnChokeLineMain%Add(ChokeLineMainBody) +! end subroutine + +! subroutine ChokeLine_Init +! implicit none +! end subroutine ChokeLine_Init + + subroutine ChokeLine_Step + use SimulationVariables + implicit none + if (data%State%ChokeLine%finished/=0) then + call CHOKE_LINE + if (data%State%ChokeLine%IsOpening .or. data%State%ChokeLine%IsClosing) then + data%State%Annular%FirstSet= 0 + data%State%AnnularComputational%RamsFirstSet= 0 + if(data%State%ChokeLine%finished==0) then + call CHOKE_LINE_SUB !only body of loop2 + endif + endif + else + call SHEAR_RAMS_SUB + endif + end subroutine ChokeLine_Step + +! subroutine ChokeLine_Output +! implicit none +! end subroutine ChokeLine_Output + +! subroutine ChokeLineMainBody +! USE ifport +! USE ifmt +! ! use CSimulationVariables +! ! USE BOP + +! implicit none + +! INTEGER :: ChokeLineDuration +! integer,dimension(8) :: ChokeLineStartTime , ChokeLineEndTime + +! ! CALL BOP_StartUp() +! loop1: DO + +! CALL DATE_AND_TIME(values=ChokeLineStartTime) + + +! CALL CHOKE_LINE + +! CALL DATE_AND_TIME(values=chokeLineEndTime) + +! chokeLineDuration = 3600000 * (chokeLineEndTime(5) - chokeLineStartTime(5)) + 60000 * (chokeLineEndTime(6) - chokeLineStartTime(6)) + 1000 * (chokeLineEndTime(7) - chokeLineStartTime(7)) + (chokeLineEndTime(8) - chokeLineStartTime(8)) + +! if (chokeLineDuration < 100) then +! call sleepqq(100 - chokeLineDuration) +! ELSE +! WRITE (*,*) 'chokeLine BOP run duration exceeded 100 ms and =', chokeLineDuration +! end if + +! IF (IsStopped==.true.) THEN +! EXIT loop1 +! ENDIF + + +! ENDDO loop1 + + +! ! CALL DEALLOCATE_ARRAYS() + +! end subroutine ChokeLineMainBody + +end module ChokeLineMain diff --git a/Equipments/BopStack/KILL_LINE.f90 b/Equipments/BopStack/KILL_LINE.f90 index b18259e..dba38e8 100644 --- a/Equipments/BopStack/KILL_LINE.f90 +++ b/Equipments/BopStack/KILL_LINE.f90 @@ -20,7 +20,7 @@ SUBROUTINE KILL_LINE data%State%RAM(6)%SuccessionCounter = data%State%RAM(6)%SuccessionCounter + 1 - if (data%EquipmentControl%BopControlPanel%KillLineValve == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + if (data%Equipments%BopControlPanel%KillLineValve == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then if ( data%State%RAM(6)%SuccessionCounter /= data%State%RAM(6)%SuccessionCounterOld+1 ) then data%State%RAM(6)%SuccessionCounter = 0 ! also in starup @@ -55,20 +55,20 @@ SUBROUTINE KILL_LINE if (data%State%KillLine%finished==1) then data%State%KillLine%LeverOld= 1.0 else - data%State%KillLine%LeverOld=data%EquipmentControl%BopControlPanel%KillLineValve + data%State%KillLine%LeverOld=data%Equipments%BopControlPanel%KillLineValve endif data%State%KillLine%finished=0 data%State%KillLine%IsOpening = .true. - data%EquipmentControl%BopControlPanel%KillLineCloseLED = LedOff + data%Equipments%BopControlPanel%KillLineCloseLED = LedOff data%State%BopStackInput%KillLineCloseLedMine = LedOff - data%EquipmentControl%BopControlPanel%KillLineOpenLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%KillLineOpenLED = LedOn !LedBlinking data%State%RAM(6)%bop_type = 3 !AbopKillLine=196.67 data%State%KillLine%Abop=(data%Configuration%BopStack%KillClose*231)/((data%State%KillLine%IDBase-data%State%KillLine%ODDrillpipe_inBase)/2.) data%State%KillLine%NeededVolume=data%State%KillLine%Abop*(data%State%KillLine%IDBase-max(data%State%KillLine%ODDrillpipe_in,data%State%KillLine%ODDrillpipe_inBase))/(2.*231) !1.5 galon for each BOP endif - if (data%EquipmentControl%BopControlPanel%KillLineValve == 1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + if (data%Equipments%BopControlPanel%KillLineValve == 1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then if ( data%State%RAM(6)%SuccessionCounter /= data%State%RAM(6)%SuccessionCounterOld+1 ) then @@ -107,7 +107,7 @@ SUBROUTINE KILL_LINE if (data%State%KillLine%finished==1) then data%State%KillLine%LeverOld= -1.0 else - data%State%KillLine%LeverOld=data%EquipmentControl%BopControlPanel%KillLineValve + data%State%KillLine%LeverOld=data%Equipments%BopControlPanel%KillLineValve endif data%State%KillLine%finished=0 data%State%KillLine%IsClosing = .true. @@ -117,10 +117,10 @@ SUBROUTINE KILL_LINE ! RETURN !end if - data%EquipmentControl%BopControlPanel%KillLineCloseLED = LedOff !new + data%Equipments%BopControlPanel%KillLineCloseLED = LedOff !new data%State%BopStackInput%KillLineCloseLedMine = LedOff !new - data%EquipmentControl%BopControlPanel%KillLineCloseLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%KillLineCloseLED = LedOn !LedBlinking data%State%RAM(6)%bop_type = 3 !AbopKillLine=196.67 data%State%KillLine%Abop=(data%Configuration%BopStack%KillOpen*231)/((data%State%KillLine%IDBase-data%State%KillLine%ODDrillpipe_inBase)/2.) @@ -169,7 +169,7 @@ SUBROUTINE KILL_LINE_SUB - if (data%EquipmentControl%BopControlPanel%KillLineValve == 1.0 .and. data%State%KillLine%LeverOld == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + if (data%Equipments%BopControlPanel%KillLineValve == 1.0 .and. data%State%KillLine%LeverOld == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then if ( data%State%RAM(6)%First_CloseTimecheck == 0 ) then @@ -194,10 +194,10 @@ SUBROUTINE KILL_LINE_SUB data%State%KillLine%closed=0 data%State%RAM(6)%p_bop=data%State%ShearRAM%PA - data%State%KillLine%LeverOld = data%EquipmentControl%BopControlPanel%KillLineValve - data%EquipmentControl%BopControlPanel%KillLineOpenLED = LedOff + data%State%KillLine%LeverOld = data%Equipments%BopControlPanel%KillLineValve + data%Equipments%BopControlPanel%KillLineOpenLED = LedOff data%State%BopStackInput%KillLineOpenLedMine = LedOff - data%EquipmentControl%BopControlPanel%KillLineCloseLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%KillLineCloseLED = LedOn !LedBlinking CALL OpenKillLine data%State%RAM(6)%bop_type = 3 !AbopKillLine=196.67 @@ -211,7 +211,7 @@ SUBROUTINE KILL_LINE_SUB data%State%KillLine%IsOpening = .false. endif - if (data%EquipmentControl%BopControlPanel%KillLineValve == -1.0 .and. data%State%KillLine%LeverOld == 1.0 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if (data%Equipments%BopControlPanel%KillLineValve == -1.0 .and. data%State%KillLine%LeverOld == 1.0 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then if ( data%State%RAM(6)%First_OpenTimecheck == 0 ) then @@ -233,10 +233,10 @@ SUBROUTINE KILL_LINE_SUB data%State%KillLine%closed=0 data%State%RAM(6)%p_bop=data%State%ShearRAM%PA - data%State%KillLine%LeverOld = data%EquipmentControl%BopControlPanel%KillLineValve - data%EquipmentControl%BopControlPanel%KillLineCloseLED = LedOff + data%State%KillLine%LeverOld = data%Equipments%BopControlPanel%KillLineValve + data%Equipments%BopControlPanel%KillLineCloseLED = LedOff data%State%BopStackInput%KillLineCloseLedMine = LedOff - data%EquipmentControl%BopControlPanel%KillLineOpenLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%KillLineOpenLED = LedOn !LedBlinking CALL OpenKillLine data%State%RAM(6)%bop_type = 3 !AbopKillLine=196.67 diff --git a/Equipments/BopStack/KILL_LINE.i90 b/Equipments/BopStack/KILL_LINE.i90 new file mode 100644 index 0000000..96e5c0c --- /dev/null +++ b/Equipments/BopStack/KILL_LINE.i90 @@ -0,0 +1,311 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/KILL_LINE.f90" + + +SUBROUTINE KILL_LINE + use SimulationVariables + USE CAccumulatorVariables + USE CBopStackVariables + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants +! use CSimulationVariables + + implicit none + + +!===================================================================== +! KILL LINE 1- BOP CAMERON Type U 5000 +! START CONDITIONS FOR KILL LINE 1 +!===================================================================== + + data%State%RAM(6)%SuccessionCounter = data%State%RAM(6)%SuccessionCounter + 1 + + + if (data%Equipments%BopControlPanel%KillLineValve == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + + if ( data%State%RAM(6)%SuccessionCounter /= data%State%RAM(6)%SuccessionCounterOld+1 ) then + data%State%RAM(6)%SuccessionCounter = 0 ! also in starup + data%State%RAM(6)%SuccessionCounterOld = 0 ! also in starup + return + else + data%State%RAM(6)%SuccessionCounterOld= data%State%RAM(6)%SuccessionCounter + endif + + + if ( data%State%RAM(6)%SuccessionCounter < int(2.5/data%State%RamLine%DeltaT_BOP) ) then + return + endif + + data%State%RAM(6)%First_CloseTimecheck= 1 + + + + if (data%State%BopStackInput%KillLineOpenLedMine == LedOn) then + RETURN + end if + data%State%KillLine%closed=0 + data%State%RAM(6)%vdis_tot=0 + data%State%RAM(6)%vdis_bottles=0. + data%State%RAM(6)%fvr_air=0. + data%State%RAM(6)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(6)%Qzero=70 + data%State%RAM(6)%Q=data%State%RAM(6)%Qzero + data%State%RAM(6)%flow=70 + data%State%RAM(6)%tol=0.0037 + if (data%State%KillLine%finished==1) then + data%State%KillLine%LeverOld= 1.0 + else + data%State%KillLine%LeverOld=data%Equipments%BopControlPanel%KillLineValve + endif + data%State%KillLine%finished=0 + data%State%KillLine%IsOpening = .true. + data%Equipments%BopControlPanel%KillLineCloseLED = LedOff + data%State%BopStackInput%KillLineCloseLedMine = LedOff + data%Equipments%BopControlPanel%KillLineOpenLED = LedOn !LedBlinking + data%State%RAM(6)%bop_type = 3 +!AbopKillLine=196.67 + data%State%KillLine%Abop=(data%Configuration%BopStack%KillClose*231)/((data%State%KillLine%IDBase-data%State%KillLine%ODDrillpipe_inBase)/2.) + data%State%KillLine%NeededVolume=data%State%KillLine%Abop*(data%State%KillLine%IDBase-max(data%State%KillLine%ODDrillpipe_in,data%State%KillLine%ODDrillpipe_inBase))/(2.*231) !1.5 galon for each BOP + endif + + if (data%Equipments%BopControlPanel%KillLineValve == 1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + + + if ( data%State%RAM(6)%SuccessionCounter /= data%State%RAM(6)%SuccessionCounterOld+1 ) then + data%State%RAM(6)%SuccessionCounter = 0 ! also in starup + data%State%RAM(6)%SuccessionCounterOld = 0 ! also in starup + return + else + data%State%RAM(6)%SuccessionCounterOld= data%State%RAM(6)%SuccessionCounter + endif + + + if ( data%State%RAM(6)%SuccessionCounter < int(2.5/data%State%RamLine%DeltaT_BOP) ) then + return + endif + + data%State%RAM(6)%First_OpenTimecheck= 1 + + + + if (data%State%BopStackInput%KillLineCloseLedMine == LedOn) then + RETURN + end if + data%State%KillLine%closed=0 + data%State%RAM(6)%vdis_tot=0 + data%State%RAM(6)%vdis_bottles=0. + data%State%RAM(6)%fvr_air=0. + data%State%RAM(6)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(6)%Qzero=70 + data%State%RAM(6)%Q=data%State%RAM(6)%Qzero + data%State%RAM(6)%flow=70 + data%State%RAM(6)%tol=0.0037 + + + + if (data%State%KillLine%finished==1) then + data%State%KillLine%LeverOld= -1.0 + else + data%State%KillLine%LeverOld=data%Equipments%BopControlPanel%KillLineValve + endif + data%State%KillLine%finished=0 + data%State%KillLine%IsClosing = .true. + + +!if (KillLineCloseLed == LedOn) then +! RETURN +!end if + + data%Equipments%BopControlPanel%KillLineCloseLED = LedOff !new + data%State%BopStackInput%KillLineCloseLedMine = LedOff !new + + data%Equipments%BopControlPanel%KillLineCloseLED = LedOn !LedBlinking + data%State%RAM(6)%bop_type = 3 +!AbopKillLine=196.67 + data%State%KillLine%Abop=(data%Configuration%BopStack%KillOpen*231)/((data%State%KillLine%IDBase-data%State%KillLine%ODDrillpipe_inBase)/2.) + data%State%KillLine%NeededVolume=data%State%KillLine%Abop*(data%State%KillLine%IDBase-max(data%State%KillLine%ODDrillpipe_in,data%State%KillLine%ODDrillpipe_inBase))/(2.*231) !1.5 galon for each BOP + endif + +!========================================================================== + +if (data%State%KillLine%IsOpening .or. data%State%KillLine%IsClosing) then + CALL KILL_LINE_SUB +end if + + + END SUBROUTINE KILL_LINE + + + + + + + + + + + +SUBROUTINE KILL_LINE_SUB + + use SimulationVariables + USE CAccumulatorVariables + USE CBopStackVariables + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants +! use CSimulationVariables + + implicit none + + + data%State%Annular%FirstSet= 0 + data%State%AnnularComputational%RamsFirstSet= 0 + +! loop6: do while (finished_KillLine==0) + + + data%State%RAM(6)%SuccessionCounter = data%State%RAM(6)%SuccessionCounter + 1 + + + + if (data%Equipments%BopControlPanel%KillLineValve == 1.0 .and. data%State%KillLine%LeverOld == -1.0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + + if ( data%State%RAM(6)%First_CloseTimecheck == 0 ) then + + + if ( data%State%RAM(6)%SuccessionCounter /= data%State%RAM(6)%SuccessionCounterOld+1 ) then + data%State%RAM(6)%SuccessionCounter = 0 ! also in starup + data%State%RAM(6)%SuccessionCounterOld = 0 ! also in starup + return + else + data%State%RAM(6)%SuccessionCounterOld= data%State%RAM(6)%SuccessionCounter + endif + + + + if ( data%State%RAM(6)%SuccessionCounter < int(2.5/data%State%RamLine%DeltaT_BOP) ) then + return + endif + + endif + + + + data%State%KillLine%closed=0 + data%State%RAM(6)%p_bop=data%State%ShearRAM%PA + data%State%KillLine%LeverOld = data%Equipments%BopControlPanel%KillLineValve + data%Equipments%BopControlPanel%KillLineOpenLED = LedOff + data%State%BopStackInput%KillLineOpenLedMine = LedOff + data%Equipments%BopControlPanel%KillLineCloseLED = LedOn !LedBlinking + CALL OpenKillLine + data%State%RAM(6)%bop_type = 3 +!AbopKillLine=196.67 + data%State%KillLine%Abop=(data%Configuration%BopStack%KillClose*231)/((data%State%KillLine%IDBase-data%State%KillLine%ODDrillpipe_inBase)/2.) + data%State%KillLine%NeededVolume=data%State%KillLine%Abop*(data%State%KillLine%ID-max(data%State%KillLine%ODDrillpipe_in,data%State%KillLine%ODDrillpipe_inBase))/(2.*231) + + data%State%RAM(6)%vdis_bottles=0. + data%State%RAM(6)%fvr_air=0. + data%State%RAM(6)%vdis_elecp=0. + data%State%KillLine%IsClosing = .true. + data%State%KillLine%IsOpening = .false. + endif + + if (data%Equipments%BopControlPanel%KillLineValve == -1.0 .and. data%State%KillLine%LeverOld == 1.0 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + + + if ( data%State%RAM(6)%First_OpenTimecheck == 0 ) then + + if ( data%State%RAM(6)%SuccessionCounter /= data%State%RAM(6)%SuccessionCounterOld+1 ) then + data%State%RAM(6)%SuccessionCounter = 0 ! also in starup + data%State%RAM(6)%SuccessionCounterOld = 0 ! also in starup + return + else + data%State%RAM(6)%SuccessionCounterOld= data%State%RAM(6)%SuccessionCounter + endif + + if ( data%State%RAM(6)%SuccessionCounter < int(2.5/data%State%RamLine%DeltaT_BOP) ) then + return + endif + + endif + + + data%State%KillLine%closed=0 + data%State%RAM(6)%p_bop=data%State%ShearRAM%PA + data%State%KillLine%LeverOld = data%Equipments%BopControlPanel%KillLineValve + data%Equipments%BopControlPanel%KillLineCloseLED = LedOff + data%State%BopStackInput%KillLineCloseLedMine = LedOff + data%Equipments%BopControlPanel%KillLineOpenLED = LedOn !LedBlinking + CALL OpenKillLine + data%State%RAM(6)%bop_type = 3 +!AbopKillLine=196.67 + data%State%KillLine%Abop=(data%Configuration%BopStack%KillOpen*231)/((data%State%KillLine%IDBase-data%State%KillLine%ODDrillpipe_inBase)/2.) + data%State%KillLine%NeededVolume=data%State%KillLine%Abop*(data%State%KillLine%IDBase-data%State%KillLine%ID)/(2.*231) + data%State%RAM(6)%vdis_bottles=0. + data%State%RAM(6)%fvr_air=0. + data%State%RAM(6)%vdis_elecp=0. + + data%State%KillLine%IsOpening = .true. + data%State%KillLine%IsClosing = .false. + endif + + + data%State%RAM(6)%First_CloseTimecheck = 0 + data%State%RAM(6)%First_OpenTimecheck = 0 + + + data%State%RAM(6)%time=data%State%RAM(6)%time+data%State%RamLine%DeltaT_BOP !overal time (s) + + + +!=================================================== +! BOP +!=================================================== +if (data%State%KillLine%closed==0) then !bop closing + call bop_code(5,data%State%KillLine%H_Bop,6) !ramtype=5 6=RNUMBER +endif !bop is closing +!================================================================ +if (data%State%KillLine%closed==1) then + data%State%RAM(6)%Q=0 +!p_bop=pram_reg + data%State%RAM(6)%p_bop=data%State%ShearRAM%PA + data%State%RAMS%minloss(6,17)=0. !RNUMBER=6 +endif + +data%State%RAM(6)%timecounter_ram=data%State%RAM(6)%timecounter_ram+1 + + + + + +! MiddleRamsStatus = IDshearBop +! UpperRamsStatus = IDPipeRam1 +! LowerRamsStatus = IDPipeRam2 +! AnnularStatus = IDAnnular +! AccumulatorPressureGauge = p_acc +! ManifoldPressureGauge= pram_reg +! AnnularPressureGauge=Pannular_reg +! +! +! +! WRITE(60,60) data%State%RAM(6)%time,data%State%RAM(6)%Q,data%State%RAM(6)%vdis_tot,p_acc, & +! pram_reg,Pannular_reg,data%State%RAM(6)%p_bop,IDshearBop, & +! IDPipeRam1,IDPipeRam2,IDAnnular +!60 FORMAT(11(f18.5)) + + +! call sleepqq(100) + +if (data%State%KillLine%closed==1) then +! if ((UpperRamsValve==1. .and. UpperRamsFailureMalf==0) .or. (UpperRamsValve==-1.0 .and. UpperRamsFailureMalf==0) .or. (MiddleRamsValve==1. .and. MiddleRamsFailureMalf==0) .or. (MiddleRamsValve==-1.0 .and. MiddleRamsFailureMalf==0) .or. (LowerRamsValve==1. .and. LowerRamsFailureMalf==0) .or. (LowerRamsValve==-1.0 .and. LowerRamsFailureMalf==0) .or. (AnnularValve==1. .and. AnnularFailureMalf==0) .or. (AnnularValve==-1.0 .and. AnnularFailureMalf==0) .or. ChokeLineValve==1. .or. ChokeLineValve==-1.0) then + data%State%KillLine%finished=1 +! endif +endif + +! if (IsStopped == .true.) return + +! end do loop6 !while finished_KillLine==0 + +END SUBROUTINE KILL_LINE_SUB diff --git a/Equipments/BopStack/LOSS_INPUTS.f90 b/Equipments/BopStack/LOSS_INPUTS.f90 index 5c17078..b16f3d7 100644 --- a/Equipments/BopStack/LOSS_INPUTS.f90 +++ b/Equipments/BopStack/LOSS_INPUTS.f90 @@ -339,9 +339,9 @@ implicit none !Pannular_regset=min(AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously !write(*,*) 'pumps_charge_bottle' - if(data%EquipmentControl%BopControlPanel%ByePassValve == -1.0) then + if(data%Equipments%BopControlPanel%ByePassValve == -1.0) then data%State%BopStackAcc%ByPassOld= -1.0 - elseif(data%EquipmentControl%BopControlPanel%ByePassValve == 1.0) then + elseif(data%Equipments%BopControlPanel%ByePassValve == 1.0) then data%State%BopStackAcc%ByPassOld= 1.0 endif @@ -679,9 +679,9 @@ enddo data%State%RAM(RNUMBER)%loss_after= data%State%RAM(RNUMBER)%pipe_loss2+ data%State%RAM(RNUMBER)%minor_loss2+ data%State%RAM(RNUMBER)%static_loss2 !(psi) !======================================================= - if(data%EquipmentControl%BopControlPanel%ByePassValve == -1.0) then + if(data%Equipments%BopControlPanel%ByePassValve == -1.0) then data%State%BopStackAcc%ByPassOld= -1.0 - elseif(data%EquipmentControl%BopControlPanel%ByePassValve == 1.0) then + elseif(data%Equipments%BopControlPanel%ByePassValve == 1.0) then data%State%BopStackAcc%ByPassOld= 1.0 endif ! write(*,*) 'ByPassOld=', ByPassOld @@ -786,9 +786,9 @@ if (ramtype==1) then !for shear ram if (data%State%RamLine%ShearRamIsClosing) then data%State%ShearRAM%IDshearBop=0. + data%State%ShearRAM%ShearIsNotAllowed*data%State%ShearRAM%ODDrillpipe_inShearRam - data%EquipmentControl%BopControlPanel%MiddleRamsCloseLED = LedOn + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOn data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOn - data%EquipmentControl%BopControlPanel%MiddleRamsOpenLED = LedOff + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOff data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOff if (data%State%TD_BOP%BOPConnectionPossibility(3) == 1 .and. data%State%ShearRAM%ShearIsNotAllowed==0) then CALL CloseMiddleRams @@ -798,9 +798,9 @@ if (ramtype==1) then !for shear ram if (data%State%RamLine%ShearRamIsOpening) then data%State%ShearRAM%IDshearBop=data%State%ShearRAM%IDshearBopBase - data%EquipmentControl%BopControlPanel%MiddleRamsOpenLED = LedOn + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOn data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOn - data%EquipmentControl%BopControlPanel%MiddleRamsCloseLED = LedOff + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOff data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOff CALL OpenMiddleRams data%State%RamLine%ShearBop_Situation_forTD= 0 ! open - for TD code @@ -830,9 +830,9 @@ if (ramtype==2) then !for pipe ram1 if (data%State%PipeRam1%IsClosing) then data%State%PipeRam1%ID=max(data%State%PipeRam1%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase) - data%EquipmentControl%BopControlPanel%UpperRamsCloseLED = LedOn + data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOn data%State%BopStackInput%UpperRamsCloseLEDMine = LedOn - data%EquipmentControl%BopControlPanel%UpperRamsOpenLED = LedOff + data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOff data%State%BopStackInput%UpperRamsOpenLEDMine = LedOff if (data%State%TD_BOP%BOPConnectionPossibility(2) == 1) then CALL CloseUpperRams ! for C code @@ -845,9 +845,9 @@ if (ramtype==2) then !for pipe ram1 if (data%State%PipeRam1%IsOpening) then data%State%PipeRam1%ID=data%State%PipeRam1%IDBase - data%EquipmentControl%BopControlPanel%UpperRamsOpenLED = LedOn + data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOn data%State%BopStackInput%UpperRamsOpenLEDMine = LedOn - data%EquipmentControl%BopControlPanel%UpperRamsCloseLED = LedOff + data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOff data%State%BopStackInput%UpperRamsCloseLEDMine = LedOff Call OpenUpperRams ! for C code data%State%PipeRam1%Situation_forTD= 0 ! open - for TD code @@ -878,9 +878,9 @@ if (ramtype==3) then !for pipe ram2 if (data%State%PipeRam2%IsClosing) then data%State%PipeRam2%ID=max(data%State%PipeRam2%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase) - data%EquipmentControl%BopControlPanel%LowerRamsCloseLED = LedOn + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOn data%State%BopStackInput%LowerRamsCloseLEDMine = LedOn - data%EquipmentControl%BopControlPanel%LowerRamsOpenLED = LedOff + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOff data%State%BopStackInput%LowerRamsOpenLEDMine = LedOff if (data%State%TD_BOP%BOPConnectionPossibility(4) == 1) then CALL CloseLowerRams @@ -890,9 +890,9 @@ if (ramtype==3) then !for pipe ram2 if (data%State%PipeRam2%IsOpening) then data%State%PipeRam2%ID=data%State%PipeRam1%IDBase - data%EquipmentControl%BopControlPanel%LowerRamsOpenLED = LedOn + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOn data%State%BopStackInput%LowerRamsOpenLEDMine = LedOn - data%EquipmentControl%BopControlPanel%LowerRamsCloseLED = LedOff + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOff data%State%BopStackInput%LowerRamsCloseLEDMine = LedOff CALL OpenLowerRams data%State%PipeRam2%Situation_forTD= 0 ! open - for TD code @@ -922,18 +922,18 @@ if (ramtype==4) then !for Choke Line if (data%State%ChokeLine%IsClosing) then data%State%ChokeLine%ID=max(data%State%ChokeLine%ODDrillpipe_in,data%State%ChokeLine%ODDrillpipe_inBase) - data%EquipmentControl%BopControlPanel%ChokeLineCloseLED = LedOn + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOn data%State%BopStackInput%ChokeLineCloseLEDMine = LedOn - data%EquipmentControl%BopControlPanel%ChokeLineOpenLED = LedOff + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOff data%State%BopStackInput%ChokeLineOpenLEDMine = LedOff CALL CloseChokeLine endif if (data%State%ChokeLine%IsOpening) then data%State%ChokeLine%ID=data%State%ChokeLine%IDBase - data%EquipmentControl%BopControlPanel%ChokeLineOpenLED = LedOn + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOn data%State%BopStackInput%ChokeLineOpenLEDMine = LedOn - data%EquipmentControl%BopControlPanel%ChokeLineCloseLED = LedOff + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOff data%State%BopStackInput%ChokeLineCloseLEDMine = LedOff CALL OpenChokeLine endif @@ -961,18 +961,18 @@ if (ramtype==5) then !for Kill Line if (data%State%KillLine%IsClosing) then data%State%KillLine%ID=max(data%State%KillLine%ODDrillpipe_in,data%State%KillLine%ODDrillpipe_inBase) - data%EquipmentControl%BopControlPanel%KillLineCloseLED = LedOn + data%Equipments%BopControlPanel%KillLineCloseLED = LedOn data%State%BopStackInput%KillLineCloseLedMine = LedOn - data%EquipmentControl%BopControlPanel%KillLineOpenLED = LedOff + data%Equipments%BopControlPanel%KillLineOpenLED = LedOff data%State%BopStackInput%KillLineOpenLedMine = LedOff CALL CloseKillLine endif if (data%State%KillLine%IsOpening) then data%State%KillLine%ID=data%State%KillLine%IDBase - data%EquipmentControl%BopControlPanel%KillLineOpenLED = LedOn + data%Equipments%BopControlPanel%KillLineOpenLED = LedOn data%State%BopStackInput%KillLineOpenLedMine = LedOn - data%EquipmentControl%BopControlPanel%KillLineCloseLED = LedOff + data%Equipments%BopControlPanel%KillLineCloseLED = LedOff data%State%BopStackInput%KillLineCloseLedMine = LedOff CALL OpenKillLine endif @@ -1231,10 +1231,10 @@ data%State%RamLine%P_ACC=data%State%RamLine%B1*exp(data%State%RamLine%B2*data%St if (data%State%Annular%AnnularIsClosing) then data%State%Annular%IDAnnular=max(data%State%Annular%ODDrillpipe_inAnnular,data%State%Annular%ODDrillpipe_inAnnularBase) - data%EquipmentControl%BopControlPanel%AnnularCloseLED = LedOn + data%Equipments%BopControlPanel%AnnularCloseLED = LedOn data%State%BopStackInput%AnnularCloseLedMine = LedOn - data%EquipmentControl%BopControlPanel%AnnularOpenLED = LedOff + data%Equipments%BopControlPanel%AnnularOpenLED = LedOff data%State%BopStackInput%AnnularOpenLedMine = LedOff if (data%State%TD_BOP%BOPConnectionPossibility(1) == 1) then @@ -1248,10 +1248,10 @@ data%State%RamLine%P_ACC=data%State%RamLine%B1*exp(data%State%RamLine%B2*data%St if (data%State%Annular%AnnularIsOpening) then data%State%Annular%IDAnnular=data%State%Annular%IDAnnularBase - data%EquipmentControl%BopControlPanel%AnnularOpenLED = LedOn + data%Equipments%BopControlPanel%AnnularOpenLED = LedOn data%State%BopStackInput%AnnularOpenLedMine = LedOn - data%EquipmentControl%BopControlPanel%AnnularCloseLED = LedOff + data%Equipments%BopControlPanel%AnnularCloseLED = LedOff data%State%BopStackInput%AnnularCloseLedMine = LedOff CALL OpenAnnular diff --git a/Equipments/BopStack/LOSS_INPUTS.i90 b/Equipments/BopStack/LOSS_INPUTS.i90 new file mode 100644 index 0000000..d98449f --- /dev/null +++ b/Equipments/BopStack/LOSS_INPUTS.i90 @@ -0,0 +1,1268 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/LOSS_INPUTS.f90" + SUBROUTINE DEALLOCATE_ARRAYS() +use SimulationVariables +implicit none +!=========================================================================== +! RAMLINE MINOR LOSSES INPUT +!=========================================================================== + DEALLOCATE (data%State%BopStackInput%MINORS1,data%State%RamLine%MINORDIAMETER_RAMLINE,data%State%RamLine%AREAMINOR_RAMLINE & + ,data%State%RamLine%LF_RAMLINE,data%State%RamLine%CV_RAMLINE,data%State%RamLine%NOTE_RAMLINE,data%State%RAMS%minlosspa,data%State%RAMS%minloss) +!=========================================================================== +! RAMLINE PIPNING LOSSES INPUT +!=========================================================================== + DEALLOCATE (data%State%BopStackInput%PIPINGS_RAMLINE,data%State%RamLine%DIAM_RAMLINE_INCH, & + data%State%RamLine%AREA_RAMLINE,data%State%RamLine%LENGT_RAMLINE,data%State%RamLine%ROUGHNESS_RAMLINE,data%State%RamLine%RELROUGH_RAMLINE & + ,data%State%RAMS%Re_ramline,data%State%RAMS%fric,data%State%RAMS%fricloss) +!=========================================================================== +! ANNULAR MINOR LOSSES INPUT +!=========================================================================== + DEALLOCATE (data%State%BopStackInput%MINORS_ANNULAR,data%State%AnnularComputational%MINORDIAMETER_ANNULARLINE,data%State%AnnularComputational%AREAMINOR_ANNULARLINE & + ,data%State%AnnularComputational%LF_ANNULARLINE,data%State%AnnularComputational%CV_ANNULARLINE,data%State%AnnularComputational%NOTE_ANNULARLINE,data%State%AnnularComputational%minlosspa_ANNULAR,data%State%AnnularComputational%minloss_ANNULAR) +!=========================================================================== +! ANNULAR PIPNING LOSSES INPUT +!=========================================================================== + DEALLOCATE (data%State%BopStackInput%PIPINGS_ANNULAR,data%State%AnnularComputational%DIAM_ANNULARLINE_INCH,data%State%AnnularComputational%AREA_ANNULARLINE, & + data%State%AnnularComputational%LENGT_ANNULARLINE,data%State%AnnularComputational%ROUGHNESS_ANNULARLINE,data%State%AnnularComputational%RELROUGH_ANNULARLINE & + ,data%State%AnnularComputational%Re_ANNULARline,data%State%AnnularComputational%fricANNULAR,data%State%AnnularComputational%friclossANNULAR) +!=========================================================================== +! AIR PUMP LOSSES INPUT +!=========================================================================== +DEALLOCATE (data%State%BopStackInput%PIPINGS_AIRPUMP,data%State%RamLine%DIAM_AIR_INCH, & + data%State%RamLine%Re_air,data%State%RamLine%AREA_AIR,data%State%RamLine%LENGT_AIR,data%State%RamLine%ROUGHNESS_AIRPLINE,data%State%RamLine%REL_ROUGHAIR, & + data%State%RamLine%fric_air,data%State%RamLine%fricloss_air) +!================================================================ +DEALLOCATE (data%State%BopStackInput%MINORS_AIRPUMP,data%State%RamLine%MINORDIAM_AIR_INCH, & + data%State%RamLine%MINORAREA_AIR,data%State%RamLine%LF_AIR,data%State%RamLine%CV_AIR,data%State%RamLine%NOTE_AIR & + ,data%State%RamLine%minlosspa_air,data%State%RamLine%minloss_air) + +!=========================================================================== +! DELAY ARRAYS +!=========================================================================== +call data%State%AnnularComputational%Pannular_regDelay%Empty() + + + + END + + + + + + + + + + + +SUBROUTINE LOSS_INPUTS() +use SimulationVariables +implicit none +INTEGER I + +!=========================================================================== +! RAMLINE MINOR LOSSES INPUT +!=========================================================================== +data%State%RamLine%NO_MINORSRAMLINE=34 + +ALLOCATE (data%State%BopStackInput%MINORS1(data%State%RamLine%NO_MINORSRAMLINE,4)) + +! ID(INCH) LF CV NOTE(BAR) DESCRIPTION +data%State%BopStackInput%MINORS1(1,1:4)= (/2., 2., 0., 0./) !Acc.tee +data%State%BopStackInput%MINORS1(2,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee +data%State%BopStackInput%MINORS1(3,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee +data%State%BopStackInput%MINORS1(4,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee +data%State%BopStackInput%MINORS1(5,1:4)= (/2., 0.9, 0., 0./) !tee +data%State%BopStackInput%MINORS1(6,1:4)= (/2., 2., 0., 0./) !tee +data%State%BopStackInput%MINORS1(7,1:4)= (/2., 0., 105., 0./) !valve +data%State%BopStackInput%MINORS1(8,1:4)= (/2., 0.9, 0., 0./) !tee +data%State%BopStackInput%MINORS1(9,1:4)= (/2., 0., 105., 0./) !valve +data%State%BopStackInput%MINORS1(10,1:4)= (/2., 0.42, 0., 0./) !elbow +data%State%BopStackInput%MINORS1(11,1:4)= (/2., 0.42, 0., 0./) !elbow +data%State%BopStackInput%MINORS1(12,1:4)= (/2., 0.8, 0., 0./) !unionA +data%State%BopStackInput%MINORS1(13,1:4)= (/2., 0.8, 0., 0./) !unionA +data%State%BopStackInput%MINORS1(14,1:4)= (/2., 1.5, 0., 0./) !elbow +data%State%BopStackInput%MINORS1(15,1:4)= (/2., 0., 425., 0./) !valve +data%State%BopStackInput%MINORS1(16,1:4)= (/2., 2., 0., 0./) !tee +data%State%BopStackInput%MINORS1(17,1:4)= (/0.75, 0., 1.5, 0./) !REGULATOR +data%State%BopStackInput%MINORS1(18,1:4)= (/1., 2., 0., 0./) !tee +data%State%BopStackInput%MINORS1(19,1:4)= (/1., 1.5, 0., 0./) !elbow +data%State%BopStackInput%MINORS1(20,1:4)= (/1., 0.42, 0., 0./) !elbow +data%State%BopStackInput%MINORS1(21,1:4)= (/1., 0.42, 0., 0./) !elbow +data%State%BopStackInput%MINORS1(22,1:4)= (/1., 1.5, 0., 0./) !elbow +data%State%BopStackInput%MINORS1(23,1:4)= (/1., 0., 105., 0./) !valve +data%State%BopStackInput%MINORS1(24,1:4)= (/1., 0.9, 0., 0./) !tee +data%State%BopStackInput%MINORS1(25,1:4)= (/1., 0., 0., 0.5/) !FT +data%State%BopStackInput%MINORS1(26,1:4)= (/1., 0., 0., 3.4/) !filter +data%State%BopStackInput%MINORS1(27,1:4)= (/1., 0., 105., 0./) !valve +data%State%BopStackInput%MINORS1(28,1:4)= (/1., 0.9, 0., 0./) !tee +data%State%BopStackInput%MINORS1(29,1:4)= (/1., 1.5, 0., 0./) !elbow +data%State%BopStackInput%MINORS1(30,1:4)= (/1., 1.5, 0., 0./) !elbow +data%State%BopStackInput%MINORS1(31,1:4)= (/1., 0., 9.2, 0./) !valve +data%State%BopStackInput%MINORS1(32,1:4)= (/1., 0.8, 0., 0./) !unionA +data%State%BopStackInput%MINORS1(33,1:4)= (/1., 0.8, 0., 0./) !unionA +data%State%BopStackInput%MINORS1(34,1:4)= (/0.75, 0.35, 0., 0./) !contraction + + +ALLOCATE (data%State%RamLine%MINORDIAMETER_RAMLINE(data%State%RamLine%NO_MINORSRAMLINE),data%State%RamLine%AREAMINOR_RAMLINE(data%State%RamLine%NO_MINORSRAMLINE),data%State%RamLine%LF_RAMLINE(data%State%RamLine%NO_MINORSRAMLINE),data%State%RamLine%CV_RAMLINE(data%State%RamLine%NO_MINORSRAMLINE) & + ,data%State%RamLine%NOTE_RAMLINE(data%State%RamLine%NO_MINORSRAMLINE),data%State%RAMS%minlosspa(6,data%State%RamLine%NO_MINORSRAMLINE),data%State%RAMS%minloss(6,data%State%RamLine%NO_MINORSRAMLINE)) + + + +DO I=1,data%State%RamLine%NO_MINORSRAMLINE + data%State%RamLine%MINORDIAMETER_RAMLINE(I)=data%State%BopStackInput%MINORS1(I,1) + data%State%RamLine%LF_RAMLINE(I)=data%State%BopStackInput%MINORS1(I,2) + data%State%RamLine%CV_RAMLINE(I)=data%State%BopStackInput%MINORS1(I,3) + data%State%RamLine%NOTE_RAMLINE(I)=data%State%BopStackInput%MINORS1(I,4) + + + data%State%RamLine%AREAMINOR_RAMLINE(I)=PI*(data%State%RamLine%MINORDIAMETER_RAMLINE(I)*0.0254)**2/4. !D(in), AREA(m) +ENDDO + + +!=========================================================================== +! RAMLINE PIPNING LOSSES INPUT +!=========================================================================== +data%State%RamLine%NO_PIPINGSRAMLINE=15 + +ALLOCATE (data%State%BopStackInput%PIPINGS_RAMLINE(data%State%RamLine%NO_PIPINGSRAMLINE,3)) + +! ID(INCH) L(MM) ROUGHNESS(MM)=e DESCRIPTION +data%State%BopStackInput%PIPINGS_RAMLINE(1,1:3)= (/2., 1035., 0.03/) !Avg.acc.distance +data%State%BopStackInput%PIPINGS_RAMLINE(2,1:3)= (/2., 730., 0.03/) !Acc.end.horizontal +data%State%BopStackInput%PIPINGS_RAMLINE(3,1:3)= (/2., 2000., 0.03/) !Acc.end.vertical +data%State%BopStackInput%PIPINGS_RAMLINE(4,1:3)= (/2., 6000., 0.05/) !Hyd.hose +data%State%BopStackInput%PIPINGS_RAMLINE(5,1:3)= (/2., 2370., 0.03/) !Corner.vertical1 +data%State%BopStackInput%PIPINGS_RAMLINE(6,1:3)= (/2., 210., 0.03/) !Add.from.bend +data%State%BopStackInput%PIPINGS_RAMLINE(7,1:3)= (/1., 780., 0.03/) !Corner.horizontal1 +data%State%BopStackInput%PIPINGS_RAMLINE(8,1:3)= (/1., 780., 0.03/) !Corner.horizontal2 +data%State%BopStackInput%PIPINGS_RAMLINE(9,1:3)= (/1., 750., 0.03/) !Extra.length.back +data%State%BopStackInput%PIPINGS_RAMLINE(10,1:3)= (/1., 800., 0.03/) !Corner.horizontal3 +data%State%BopStackInput%PIPINGS_RAMLINE(11,1:3)= (/1., 1650., 0.03/) !Corner.vertical2 +data%State%BopStackInput%PIPINGS_RAMLINE(12,1:3)= (/1., 340., 0.03/) !12.Valves.horizontal +data%State%BopStackInput%PIPINGS_RAMLINE(13,1:3)= (/1., 1650., 0.03/) !Valves.vertical +data%State%BopStackInput%PIPINGS_RAMLINE(14,1:3)= (/1., 31000., 10./) !Hyd.hose +data%State%BopStackInput%PIPINGS_RAMLINE(15,1:3)= (/1., 526., 0.03/) !Add.from.bend + + + + ALLOCATE (data%State%RamLine%DIAM_RAMLINE_INCH(data%State%RamLine%NO_PIPINGSRAMLINE), & + data%State%RamLine%AREA_RAMLINE(data%State%RamLine%NO_PIPINGSRAMLINE),data%State%RamLine%LENGT_RAMLINE(data%State%RamLine%NO_PIPINGSRAMLINE),data%State%RamLine%ROUGHNESS_RAMLINE(data%State%RamLine%NO_PIPINGSRAMLINE),data%State%RamLine%RELROUGH_RAMLINE(data%State%RamLine%NO_PIPINGSRAMLINE) & + ,data%State%RAMS%Re_ramline(6,data%State%RamLine%NO_PIPINGSRAMLINE),data%State%RAMS%fric(6,data%State%RamLine%NO_PIPINGSRAMLINE),data%State%RAMS%fricloss(6,data%State%RamLine%NO_PIPINGSRAMLINE)) + +DO I=1,data%State%RamLine%NO_PIPINGSRAMLINE + data%State%RamLine%DIAM_RAMLINE_INCH(I)=data%State%BopStackInput%PIPINGS_RAMLINE(I,1) + data%State%RamLine%LENGT_RAMLINE(I)=data%State%BopStackInput%PIPINGS_RAMLINE(I,2) + data%State%RamLine%ROUGHNESS_RAMLINE(I)=data%State%BopStackInput%PIPINGS_RAMLINE(I,3) + + + + data%State%RamLine%AREA_RAMLINE(I)=PI*(data%State%RamLine%DIAM_RAMLINE_INCH(I)*0.0254)**2/4 !D(in), AREA(m) + data%State%RamLine%RELROUGH_RAMLINE(I)=data%State%RamLine%ROUGHNESS_RAMLINE(I)/(data%State%RamLine%DIAM_RAMLINE_INCH(I)*25.4) !e/D +!DIAM_RAMLINE_MM(I)=DIAM_RAMLINE_MM(I)*.001 ! (m) + data%State%RamLine%LENGT_RAMLINE(I)=data%State%RamLine%LENGT_RAMLINE(I)*.001 ! (m) +ENDDO + + + +!=========================================================================== +! ANNULAR PREVENTER MINOR LOSSES INPUT +!=========================================================================== +data%State%AnnularComputational%NO_MinorsAnnularLine=29 + +ALLOCATE (data%State%BopStackInput%MINORS_ANNULAR(data%State%AnnularComputational%NO_MinorsAnnularLine,4)) + +! ID(INCH) LF CV NOTE(BAR) DESCRIPTION +data%State%BopStackInput%MINORS_ANNULAR(1,1:4)= (/2., 2., 0., 0./) !Acc.tee +data%State%BopStackInput%MINORS_ANNULAR(2,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee +data%State%BopStackInput%MINORS_ANNULAR(3,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee +data%State%BopStackInput%MINORS_ANNULAR(4,1:4)= (/2., 0.9, 0., 0./) !Avg.acc.tee +data%State%BopStackInput%MINORS_ANNULAR(5,1:4)= (/2., 0.9, 0., 0./) !tee +data%State%BopStackInput%MINORS_ANNULAR(6,1:4)= (/2., 2., 0., 0./) !tee +data%State%BopStackInput%MINORS_ANNULAR(7,1:4)= (/2., 0., 105., 0./) !valve +data%State%BopStackInput%MINORS_ANNULAR(8,1:4)= (/2., 0.9, 0., 0./) !tee +data%State%BopStackInput%MINORS_ANNULAR(9,1:4)= (/2., 0., 105., 0./) !valve +data%State%BopStackInput%MINORS_ANNULAR(10,1:4)= (/2., 0.42, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(11,1:4)= (/2., 0.42, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(12,1:4)= (/2., 0.8, 0., 0./) !unionA +data%State%BopStackInput%MINORS_ANNULAR(13,1:4)= (/2., 0.8, 0., 0./) !unionA +data%State%BopStackInput%MINORS_ANNULAR(14,1:4)= (/2., 1.5, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(15,1:4)= (/2., 0., 425., 0./) !valve +data%State%BopStackInput%MINORS_ANNULAR(16,1:4)= (/2., 2., 0., 0./) !tee +data%State%BopStackInput%MINORS_ANNULAR(17,1:4)= (/0.75, 0., 1.5, 0./) !REGULATOR +data%State%BopStackInput%MINORS_ANNULAR(18,1:4)= (/1., 2., 0., 0./) !tee +data%State%BopStackInput%MINORS_ANNULAR(19,1:4)= (/1., 1.5, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(20,1:4)= (/1., 0.42, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(21,1:4)= (/1., 0.42, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(22,1:4)= (/1., 1.5, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(23,1:4)= (/1., 0., 3.2, 0./) !valve +data%State%BopStackInput%MINORS_ANNULAR(24,1:4)= (/1., 2., 0., 0./) !tee +data%State%BopStackInput%MINORS_ANNULAR(25,1:4)= (/1., 1.5, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(26,1:4)= (/1., 0.42, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(27,1:4)= (/1., 0.42, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(28,1:4)= (/1., 1.5, 0., 0./) !elbow +data%State%BopStackInput%MINORS_ANNULAR(29,1:4)= (/1., 0., 3.2, 0./) !valve + + + + ALLOCATE (data%State%AnnularComputational%MINORDIAMETER_ANNULARLINE(data%State%AnnularComputational%NO_MinorsAnnularLine),data%State%AnnularComputational%AREAMINOR_ANNULARLINE(data%State%AnnularComputational%NO_MinorsAnnularLine),data%State%AnnularComputational%LF_ANNULARLINE(data%State%AnnularComputational%NO_MinorsAnnularLine) & + ,data%State%AnnularComputational%CV_ANNULARLINE(data%State%AnnularComputational%NO_MinorsAnnularLine),data%State%AnnularComputational%NOTE_ANNULARLINE(data%State%AnnularComputational%NO_MinorsAnnularLine),data%State%AnnularComputational%minlosspa_ANNULAR(data%State%AnnularComputational%NO_MinorsAnnularLine),data%State%AnnularComputational%minloss_ANNULAR(data%State%AnnularComputational%NO_MinorsAnnularLine)) + + + +DO I=1,data%State%AnnularComputational%NO_MinorsAnnularLine + data%State%AnnularComputational%MINORDIAMETER_ANNULARLINE(I)=data%State%BopStackInput%MINORS_ANNULAR(I,1) + data%State%AnnularComputational%LF_ANNULARLINE(I)=data%State%BopStackInput%MINORS_ANNULAR(I,2) + data%State%AnnularComputational%CV_ANNULARLINE(I)=data%State%BopStackInput%MINORS_ANNULAR(I,3) + data%State%AnnularComputational%NOTE_ANNULARLINE(I)=data%State%BopStackInput%MINORS_ANNULAR(I,4) + + data%State%AnnularComputational%AREAMINOR_ANNULARLINE(I)=PI*(data%State%AnnularComputational%MINORDIAMETER_ANNULARLINE(I)*0.0254)**2/4. !D(in), AREA(m) +ENDDO + + +!=========================================================================== +! ANNULAR PREVENTER PIPNING LOSSES INPUT +!=========================================================================== +data%State%AnnularComputational%NO_PipingsAnnularLine=10 + +ALLOCATE (data%State%BopStackInput%PIPINGS_ANNULAR(data%State%AnnularComputational%NO_PipingsAnnularLine,3)) + +! ID(INCH) L(MM) ROUGHNESS(MM)=e DESCRIPTION +data%State%BopStackInput%PIPINGS_ANNULAR(1,1:3)= (/2., 1035., 0.03/) !Avg.acc.distance +data%State%BopStackInput%PIPINGS_ANNULAR(2,1:3)= (/2., 730., 0.03/) !Acc.endhorizontal +data%State%BopStackInput%PIPINGS_ANNULAR(3,1:3)= (/2., 2000., 0.03/) !Acc.endvertical +data%State%BopStackInput%PIPINGS_ANNULAR(4,1:3)= (/2., 6000., 0.03/) !Hyd.hose +data%State%BopStackInput%PIPINGS_ANNULAR(5,1:3)= (/2., 2370., 0.03/) !Corner.vertical1 +data%State%BopStackInput%PIPINGS_ANNULAR(6,1:3)= (/2., 210., 0.03/) !Add.frombend +data%State%BopStackInput%PIPINGS_ANNULAR(7,1:3)= (/2., 1000., 0.03/) !manifold +data%State%BopStackInput%PIPINGS_ANNULAR(8,1:3)= (/1., 46000., 0.03/) !pipe +data%State%BopStackInput%PIPINGS_ANNULAR(9,1:3)= (/2., 1000., 0.03/) !manifold +data%State%BopStackInput%PIPINGS_ANNULAR(10,1:3)= (/1., 46000., 0.03/) !pipe + + + + + ALLOCATE (data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(data%State%AnnularComputational%NO_PipingsAnnularLine),data%State%AnnularComputational%AREA_ANNULARLINE(data%State%AnnularComputational%NO_PipingsAnnularLine),data%State%AnnularComputational%LENGT_ANNULARLINE(data%State%AnnularComputational%NO_PipingsAnnularLine) & + ,data%State%AnnularComputational%ROUGHNESS_ANNULARLINE(data%State%AnnularComputational%NO_PipingsAnnularLine),data%State%AnnularComputational%RELROUGH_ANNULARLINE(data%State%AnnularComputational%NO_PipingsAnnularLine) & + ,data%State%AnnularComputational%Re_ANNULARline(data%State%AnnularComputational%NO_PipingsAnnularLine),data%State%AnnularComputational%fricANNULAR(data%State%AnnularComputational%NO_PipingsAnnularLine),data%State%AnnularComputational%friclossANNULAR(data%State%AnnularComputational%NO_PipingsAnnularLine)) + + +DO I=1,data%State%AnnularComputational%NO_PipingsAnnularLine + data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(I)=data%State%BopStackInput%PIPINGS_ANNULAR(I,1) + data%State%AnnularComputational%LENGT_ANNULARLINE(I)=data%State%BopStackInput%PIPINGS_ANNULAR(I,2) + data%State%AnnularComputational%ROUGHNESS_ANNULARLINE(I)=data%State%BopStackInput%PIPINGS_ANNULAR(I,3) + + + data%State%AnnularComputational%AREA_ANNULARLINE(I)=PI*(data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(I)*0.0254)**2/4. !D(in), AREA(m) + data%State%AnnularComputational%RELROUGH_ANNULARLINE(I)=data%State%AnnularComputational%ROUGHNESS_ANNULARLINE(I)/(data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(I)*25.4) +!DIAM_ANNULARLINE_MM(I)=DIAM_ANNULARLINE_MM(I)*.001 ! (m) + data%State%AnnularComputational%LENGT_ANNULARLINE(I)=data%State%AnnularComputational%LENGT_ANNULARLINE(I)*.001 ! (m) + ENDDO + + +!=========================================================================== +! AIR PUMP LOSSES INPUT +!=========================================================================== +data%State%RamLine%NO_PIPINGS_AIRPLINE=1 + +ALLOCATE (data%State%BopStackInput%PIPINGS_AIRPUMP(data%State%RamLine%NO_PIPINGS_AIRPLINE,3)) + +! ID(INCH) L(MM) ROUGHNESS(MM)=e DESCRIPTION +data%State%BopStackInput%PIPINGS_AIRPUMP(1,1:3)= (/2., 10000., 0.03/) !Avg.acc.distance + + + + + ALLOCATE (data%State%RamLine%DIAM_AIR_INCH(data%State%RamLine%NO_PIPINGS_AIRPLINE),data%State%RamLine%Re_air(data%State%RamLine%NO_PIPINGS_AIRPLINE),data%State%RamLine%AREA_AIR(data%State%RamLine%NO_PIPINGS_AIRPLINE), & + data%State%RamLine%LENGT_AIR(data%State%RamLine%NO_PIPINGS_AIRPLINE),data%State%RamLine%ROUGHNESS_AIRPLINE(data%State%RamLine%NO_PIPINGS_AIRPLINE),data%State%RamLine%REL_ROUGHAIR(data%State%RamLine%NO_PIPINGS_AIRPLINE), & + data%State%RamLine%fric_air(data%State%RamLine%NO_PIPINGS_AIRPLINE),data%State%RamLine%fricloss_air(data%State%RamLine%NO_PIPINGS_AIRPLINE)) + + + +DO I=1,data%State%RamLine%NO_PIPINGS_AIRPLINE + data%State%RamLine%DIAM_AIR_INCH(I)=data%State%BopStackInput%PIPINGS_AIRPUMP(I,1) + data%State%RamLine%LENGT_AIR(I)=data%State%BopStackInput%PIPINGS_AIRPUMP(I,2) + data%State%RamLine%ROUGHNESS_AIRPLINE(I)=data%State%BopStackInput%PIPINGS_AIRPUMP(I,3) + + + data%State%RamLine%AREA_AIR(I)=PI*(data%State%RamLine%DIAM_AIR_INCH(I)*0.0254)**2/4 !D(in), AREA(m) + data%State%RamLine%REL_ROUGHAIR(I)=data%State%RamLine%ROUGHNESS_AIRPLINE(I)/(data%State%RamLine%DIAM_AIR_INCH(I)*25.4) +!DIAM_RAMLINE_MM(I)=DIAM_RAMLINE_MM(I)*.001 ! (m) + data%State%RamLine%LENGT_AIR(I)=data%State%RamLine%LENGT_AIR(I)*.001 ! (m) + ENDDO + + + +!================================================================ +data%State%RamLine%NO_MINORS_AIRPLINE=6 + +ALLOCATE (data%State%BopStackInput%MINORS_AIRPUMP(data%State%RamLine%NO_MINORS_AIRPLINE,4)) + +! ID(INCH) LF CV NOTE(BAR) DESCRIPTION +data%State%BopStackInput%MINORS_AIRPUMP(1,1:4)= (/2., 10., 0., 0./) !Acc.tee +data%State%BopStackInput%MINORS_AIRPUMP(2,1:4)= (/2., 11., 0., 0./) !elbow +data%State%BopStackInput%MINORS_AIRPUMP(3,1:4)= (/1., 0., 0., 3.4/) !filter +data%State%BopStackInput%MINORS_AIRPUMP(4,1:4)= (/2., 0., 105., 0./) !valve +data%State%BopStackInput%MINORS_AIRPUMP(5,1:4)= (/1., 0., 9.2, 0./) !valve +data%State%BopStackInput%MINORS_AIRPUMP(6,1:4)= (/2., 6.4, 0., 0./) !unionA + + + + ALLOCATE (data%State%RamLine%MINORDIAM_AIR_INCH(data%State%RamLine%NO_MINORS_AIRPLINE),data%State%RamLine%MINORAREA_AIR(data%State%RamLine%NO_MINORS_AIRPLINE), & + data%State%RamLine%LF_AIR(data%State%RamLine%NO_MINORS_AIRPLINE),data%State%RamLine%CV_AIR(data%State%RamLine%NO_MINORS_AIRPLINE),data%State%RamLine%NOTE_AIR(data%State%RamLine%NO_MINORS_AIRPLINE) & + ,data%State%RamLine%minlosspa_air(data%State%RamLine%NO_MINORS_AIRPLINE),data%State%RamLine%minloss_air(data%State%RamLine%NO_MINORS_AIRPLINE)) + + + +DO I=1,data%State%RamLine%NO_MINORS_AIRPLINE + data%State%RamLine%MINORDIAM_AIR_INCH(I)=data%State%BopStackInput%MINORS_AIRPUMP(I,1) + data%State%RamLine%LF_AIR(I)=data%State%BopStackInput%MINORS_AIRPUMP(I,2) + data%State%RamLine%CV_AIR(I)=data%State%BopStackInput%MINORS_AIRPUMP(I,3) + data%State%RamLine%NOTE_AIR(I)=data%State%BopStackInput%MINORS_AIRPUMP(I,4) + + + data%State%RamLine%MINORAREA_AIR(I)=PI*(data%State%RamLine%MINORDIAM_AIR_INCH(I)*0.0254)**2/4. !D(in), AREA(m) +ENDDO + + + + END + +SUBROUTINE pumps_charge_bottle() +use SimulationVariables +USE CAccumulatorVariables +USE CBopStackVariables +use CBopControlPanel + use SimulationVariables +USE CEquipmentsConstants +! use CSimulationVariables +implicit none + +!Pannular_regset=min(AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously +!write(*,*) 'pumps_charge_bottle' + + if(data%Equipments%BopControlPanel%ByePassValve == -1.0) then + data%State%BopStackAcc%ByPassOld= -1.0 + elseif(data%Equipments%BopControlPanel%ByePassValve == 1.0) then + data%State%BopStackAcc%ByPassOld= 1.0 + endif + + +!===================================================================== +! ACCUMULATOR +!=====for a 10 gal bottle,precharge=1000psig curve BOSCH-isotherm===== +!for charging bottles by the pump +!((((((((IN OUTER LOOP)))))) +! ba1=1003; ba2=.03375; ba3=4.014; ba4=.2458; +if (data%State%RamLine%AIRP_SWITCH==0) data%State%Pumps%DELTAV_AIR=0 +data%State%RamLine%FVR=data%State%RamLine%FVR+data%State%Pumps%DELTAV_AIR+data%State%Pumps%DELTAV_ELECP + +data%State%RamLine%pacc_before=data%State%RamLine%P_ACC +data%State%RamLine%P_ACC=data%State%RamLine%B1*exp(data%State%RamLine%B2*data%State%RamLine%FVR/data%State%BopStackAcc%NOBOTTLES)+data%State%RamLine%B3*exp(data%State%RamLine%B4*data%State%RamLine%FVR/data%State%BopStackAcc%NOBOTTLES) ! adiabatic(psig)<<<< 8=no. of bottles + +!===================================================================== + + + if(data%State%BopStackAcc%ByPassOld == 1.0) then + + if (data%State%BopStackAcc%pram_reg BaseDifferenceP) then + data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%pram_reg + (data%State%BopStackAcc%PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20. + else + + if (data%State%BopStackAcc%pram_reg BaseDifferenceP) then + data%State%BopStackAcc%pram_reg= data%State%BopStackAcc%pram_reg + (data%State%BopStackAcc%PressureDifference/PressureDifferenceSteps) ! PressureDifferenceSteps = 20. + else + data%State%BopStackAcc%pram_reg= data%State%RamLine%P_ACC- MAXVAL(data%State%RAM%loss_before) + endif + + endif + + +!Pannular_reg= min(p_acc,Pannular_regset) + + + end + + +SUBROUTINE airpump_code() +use SimulationVariables +use CSounds +implicit none +INTEGER I + + + +data%State%Pumps%QAIR=data%State%Pumps%Qiter+.1 !(gpm) maximum flow for the start +data%State%RamLine%diffp_air=-10 +data%State%RamLine%losses_air=10 + +!=================================================================== +! AIR OPERATED PUMP +!=================for air consumption at 8 bar====================== +do while (data%State%RamLine%diffp_air<0) + data%State%Pumps%QAIR=data%State%Pumps%QAIR-.1 +! Qup=QAIR_PUMP; +! bba1 =31.8; bba2 =-725.7 ; bba3 =4154; + data%State%Pumps%P_AIRP=data%State%RamLine%BBA1*data%State%Pumps%QAIR**2+data%State%RamLine%BBA2*data%State%Pumps%QAIR+data%State%RamLine%BBA3 !(psig) + data%State%RamLine%kinetic_air=sg*wdens*(data%State%Pumps%QAIR*6.30902e-5/((1/4.)*pi*(2*0.254e-1)**2))**2/(2*6895) !(psi) + + + data%State%RamLine%diffp_air=data%State%Pumps%P_AIRP+data%State%RamLine%kinetic_air-data%State%RamLine%P_ACC + +end do !returns Qup + + + do while (abs((data%State%RamLine%diffp_air-data%State%RamLine%losses_air)/data%State%RamLine%diffp_air)>data%State%Pumps%TOL_AIR) !finding correct QAIR_pump for 1 timecounter_ram + +if (data%State%RamLine%diffp_air-data%State%RamLine%losses_air>0) then + data%State%Pumps%QAIR=data%State%Pumps%QAIR+.01 +else + data%State%Pumps%QAIR=data%State%Pumps%QAIR-.01 +endif + +!=================================================================== +! AIR OPERATED PUMP +! Maximator - Model: GX (35) +!=================for air consumption at 8 bar====================== + + data%State%Pumps%P_AIRP=data%State%RamLine%BBA1*data%State%Pumps%QAIR**2+data%State%RamLine%BBA2*data%State%Pumps%QAIR+data%State%RamLine%BBA3 !(psig) + data%State%RamLine%kinetic_air=sg*wdens*(data%State%Pumps%QAIR*6.30902e-005/((1/4.)*pi*(2*0.254e-1)**2))**2/(2*6895) !(psi) + + data%State%RamLine%diffp_air=data%State%Pumps%P_AIRP+data%State%RamLine%kinetic_air-data%State%RamLine%P_ACC + + +!===========================LOSSES==================================== + do i=1,data%State%RamLine%NO_PIPINGS_AIRPLINE +data%State%RamLine%Re_air(i)=data%State%Pumps%QAIR*6.30902e-005*data%State%RamLine%DIAM_AIR_INCH(I)*0.0254/(data%State%RamLine%AREA_AIR(i)*nu) +enddo + +do i=1,data%State%RamLine%NO_PIPINGS_AIRPLINE + if (data%State%RamLine%Re_air(i)data%State%ShearRAM%NeededVolumeShearRams) then + + data%State%RamLine%ShearBop_closed=1 +!ShearBop_closed_withPossibility= ShearBop_closed * TD_BOPConnectionPossibility(3) + + data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17) + data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck + + if (data%State%RamLine%ShearRamIsClosing) then + data%State%ShearRAM%IDshearBop=0. + data%State%ShearRAM%ShearIsNotAllowed*data%State%ShearRAM%ODDrillpipe_inShearRam + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOn + data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOn + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOff + data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOff + if (data%State%TD_BOP%BOPConnectionPossibility(3) == 1 .and. data%State%ShearRAM%ShearIsNotAllowed==0) then + CALL CloseMiddleRams + data%State%RamLine%ShearBop_Situation_forTD= 1 ! closed - for TD code + endif + endif + + if (data%State%RamLine%ShearRamIsOpening) then + data%State%ShearRAM%IDshearBop=data%State%ShearRAM%IDshearBopBase + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOn + data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOn + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOff + data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOff + CALL OpenMiddleRams + data%State%RamLine%ShearBop_Situation_forTD= 0 ! open - for TD code + endif + + endif + + data%State%ShearRAM%IDshearBopFinal= data%State%ShearRAM%IDshearBop ! for output data + +endif + +if (ramtype==2) then !for pipe ram1 + if (data%State%PipeRam1%IsClosing) then + data%State%PipeRam1%ID=(2.*(data%State%PipeRam1%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%PipeRam1%A)+max(data%State%PipeRam1%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase) + endif + + if (data%State%PipeRam1%IsOpening) then + data%State%PipeRam1%ID=data%State%PipeRam1%IDBase-2.*(data%State%PipeRam1%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%PipeRam1%A + endif + + if ( data%State%RAM(RNUMBER)%vdis_tot>data%State%PipeRam1%NeededVolume) then + + data%State%PipeRam1%closed=1 +!PipeRam1_Situation_forTD= PipeRam1_closed * TD_BOPConnectionPossibility(2) + data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17) + data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck + + if (data%State%PipeRam1%IsClosing) then + data%State%PipeRam1%ID=max(data%State%PipeRam1%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase) + data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOn + data%State%BopStackInput%UpperRamsCloseLEDMine = LedOn + data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOff + data%State%BopStackInput%UpperRamsOpenLEDMine = LedOff + if (data%State%TD_BOP%BOPConnectionPossibility(2) == 1) then + CALL CloseUpperRams ! for C code + call Set_BlowoutFromAnnular(.true.) + + + data%State%PipeRam1%Situation_forTD= 1 ! closed - for TD code + endif + endif + + if (data%State%PipeRam1%IsOpening) then + data%State%PipeRam1%ID=data%State%PipeRam1%IDBase + data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOn + data%State%BopStackInput%UpperRamsOpenLEDMine = LedOn + data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOff + data%State%BopStackInput%UpperRamsCloseLEDMine = LedOff + Call OpenUpperRams ! for C code + data%State%PipeRam1%Situation_forTD= 0 ! open - for TD code + endif + + endif + + data%State%ShearRAM%IDPipeRam1Final= data%State%PipeRam1%ID ! for output data + +endif + + +if (ramtype==3) then !for pipe ram2 + if (data%State%PipeRam2%IsClosing) then + data%State%PipeRam2%ID=(2.*(data%State%PipeRam2%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%PipeRam1%A)+max(data%State%PipeRam2%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase) + endif + + if (data%State%PipeRam2%IsOpening) then + data%State%PipeRam2%ID=data%State%PipeRam1%IDBase-2.*(data%State%PipeRam2%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%PipeRam1%A + endif + + if ( data%State%RAM(RNUMBER)%vdis_tot>data%State%PipeRam2%NeededVolume) then + + data%State%PipeRam2%closed=1 +!PipeRam2_closed_withPossibility= PipeRam2_closed * TD_BOPConnectionPossibility(4) + data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17) + data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck + + if (data%State%PipeRam2%IsClosing) then + data%State%PipeRam2%ID=max(data%State%PipeRam2%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase) + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOn + data%State%BopStackInput%LowerRamsCloseLEDMine = LedOn + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOff + data%State%BopStackInput%LowerRamsOpenLEDMine = LedOff + if (data%State%TD_BOP%BOPConnectionPossibility(4) == 1) then + CALL CloseLowerRams + data%State%PipeRam2%Situation_forTD= 1 ! closed - for TD code + endif + endif + + if (data%State%PipeRam2%IsOpening) then + data%State%PipeRam2%ID=data%State%PipeRam1%IDBase + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOn + data%State%BopStackInput%LowerRamsOpenLEDMine = LedOn + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOff + data%State%BopStackInput%LowerRamsCloseLEDMine = LedOff + CALL OpenLowerRams + data%State%PipeRam2%Situation_forTD= 0 ! open - for TD code + endif + + endif + + data%State%ShearRAM%IDPipeRam2Final= data%State%PipeRam2%ID ! for output data + +endif + + +if (ramtype==4) then !for Choke Line + if (data%State%ChokeLine%IsClosing) then + data%State%ChokeLine%ID=(2.*(data%State%ChokeLine%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%ChokeLine%Abop)+max(data%State%ChokeLine%ODDrillpipe_in,data%State%ChokeLine%ODDrillpipe_inBase) + endif + + if (data%State%ChokeLine%IsOpening) then + data%State%ChokeLine%ID=data%State%ChokeLine%IDBase-2.*(data%State%ChokeLine%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%ChokeLine%Abop + endif + + if ( data%State%RAM(RNUMBER)%vdis_tot>data%State%ChokeLine%NeededVolume) then + + data%State%ChokeLine%closed=1 + data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17) + data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck + + if (data%State%ChokeLine%IsClosing) then + data%State%ChokeLine%ID=max(data%State%ChokeLine%ODDrillpipe_in,data%State%ChokeLine%ODDrillpipe_inBase) + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOn + data%State%BopStackInput%ChokeLineCloseLEDMine = LedOn + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOff + data%State%BopStackInput%ChokeLineOpenLEDMine = LedOff + CALL CloseChokeLine + endif + + if (data%State%ChokeLine%IsOpening) then + data%State%ChokeLine%ID=data%State%ChokeLine%IDBase + data%Equipments%BopControlPanel%ChokeLineOpenLED = LedOn + data%State%BopStackInput%ChokeLineOpenLEDMine = LedOn + data%Equipments%BopControlPanel%ChokeLineCloseLED = LedOff + data%State%BopStackInput%ChokeLineCloseLEDMine = LedOff + CALL OpenChokeLine + endif + + endif + +endif + + + +if (ramtype==5) then !for Kill Line + if (data%State%KillLine%IsClosing) then + data%State%KillLine%ID=(2.*(data%State%KillLine%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%KillLine%Abop)+max(data%State%KillLine%ODDrillpipe_in,data%State%KillLine%ODDrillpipe_inBase) + endif + + if (data%State%KillLine%IsOpening) then + data%State%KillLine%ID=data%State%KillLine%IDBase-2.*(data%State%KillLine%NeededVolume- data%State%RAM(RNUMBER)%vdis_tot)*231./data%State%KillLine%Abop + endif + + if ( data%State%RAM(RNUMBER)%vdis_tot>data%State%KillLine%NeededVolume) then + + data%State%KillLine%closed=1 + data%State%BopStackAcc%pram_reg=data%State%BopStackAcc%pram_reg+data%State%RAMS%minloss(RNUMBER,17) + data%State%RamLine%P_ACC= data%State%RAM(RNUMBER)%p_acccheck + + if (data%State%KillLine%IsClosing) then + data%State%KillLine%ID=max(data%State%KillLine%ODDrillpipe_in,data%State%KillLine%ODDrillpipe_inBase) + data%Equipments%BopControlPanel%KillLineCloseLED = LedOn + data%State%BopStackInput%KillLineCloseLedMine = LedOn + data%Equipments%BopControlPanel%KillLineOpenLED = LedOff + data%State%BopStackInput%KillLineOpenLedMine = LedOff + CALL CloseKillLine + endif + + if (data%State%KillLine%IsOpening) then + data%State%KillLine%ID=data%State%KillLine%IDBase + data%Equipments%BopControlPanel%KillLineOpenLED = LedOn + data%State%BopStackInput%KillLineOpenLedMine = LedOn + data%Equipments%BopControlPanel%KillLineCloseLED = LedOff + data%State%BopStackInput%KillLineCloseLedMine = LedOff + CALL OpenKillLine + endif + + endif + +endif + + + + +!if (ramtype==4) then !for annular +! if (AnnularIsClosing) then +! IDAnnular=((NeededVolumeAnnular-vdis_tot)*231./AbopAnnular)+ODDrillpipe_inAnnular +! endif +! +! if (AnnularIsOpening) then +! IDAnnular=IDAnnularBase-(NeededVolumeAnnular-vdis_tot)*231./AbopAnnular +! endif +! +! if (vdis_tot>NeededVolumeAnnular) then +! +! Annular_closed=1 +! p_acc= data%State%RAM(RNUMBER)%p_acccheck +! +! if (AnnularIsClosing) then +! IDAnnular=ODDrillpipe_inAnnular +! AnnularCloseLed = LedOn +! AnnularOpenLed = LedOff +! endif +! +! if (AnnularIsOpening) then +! IDAnnular=IDAnnularBase +! AnnularOpenLed = LedOn +! AnnularCloseLed = LedOff +! endif +! +! endif +! +!endif + + + end + + + + SUBROUTINE bop_codeAnnular(RNUMBER) + + use SimulationVariables + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants + use SimulationVariables !@ +implicit none +INTEGER RNUMBER, I + + +!Pannular_regset=min(AnnularRegulatorSetControl,1700.) ! for changing its set conditions instantaneously + +!==================================================== +! BOP back pressure without DP +!==================================================== +!if (bop_type==3) then +!p_annular=510.725-(30.145*IDAnnular) + data%State%AnnularComputational%p_annular=448-(19.7*data%State%Annular%IDAnnular) +! Q=flow +! endif + + + + data%State%RAM(RNUMBER)%clock=0 +!======================Losses============================ + data%State%RAM(RNUMBER)%loss_after=0 !initial value + data%State%RAM(RNUMBER)%diffp_ram=1000 !initial value + data%State%RAM(RNUMBER)%loss_before=0 + +!Q=0.0055; %initial flow rate (m^3/s) + + data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%flow + +!write(*,*) 'Q1=' , Q +!write(*,*) 'tol=' , tol +do while (abs( data%State%RAM(RNUMBER)%diffp_ram- data%State%RAM(RNUMBER)%loss_after)/ data%State%RAM(RNUMBER)%diffp_ram>data%State%Annular%tolAnnular) + if (data%State%RAM(RNUMBER)%Bottles_Charged_MalfActive==.true.) exit +! while abs( data%State%RAM(RNUMBER)%diffp_ram- data%State%RAM(RNUMBER)%loss_after)>10 + data%State%RAM(RNUMBER)%clock= data%State%RAM(RNUMBER)%clock+1 + +if ( data%State%RAM(RNUMBER)%clock>20) then +! tclock=clock + data%State%Annular%tolAnnular=data%State%Annular%tolzeroAnnular+(floor( data%State%RAM(RNUMBER)%clock/10)-1)*.001 +endif +! if (clock==1) continue + + if ( data%State%RAM(RNUMBER)%clock/=1 .and. data%State%RAM(RNUMBER)%loss_after> data%State%RAM(RNUMBER)%diffp_ram) then + data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%Q-.1 + elseif ( data%State%RAM(RNUMBER)%clock/=1 .and. data%State%RAM(RNUMBER)%loss_after<= data%State%RAM(RNUMBER)%diffp_ram) then + data%State%RAM(RNUMBER)%Q=data%State%RAM(RNUMBER)%Q+.01 + + endif + +!====================Before Regulator========================= +do i=1,data%State%AnnularComputational%NO_PipingsAnnularLine +data%State%AnnularComputational%Re_ANNULARline(i)=data%State%RAM(RNUMBER)%Q*6.30902e-5*data%State%AnnularComputational%DIAM_ANNULARLINE_INCH(i)*0.0254/(data%State%AnnularComputational%AREA_ANNULARLINE(i)*nu) + +enddo + + + +do i=1,data%State%AnnularComputational%NO_PipingsAnnularLine + if (data%State%AnnularComputational%Re_ANNULARline(i)= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%State%RAM(2)%First_OpenTimecheck= 1 + + data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOff !new + data%State%BopStackInput%UpperRamsCloseLEDMine = LedOff !new + data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOn !LedBlinking + + data%State%RAM(2)%FourwayValve = 1 + + endif + + endif + + if (data%State%RAM(2)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then ! 1: Open , 0: Close +!write(*,*) 'open 2' + + data%State%RAM(2)%FourwayValve = 0 + + + data%State%PipeRam1%closed=0 +!PipeRam1_closed_withPossibility= PipeRam1_closed * TD_BOPConnectionPossibility(2) + data%State%RAM(2)%vdis_tot=0 + data%State%RAM(2)%vdis_bottles=0. + data%State%RAM(2)%fvr_air=0. + data%State%RAM(2)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(2)%Qzero=70 + data%State%RAM(2)%Q=data%State%RAM(2)%Qzero + data%State%RAM(2)%flow=70 + data%State%RAM(2)%tol=0.0037 + + + + if (data%State%PipeRam1%finished==1) then + data%State%PipeRam1%PipeRams1DotLeverOld=1.0 + else + data%State%PipeRam1%PipeRams1DotLeverOld=data%Equipments%BopControlPanel%UpperRamsValve + endif + data%State%PipeRam1%finished=0 + data%State%PipeRam1%IsOpening = .true. + data%State%PipeRam1%IsClosing = .false. + + +!if (UpperRamsOpenLED == LedOn) then +! RETURN +!end if + + + + data%State%RAM(2)%bop_type = 3 +!AbopPipeRam=186.5 + data%State%PipeRam1%A=(data%Configuration%BopStack%UpperRamOpen*231)/((data%State%PipeRam1%IDBase-data%State%PipeRam1%ODDrillpipe_inBase)/2.) + data%State%PipeRam1%NeededVolume=data%State%PipeRam1%A*(data%State%PipeRam1%IDBase-max(data%State%PipeRam1%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase))/(2.*231) !3.48 galon for each BOP + endif + +!===================================================================== + + data%State%Annular%FirstSet= 0 + data%State%AnnularComputational%RamsFirstSet= 0 +if (data%State%PipeRam1%IsOpening .or. data%State%PipeRam1%IsClosing .or. data%State%RAM(2)%Bottles_Charged_MalfActive) then + data%State%Annular%FirstSet= 0 + data%State%AnnularComputational%RamsFirstSet= 0 + CALL PIPE_RAMS1_SUB +end if + + + END SUBROUTINE PIPE_RAMS1 + + + + + + + + + + + +SUBROUTINE PIPE_RAMS1_SUB + + use SimulationVariables + USE CBopStackVariables + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants +! use CSimulationVariables + implicit none + + +! FirstSet= 0 +! RamsFirstSet= 0 + +! loop3: do while (finished_pipe1==0) + + + data%State%RAM(2)%SuccessionCounter = data%State%RAM(2)%SuccessionCounter + 1 + + + if (data%Equipments%BopControlPanel%UpperRamsValve == 1.0 .and. data%State%PipeRam1%PipeRams1DotLeverOld == -1.0 .and. data%State%PipeRam1%UpperRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + + + + if ( data%State%RAM(2)%First_CloseTimecheck == 0 ) then + + + if ( data%State%RAM(2)%SuccessionCounter /= data%State%RAM(2)%SuccessionCounterOld+1 ) then + data%State%RAM(2)%SuccessionCounter = 0 ! also in starup + data%State%RAM(2)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(2)%SuccessionCounterOld= data%State%RAM(2)%SuccessionCounter + endif + + + + if ( data%State%RAM(2)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOff + data%State%BopStackInput%UpperRamsOpenLEDMine = LedOff + data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOn !LedBlinking + + data%State%RAM(2)%FourwayValve = 1 + + endif + + endif + + endif + + if (data%State%RAM(2)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then +!write(*,*) 'close 4' + + data%State%RAM(2)%FourwayValve = 0 + + + data%State%PipeRam1%closed=0 +!PipeRam1_closed_withPossibility= PipeRam1_closed * TD_BOPConnectionPossibility(2) ! for TD code + CALL OpenUpperRams ! for C code + data%State%PipeRam1%Situation_forTD= 0 ! open - for TD code + data%State%RAM(2)%p_bop=data%State%ShearRAM%PA + data%State%PipeRam1%PipeRams1DotLeverOld = data%Equipments%BopControlPanel%UpperRamsValve + + + data%State%RAM(2)%bop_type = 3 +!AbopPipeRam=196.67 + data%State%PipeRam1%A=(data%Configuration%BopStack%UpperRamClose*231)/((data%State%PipeRam1%IDBase-data%State%PipeRam1%ODDrillpipe_inBase)/2.) +!write(*,*) 'NeededVolumeShearRams1=',NeededVolumeShearRams + data%State%PipeRam1%NeededVolume=data%State%PipeRam1%A*(data%State%PipeRam1%ID-max(data%State%PipeRam1%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase))/(2.*231) +! write(*,*) 'NeededVolumeShearRams2=',NeededVolumeShearRams + + data%State%RAM(2)%vdis_bottles=0. + data%State%RAM(2)%fvr_air=0. + data%State%RAM(2)%vdis_elecp=0. + data%State%PipeRam1%IsClosing = .true. + data%State%PipeRam1%IsOpening = .false. + endif + + if (data%Equipments%BopControlPanel%UpperRamsValve == -1.0 .and. data%State%PipeRam1%PipeRams1DotLeverOld == 1.0 .and. data%State%PipeRam1%UpperRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + + + if ( data%State%RAM(2)%First_OpenTimecheck == 0 ) then + + if ( data%State%RAM(2)%SuccessionCounter /= data%State%RAM(2)%SuccessionCounterOld+1 ) then + data%State%RAM(2)%SuccessionCounter = 0 ! also in starup + data%State%RAM(2)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(2)%SuccessionCounterOld= data%State%RAM(2)%SuccessionCounter + endif + + if ( data%State%RAM(2)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%Equipments%BopControlPanel%UpperRamsCloseLED = LedOff + data%State%BopStackInput%UpperRamsCloseLEDMine = LedOff + data%Equipments%BopControlPanel%UpperRamsOpenLED = LedOn !LedBlinking + + data%State%RAM(2)%FourwayValve = 1 + + + endif + + endif + + endif + + if (data%State%RAM(2)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then +!write(*,*) 'open 4' + + data%State%RAM(2)%FourwayValve = 0 + + + + data%State%PipeRam1%closed=0 +!PipeRam1_closed_withPossibility= PipeRam1_closed * TD_BOPConnectionPossibility(2) + CALL OpenUpperRams + data%State%PipeRam1%Situation_forTD= 0 ! open - for TD code + data%State%RAM(2)%p_bop=data%State%ShearRAM%PA + data%State%PipeRam1%PipeRams1DotLeverOld = data%Equipments%BopControlPanel%UpperRamsValve + + data%State%RAM(2)%bop_type = 3 +!AbopPipeRam=186.5 + data%State%PipeRam1%A=(data%Configuration%BopStack%UpperRamOpen*231)/((data%State%PipeRam1%IDBase-data%State%PipeRam1%ODDrillpipe_inBase)/2.) + data%State%PipeRam1%NeededVolume=data%State%PipeRam1%A*(data%State%PipeRam1%IDBase-data%State%PipeRam1%ID)/(2.*231) + data%State%RAM(2)%vdis_bottles=0. + data%State%RAM(2)%fvr_air=0. + data%State%RAM(2)%vdis_elecp=0. + + data%State%PipeRam1%IsOpening = .true. + data%State%PipeRam1%IsClosing = .false. + endif + + + data%State%RAM(2)%First_CloseTimecheck = 0 + data%State%RAM(2)%First_OpenTimecheck = 0 + + + data%State%RAM(2)%time=data%State%RAM(2)%time+data%State%RamLine%DeltaT_BOP !overal time (s) + + + +!=================================================== +! BOP +!=================================================== +if (data%State%PipeRam1%closed==0) then !bop closing + call bop_code(2,data%State%PipeRam1%H,2) !ramtype=2 2=RNUMBER +endif !bop is closing +!================================================================ +if (data%State%PipeRam1%closed==1) then + data%State%RAM(2)%Q=0 +!p_bop=pram_reg + data%State%RAM(2)%p_bop=data%State%ShearRAM%PA + data%State%RAMS%minloss(2,17)=0. !RNUMBER=2 +endif + +data%State%RAM(2)%timecounter_ram=data%State%RAM(2)%timecounter_ram+1 + + + + + +! MiddleRamsStatus = IDshearBop +! UpperRamsStatus = IDPipeRam1 +! LowerRamsStatus = IDPipeRam2 +! AnnularStatus = IDAnnular +! AccumulatorPressureGauge = p_acc +! ManifoldPressureGauge= pram_reg +! AnnularPressureGauge=Pannular_reg +! +! +! +! WRITE(60,60) data%State%RAM(2)%time,data%State%RAM(2)%Q,data%State%RAM(2)%vdis_tot,p_acc, & +! pram_reg,Pannular_reg,data%State%RAM(2)%p_bop,IDshearBop, & +! IDPipeRam1,IDPipeRam2,IDAnnular +!60 FORMAT(11(f18.5)) + + +! call sleepqq(100) + +if (data%State%PipeRam1%closed==1) then +! if ((MiddleRamsValve==1. .and. MiddleRamsFailureMalf==0) .or. (MiddleRamsValve==-1.0 .and. MiddleRamsFailureMalf==0) .or. (LowerRamsValve==1. .and. LowerRamsFailureMalf==0) .or. (LowerRamsValve==-1.0 .and. LowerRamsFailureMalf==0) .or. (AnnularValve==1. .and. AnnularFailureMalf==0) .or. (AnnularValve==-1.0 .and. AnnularFailureMalf==0) .or. ChokeLineValve==1. .or. ChokeLineValve==-1.0 .or. KillLineValve==1. .or. KillLineValve==-1.0) then + data%State%PipeRam1%finished=1 +! endif +endif + +! if (IsStopped == .true.) return + +! end do loop3 !while finished_pipe1==0 + + + + + + + if ( data%State%PipeRam1%finished==1 .and. data%State%RAM(2)%Bottles_Charged_MalfActive==.true.) then + call bop_code(2,data%State%PipeRam1%H,2) !ramtype=2 2=RNUMBER +! call sleepqq(100) + endif + + + + + + +END SUBROUTINE PIPE_RAMS1_SUB diff --git a/Equipments/BopStack/PIPE_RAM2.f90 b/Equipments/BopStack/PIPE_RAM2.f90 index c9e8ae0..30b5096 100644 --- a/Equipments/BopStack/PIPE_RAM2.f90 +++ b/Equipments/BopStack/PIPE_RAM2.f90 @@ -19,7 +19,7 @@ SUBROUTINE PIPE_RAMS2 data%State%RAM(3)%SuccessionCounter = data%State%RAM(3)%SuccessionCounter + 1 - if (data%EquipmentControl%BopControlPanel%LowerRamsValve == 1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if (data%Equipments%BopControlPanel%LowerRamsValve == 1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then !write(*,*) 'close 1' @@ -42,9 +42,9 @@ SUBROUTINE PIPE_RAMS2 data%State%RAM(3)%First_CloseTimecheck= 1 - data%EquipmentControl%BopControlPanel%LowerRamsOpenLED = LedOff + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOff data%State%BopStackInput%LowerRamsOpenLEDMine = LedOff - data%EquipmentControl%BopControlPanel%LowerRamsCloseLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOn !LedBlinking data%State%RAM(3)%FourwayValve = 1 @@ -76,7 +76,7 @@ SUBROUTINE PIPE_RAMS2 if (data%State%PipeRam2%finished==1) then data%State%PipeRam2%LeverOld=-1.0 else - data%State%PipeRam2%LeverOld=data%EquipmentControl%BopControlPanel%LowerRamsValve + data%State%PipeRam2%LeverOld=data%Equipments%BopControlPanel%LowerRamsValve endif data%State%PipeRam2%finished=0 data%State%PipeRam2%IsClosing = .true. @@ -90,7 +90,7 @@ SUBROUTINE PIPE_RAMS2 !write(*,*) 'close 1' endif - if (data%EquipmentControl%BopControlPanel%LowerRamsValve == -1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if (data%Equipments%BopControlPanel%LowerRamsValve == -1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then !write(*,*) 'open 1' if (data%State%BopStackInput%LowerRamsOpenLEDMine == LedOn) then @@ -112,9 +112,9 @@ SUBROUTINE PIPE_RAMS2 data%State%RAM(3)%First_OpenTimecheck= 1 - data%EquipmentControl%BopControlPanel%LowerRamsCloseLED = LedOff !new + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOff !new data%State%BopStackInput%LowerRamsCloseLEDMine = LedOff !new - data%EquipmentControl%BopControlPanel%LowerRamsOpenLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOn !LedBlinking data%State%RAM(3)%FourwayValve = 1 @@ -144,7 +144,7 @@ SUBROUTINE PIPE_RAMS2 if (data%State%PipeRam2%finished==1) then data%State%PipeRam2%LeverOld=1.0 else - data%State%PipeRam2%LeverOld=data%EquipmentControl%BopControlPanel%LowerRamsValve + data%State%PipeRam2%LeverOld=data%Equipments%BopControlPanel%LowerRamsValve endif data%State%PipeRam2%finished=0 data%State%PipeRam2%IsOpening = .true. @@ -208,7 +208,7 @@ SUBROUTINE PIPE_RAMS2_SUB data%State%RAM(3)%SuccessionCounter = data%State%RAM(3)%SuccessionCounter + 1 - if (data%EquipmentControl%BopControlPanel%LowerRamsValve == 1.0 .and. data%State%PipeRam2%LeverOld == -1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if (data%Equipments%BopControlPanel%LowerRamsValve == 1.0 .and. data%State%PipeRam2%LeverOld == -1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then !write(*,*) 'close 3' @@ -228,9 +228,9 @@ SUBROUTINE PIPE_RAMS2_SUB if ( data%State%RAM(3)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then !return - data%EquipmentControl%BopControlPanel%LowerRamsOpenLED = LedOff + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOff data%State%BopStackInput%LowerRamsOpenLEDMine = LedOff - data%EquipmentControl%BopControlPanel%LowerRamsCloseLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOn !LedBlinking data%State%RAM(3)%FourwayValve = 1 @@ -252,7 +252,7 @@ SUBROUTINE PIPE_RAMS2_SUB data%State%PipeRam2%closed=0 !PipeRam2_closed_withPossibility= PipeRam2_closed * TD_BOPConnectionPossibility(4) data%State%RAM(3)%p_bop=data%State%ShearRAM%PA - data%State%PipeRam2%LeverOld = data%EquipmentControl%BopControlPanel%LowerRamsValve + data%State%PipeRam2%LeverOld = data%Equipments%BopControlPanel%LowerRamsValve CALL OpenLowerRams data%State%PipeRam2%Situation_forTD= 0 ! open - for TD code @@ -270,7 +270,7 @@ SUBROUTINE PIPE_RAMS2_SUB endif - if (data%EquipmentControl%BopControlPanel%LowerRamsValve == -1.0 .and. data%State%PipeRam2%LeverOld == 1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if (data%Equipments%BopControlPanel%LowerRamsValve == -1.0 .and. data%State%PipeRam2%LeverOld == 1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then !write(*,*) 'open 3' @@ -287,9 +287,9 @@ SUBROUTINE PIPE_RAMS2_SUB if ( data%State%RAM(3)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then !return - data%EquipmentControl%BopControlPanel%LowerRamsCloseLED = LedOff + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOff data%State%BopStackInput%LowerRamsCloseLEDMine = LedOff - data%EquipmentControl%BopControlPanel%LowerRamsOpenLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOn !LedBlinking data%State%RAM(3)%FourwayValve = 1 @@ -309,7 +309,7 @@ SUBROUTINE PIPE_RAMS2_SUB data%State%PipeRam2%closed=0 !PipeRam2_closed_withPossibility= PipeRam2_closed * TD_BOPConnectionPossibility(4) data%State%RAM(3)%p_bop=data%State%ShearRAM%PA - data%State%PipeRam2%LeverOld = data%EquipmentControl%BopControlPanel%LowerRamsValve + data%State%PipeRam2%LeverOld = data%Equipments%BopControlPanel%LowerRamsValve CALL OpenLowerRams data%State%PipeRam2%Situation_forTD= 0 ! open - for TD code diff --git a/Equipments/BopStack/PIPE_RAM2.i90 b/Equipments/BopStack/PIPE_RAM2.i90 new file mode 100644 index 0000000..a23c808 --- /dev/null +++ b/Equipments/BopStack/PIPE_RAM2.i90 @@ -0,0 +1,399 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/PIPE_RAM2.f90" + + +SUBROUTINE PIPE_RAMS2 + use SimulationVariables + USE CBopStackVariables + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants +! ! use CSimulationVariables + implicit none + + +!write(*,*) 'checkpoint 1' + +!===================================================================== +! PIPE RAMS 2- BOP CAMERON Type U 5000 +! START CONDITIONS FOR PIPE RAMS 2 +!===================================================================== + data%State%RAM(3)%SuccessionCounter = data%State%RAM(3)%SuccessionCounter + 1 + + + if (data%Equipments%BopControlPanel%LowerRamsValve == 1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then +!write(*,*) 'close 1' + + + if (data%State%BopStackInput%LowerRamsCloseLEDMine == LedOn) then + RETURN + end if + + + if ( data%State%RAM(3)%SuccessionCounter /= data%State%RAM(3)%SuccessionCounterOld+1 ) then + data%State%RAM(3)%SuccessionCounter = 0 ! also in starup + data%State%RAM(3)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(3)%SuccessionCounterOld= data%State%RAM(3)%SuccessionCounter + endif + + + if ( data%State%RAM(3)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%State%RAM(3)%First_CloseTimecheck= 1 + + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOff + data%State%BopStackInput%LowerRamsOpenLEDMine = LedOff + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOn !LedBlinking + + data%State%RAM(3)%FourwayValve = 1 + + endif + + + endif + + + + if (data%State%RAM(3)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then ! 1: Open , 0: Close +!write(*,*) 'close 2' + + + + data%State%RAM(3)%FourwayValve = 0 + + data%State%PipeRam2%closed=0 +!PipeRam2_closed_withPossibility= PipeRam2_closed * TD_BOPConnectionPossibility(4) + data%State%RAM(3)%vdis_tot=0 + data%State%RAM(3)%vdis_bottles=0. + data%State%RAM(3)%fvr_air=0. + data%State%RAM(3)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(3)%Qzero=70 + data%State%RAM(3)%Q=data%State%RAM(3)%Qzero + data%State%RAM(3)%flow=70 + data%State%RAM(3)%tol=0.0037 + if (data%State%PipeRam2%finished==1) then + data%State%PipeRam2%LeverOld=-1.0 + else + data%State%PipeRam2%LeverOld=data%Equipments%BopControlPanel%LowerRamsValve + endif + data%State%PipeRam2%finished=0 + data%State%PipeRam2%IsClosing = .true. + data%State%PipeRam2%IsOpening = .false. + + + data%State%RAM(3)%bop_type = 3 +!AbopPipeRam=196.67 + data%State%PipeRam1%A=(data%Configuration%BopStack%LowerRamClose*231)/((data%State%PipeRam1%IDBase-data%State%PipeRam1%ODDrillpipe_inBase)/2.) + data%State%PipeRam2%NeededVolume=data%State%PipeRam1%A*(data%State%PipeRam1%IDBase-max(data%State%PipeRam2%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase))/(2.*231) !galon for each BOP +!write(*,*) 'close 1' + endif + + if (data%Equipments%BopControlPanel%LowerRamsValve == -1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then +!write(*,*) 'open 1' + + if (data%State%BopStackInput%LowerRamsOpenLEDMine == LedOn) then + RETURN + end if + + + if ( data%State%RAM(3)%SuccessionCounter /= data%State%RAM(3)%SuccessionCounterOld+1 ) then + data%State%RAM(3)%SuccessionCounter = 0 ! also in starup + data%State%RAM(3)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(3)%SuccessionCounterOld= data%State%RAM(3)%SuccessionCounter + endif + + + if ( data%State%RAM(3)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%State%RAM(3)%First_OpenTimecheck= 1 + + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOff !new + data%State%BopStackInput%LowerRamsCloseLEDMine = LedOff !new + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOn !LedBlinking + + data%State%RAM(3)%FourwayValve = 1 + + endif + + + endif + + + if (data%State%RAM(3)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then ! 1: Open , 0: Close +!write(*,*) 'open 2' + + data%State%RAM(3)%FourwayValve = 0 + + data%State%PipeRam2%closed=0 +!PipeRam2_closed_withPossibility= PipeRam2_closed * TD_BOPConnectionPossibility(4) + data%State%RAM(3)%vdis_tot=0 + data%State%RAM(3)%vdis_bottles=0. + data%State%RAM(3)%fvr_air=0. + data%State%RAM(3)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(3)%Qzero=70 + data%State%RAM(3)%Q=data%State%RAM(3)%Qzero + data%State%RAM(3)%flow=70 + data%State%RAM(3)%tol=0.0037 + + if (data%State%PipeRam2%finished==1) then + data%State%PipeRam2%LeverOld=1.0 + else + data%State%PipeRam2%LeverOld=data%Equipments%BopControlPanel%LowerRamsValve + endif + data%State%PipeRam2%finished=0 + data%State%PipeRam2%IsOpening = .true. + data%State%PipeRam2%IsClosing = .false. + + +!if (LowerRamsOpenLED == LedOn) then +! RETURN +!end if + + + data%State%RAM(3)%bop_type = 3 +!AbopPipeRam=186.5 + data%State%PipeRam1%A=(data%Configuration%BopStack%LowerRamOpen*231)/((data%State%PipeRam1%IDBase-data%State%PipeRam1%ODDrillpipe_inBase)/2.) + data%State%PipeRam2%NeededVolume=data%State%PipeRam1%A*(data%State%PipeRam1%IDBase-max(data%State%PipeRam2%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase))/(2.*231) !galon for each BOP +!write(*,*) 'open 1' + + endif + + +!===================================================================== + + if (data%State%PipeRam2%IsOpening .or. data%State%PipeRam2%IsClosing .or. data%State%RAM(3)%Bottles_Charged_MalfActive) then + data%State%Annular%FirstSet= 0 + data%State%AnnularComputational%RamsFirstSet= 0 + CALL PIPE_RAMS2_SUB + end if + +END SUBROUTINE PIPE_RAMS2 + + + + + + + + + + + + +SUBROUTINE PIPE_RAMS2_SUB + + use SimulationVariables + USE CBopStackVariables + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants +! use CSimulationVariables + implicit none + + +! FirstSet= 0 +! RamsFirstSet= 0 + +! loop4: do while (finished_pipe2==0) + +!write(*,*) 'checkpoint 2' + + + data%State%RAM(3)%SuccessionCounter = data%State%RAM(3)%SuccessionCounter + 1 + + + if (data%Equipments%BopControlPanel%LowerRamsValve == 1.0 .and. data%State%PipeRam2%LeverOld == -1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + +!write(*,*) 'close 3' + + if ( data%State%RAM(3)%First_CloseTimecheck == 0 ) then + + + if ( data%State%RAM(3)%SuccessionCounter /= data%State%RAM(3)%SuccessionCounterOld+1 ) then + data%State%RAM(3)%SuccessionCounter = 0 ! also in starup + data%State%RAM(3)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(3)%SuccessionCounterOld= data%State%RAM(3)%SuccessionCounter + endif + + + + if ( data%State%RAM(3)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOff + data%State%BopStackInput%LowerRamsOpenLEDMine = LedOff + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOn !LedBlinking + + data%State%RAM(3)%FourwayValve = 1 + + endif + + endif + + + + + endif + + if (data%State%RAM(3)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then +!write(*,*) 'close 4' + + data%State%RAM(3)%FourwayValve = 0 + + + data%State%PipeRam2%closed=0 +!PipeRam2_closed_withPossibility= PipeRam2_closed * TD_BOPConnectionPossibility(4) + data%State%RAM(3)%p_bop=data%State%ShearRAM%PA + data%State%PipeRam2%LeverOld = data%Equipments%BopControlPanel%LowerRamsValve + + CALL OpenLowerRams + data%State%PipeRam2%Situation_forTD= 0 ! open - for TD code + data%State%RAM(3)%bop_type = 3 +!AbopPipeRam=196.67 + data%State%PipeRam1%A=(data%Configuration%BopStack%LowerRamClose*231)/((data%State%PipeRam1%IDBase-data%State%PipeRam1%ODDrillpipe_inBase)/2.) + data%State%PipeRam2%NeededVolume=data%State%PipeRam1%A*(data%State%PipeRam2%ID-max(data%State%PipeRam2%ODDrillpipe_in,data%State%PipeRam1%ODDrillpipe_inBase))/(2.*231) + + data%State%RAM(3)%vdis_bottles=0. + data%State%RAM(3)%fvr_air=0. + data%State%RAM(3)%vdis_elecp=0. + data%State%PipeRam2%IsClosing = .true. + data%State%PipeRam2%IsOpening = .false. +!write(*,*) 'close 2' + + endif + + if (data%Equipments%BopControlPanel%LowerRamsValve == -1.0 .and. data%State%PipeRam2%LeverOld == 1.0 .and. data%State%PipeRam2%LowerRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then +!write(*,*) 'open 3' + + + if ( data%State%RAM(3)%First_OpenTimecheck == 0 ) then + + if ( data%State%RAM(3)%SuccessionCounter /= data%State%RAM(3)%SuccessionCounterOld+1 ) then + data%State%RAM(3)%SuccessionCounter = 0 ! also in starup + data%State%RAM(3)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(3)%SuccessionCounterOld= data%State%RAM(3)%SuccessionCounter + endif + + if ( data%State%RAM(3)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%Equipments%BopControlPanel%LowerRamsCloseLED = LedOff + data%State%BopStackInput%LowerRamsCloseLEDMine = LedOff + data%Equipments%BopControlPanel%LowerRamsOpenLED = LedOn !LedBlinking + + data%State%RAM(3)%FourwayValve = 1 + + endif + + endif + + + endif + + + if (data%State%RAM(3)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then +!write(*,*) 'open 4' + + data%State%RAM(3)%FourwayValve = 0 + + data%State%PipeRam2%closed=0 +!PipeRam2_closed_withPossibility= PipeRam2_closed * TD_BOPConnectionPossibility(4) + data%State%RAM(3)%p_bop=data%State%ShearRAM%PA + data%State%PipeRam2%LeverOld = data%Equipments%BopControlPanel%LowerRamsValve + + CALL OpenLowerRams + data%State%PipeRam2%Situation_forTD= 0 ! open - for TD code + data%State%RAM(3)%bop_type = 3 +!AbopPipeRam=186.5 + data%State%PipeRam1%A=(data%Configuration%BopStack%LowerRamOpen*231)/((data%State%PipeRam1%IDBase-data%State%PipeRam1%ODDrillpipe_inBase)/2.) + data%State%PipeRam2%NeededVolume=data%State%PipeRam1%A*(data%State%PipeRam1%IDBase-data%State%PipeRam2%ID)/(2.*231) + data%State%RAM(3)%vdis_bottles=0. + data%State%RAM(3)%fvr_air=0. + data%State%RAM(3)%vdis_elecp=0. + + data%State%PipeRam2%IsOpening = .true. + data%State%PipeRam2%IsClosing = .false. +!write(*,*) 'open 2' + + endif + + + data%State%RAM(3)%First_CloseTimecheck = 0 + data%State%RAM(3)%First_OpenTimecheck = 0 + + + data%State%RAM(3)%time=data%State%RAM(3)%time+data%State%RamLine%DeltaT_BOP !overal time (s) + + + +!=================================================== +! BOP +!=================================================== +if (data%State%PipeRam2%closed==0) then !bop closing +!write(*,*) 'BOP code is called' + call bop_code(3,data%State%PipeRam2%H_Bop,3) !ramtype=3 3=RNUMBER +endif !bop is closing +!================================================================ +if (data%State%PipeRam2%closed==1) then + data%State%RAM(3)%Q=0 +!p_bop=pram_reg + data%State%RAM(3)%p_bop=data%State%ShearRAM%PA + data%State%RAMS%minloss(3,17)=0. !RNUMBER=3 +endif + +data%State%RAM(3)%timecounter_ram=data%State%RAM(3)%timecounter_ram+1 + + + + + +! MiddleRamsStatus = IDshearBop +! UpperRamsStatus = IDPipeRam1 +! LowerRamsStatus = IDPipeRam2 +! AnnularStatus = IDAnnular +! AccumulatorPressureGauge = p_acc +! ManifoldPressureGauge= pram_reg +! AnnularPressureGauge=Pannular_reg +! +! +! +! WRITE(60,60) data%State%RAM(3)%time,data%State%RAM(3)%Q,data%State%RAM(3)%vdis_tot,p_acc, & +! pram_reg,Pannular_reg,data%State%RAM(3)%p_bop,IDshearBop, & +! IDPipeRam1,IDPipeRam2,IDAnnular +!60 FORMAT(11(f18.5)) + + +! call sleepqq(100) + +if (data%State%PipeRam2%closed==1) then + +! if ((MiddleRamsValve==1. .and. MiddleRamsFailureMalf==0) .or. (MiddleRamsValve==-1.0 .and. MiddleRamsFailureMalf==0) .or. (UpperRamsValve==1. .and. UpperRamsFailureMalf==0) .or. (UpperRamsValve==-1.0 .and. UpperRamsFailureMalf==0) .or. (AnnularValve==1. .and. AnnularFailureMalf==0) .or. (AnnularValve==-1.0 .and. AnnularFailureMalf==0) .or. ChokeLineValve==1. .or. ChokeLineValve==-1.0 .or. KillLineValve==1. .or. KillLineValve==-1.0) then + data%State%PipeRam2%finished=1 +! endif +endif + +! if (IsStopped == .true.) return + + +! end do loop4 !while finished_pipe2==0 + + if ( data%State%PipeRam2%finished==1 .and. data%State%RAM(3)%Bottles_Charged_MalfActive==.true.) then + call bop_code(3,data%State%PipeRam2%H_Bop,3) !ramtype=3 3=RNUMBER +! call sleepqq(100) + endif + + + + +END SUBROUTINE PIPE_RAMS2_SUB diff --git a/Equipments/BopStack/SHEAR_RAM.f90 b/Equipments/BopStack/SHEAR_RAM.f90 index de298f9..37f0cb6 100644 --- a/Equipments/BopStack/SHEAR_RAM.f90 +++ b/Equipments/BopStack/SHEAR_RAM.f90 @@ -17,7 +17,7 @@ SUBROUTINE SHEAR_RAMS data%State%RAM(4)%SuccessionCounter = data%State%RAM(4)%SuccessionCounter + 1 - if (data%EquipmentControl%BopControlPanel%MiddleRamsValve == 1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if (data%Equipments%BopControlPanel%MiddleRamsValve == 1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then if (data%State%BopStackInput%MiddleRamsCloseLEDMine == LedOn) then RETURN @@ -38,9 +38,9 @@ SUBROUTINE SHEAR_RAMS data%State%RAM(4)%First_CloseTimecheck= 1 - data%EquipmentControl%BopControlPanel%MiddleRamsOpenLED = LedOff + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOff data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOff - data%EquipmentControl%BopControlPanel%MiddleRamsCloseLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOn !LedBlinking data%State%RAM(4)%FourwayValve = 1 @@ -70,7 +70,7 @@ SUBROUTINE SHEAR_RAMS if (data%State%RamLine%FINISHED_shear==1) then data%State%RamLine%ShearRamsLeverOld=-1.0 else - data%State%RamLine%ShearRamsLeverOld=data%EquipmentControl%BopControlPanel%MiddleRamsValve + data%State%RamLine%ShearRamsLeverOld=data%Equipments%BopControlPanel%MiddleRamsValve endif data%State%RamLine%FINISHED_shear=0 data%State%RamLine%ShearRamIsClosing = .true. @@ -86,7 +86,7 @@ SUBROUTINE SHEAR_RAMS data%State%ShearRAM%VB=data%State%ShearRAM%NeededVolumeShearRams endif - if (data%EquipmentControl%BopControlPanel%MiddleRamsValve == -1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1) then + if (data%Equipments%BopControlPanel%MiddleRamsValve == -1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then if (data%State%BopStackInput%MiddleRamsOpenLEDMine == LedOn) then RETURN @@ -106,9 +106,9 @@ SUBROUTINE SHEAR_RAMS data%State%RAM(4)%First_OpenTimecheck= 1 - data%EquipmentControl%BopControlPanel%MiddleRamsCloseLED = LedOff !new + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOff !new data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOff !new - data%EquipmentControl%BopControlPanel%MiddleRamsOpenLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOn !LedBlinking endif @@ -137,7 +137,7 @@ SUBROUTINE SHEAR_RAMS if (data%State%RamLine%FINISHED_shear==1) then data%State%RamLine%ShearRamsLeverOld=1.0 else - data%State%RamLine%ShearRamsLeverOld=data%EquipmentControl%BopControlPanel%MiddleRamsValve + data%State%RamLine%ShearRamsLeverOld=data%Equipments%BopControlPanel%MiddleRamsValve endif data%State%RamLine%FINISHED_shear=0 data%State%RamLine%ShearRamIsOpening = .true. @@ -177,7 +177,7 @@ SUBROUTINE SHEAR_RAMS_SUB ! loop2: do while (finished_shear==0) data%State%RAM(4)%SuccessionCounter = data%State%RAM(4)%SuccessionCounter + 1 - if (data%EquipmentControl%BopControlPanel%MiddleRamsValve == 1.0 .and. data%State%RamLine%ShearRamsLeverOld == -1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1 .and. data%State%RAM(4)%First_CloseTimecheck == 0) then + if (data%Equipments%BopControlPanel%MiddleRamsValve == 1.0 .and. data%State%RamLine%ShearRamsLeverOld == -1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RAM(4)%First_CloseTimecheck == 0) then if ( data%State%RAM(4)%SuccessionCounter /= data%State%RAM(4)%SuccessionCounterOld+1 ) then data%State%RAM(4)%SuccessionCounter = 0 ! also in starup data%State%RAM(4)%SuccessionCounterOld = 0 ! also in starup @@ -185,9 +185,9 @@ SUBROUTINE SHEAR_RAMS_SUB data%State%RAM(4)%SuccessionCounterOld= data%State%RAM(4)%SuccessionCounter endif if ( data%State%RAM(4)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then - data%EquipmentControl%BopControlPanel%MiddleRamsOpenLED = LedOff + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOff data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOff - data%EquipmentControl%BopControlPanel%MiddleRamsCloseLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOn !LedBlinking data%State%RAM(4)%FourwayValve = 1 endif endif @@ -196,7 +196,7 @@ SUBROUTINE SHEAR_RAMS_SUB data%State%RAM(4)%FourwayValve = 0 data%State%RamLine%ShearBop_closed=0 data%State%RAM(4)%p_bop=data%State%ShearRAM%PA - data%State%RamLine%ShearRamsLeverOld = data%EquipmentControl%BopControlPanel%MiddleRamsValve + data%State%RamLine%ShearRamsLeverOld = data%Equipments%BopControlPanel%MiddleRamsValve CALL OpenMiddleRams ! for C code data%State%RamLine%ShearBop_Situation_forTD= 0 ! open - for TD code data%State%RAM(4)%bop_type = 2 @@ -209,7 +209,7 @@ SUBROUTINE SHEAR_RAMS_SUB data%State%RamLine%ShearRamIsOpening = .false. endif - if (data%EquipmentControl%BopControlPanel%MiddleRamsValve == -1.0 .and. data%State%RamLine%ShearRamsLeverOld == 1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%EquipmentControl%BopControlPanel%AirMasterValve==1 .and. data%State%RAM(4)%First_OpenTimecheck == 0) then + if (data%Equipments%BopControlPanel%MiddleRamsValve == -1.0 .and. data%State%RamLine%ShearRamsLeverOld == 1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RAM(4)%First_OpenTimecheck == 0) then if ( data%State%RAM(4)%SuccessionCounter /= data%State%RAM(4)%SuccessionCounterOld+1 ) then data%State%RAM(4)%SuccessionCounter = 0 ! also in starup data%State%RAM(4)%SuccessionCounterOld = 0 ! also in starup @@ -219,9 +219,9 @@ SUBROUTINE SHEAR_RAMS_SUB endif if ( data%State%RAM(4)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then - data%EquipmentControl%BopControlPanel%MiddleRamsCloseLED = LedOff + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOff data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOff - data%EquipmentControl%BopControlPanel%MiddleRamsOpenLED = LedOn !LedBlinking + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOn !LedBlinking data%State%RAM(4)%FourwayValve = 1 endif endif @@ -230,7 +230,7 @@ SUBROUTINE SHEAR_RAMS_SUB data%State%RAM(4)%FourwayValve = 0 data%State%RamLine%ShearBop_closed=0 data%State%RAM(4)%p_bop=data%State%ShearRAM%PA - data%State%RamLine%ShearRamsLeverOld = data%EquipmentControl%BopControlPanel%MiddleRamsValve + data%State%RamLine%ShearRamsLeverOld = data%Equipments%BopControlPanel%MiddleRamsValve CALL OpenMiddleRams data%State%RamLine%ShearBop_Situation_forTD= 0 ! open - for TD code data%State%RAM(4)%bop_type = 3 @@ -260,7 +260,8 @@ SUBROUTINE SHEAR_RAMS_SUB endif data%State%RAM(4)%timecounter_ram=data%State%RAM(4)%timecounter_ram+1 - call sleepqq(100) + ! commented by mahmood + ! call sleepqq(100) if (data%State%RamLine%ShearBop_closed==1) then data%State%RamLine%FINISHED_shear=1 diff --git a/Equipments/BopStack/SHEAR_RAM.i90 b/Equipments/BopStack/SHEAR_RAM.i90 new file mode 100644 index 0000000..ba88a31 --- /dev/null +++ b/Equipments/BopStack/SHEAR_RAM.i90 @@ -0,0 +1,278 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/SHEAR_RAM.f90" + +SUBROUTINE SHEAR_RAMS + use SimulationVariables + USE CBopStackVariables + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants +! use CSimulationVariables + implicit none + + + +!===================================================================== +! SHEAR RAMS- BOP CAMERON Type U 5000 +! START CONDITIONS FOR SHEAR RAMS +!===================================================================== + + data%State%RAM(4)%SuccessionCounter = data%State%RAM(4)%SuccessionCounter + 1 + + if (data%Equipments%BopControlPanel%MiddleRamsValve == 1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + + if (data%State%BopStackInput%MiddleRamsCloseLEDMine == LedOn) then + RETURN + end if + + + if ( data%State%RAM(4)%SuccessionCounter /= data%State%RAM(4)%SuccessionCounterOld+1 ) then + data%State%RAM(4)%SuccessionCounter = 0 ! also in starup + data%State%RAM(4)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(4)%SuccessionCounterOld= data%State%RAM(4)%SuccessionCounter + endif + + + if ( data%State%RAM(4)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%State%RAM(4)%First_CloseTimecheck= 1 + + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOff + data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOff + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOn !LedBlinking + + data%State%RAM(4)%FourwayValve = 1 + + endif + + endif + + + if (data%State%RAM(4)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then ! 1: Open , 0: Close +!write(*,*) 'close 2' + data%State%RAM(4)%FourwayValve = 0 + + + data%State%RamLine%ShearBop_closed=0 +!ShearBop_closed_withPossibility= ShearBop_closed * TD_BOPConnectionPossibility(3) + data%State%RAM(4)%vdis_tot=0 + data%State%RAM(4)%vdis_bottles=0. + data%State%RAM(4)%fvr_air=0. + data%State%RAM(4)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(4)%Qzero=70 + data%State%RAM(4)%Q=data%State%RAM(4)%Qzero + data%State%RAM(4)%flow=70 + data%State%RAM(4)%tol=0.0037 + + + if (data%State%RamLine%FINISHED_shear==1) then + data%State%RamLine%ShearRamsLeverOld=-1.0 + else + data%State%RamLine%ShearRamsLeverOld=data%Equipments%BopControlPanel%MiddleRamsValve + endif + data%State%RamLine%FINISHED_shear=0 + data%State%RamLine%ShearRamIsClosing = .true. + data%State%RamLine%ShearRamIsOpening = .false. + + data%State%RAM(4)%bop_type = 2 +!NeededVolumeShearRams=5.8 !galon for each BOP +!AbopShearRam=196.67 !(in^2) + data%State%ShearRAM%AbopShearRam=(data%Configuration%BopStack%BlindRamClose*231)/(data%State%ShearRAM%IDshearBopBase/2.) +!NeededVolumeShearRams=BlindRamClose !galon for each BOP **changed + data%State%ShearRAM%NeededVolumeShearRams=data%State%ShearRAM%AbopShearRam*(data%State%ShearRAM%IDshearBopBase-data%State%ShearRAM%ShearIsNotAllowed*data%State%ShearRAM%ODDrillpipe_inShearRam)/(2.*231) !3.67 galon for each BOP ! **changed + data%State%ShearRAM%VA=data%State%ShearRAM%AbopShearRam*(data%State%ShearRAM%IDshearBopBase-data%State%ShearRAM%ODDrillpipe_inShearRam)/(2.*231) + data%State%ShearRAM%VB=data%State%ShearRAM%NeededVolumeShearRams + endif + + if (data%Equipments%BopControlPanel%MiddleRamsValve == -1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1) then + + if (data%State%BopStackInput%MiddleRamsOpenLEDMine == LedOn) then + RETURN + end if + + if ( data%State%RAM(4)%SuccessionCounter /= data%State%RAM(4)%SuccessionCounterOld+1 ) then + data%State%RAM(4)%SuccessionCounter = 0 ! also in starup + data%State%RAM(4)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(4)%SuccessionCounterOld= data%State%RAM(4)%SuccessionCounter + endif + + + if ( data%State%RAM(4)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then +!return + + data%State%RAM(4)%First_OpenTimecheck= 1 + + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOff !new + data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOff !new + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOn !LedBlinking + + endif + + endif + + + if (data%State%RAM(4)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then ! 1: Open , 0: Close +!write(*,*) 'open 2' + + data%State%RAM(4)%FourwayValve = 0 + + + + data%State%RamLine%ShearBop_closed=0 +!ShearBop_closed_withPossibility= ShearBop_closed * TD_BOPConnectionPossibility(3) + data%State%RAM(4)%vdis_tot=0 + data%State%RAM(4)%vdis_bottles=0. + data%State%RAM(4)%fvr_air=0. + data%State%RAM(4)%vdis_elecp=0. + data%State%Pumps%Qiter=7 + data%State%RAM(4)%Qzero=70 + data%State%RAM(4)%Q=data%State%RAM(4)%Qzero + data%State%RAM(4)%flow=70 + data%State%RAM(4)%tol=0.0037 + + if (data%State%RamLine%FINISHED_shear==1) then + data%State%RamLine%ShearRamsLeverOld=1.0 + else + data%State%RamLine%ShearRamsLeverOld=data%Equipments%BopControlPanel%MiddleRamsValve + endif + data%State%RamLine%FINISHED_shear=0 + data%State%RamLine%ShearRamIsOpening = .true. + data%State%RamLine%ShearRamIsClosing = .false. + + data%State%RAM(4)%bop_type = 3 +!AbopShearRam=186.5 !(in^2) + data%State%ShearRAM%AbopShearRam=(data%Configuration%BopStack%BlindRamOpen*231)/(data%State%ShearRAM%IDshearBopBase/2.) +!NeededVolumeShearRams=5.5 !galon for each BOP +!NeededVolumeShearRams=BlindRamOpen ! **changed + data%State%ShearRAM%NeededVolumeShearRams=data%State%ShearRAM%AbopShearRam*(data%State%ShearRAM%IDshearBopBase-data%State%ShearRAM%ShearIsNotAllowed*data%State%ShearRAM%ODDrillpipe_inShearRam)/(2.*231) !3.67 galon for each BOP ! **changed +!va=AbopShearRam*(IDshearBopBase-ODDrillpipe_inShearRam)/(2.*231) +!vb=NeededVolumeShearRams + endif +!===================================================================== +! if (ShearRamIsOpening .or. ShearRamIsClosing .or. data%State%RAM(4)%Bottles_Charged_MalfActive) then +! CALL SHEAR_RAMS_SUB +! end if + +END SUBROUTINE SHEAR_RAMS + + + + + +SUBROUTINE SHEAR_RAMS_SUB + use SimulationVariables + USE CBopStackVariables + use CBopControlPanel + use SimulationVariables + USE CEquipmentsConstants +! use CSimulationVariables + implicit none + +! FirstSet= 0 +! RamsFirstSet= 0 + +! loop2: do while (finished_shear==0) + data%State%RAM(4)%SuccessionCounter = data%State%RAM(4)%SuccessionCounter + 1 + if (data%Equipments%BopControlPanel%MiddleRamsValve == 1.0 .and. data%State%RamLine%ShearRamsLeverOld == -1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RAM(4)%First_CloseTimecheck == 0) then + if ( data%State%RAM(4)%SuccessionCounter /= data%State%RAM(4)%SuccessionCounterOld+1 ) then + data%State%RAM(4)%SuccessionCounter = 0 ! also in starup + data%State%RAM(4)%SuccessionCounterOld = 0 ! also in starup + else + data%State%RAM(4)%SuccessionCounterOld= data%State%RAM(4)%SuccessionCounter + endif + if ( data%State%RAM(4)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOff + data%State%BopStackInput%MiddleRamsOpenLEDMine = LedOff + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOn !LedBlinking + data%State%RAM(4)%FourwayValve = 1 + endif + endif + + if (data%State%RAM(4)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + data%State%RAM(4)%FourwayValve = 0 + data%State%RamLine%ShearBop_closed=0 + data%State%RAM(4)%p_bop=data%State%ShearRAM%PA + data%State%RamLine%ShearRamsLeverOld = data%Equipments%BopControlPanel%MiddleRamsValve + CALL OpenMiddleRams ! for C code + data%State%RamLine%ShearBop_Situation_forTD= 0 ! open - for TD code + data%State%RAM(4)%bop_type = 2 + data%State%ShearRAM%AbopShearRam=(data%Configuration%BopStack%BlindRamClose*231)/(data%State%ShearRAM%IDshearBopBase/2.) + data%State%ShearRAM%NeededVolumeShearRams=data%State%ShearRAM%AbopShearRam*(data%State%ShearRAM%IDshearBop-data%State%ShearRAM%ShearIsNotAllowed*data%State%ShearRAM%ODDrillpipe_inShearRam)/(2.*231) ! **changed + data%State%RAM(4)%vdis_bottles=0. + data%State%RAM(4)%fvr_air=0. + data%State%RAM(4)%vdis_elecp=0. + data%State%RamLine%ShearRamIsClosing = .true. + data%State%RamLine%ShearRamIsOpening = .false. + endif + + if (data%Equipments%BopControlPanel%MiddleRamsValve == -1.0 .and. data%State%RamLine%ShearRamsLeverOld == 1.0 .and. data%State%ShearRAM%MiddleRamsFailureMalf==0 .and. data%State%BopStackAcc%RigAirMalf==0 .and. data%Equipments%BopControlPanel%AirMasterValve==1 .and. data%State%RAM(4)%First_OpenTimecheck == 0) then + if ( data%State%RAM(4)%SuccessionCounter /= data%State%RAM(4)%SuccessionCounterOld+1 ) then + data%State%RAM(4)%SuccessionCounter = 0 ! also in starup + data%State%RAM(4)%SuccessionCounterOld = 0 ! also in starup +!return + else + data%State%RAM(4)%SuccessionCounterOld= data%State%RAM(4)%SuccessionCounter + endif + + if ( data%State%RAM(4)%SuccessionCounter >= int(2.5/data%State%RamLine%DeltaT_BOP) ) then + data%Equipments%BopControlPanel%MiddleRamsCloseLED = LedOff + data%State%BopStackInput%MiddleRamsCloseLEDMine = LedOff + data%Equipments%BopControlPanel%MiddleRamsOpenLED = LedOn !LedBlinking + data%State%RAM(4)%FourwayValve = 1 + endif + endif + + if (data%State%RAM(4)%FourwayValve == 1 .and. data%State%RamLine%P_ACC>data%State%BopStackAcc%acc_MinPressure) then + data%State%RAM(4)%FourwayValve = 0 + data%State%RamLine%ShearBop_closed=0 + data%State%RAM(4)%p_bop=data%State%ShearRAM%PA + data%State%RamLine%ShearRamsLeverOld = data%Equipments%BopControlPanel%MiddleRamsValve + CALL OpenMiddleRams + data%State%RamLine%ShearBop_Situation_forTD= 0 ! open - for TD code + data%State%RAM(4)%bop_type = 3 + data%State%ShearRAM%NeededVolumeShearRams=data%State%ShearRAM%AbopShearRam*(data%State%ShearRAM%IDshearBopBase-data%State%ShearRAM%IDshearBop)/(2.*231) + data%State%RAM(4)%vdis_bottles=0. + data%State%RAM(4)%fvr_air=0. + data%State%RAM(4)%vdis_elecp=0. + data%State%RamLine%ShearRamIsOpening = .true. + data%State%RamLine%ShearRamIsClosing = .false. + endif + + data%State%RAM(4)%First_CloseTimecheck = 0 + data%State%RAM(4)%First_OpenTimecheck = 0 + data%State%RAM(4)%time=data%State%RAM(4)%time+data%State%RamLine%DeltaT_BOP !overal time (s) + +!=================================================== +! BOP +!=================================================== + if (data%State%RamLine%ShearBop_closed==0) then !bop closing + call bop_code(1,data%State%ShearRAM%H_ShearRamBop,4) !ramtype=1 4=RNUMBER + endif !bop is closing +!================================================================ + if (data%State%RamLine%ShearBop_closed==1) then + data%State%RAM(4)%Q=0 + data%State%RAM(4)%p_bop=data%State%ShearRAM%PA + data%State%RAMS%minloss(4,17)=0. !RNUMBER=4 + endif + + data%State%RAM(4)%timecounter_ram=data%State%RAM(4)%timecounter_ram+1 +! commented by mahmood +! call sleepqq(100) + + if (data%State%RamLine%ShearBop_closed==1) then + data%State%RamLine%FINISHED_shear=1 + endif +! if (IsStopped == .true.) return +! end do loop2 !while finished_shear==0 + +! if ( finished_shear==1 .and. data%State%RAM(4)%Bottles_Charged_MalfActive==.true.) then +! call bop_code(1,H_ShearRamBop,4) !ramtype=1 4=RNUMBER +! call sleepqq(100) +! endif + +END SUBROUTINE SHEAR_RAMS_SUB diff --git a/Equipments/BopStack/VARIABLES.i90 b/Equipments/BopStack/VARIABLES.i90 new file mode 100644 index 0000000..b345fec --- /dev/null +++ b/Equipments/BopStack/VARIABLES.i90 @@ -0,0 +1,181 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/BopStack/VARIABLES.f90" +MODULE BopVariables + use DynamicDoubleArray, only:DynamicDoubleArrayType + IMPLICIT NONE + + + + +!=========================================================================== +! INPUT VARIABLES +!=========================================================================== +type :: BopStackInputType + REAL,ALLOCATABLE:: MINORS1(:,:),PIPINGS_RAMLINE(:,:),MINORS_ANNULAR(:,:),PIPINGS_ANNULAR(:,:),PIPINGS_AIRPUMP(:,:),MINORS_AIRPUMP(:,:) + integer AnnularOpenLedMine,AnnularCloseLedMine,UpperRamsCloseLEDMine,UpperRamsOpenLEDMine,LowerRamsOpenLEDMine,LowerRamsCloseLEDMine + integer MiddleRamsOpenLEDMine,MiddleRamsCloseLEDMine,KillLineOpenLedMine,KillLineCloseLedMine,ChokeLineOpenLEDMine,ChokeLineCloseLEDMine + integer BOP_timeCounter +end type BopStackInputType +!=========================================================================== +! ACC. VARIABLES +!=========================================================================== +REAL,PARAMETER :: PressureDifferenceSteps = 20. ,BaseDifferenceP= 200. ! psi +type::BopStackAccType + REAL FVR_TOT,BOTTLE_CAPACITY,PRAMS_REGSET,acc_ChargedPressure,acc_MinPressure,ACC_PRECHARGE,ByPassOld + REAL pram_reg,test1,test2,test3,test4,test5,test6,test7,test8,test9,ax,bx + integer NOBOTTLES,AccPupmsFailMalf,AirSupplyPressureGaugeMalf,ManifoldPressureGaugeMalf,AccumulatorPressureGaugeMalf,RigAirMalf + real Cumulative_AirVolume, PressureDifference + integer SoundKoomeyAirPump +end type BopStackAccType +!=========================================================================== + +! RAM LINE COMPUTATIONAL VARIABLES +!=========================================================================== +type:: RamLineType + logical ShearRamIsClosing,ShearRamIsOpening + REAL ShearRamsLeverOld,NoActiveRmas +!REAL checkp,p_acccheck + REAL P_ACC,FVR,DeltaT_BOP + REAL diffp_air,losses_air,Qup,kinetic_air,pipe_loss1air,minor_loss1air,static_loss1air!,pipe_loss1_before,minor_loss1,static_loss1,kinetic_loss1,pipe_loss1 +!REAL loss_before,pipe_loss2,minor_loss2,deltah,static_loss2,kinetic_loss2,loss_after + integer AIRP_SWITCH,ELECP_SWITCH,ShearBop_closed,FINISHED_shear,EOF,NO_MINORSRAMLINE,NO_PIPINGSRAMLINE,NO_PIPINGS_AIRPLINE,NO_MINORS_AIRPLINE + integer counter,iteration,ShearBop_Situation_forTD + real BA1,BA2,BA3,BA4,BBA1,BBA2,BBA3,BBA4 + REAL B1,B2,B3,B4 + REAL,ALLOCATABLE:: Re_air(:),DIAM_AIR_MM(:),DIAM_AIR_INCH(:),AREA_AIR(:),REL_ROUGHAIR(:),LENGT_AIR(:),LF_AIR(:),CV_AIR(:),NOTE_AIR(:) + REAL,ALLOCATABLE:: fric_air(:),fricloss_air(:),minlosspa_air(:),minloss_air(:) + REAL,ALLOCATABLE:: MINORDIAM_AIR_INCH(:),MINORAREA_AIR(:) + REAL,ALLOCATABLE:: DIAM_RAMLINE_INCH(:),DIAM_RAMLINE_MM(:),AREA_RAMLINE(:),ROUGHNESS_AIRPLINE(:),ROUGHNESS_RAMLINE(:),RELROUGH_RAMLINE(:),LENGT_RAMLINE(:),LF_RAMLINE(:),CV_RAMLINE(:),NOTE_RAMLINE(:),AREAMINOR_RAMLINE(:) +!REAL,ALLOCATABLE:: Re_ramline(:),fric(:),fricloss(:) + REAL,ALLOCATABLE:: MINORDIAMETER_RAMLINE(:) + INTEGER,ALLOCATABLE:: ITEM(:),ITEM_PIPING(:),ITEM_PIPINGAIR(:),ITEM_MINORAIR(:) + CHARACTER,ALLOCATABLE:: DECRIPTION(:),DECRIPTION2(:),DECRIPTION_RAM(:),DESCRIPTION_AIR1(:),DESCRIPTION_AIR2(:) + real:: counter_airp,pacc_before + integer Annular_active,ShearBop_active,PipeRam1_active,PipeRam2_active,ChokeLine_active,KillLine_active +end type RamLineType + +!=========================================================================== +! ANNULAR PREVENTER COMPUTATIONAL VARIABLES +!=========================================================================== +type::AnnularComputationalType + integer PannularTimeStepDelay + type(DynamicDoubleArrayType) :: Pannular_regDelay + logical AnnPressureRise + integer NO_MinorsAnnularLine,NO_PipingsAnnularLine,RamsFirstSet + REAL pa_annular,p_annular + REAL,ALLOCATABLE:: MINORDIAMETER_ANNULARLINE(:),AREAMINOR_ANNULARLINE(:) +!REAL,ALLOCATABLE:: REAL_PregAnnular(:),real_IDAnnular(:),real_pAnnular(:) + REAL REAL_PregAnnular,real_IDAnnular,real_pAnnular + REAL,ALLOCATABLE:: LF_ANNULARLINE(:),CV_ANNULARLINE(:),NOTE_ANNULARLINE(:),minlosspa_ANNULAR(:),minloss_ANNULAR(:) + REAL,ALLOCATABLE:: DIAM_ANNULARLINE_INCH(:),DIAM_ANNULARLINE_MM(:),AREA_ANNULARLINE(:) + REAL,ALLOCATABLE:: LENGT_ANNULARLINE(:),ROUGHNESS_ANNULARLINE(:),RELROUGH_ANNULARLINE(:),Re_ANNULARline(:),fricANNULAR(:),friclossANNULAR(:) + INTEGER,ALLOCATABLE:: ITEMANNULAR(:),ITEM_PIPINGANNULAR(:) + CHARACTER,ALLOCATABLE:: DECRIPTIONANNULAR(:),DECRIPTION2ANNULAR(:),DECRIPTION_ANNULAR(:) + REAL WellBorePressure,acoef,Bcoef,const,AnnularSealingPressure,AnnularMovingPressure +end type AnnularComputationalType +!=========================================================================== +! ANNULAR PREVENTER VARIABLES +!=========================================================================== +type :: AnnularType + REAL (8) Pannular_reg + real Pannular_regset + logical AnnularIsClosing,AnnularIsOpening + REAL tolAnnular,tolzeroAnnular + integer Annular_closed,finished_Annular,FirstSet,AnnularFailureMalf,AnnularLeakMalf,AnnularPressureGaugeMalf,Annular_Situation_forTD + REAL AnnularLeverOld,H_AnnularBop,IDAnnular,AbopAnnular,ODDrillpipe_inAnnular,IDAnnularBase,ODDrillpipe_inAnnularBase + REAL NeededVolumeAnnular +end type AnnularType +!=========================================================================== +! PIPE RAMS 1 VARIABLES +!=========================================================================== +type::PipeRams1Type + logical IsClosing,IsOpening + REAL PipeRams1DotLeverOld,H + REAL NeededVolume,A,IDBase,ID,ODDrillpipe_in,ODDrillpipe_inBase + integer closed,finished,UpperRamsFailureMalf,UpperRamsLeakMalf,Situation_forTD +! REAL real_ID +end type PipeRams1Type +!============================================================================ +! SHEAR RAM BOP VARIABLES +!============================================================================ +type:: ShearRamType + REAL PA,PB,P_SHEAR,VA,VB,RAM_COURSE,H_REGRAM,H_ShearRamBop + REAL,ALLOCATABLE:: ALPHA_QRAM(:),ALPHA_VDISRAM(:),ALPHA_PACC(:),ALPHA_PREGRAM(:),ALPHA_PBOP(:) +!REAL,ALLOCATABLE:: REAL_TIME(:),REAL_QRAM(:),REAL_VDISRAM(:),REAL_PACC(:),REAL_PREGRAM(:),REAL_PBOP(:),real_IDshearBop(:) + REAL REAL_TIME,REAL_QRAM,REAL_VDISRAM,REAL_PACC,REAL_PREGRAM,REAL_PBOP,real_IDshearBop + REAL IDshearBopBase,IDshearBop,ODDrillpipe_inShearRam,AbopShearRam,NeededVolumeShearRams,ODDrillpipe_inShearRamBase + Real IDshearBopFinal,IDPipeRam1Final,IDPipeRam2Final,IDAnnularFinal,OpenArea_shearBop,OpenArea_PipeRam1,OpenArea_PipeRam2,OpenArea_Annular + Real MinimumOpenArea_InBOP + integer MiddleRamsFailureMalf,MiddleRamsLeakMalf,ShearIsNotAllowed +end type ShearRamType +!=========================================================================== +! PIPE RAMS 2 VARIABLES +!=========================================================================== +type::PipeRam2Type + logical IsClosing,IsOpening + REAL LeverOld,H_Bop + REAL NeededVolume,ID,ODDrillpipe_in,ODDrillpipe_inBase + integer closed,finished,LowerRamsFailureMalf,LowerRamsLeakMalf,Situation_forTD +!REAL,ALLOCATABLE:: real_IDPipeRam2(:) + REAL real_ID +end type PipeRam2Type +!=========================================================================== +! CHOKE LINE VARIABLES +!=========================================================================== +type::ChokeLineType + logical IsClosing,IsOpening + REAL LeverOld,H_Bop + REAL NeededVolume,Abop,ID,ODDrillpipe_in,IDBase,ODDrillpipe_inBase + integer closed,finished +!REAL,ALLOCATABLE:: real_IDPipeRam1(:) + REAL real_ID +end type ChokeLineType +!=========================================================================== +! KILL LINE VARIABLES +!=========================================================================== +type::KillLineType + logical IsClosing,IsOpening + REAL LeverOld,H_Bop + REAL NeededVolume,Abop,ID,ODDrillpipe_in,IDBase,ODDrillpipe_inBase + integer closed,finished +!REAL,ALLOCATABLE:: real_IDPipeRam1(:) + REAL real_ID +end type KillLineType +!============================================================================ +! OIL & ENVIRONMENT VARIABLES +!============================================================================ +! REAL:: SG=1.12,WDENS=1000,GRAVITY=9.81,RE_CR=2000 +!specific gravity of liquid +!water density(kg/m^3) +!============================================================================ +! PUMP VARIABLES +!============================================================================ +type::PumpsType + REAL P_AIRP,DELTAV_AIR,TOL_AIR,DELTAV_ELECP,Qiter + REAL ELECTRIC_ON,ELECTRIC_OFF,AIR_ON,AIR_OFF,QAIR,QELECTRIC +!REAL,ALLOCATABLE:: alpha_Qair(:),alpha_timeair(:),alpha_paccair(:),alpha_pairp(:),alpha_diffpair(:),alpha_lossesair(:),alpha_fvrair(:) + REAL alpha_Qair,alpha_timeair,alpha_paccair,alpha_pairp,alpha_diffpair,alpha_lossesair,alpha_fvrair + logical SoundKoomeyElectric +end type PumpsType + +!================================================================================= + + TYPE, PUBLIC :: BOP_TypeVars + REAL vdis_tot,vdis_bottles,deltav_bottles,fvr_air,vdis_elecp,Qzero,Q,flow,tol,TIME,timecounter_ram,clock + integer bop_type, SuccessionCounter, SuccessionCounterOld,First_CloseTimecheck,First_OpenTimecheck,FourwayValve ! FourwayValve 1: Open , 0: Close + REAL loss_before,pipe_loss2,minor_loss2,deltah,static_loss2,kinetic_loss2,loss_after,TOLZERO,diffp_ram + REAL checkp,p_acccheck,P_BOP,minor_loss1,static_loss1,kinetic_loss1,pipe_loss1 + Logical Bottles_Charged_MalfActive + END TYPE BOP_TypeVars + +! 1 : Annular (RNUMBER) +! 2 : PipeRam1 (RNUMBER) +! 3 : PipeRam2 (RNUMBER) +! 4 : ShearRam (RNUMBER) +! 5 : ChokeLine (RNUMBER) +! 6 : KillLine (RNUMBER) + + TYPE, PUBLIC :: BOP_TypeVars2D + REAL, ALLOCATABLE:: minlosspa(:,:),minloss(:,:) + REAL,ALLOCATABLE:: Re_ramline(:,:),fric(:,:),fricloss(:,:) + END TYPE BOP_TypeVars2D +END MODULE diff --git a/Equipments/ChokeControl/AirPump_Choke_Subs.f90 b/Equipments/ChokeControl/AirPump_Choke_Subs.f90 index 3b35ca5..f2c3b85 100644 --- a/Equipments/ChokeControl/AirPump_Choke_Subs.f90 +++ b/Equipments/ChokeControl/AirPump_Choke_Subs.f90 @@ -110,12 +110,12 @@ ENDDO ! INTEGER CHNUMBER ! Integer I -! loop3: do while (ABS(data%EquipmentControl%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%EquipmentControl%ChokeControlPanel%ChokePanelRigAirSwitch == 1 .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0) -! if (data%EquipmentControl%ChokeControlPanel%ChokeControlLever == 1.0) then +! loop3: do while (ABS(data%Equipments%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch == 1 .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0) +! if (data%Equipments%ChokeControlPanel%ChokeControlLever == 1.0) then ! data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .true. ! data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .false. ! endif -! if (data%EquipmentControl%ChokeControlPanel%ChokeControlLever == -1.0) then +! if (data%Equipments%ChokeControlPanel%ChokeControlLever == -1.0) then ! data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .true. ! data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .false. ! endif @@ -208,7 +208,7 @@ use SimulationVariables !@ end do !returns correct QAIR_PUMP for 1 counter data%State%AirPumpLine%QITER=data%State%AirDrivenPump%QAIR_PUMP - data%State%AirDrivenPump%QAIR_PUMP=data%State%AirDrivenPump%QAIR_PUMP*(data%EquipmentControl%ChokeControlPanel%ChokeRateControlKnob/10.) ! final Q (gpm) + data%State%AirDrivenPump%QAIR_PUMP=data%State%AirDrivenPump%QAIR_PUMP*(data%Equipments%ChokeControlPanel%ChokeRateControlKnob/10.) ! final Q (gpm) data%State%Choke%Cumulative_AirVolume_Choke= data%State%Choke%Cumulative_AirVolume_Choke + ((data%State%AirDrivenPump%QAIR_PUMP * data%State%AirPumpLine%DeltaT_Choke / 60.0 ) / (1.5*0.004329004) ) ! =strokes if ( data%State%Choke%Cumulative_AirVolume_Choke > 1.0 ) then @@ -245,10 +245,10 @@ use SimulationVariables !@ call SetSoundChokePump(data%State%Choke%SoundChokePump) data%State%CHOOKE(CHNUMBER)%PercentClose= data%State%CHOOKE(CHNUMBER)%PassedCourse/data%State%AirPumpLine%CourseBase - IF (data%EquipmentControl%ChokeControlPanel%Choke1LED==1) THEN - data%EquipmentControl%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(1)%PercentClose*10 + IF (data%Equipments%ChokeControlPanel%Choke1LED==1) THEN + data%Equipments%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(1)%PercentClose*10 ELSE ! Choke2LED==1 - data%EquipmentControl%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(2)%PercentClose*10 + data%Equipments%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(2)%PercentClose*10 ENDIF !CALL SetHydraulicChock1(nint(MIN(data%State%CHOOKE(1)%PercentClose / 0.91 , 1.0)*100)) ! CALL SetHydraulicChock2(nint(MIN(data%State%CHOOKE(2)%PercentClose / 0.91 , 1.0)*100)) diff --git a/Equipments/ChokeControl/AirPump_Choke_Subs.i90 b/Equipments/ChokeControl/AirPump_Choke_Subs.i90 new file mode 100644 index 0000000..cc1e946 --- /dev/null +++ b/Equipments/ChokeControl/AirPump_Choke_Subs.i90 @@ -0,0 +1,338 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/ChokeControl/AirPump_Choke_Subs.f90" + + SUBROUTINE DEALLOCATE_ARRAYS_CHOKE() + +USE CHOKEVARIABLES +use SimulationVariables !@ + +implicit none +write(*,*) 'deallocateeeeeeeeeeeee' +!=========================================================================== +! AIR PUMP LOSSES INPUT +!=========================================================================== +!if(allocated(PIPINGS_AIRPUMP)) deallocate(PIPINGS_AIRPUMP) + +DEALLOCATE (data%State%AirPumpLine%PIPINGS_AIRPUMP,data%State%AirPumpLine%DIAM_AIR_INCH, & + data%State%AirPumpLine%Re_air,data%State%AirPumpLine%AREA_AIR,data%State%AirPumpLine%LENGT_AIR,data%State%AirPumpLine%ROUGHNESS_AIRPLINE,data%State%AirPumpLine%REL_ROUGHAIR, & + data%State%AirPumpLine%fric_air,data%State%AirPumpLine%fricloss_air) +!================================================================ +DEALLOCATE (data%State%AirPumpLine%MINORS_AIRPUMP,data%State%AirPumpLine%MINORDIAM_AIR_INCH, & + data%State%AirPumpLine%MINORAREA_AIR,data%State%AirPumpLine%LF_AIR,data%State%AirPumpLine%CV_AIR,data%State%AirPumpLine%NOTE_AIR & + ,data%State%AirPumpLine%minlosspa_air,data%State%AirPumpLine%minloss_air) + + END + + + + + + + SUBROUTINE LOSS_INPUTS_CHOKE() +USE CHOKEVARIABLES +use SimulationVariables !@ +implicit none + Integer I + + +!=========================================================================== +! AIR PUMP LOSSES INPUT +!=========================================================================== +data%State%AirPumpLine%NO_PIPINGS_AIRPLINE=1 + +ALLOCATE (data%State%AirPumpLine%PIPINGS_AIRPUMP(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE,3)) +! ID(INCH) L(MM) ROUGHNESS(MM)=e DESCRIPTION +data%State%AirPumpLine%PIPINGS_AIRPUMP(1,1:3)= (/0.5, 60960., 0.03/) !Avg.acc.distance + +!60960= 200 ft + + + ALLOCATE (data%State%AirPumpLine%DIAM_AIR_INCH(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE),data%State%AirPumpLine%Re_air(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE),data%State%AirPumpLine%AREA_AIR(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE), & + data%State%AirPumpLine%LENGT_AIR(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE),data%State%AirPumpLine%ROUGHNESS_AIRPLINE(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE),data%State%AirPumpLine%REL_ROUGHAIR(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE), & + data%State%AirPumpLine%fric_air(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE),data%State%AirPumpLine%fricloss_air(data%State%AirPumpLine%NO_PIPINGS_AIRPLINE)) + + + +DO I=1,data%State%AirPumpLine%NO_PIPINGS_AIRPLINE + data%State%AirPumpLine%DIAM_AIR_INCH(I)=data%State%AirPumpLine%PIPINGS_AIRPUMP(I,1) + data%State%AirPumpLine%LENGT_AIR(I)=data%State%AirPumpLine%PIPINGS_AIRPUMP(I,2) + data%State%AirPumpLine%ROUGHNESS_AIRPLINE(I)=data%State%AirPumpLine%PIPINGS_AIRPUMP(I,3) + + + data%State%AirPumpLine%AREA_AIR(I)=PI*(data%State%AirPumpLine%DIAM_AIR_INCH(I)*0.0254)**2/4 !D(in), AREA(m) + data%State%AirPumpLine%REL_ROUGHAIR(I)=data%State%AirPumpLine%ROUGHNESS_AIRPLINE(I)/(data%State%AirPumpLine%DIAM_AIR_INCH(I)*25.4) +!DIAM_RAMLINE_MM(I)=DIAM_RAMLINE_MM(I)*.001 ! (m) + data%State%AirPumpLine%LENGT_AIR(I)=data%State%AirPumpLine%LENGT_AIR(I)*.001 ! (m) + ENDDO + + +!================================================================ +data%State%AirPumpLine%NO_MINORS_AIRPLINE=6 + +ALLOCATE (data%State%AirPumpLine%MINORS_AIRPUMP(data%State%AirPumpLine%NO_MINORS_AIRPLINE,4)) + +! ID(INCH) LF CV NOTE(BAR) DESCRIPTION +data%State%AirPumpLine%MINORS_AIRPUMP(1,1:4)= (/2., 10., 0., 0./) !Acc.tee +data%State%AirPumpLine%MINORS_AIRPUMP(2,1:4)= (/2., 11., 0., 0./) !elbow +data%State%AirPumpLine%MINORS_AIRPUMP(3,1:4)= (/1., 0., 0., 3.4/) !filter +data%State%AirPumpLine%MINORS_AIRPUMP(4,1:4)= (/2., 0., 105., 0./) !valve +data%State%AirPumpLine%MINORS_AIRPUMP(5,1:4)= (/1., 0., 9.2, 0./) !valve +data%State%AirPumpLine%MINORS_AIRPUMP(6,1:4)= (/2., 6.4, 0., 0./) !unionA + + + + ALLOCATE (data%State%AirPumpLine%MINORDIAM_AIR_INCH(data%State%AirPumpLine%NO_MINORS_AIRPLINE),data%State%AirPumpLine%MINORAREA_AIR(data%State%AirPumpLine%NO_MINORS_AIRPLINE), & + data%State%AirPumpLine%LF_AIR(data%State%AirPumpLine%NO_MINORS_AIRPLINE),data%State%AirPumpLine%CV_AIR(data%State%AirPumpLine%NO_MINORS_AIRPLINE),data%State%AirPumpLine%NOTE_AIR(data%State%AirPumpLine%NO_MINORS_AIRPLINE) & + ,data%State%AirPumpLine%minlosspa_air(data%State%AirPumpLine%NO_MINORS_AIRPLINE),data%State%AirPumpLine%minloss_air(data%State%AirPumpLine%NO_MINORS_AIRPLINE)) + + + +DO I=1,data%State%AirPumpLine%NO_MINORS_AIRPLINE + data%State%AirPumpLine%MINORDIAM_AIR_INCH(I)=data%State%AirPumpLine%MINORS_AIRPUMP(I,1) + data%State%AirPumpLine%LF_AIR(I)=data%State%AirPumpLine%MINORS_AIRPUMP(I,2) + data%State%AirPumpLine%CV_AIR(I)=data%State%AirPumpLine%MINORS_AIRPUMP(I,3) + data%State%AirPumpLine%NOTE_AIR(I)=data%State%AirPumpLine%MINORS_AIRPUMP(I,4) + + + data%State%AirPumpLine%MINORAREA_AIR(I)=PI*(data%State%AirPumpLine%MINORDIAM_AIR_INCH(I)*0.0254)**2/4. !D(in), AREA(m) +ENDDO + + + END + + + + + +! SUBROUTINE PIPE_RAMS_CHOKE(CHNUMBER) +! USE CHOKEVARIABLES +! use ConfigurationVariables !@ +! Use CSimulationVariables +! implicit none +! INTEGER CHNUMBER +! Integer I + +! loop3: do while (ABS(data%Equipments%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch == 1 .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0) +! if (data%Equipments%ChokeControlPanel%ChokeControlLever == 1.0) then +! data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .true. +! data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .false. +! endif +! if (data%Equipments%ChokeControlPanel%ChokeControlLever == -1.0) then +! data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .true. +! data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .false. +! endif +! data%State%AirPumpLine%TIME=data%State%AirPumpLine%TIME+data%State%AirPumpLine%DeltaT_Choke !overal time (s) +! call airpump_code_CHOKE(CHNUMBER) +! call sleepqq(100) +! if (IsStopped == .true.) return +! end do loop3 !while finished_Choke==0 +! end + + + + + + + SUBROUTINE airpump_code_CHOKE(CHNUMBER) + USE CHOKEVARIABLES +use SimulationVariables !@ + use CChokeManifold + use SimulationVariables + use CSounds + USE CChokeProblemsVariables + implicit none + Integer I + + INTEGER CHNUMBER + + data%State%AirDrivenPump%QAIR_PUMP=data%State%AirPumpLine%QITER+.1 !(gpm) maximum flow for the start + data%State%AirPumpLine%diffp_air=-10 + data%State%AirPumpLine%losses_air=10 + +!=================================================================== +! AIR OPERATED PUMP +! MODEL 10-6000W030 RATIO 55:1 +!=================for air consumption at 100 psig=================== + do while (data%State%AirPumpLine%diffp_air<0) + data%State%AirDrivenPump%QAIR_PUMP=data%State%AirDrivenPump%QAIR_PUMP-.1 +! Qup=data%State%AirDrivenPump%QAIR_PUMP; +!cc1 = 1354; cc2 = -2066; cc3 = -2109; cc4 = -513.6; cc5 = 5935 FOR OUTPUT IN GPM + data%State%AirPumpLine%P_AIRP=data%State%AirDrivenPump%cc1*(data%State%AirDrivenPump%QAIR_PUMP**4) + data%State%AirDrivenPump%cc2*(data%State%AirDrivenPump%QAIR_PUMP**3) + data%State%AirDrivenPump%cc3*(data%State%AirDrivenPump%QAIR_PUMP**2) + data%State%AirDrivenPump%cc4*data%State%AirDrivenPump%QAIR_PUMP + data%State%AirDrivenPump%cc5 !(psig) +! kinetic_air=sg*wdens*(QAIR_PUMP*6.30902e-5/((1/4.)*pi*(2*0.254e-1)**2))**2/(2*6895) !(psi) + data%State%AirPumpLine%diffp_air= data%State%AirPumpLine%P_AIRP - data%State%AirPumpLine%Pdownstrem + end do !returns Qup + + do while (abs((data%State%AirPumpLine%diffp_air-data%State%AirPumpLine%losses_air)/data%State%AirPumpLine%diffp_air)>data%State%AirPumpLine%TOL_AIR) !finding correct QAIR_pump for 1 timecounter_ram + if (data%State%AirPumpLine%diffp_air-data%State%AirPumpLine%losses_air>0) then + data%State%AirDrivenPump%QAIR_PUMP=data%State%AirDrivenPump%QAIR_PUMP+.005 + else + data%State%AirDrivenPump%QAIR_PUMP=data%State%AirDrivenPump%QAIR_PUMP-.005 + endif +!=================================================================== +! AIR OPERATED PUMP +! MODEL 10-6000W030 RATIO 55:1 +!=================for air consumption at 100 psig=================== + data%State%AirPumpLine%P_AIRP=data%State%AirDrivenPump%cc1*(data%State%AirDrivenPump%QAIR_PUMP**4) + data%State%AirDrivenPump%cc2*(data%State%AirDrivenPump%QAIR_PUMP**3) + data%State%AirDrivenPump%cc3*(data%State%AirDrivenPump%QAIR_PUMP**2) + data%State%AirDrivenPump%cc4*data%State%AirDrivenPump%QAIR_PUMP + data%State%AirDrivenPump%cc5 !(psig) +!kinetic_air=sg*wdens*(QAIR_PUMP*6.30902e-005/((1/4.)*pi*(2*0.254e-1)**2))**2/(2*6895) !(psi) + data%State%AirPumpLine%diffp_air= data%State%AirPumpLine%P_AIRP - data%State%AirPumpLine%Pdownstrem +!===========================LOSSES==================================== + do i=1,data%State%AirPumpLine%NO_PIPINGS_AIRPLINE + data%State%AirPumpLine%Re_air(i)=data%State%AirDrivenPump%QAIR_PUMP*6.30902e-005*data%State%AirPumpLine%DIAM_AIR_INCH(I)*0.0254/(data%State%AirPumpLine%AREA_AIR(i)*nu) + enddo + do i=1,data%State%AirPumpLine%NO_PIPINGS_AIRPLINE + if (data%State%AirPumpLine%Re_air(i) 1.0 ) then + data%State%Choke%SoundChokePump= 60 + data%State%Choke%Cumulative_AirVolume_Choke= data%State%Choke%Cumulative_AirVolume_Choke - 1.0 + else + data%State%Choke%SoundChokePump= 0.0 + endif + data%State%AirPumpLine%DELTAV_AIR=data%State%AirDrivenPump%QAIR_PUMP*data%State%AirPumpLine%DeltaT_Choke/60 !(galon) delta_t=1sec , Q(gpm) + if (data%State%CHOOKE(CHNUMBER)%ChokeIsClosing) data%State%CHOOKE(CHNUMBER)%PassedCourse=data%State%CHOOKE(CHNUMBER)%PassedCourse + (data%State%AirPumpLine%DELTAV_AIR*3785.412/data%State%AirPumpLine%Acylinder)!*(ChokeRateControlKnob/10.) ! 3785.412 : GALON TO CM^3 + if (data%State%CHOOKE(CHNUMBER)%ChokeIsOpening) data%State%CHOOKE(CHNUMBER)%PassedCourse=data%State%CHOOKE(CHNUMBER)%PassedCourse - (data%State%AirPumpLine%DELTAV_AIR*3785.412/data%State%AirPumpLine%Acylinder)!*(ChokeRateControlKnob/10.) +!DeltaT_Choke= 1sec or 2sec +!((((((((IN OUTER LOOP)))))) +!===============AIR PUMP OUTPUTS========================= + data%State%AirPumpLine%alpha_timeair=data%State%AirPumpLine%TIME ! overal time (s) + data%State%AirPumpLine%alpha_Pdownstrem=data%State%AirPumpLine%Pdownstrem + data%State%AirPumpLine%alpha_pairp=data%State%AirPumpLine%P_AIRP + data%State%AirPumpLine%alpha_Qair=data%State%AirDrivenPump%QAIR_PUMP +!write(*,*) 'diffp_air=',diffp_air +!pause + data%State%AirPumpLine%alpha_diffpair=data%State%AirPumpLine%diffp_air + data%State%AirPumpLine%alpha_lossesair=data%State%AirPumpLine%losses_air +!======================================================== +!OPEN(150,FILE='CHOKE_AIRPUMP_OUTPUTS.DAT') + + if (data%State%CHOOKE(CHNUMBER)%ChokeIsClosing .AND. data%State%CHOOKE(CHNUMBER)%PassedCourse>data%State%AirPumpLine%CourseBase) then + data%State%CHOOKE(CHNUMBER)%PassedCourse=data%State%AirPumpLine%CourseBase + data%State%Choke%SoundChokePump= 0.0 + endif + if (data%State%CHOOKE(CHNUMBER)%ChokeIsOpening .AND. data%State%CHOOKE(CHNUMBER)%PassedCourse<0.) then + data%State%CHOOKE(CHNUMBER)%PassedCourse=0. + data%State%Choke%SoundChokePump= 0.0 + endif + + call SetSoundChokePump(data%State%Choke%SoundChokePump) + data%State%CHOOKE(CHNUMBER)%PercentClose= data%State%CHOOKE(CHNUMBER)%PassedCourse/data%State%AirPumpLine%CourseBase + IF (data%Equipments%ChokeControlPanel%Choke1LED==1) THEN + data%Equipments%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(1)%PercentClose*10 + ELSE ! Choke2LED==1 + data%Equipments%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(2)%PercentClose*10 + ENDIF +!CALL SetHydraulicChock1(nint(MIN(data%State%CHOOKE(1)%PercentClose / 0.91 , 1.0)*100)) +! CALL SetHydraulicChock2(nint(MIN(data%State%CHOOKE(2)%PercentClose / 0.91 , 1.0)*100)) +! .91 >> 9 percent clearance + +! =================== calculating Area +! AreaChoke=0.5 +! .91 >> 9 percent clearance + + data%State%CHOOKE(1)%AreaChoke=0.01334635-(0.01334635* MIN(data%State%CHOOKE(1)%PercentClose / 0.91 , 1.0)) !ft^2 0.01334635 is ChokeAreaFullyOpen (ft^2) + data%State%CHOOKE(2)%AreaChoke=0.01334635-(0.01334635* MIN(data%State%CHOOKE(2)%PercentClose/ 0.91 , 1.0)) !ft^2 + data%State%Choke%HydraulicChoke1WashoutCoef= data%State%Choke%HydraulicChoke1WashoutCoef * data%State%CHOOKE(1)%WashoutMalf + data%State%Choke%HydraulicChoke1WashoutCoef= MIN( 0.5 , data%State%Choke%HydraulicChoke1WashoutCoef+ data%State%CHOOKE(1)%WashoutMalf*(0.5/(60.0/data%State%AirPumpLine%DeltaT_Choke)) ) ! 0.5=maximum washout coef , 60.0 sec= 1min duration time + data%State%Choke%HydraulicChoke2WashoutCoef= data%State%Choke%HydraulicChoke2WashoutCoef * data%State%CHOOKE(2)%WashoutMalf + data%State%Choke%HydraulicChoke2WashoutCoef= MIN( 0.5 , data%State%Choke%HydraulicChoke2WashoutCoef+ data%State%CHOOKE(2)%WashoutMalf*(0.5/(60.0/data%State%AirPumpLine%DeltaT_Choke)) ) ! 0.5=maximum washout coef , 60.0 sec= 1min duration time +!write(*,*) 'HydraulicChoke1WashoutCoef=' , HydraulicChoke1WashoutCoef + + IF (data%State%CHOOKE(1)%PlugMalf == 1) THEN + data%State%Choke%Present_HydraulicChoke1Plug= data%State%Choke%Present_HydraulicChoke1Plug * data%State%CHOOKE(1)%PlugMalf +! integer: HydraulicChoke1PluggedPercent,HydraulicChoke1PluggedPercent_Old,PlugTimeCounter,ChokePlugTimeDelay +! real: Present_HydraulicChoke1Plug,DeltaPlug1Percent +!write(*,*) 'HydraulicChoke1PluggedPercent=' , HydraulicChoke1PluggedPercent + + if ( (data%problems%ChokeProblems%HydraulicChoke1PluggedPercent - data%State%Choke%HydraulicChoke1PluggedPercent_Old) /= 0) then + data%State%Choke%DeltaPlug1Percent = (REAL(data%problems%ChokeProblems%HydraulicChoke1PluggedPercent)/100.) - data%State%Choke%Present_HydraulicChoke1Plug + data%State%Choke%Plug1TimeCounter = 0 +!write(*,*) 'DeltaPlug1Percent, Present_HydraulicChoke1Plug = ' ,DeltaPlug1Percent , Present_HydraulicChoke1Plug + endif + data%State%Choke%Plug1TimeCounter= data%State%Choke%Plug1TimeCounter + 1 + data%State%Choke%HydraulicChoke1PluggedPercent_Old= data%problems%ChokeProblems%HydraulicChoke1PluggedPercent + + if (data%State%Choke%Plug1TimeCounter <= data%State%Choke%ChokePlugTimeDelay) then !ChokePlugTimeDelay=600 + data%State%Choke%Present_HydraulicChoke1Plug = data%State%Choke%Present_HydraulicChoke1Plug + data%State%CHOOKE(1)%PlugMalf* ((data%State%Choke%DeltaPlug1Percent / real(data%State%Choke%ChokePlugTimeDelay))) ! real(ChokePlugTimeDelay)= 600.0 + endif +!write(*,*) 'Present_HydraulicChoke1Plug=' , Present_HydraulicChoke1Plug + ENDIF + + IF (data%State%CHOOKE(2)%PlugMalf == 1) THEN + data%State%Choke%Present_HydraulicChoke2Plug= data%State%Choke%Present_HydraulicChoke2Plug * data%State%CHOOKE(2)%PlugMalf +! integer: HydraulicChoke2PluggedPercent,HydraulicChoke2PluggedPercent_Old,PlugTimeCounter,ChokePlugTimeDelay +! real: Present_HydraulicChoke2Plug,DeltaPlug2Percent + if ( (data%problems%ChokeProblems%HydraulicChoke2PluggedPercent - data%State%Choke%HydraulicChoke2PluggedPercent_Old) /= 0 ) then + data%State%Choke%DeltaPlug2Percent = (REAL(data%problems%ChokeProblems%HydraulicChoke2PluggedPercent)/100.) - data%State%Choke%Present_HydraulicChoke2Plug + data%State%Choke%Plug2TimeCounter = 0 + endif + data%State%Choke%Plug2TimeCounter= data%State%Choke%Plug2TimeCounter + 1 + data%State%Choke%HydraulicChoke2PluggedPercent_Old= data%problems%ChokeProblems%HydraulicChoke2PluggedPercent + if (data%State%Choke%Plug2TimeCounter <= data%State%Choke%ChokePlugTimeDelay) then !ChokePlugTimeDelay=600 + data%State%Choke%Present_HydraulicChoke2Plug = data%State%Choke%Present_HydraulicChoke2Plug + data%State%CHOOKE(2)%PlugMalf *((data%State%Choke%DeltaPlug2Percent / real(data%State%Choke%ChokePlugTimeDelay))) ! real(ChokePlugTimeDelay)= 600.0 + endif + ENDIF +! fully open area is 123/64 in^2 = 0.01334635 ft^2 + data%State%CHOOKE(1)%AreaChoke=data%State%CHOOKE(1)%AreaChoke+(data%State%CHOOKE(1)%WashoutMalf*data%State%Choke%HydraulicChoke1WashoutCoef*data%State%Choke%ChokeAreaFullyOpen/144.0) ! Initialised in Choke Startup + +!write(*,*) 'data%State%CHOOKE(1)%WashoutMalf , data%State%CHOOKE(1)%AreaChoke=' ,data%State%CHOOKE(1)%WashoutMalf , data%State%CHOOKE(1)%AreaChoke + + data%State%CHOOKE(1)%AreaChoke=data%State%CHOOKE(1)%AreaChoke-(data%State%CHOOKE(1)%PlugMalf* data%State%Choke%Present_HydraulicChoke1Plug *data%State%CHOOKE(1)%AreaChoke) ! Initialised in Choke Startup + + data%State%CHOOKE(2)%AreaChoke=data%State%CHOOKE(2)%AreaChoke+(data%State%CHOOKE(2)%WashoutMalf*data%State%Choke%HydraulicChoke2WashoutCoef*data%State%Choke%ChokeAreaFullyOpen/144.0) ! Initialised in Choke Startup + data%State%CHOOKE(2)%AreaChoke=data%State%CHOOKE(2)%AreaChoke-(data%State%CHOOKE(2)%PlugMalf* data%State%Choke%Present_HydraulicChoke2Plug *data%State%CHOOKE(2)%AreaChoke) ! Initialised in Choke Startup +!write(*,*) 'data%State%CHOOKE(2)%WashoutMalf , data%State%CHOOKE(2)%AreaChoke=' ,data%State%CHOOKE(2)%WashoutMalf , data%State%CHOOKE(2)%AreaChoke + + + data%State%CHOOKE(1)%AreaChokeFinal= data%State%CHOOKE(1)%AreaChoke + data%State%CHOOKE(2)%AreaChokeFinal= data%State%CHOOKE(2)%AreaChoke + +! 144: ft^2 to in^2 + CALL SetHydraulicChock1(100 - nint((data%State%CHOOKE(1)%AreaChokeFinal/(data%State%Choke%ChokeAreaFullyOpen/144.))*100)) ! for manifold valve + CALL SetHydraulicChock2(100 - nint((data%State%CHOOKE(2)%AreaChokeFinal/(data%State%Choke%ChokeAreaFullyOpen/144.))*100)) ! for manifold valve + + +!write(*,*) 'data%State%CHOOKE(1)%PercentClose=' , data%State%CHOOKE(1)%PercentClose ! close percent 0 to 100 +!write(*,*) 'ChokePosition=' , ChokePosition ! close position 0 to 10 for display +!write(*,*) 'data%State%CHOOKE(1)%AreaChokeFinal=' , data%State%CHOOKE(1)%AreaChokeFinal ! Open Area (in^2) with clearance +!write(*,*) '(ChokeAreaFullyOpen/144.)=' , (ChokeAreaFullyOpen/144.) +!write(*,*) 'valve value=' , 100 - nint((data%State%CHOOKE(1)%AreaChokeFinal/(ChokeAreaFullyOpen/144.))*100) ! percent close 0 to 100 with clearance +!write(*,*) 'Valve(33)%Status=' , Valve(33)%Status ! T : open , F: close +! =================== calculating Area +!write(*,*) 'data%State%CHOOKE(1)%AreaChoke= ' , data%State%CHOOKE(1)%AreaChoke +!WRITE(150,50) alpha_timeair,alpha_Qair,alpha_pairp, & +!alpha_Pdownstrem,alpha_diffpair,alpha_lossesair,data%State%CHOOKE(CHNUMBER)%PassedCourse +!50 FORMAT(7(f15.5)) +!======================================================================================== +!======================================================================================== +! write(*,*) PassedCourse + end diff --git a/Equipments/ChokeControl/CHOKE.f90 b/Equipments/ChokeControl/CHOKE.f90 index 75ced6b..298e19f 100644 --- a/Equipments/ChokeControl/CHOKE.f90 +++ b/Equipments/ChokeControl/CHOKE.f90 @@ -18,25 +18,25 @@ use SimulationVariables !@@@ ! function CHOKE_MainBody1 result(CHNUMBER) ! implicit none ! INTEGER CHNUMBER - ! IF(data%EquipmentControl%ChokeControlPanel%ChokeSelectorSwitch== 1) THEN - ! data%EquipmentControl%ChokeControlPanel%Choke1LED=1 - ! data%EquipmentControl%ChokeControlPanel%Choke2LED=0 + ! IF(data%Equipments%ChokeControlPanel%ChokeSelectorSwitch== 1) THEN + ! data%Equipments%ChokeControlPanel%Choke1LED=1 + ! data%Equipments%ChokeControlPanel%Choke2LED=0 ! CHNUMBER=1 ! ELSE - ! data%EquipmentControl%ChokeControlPanel%Choke2LED=1 - ! data%EquipmentControl%ChokeControlPanel%Choke1LED=0 + ! data%Equipments%ChokeControlPanel%Choke2LED=1 + ! data%Equipments%ChokeControlPanel%Choke1LED=0 ! CHNUMBER=2 ! ENDIF ! end function CHOKE_MainBody1 ! CALL PIPE_RAMS_CHOKE(CHNUMBER) ! subroutine Choke_innerLoop - ! ! do while (ABS(data%EquipmentControl%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%EquipmentControl%ChokeControlPanel%ChokePanelRigAirSwitch == 1 .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0) - ! if (data%EquipmentControl%ChokeControlPanel%ChokeControlLever == 1.0) then + ! ! do while (ABS(data%Equipments%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch == 1 .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0) + ! if (data%Equipments%ChokeControlPanel%ChokeControlLever == 1.0) then ! data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .true. ! data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .false. ! endif - ! if (data%EquipmentControl%ChokeControlPanel%ChokeControlLever == -1.0) then + ! if (data%Equipments%ChokeControlPanel%ChokeControlLever == -1.0) then ! data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .true. ! data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .false. ! endif @@ -49,10 +49,10 @@ use SimulationVariables !@@@ ! end subroutine Choke_innerLoop subroutine CHOKE_MainBody2 - IF (data%EquipmentControl%ChokeControlPanel%Choke1LED==1) THEN - data%EquipmentControl%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(1)%PercentClose*10 ! display monitor + IF (data%Equipments%ChokeControlPanel%Choke1LED==1) THEN + data%Equipments%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(1)%PercentClose*10 ! display monitor ELSE ! Choke2LED==1 - data%EquipmentControl%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(2)%PercentClose*10 ! display monitor + data%Equipments%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(2)%PercentClose*10 ! display monitor ENDIF ! =================== calculating Area ! AreaChoke=0.5 diff --git a/Equipments/ChokeControl/CHOKE.i90 b/Equipments/ChokeControl/CHOKE.i90 new file mode 100644 index 0000000..bb81a63 --- /dev/null +++ b/Equipments/ChokeControl/CHOKE.i90 @@ -0,0 +1,141 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/ChokeControl/CHOKE.f90" + + +module ChokeModule + USE CHOKEVARIABLES +use SimulationVariables !@ +!use CDataDisplayConsole +! !@use ConfigurationVariables, CasingPressureDataDisplay=>CasingPressure!, StandPipePressureDataDisplay=>StandPipePressure + USE CChokeProblemsVariables +!use CChokeControlPanelVariables +! !@use ConfigurationVariables, StandPipePressureChoke=>StandPipePressure + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use CChokeManifold + use SimulationVariables + + contains + +! function CHOKE_MainBody1 result(CHNUMBER) +! implicit none +! INTEGER CHNUMBER +! IF(data%Equipments%ChokeControlPanel%ChokeSelectorSwitch== 1) THEN +! data%Equipments%ChokeControlPanel%Choke1LED=1 +! data%Equipments%ChokeControlPanel%Choke2LED=0 +! CHNUMBER=1 +! ELSE +! data%Equipments%ChokeControlPanel%Choke2LED=1 +! data%Equipments%ChokeControlPanel%Choke1LED=0 +! CHNUMBER=2 +! ENDIF +! end function CHOKE_MainBody1 +! CALL PIPE_RAMS_CHOKE(CHNUMBER) + +! subroutine Choke_innerLoop +! ! do while (ABS(data%Equipments%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch == 1 .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0) +! if (data%Equipments%ChokeControlPanel%ChokeControlLever == 1.0) then +! data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .true. +! data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .false. +! endif +! if (data%Equipments%ChokeControlPanel%ChokeControlLever == -1.0) then +! data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .true. +! data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .false. +! endif +! data%State%AirPumpLine%TIME=data%State%AirPumpLine%TIME+data%State%AirPumpLine%DeltaT_Choke !overal time (s) +! call airpump_code_CHOKE(CHNUMBER) +! ! call sleepqq(100) +! ! if (IsStopped == .true.) return +! ! enddo +! end if +! end subroutine Choke_innerLoop + + subroutine CHOKE_MainBody2 + IF (data%Equipments%ChokeControlPanel%Choke1LED==1) THEN + data%Equipments%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(1)%PercentClose*10 ! display monitor + ELSE ! Choke2LED==1 + data%Equipments%ChokeControlPanel%ChokePosition= (1 - data%State%Choke%GaugeChokePositionMailf) * data%State%CHOOKE(2)%PercentClose*10 ! display monitor + ENDIF +! =================== calculating Area +! AreaChoke=0.5 +! .91 >> 9 percent clearance + data%State%CHOOKE(1)%AreaChoke=0.01334635-(0.01334635* MIN(data%State%CHOOKE(1)%PercentClose / 0.91 , 1.0)) !ft^2 0.01334635 is ChokeAreaFullyOpen (ft^2) + data%State%CHOOKE(2)%AreaChoke=0.01334635-(0.01334635* MIN(data%State%CHOOKE(2)%PercentClose/ 0.91 , 1.0)) !ft^2 +!write(*,*) 'data%State%CHOOKE(1)%AreaChoke= ' , data%State%CHOOKE(1)%AreaChoke + data%State%Choke%HydraulicChoke1WashoutCoef= data%State%Choke%HydraulicChoke1WashoutCoef * data%State%CHOOKE(1)%WashoutMalf + data%State%Choke%HydraulicChoke1WashoutCoef= MIN( 0.5 , data%State%Choke%HydraulicChoke1WashoutCoef+ data%State%CHOOKE(1)%WashoutMalf*(0.5/(180.0/data%State%AirPumpLine%DeltaT_Choke)) ) ! 0.5 = maximum washout coef , 180.0 sec = 3 min duration time + data%State%Choke%HydraulicChoke2WashoutCoef= data%State%Choke%HydraulicChoke2WashoutCoef * data%State%CHOOKE(2)%WashoutMalf + data%State%Choke%HydraulicChoke2WashoutCoef= MIN( 0.5 , data%State%Choke%HydraulicChoke2WashoutCoef+ data%State%CHOOKE(2)%WashoutMalf*(0.5/(180.0/data%State%AirPumpLine%DeltaT_Choke)) ) ! 0.5 = maximum washout coef , 180.0 sec = 3 min duration time +!write(*,*) 'HydraulicChoke1WashoutCoef=' , HydraulicChoke1WashoutCoef + IF (data%State%CHOOKE(1)%PlugMalf == 1) THEN + data%State%Choke%Present_HydraulicChoke1Plug= data%State%Choke%Present_HydraulicChoke1Plug * data%State%CHOOKE(1)%PlugMalf +! integer: HydraulicChoke1PluggedPercent,HydraulicChoke1PluggedPercent_Old,PlugTimeCounter,ChokePlugTimeDelay +! real: Present_HydraulicChoke1Plug,DeltaPlug1Percent +!write(*,*) 'HydraulicChoke1PluggedPercent=' , HydraulicChoke1PluggedPercent + if ( (data%problems%ChokeProblems%HydraulicChoke1PluggedPercent - data%State%Choke%HydraulicChoke1PluggedPercent_Old) /= 0) then + data%State%Choke%DeltaPlug1Percent = (REAL(data%problems%ChokeProblems%HydraulicChoke1PluggedPercent)/100.) - data%State%Choke%Present_HydraulicChoke1Plug + data%State%Choke%Plug1TimeCounter = 0 +!write(*,*) 'DeltaPlug1Percent, Present_HydraulicChoke1Plug = ' ,DeltaPlug1Percent , Present_HydraulicChoke1Plug + endif + data%State%Choke%Plug1TimeCounter= data%State%Choke%Plug1TimeCounter + 1 + data%State%Choke%HydraulicChoke1PluggedPercent_Old= data%problems%ChokeProblems%HydraulicChoke1PluggedPercent + if (data%State%Choke%Plug1TimeCounter <= data%State%Choke%ChokePlugTimeDelay) then !ChokePlugTimeDelay=1800 + data%State%Choke%Present_HydraulicChoke1Plug = data%State%Choke%Present_HydraulicChoke1Plug + data%State%CHOOKE(1)%PlugMalf* ((data%State%Choke%DeltaPlug1Percent / real(data%State%Choke%ChokePlugTimeDelay))) ! real(ChokePlugTimeDelay)= 600.0 + endif + +!write(*,*) 'Present_HydraulicChoke1Plug=' , Present_HydraulicChoke1Plug + ENDIF + + IF (data%State%CHOOKE(2)%PlugMalf == 1) THEN + data%State%Choke%Present_HydraulicChoke2Plug= data%State%Choke%Present_HydraulicChoke2Plug * data%State%CHOOKE(2)%PlugMalf +! integer: HydraulicChoke2PluggedPercent,HydraulicChoke2PluggedPercent_Old,PlugTimeCounter,ChokePlugTimeDelay +! real: Present_HydraulicChoke2Plug,DeltaPlug2Percent + if ( (data%problems%ChokeProblems%HydraulicChoke2PluggedPercent - data%State%Choke%HydraulicChoke2PluggedPercent_Old) /= 0 ) then + data%State%Choke%DeltaPlug2Percent = (REAL(data%problems%ChokeProblems%HydraulicChoke2PluggedPercent)/100.) - data%State%Choke%Present_HydraulicChoke2Plug + data%State%Choke%Plug2TimeCounter = 0 + endif + data%State%Choke%Plug2TimeCounter= data%State%Choke%Plug2TimeCounter + 1 + data%State%Choke%HydraulicChoke2PluggedPercent_Old= data%problems%ChokeProblems%HydraulicChoke2PluggedPercent + if (data%State%Choke%Plug2TimeCounter <= data%State%Choke%ChokePlugTimeDelay) then !ChokePlugTimeDelay=1800 + data%State%Choke%Present_HydraulicChoke2Plug = data%State%Choke%Present_HydraulicChoke2Plug + data%State%CHOOKE(2)%PlugMalf *((data%State%Choke%DeltaPlug2Percent / real(data%State%Choke%ChokePlugTimeDelay))) ! real(ChokePlugTimeDelay)= 1800.0 + endif + ENDIF +! fully open area is 123/64 in^2 = 0.01334635 ft^2 + data%State%CHOOKE(1)%AreaChoke=data%State%CHOOKE(1)%AreaChoke+(data%State%CHOOKE(1)%WashoutMalf*data%State%Choke%HydraulicChoke1WashoutCoef*data%State%Choke%ChokeAreaFullyOpen/144.0) ! Initialised in Choke Startup + +!write(*,*) 'data%State%CHOOKE(1)%WashoutMalf , data%State%CHOOKE(1)%AreaChoke=' ,data%State%CHOOKE(1)%WashoutMalf , data%State%CHOOKE(1)%AreaChoke + + data%State%CHOOKE(1)%AreaChoke=data%State%CHOOKE(1)%AreaChoke-(data%State%CHOOKE(1)%PlugMalf* data%State%Choke%Present_HydraulicChoke1Plug *data%State%CHOOKE(1)%AreaChoke) ! Initialised in Choke Startup + + data%State%CHOOKE(2)%AreaChoke=data%State%CHOOKE(2)%AreaChoke+(data%State%CHOOKE(2)%WashoutMalf*data%State%Choke%HydraulicChoke2WashoutCoef*data%State%Choke%ChokeAreaFullyOpen/144.0) ! Initialised in Choke Startup + data%State%CHOOKE(2)%AreaChoke=data%State%CHOOKE(2)%AreaChoke-(data%State%CHOOKE(2)%PlugMalf* data%State%Choke%Present_HydraulicChoke2Plug *data%State%CHOOKE(2)%AreaChoke) ! Initialised in Choke Startup +!write(*,*) 'data%State%CHOOKE(2)%WashoutMalf , data%State%CHOOKE(2)%AreaChoke=' ,data%State%CHOOKE(2)%WashoutMalf , data%State%CHOOKE(2)%AreaChoke + + + data%State%CHOOKE(1)%AreaChokeFinal= data%State%CHOOKE(1)%AreaChoke + data%State%CHOOKE(2)%AreaChokeFinal= data%State%CHOOKE(2)%AreaChoke + +! 144: ft^2 to in^2 + CALL SetHydraulicChock1(100 - nint((data%State%CHOOKE(1)%AreaChokeFinal/(data%State%Choke%ChokeAreaFullyOpen/144.))*100)) ! for manifold valve + CALL SetHydraulicChock2(100 - nint((data%State%CHOOKE(2)%AreaChokeFinal/(data%State%Choke%ChokeAreaFullyOpen/144.))*100)) ! for manifold valve + +!write(*,*) 'data%State%CHOOKE(1)%PercentClose=' , data%State%CHOOKE(1)%PercentClose ! close percent 0 to 100 +!write(*,*) 'ChokePosition=' , ChokePosition ! close position 0 to 10 for display +!write(*,*) 'data%State%CHOOKE(1)%AreaChokeFinal=' , data%State%CHOOKE(1)%AreaChokeFinal ! Open Area (in^2) with clearance +!write(*,*) '(ChokeAreaFullyOpen/144.)=' , (ChokeAreaFullyOpen/144.) +!write(*,*) 'valve value=' , 100 - nint((data%State%CHOOKE(1)%AreaChokeFinal/(ChokeAreaFullyOpen/144.))*100) ! percent close 0 to 100 with clearance +!write(*,*) 'Valve(33)%Status=' , Valve(33)%Status ! T : open , F: close +! =================== calculating Area + +!AreaChoke= data%State%CHOOKE(1)%AreaChoke !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< badan moteghayer 1 ya 2 shavad + +! write(*,*) 'AreaChoke:',AreaChoke + +!=========================================================================== +! MUD PUMP STROKES +! & TOTAL STROKE- CHOKE CONTROL PANEL +!=========================================================================== + +!************************* IN MUD SYSTEM MODULE************************* + end subroutine CHOKE_MainBody2 + +end module ChokeModule diff --git a/Equipments/ChokeControl/ChokeControlMain.f90 b/Equipments/ChokeControl/ChokeControlMain.f90 index 6bd16b8..cee1356 100644 --- a/Equipments/ChokeControl/ChokeControlMain.f90 +++ b/Equipments/ChokeControl/ChokeControlMain.f90 @@ -24,21 +24,21 @@ use SimulationVariables !@ implicit none INTEGER CHNUMBER - IF(data%EquipmentControl%ChokeControlPanel%ChokeSelectorSwitch== 1) THEN - data%EquipmentControl%ChokeControlPanel%Choke1LED=1 - data%EquipmentControl%ChokeControlPanel%Choke2LED=0 + IF(data%Equipments%ChokeControlPanel%ChokeSelectorSwitch== 1) THEN + data%Equipments%ChokeControlPanel%Choke1LED=1 + data%Equipments%ChokeControlPanel%Choke2LED=0 CHNUMBER=1 ELSE - data%EquipmentControl%ChokeControlPanel%Choke2LED=1 - data%EquipmentControl%ChokeControlPanel%Choke1LED=0 + data%Equipments%ChokeControlPanel%Choke2LED=1 + data%Equipments%ChokeControlPanel%Choke1LED=0 CHNUMBER=2 ENDIF - if(ABS(data%EquipmentControl%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%EquipmentControl%ChokeControlPanel%ChokePanelRigAirSwitch == 1 .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0) then - if (data%EquipmentControl%ChokeControlPanel%ChokeControlLever == 1.0) then + if(ABS(data%Equipments%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch == 1 .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0) then + if (data%Equipments%ChokeControlPanel%ChokeControlLever == 1.0) then data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .true. data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .false. endif - if (data%EquipmentControl%ChokeControlPanel%ChokeControlLever == -1.0) then + if (data%Equipments%ChokeControlPanel%ChokeControlLever == -1.0) then data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .true. data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .false. endif diff --git a/Equipments/ChokeControl/ChokeControlMain.i90 b/Equipments/ChokeControl/ChokeControlMain.i90 new file mode 100644 index 0000000..c5c379a --- /dev/null +++ b/Equipments/ChokeControl/ChokeControlMain.i90 @@ -0,0 +1,89 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/ChokeControl/ChokeControlMain.f90" +module ChokeControlMain + USE CHOKEVARIABLES +use SimulationVariables !@ + implicit none + public + contains + +! subroutine ChokeControl_Setup() +! ! use CSimulationVariables +! implicit none +! call OnSimulationInitialization%Add(ChokeControl_Init) +! call OnSimulationStop%Add(ChokeControl_Init) +! call OnChokeControlStep%Add(ChokeControl_Step) +! call OnChokeControlOutput%Add(ChokeControl_Output) +! call OnChokeControlMain%Add(ChokeControlMainBody) +! end subroutine + + subroutine ChokeControl_Init + call Choke_StartUp + end subroutine ChokeControl_Init + + subroutine ChokeControl_Step + use ChokeModule + implicit none + INTEGER CHNUMBER + + IF(data%Equipments%ChokeControlPanel%ChokeSelectorSwitch== 1) THEN + data%Equipments%ChokeControlPanel%Choke1LED=1 + data%Equipments%ChokeControlPanel%Choke2LED=0 + CHNUMBER=1 + ELSE + data%Equipments%ChokeControlPanel%Choke2LED=1 + data%Equipments%ChokeControlPanel%Choke1LED=0 + CHNUMBER=2 + ENDIF + if(ABS(data%Equipments%ChokeControlPanel%ChokeControlLever)==1.0 .AND. data%Equipments%ChokeControlPanel%ChokePanelRigAirSwitch == 1 .AND. data%State%CHOOKE(CHNUMBER)%FailMalf==0 .AND. data%State%AirDrivenPump%ChokeAirFail==0) then + if (data%Equipments%ChokeControlPanel%ChokeControlLever == 1.0) then + data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .true. + data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .false. + endif + if (data%Equipments%ChokeControlPanel%ChokeControlLever == -1.0) then + data%State%CHOOKE(CHNUMBER)%ChokeIsOpening = .true. + data%State%CHOOKE(CHNUMBER)%ChokeIsClosing = .false. + endif + data%State%AirPumpLine%TIME=data%State%AirPumpLine%TIME+data%State%AirPumpLine%DeltaT_Choke !overal time (s) + call airpump_code_CHOKE(CHNUMBER) + else + call CHOKE_MainBody2() + endif + end subroutine ChokeControl_Step + +! subroutine ChokeControl_Output +! implicit none +! end subroutine ChokeControl_Output + +! subroutine ChokeControlMainBody +! use CRigSizeVariables +! use CHOKE +! implicit none + +! CALL Choke_StartUp() +! loop1: DO +! CALL CHOKE_MainBody +! call sleepqq(100) +! !IF (IsStopped==.true.) THEN +! ! EXIT loop1 +! !ENDIF +! !write(*,*) '1111111111111' +! if(IsStopped) then +! !write(*,*) '22222222222222' + +! CALL DEALLOCATE_ARRAYS_CHOKE() +! !write(*,*) '333333333' + +! call Quit() +! end if + + + +! ENDDO loop1 + +! CLOSE(150) + +! !CALL DEALLOCATE_ARRAYS_CHOKE() + +! end subroutine ChokeControlMainBody + +end module ChokeControlMain diff --git a/Equipments/ChokeControl/ChokeStartup.f90 b/Equipments/ChokeControl/ChokeStartup.f90 index d0cb17a..3dc0bdd 100644 --- a/Equipments/ChokeControl/ChokeStartup.f90 +++ b/Equipments/ChokeControl/ChokeStartup.f90 @@ -96,7 +96,7 @@ data%State%Choke%DeltaPlug2Percent = 0.0 !======================AIRPUMP INPUTS(CONSTANTS)=========================== data%State%AirPumpLine%CourseBase= 24. !cm data%State%CHOOKE%PassedCourse= 0. - data%EquipmentControl%ChokeControlPanel%ChokePosition=0. + data%Equipments%ChokeControlPanel%ChokePosition=0. data%State%AirPumpLine%Acylinder= PI*(8.**2)/4. ! (CM^2), 8=DIAMETER, 24=course , 3785.412: cm^3 to galon diff --git a/Equipments/ChokeControl/ChokeStartup.i90 b/Equipments/ChokeControl/ChokeStartup.i90 new file mode 100644 index 0000000..76b9ca2 --- /dev/null +++ b/Equipments/ChokeControl/ChokeStartup.i90 @@ -0,0 +1,128 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/ChokeControl/ChokeStartup.f90" + SUBROUTINE Choke_StartUp() + + USE CHOKEVARIABLES +use SimulationVariables !@ + USE CChokeProblemsVariables + implicit none + + CALL LOSS_INPUTS_CHOKE() + +!OPEN(150,FILE='CHOKE_AIRPUMP_OUTPUTS.DAT') + + +!data%State%CHOOKE(1)%WashoutMalf=1 +!data%State%CHOOKE(1)%PlugMalf=0 +!data%State%CHOOKE(1)%FailMalf=0 +! +!data%State%CHOOKE(2)%WashoutMalf=1 +!data%State%CHOOKE(2)%PlugMalf=0 +!data%State%CHOOKE(2)%FailMalf=0 +! +! +!ChokeAirFail=0 +! +!GaugeChokePositionMailf=0 + + + + + + + + data%State%Choke%kRatio=1.4 +data%State%Choke%Cp=0.24 +data%State%Choke%CL=0.8 + +data%State%Choke%x1=0.5 + +data%State%Choke%LiquidPPG=9. +data%State%Choke%LiquidDensity=data%State%Choke%LiquidPPG*7.48 !lbm/ft**3 + +data%State%Choke%VL=1.0/data%State%Choke%LiquidDensity !SpecificVolume of Liquid + +data%State%Choke%Cv=data%State%Choke%Cp/data%State%Choke%kRatio + +data%State%Choke%nPolytripic=1+(data%State%Choke%x1*(data%State%Choke%Cp-data%State%Choke%Cv)/(data%State%Choke%x1*data%State%Choke%Cv+(1-data%State%Choke%x1)*data%State%Choke%CL)) + +data%State%Choke%VG1=1./0.748 !lbm/ft**3 Specific Volume of Air, Upstream + +data%State%Choke%Cdrag=0.8 +data%State%Choke%Pwh=1400. !psi + + +data%State%Choke%Patm=14.7 +data%State%Choke%MixDens2=data%State%Choke%x1*data%State%Choke%VG1 !lbm/ft**3 + + + +data%State%Choke%epsilon_abs= 1e-5 +data%State%Choke%epsilon_step= 1e-5 + + +!ChokeDiameter= 32/64. !in + +data%State%CHOOKE%PercentClose= 0.0 +!AreaChoke=0.01334635 + +! data%State%CHOOKE(1)%AreaChoke=0.01334635 +!ChokeAreaFullyOpen = 123.d0 / 64.d0 ! fully open area is 123/64 in^2 = 0.01334635 ft^2 + +data%State%AirPumpLine%DeltaT_Choke=0.1 +!TotalStrokes1=0. +!TotalStrokes2=0. + +data%State%Choke%HydraulicChoke1WashoutCoef= 0.0 +data%State%Choke%HydraulicChoke2WashoutCoef= 0.0 + + + +data%State%Choke%ChokePlugTimeDelay = int(180./data%State%AirPumpLine%DeltaT_Choke) ! =1800 = 180/0.1 : for 3 min delay + +data%State%Choke%Present_HydraulicChoke1Plug = REAL(data%problems%ChokeProblems%HydraulicChoke1PluggedPercent)/100. +data%State%Choke%HydraulicChoke1PluggedPercent_Old= data%problems%ChokeProblems%HydraulicChoke1PluggedPercent +data%State%Choke%Plug1TimeCounter= 0 +data%State%Choke%DeltaPlug1Percent = 0.0 + +data%State%Choke%Present_HydraulicChoke2Plug = REAL(data%problems%ChokeProblems%HydraulicChoke2PluggedPercent)/100. +data%State%Choke%HydraulicChoke2PluggedPercent_Old= data%problems%ChokeProblems%HydraulicChoke2PluggedPercent +data%State%Choke%Plug2TimeCounter= 0 +data%State%Choke%DeltaPlug2Percent = 0.0 + + + + + + +!======================AIRPUMP INPUTS(CONSTANTS)=========================== + data%State%AirPumpLine%CourseBase= 24. !cm + data%State%CHOOKE%PassedCourse= 0. + data%Equipments%ChokeControlPanel%ChokePosition=0. + + data%State%AirPumpLine%Acylinder= PI*(8.**2)/4. ! (CM^2), 8=DIAMETER, 24=course , 3785.412: cm^3 to galon + + + data%State%CHOOKE%ChokeIsOpening = .false. + data%State%CHOOKE%ChokeIsClosing = .false. + + + data%State%AirPumpLine%P_AIRP=0 + + data%State%AirDrivenPump%cc1 = 0.1354; data%State%AirDrivenPump%cc2 = -2.066; data%State%AirDrivenPump%cc3 = -21.09; data%State%AirDrivenPump%cc4 = -51.36; data%State%AirDrivenPump%cc5 = 5935 ! FOR OUTPUT IN GPM +! cc1 = 4.754e-07; cc2 = -0.0001676; cc3 = -0.03953; cc4 = -2.223; cc5 = 5935 FOR OUTPUT IN IN^3/MIN + + +data%State%AirPumpLine%Pdownstrem= 4950 !+0.01*Pchoke (psi) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +data%State%AirPumpLine%QITER=5. !(gpm) + +! Q=0.0003585; true +data%State%AirPumpLine%TIME=0 +data%State%AirPumpLine%TOL_AIR=0.05 + +data%State%AirPumpLine%alpha_Qair=0 +data%State%AirPumpLine%alpha_timeair=0 +data%State%AirPumpLine%alpha_Pdownstrem=data%State%AirPumpLine%Pdownstrem +data%State%AirPumpLine%alpha_diffpair=0 +data%State%AirPumpLine%alpha_lossesair=0 + + end diff --git a/Equipments/Drawworks/DrawworksMain.i90 b/Equipments/Drawworks/DrawworksMain.i90 new file mode 100644 index 0000000..822a9f0 --- /dev/null +++ b/Equipments/Drawworks/DrawworksMain.i90 @@ -0,0 +1,33 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/Drawworks/DrawworksMain.f90" +module DrawworksMain + implicit none + public + contains + +! subroutine Drawworks_Setup() +! use CSimulationVariables +! implicit none +! call OnSimulationInitialization%Add(Drawworks_Init) +! call OnSimulationStop%Add(Drawworks_Init) +! call OnDrawworksStep%Add(Drawworks_Step) +! call OnDrawworksOutput%Add(Drawworks_Output) +! call OnDrawworksMain%Add(DrawworksMainBody) +! end subroutine + + subroutine Drawworks_Init + call Drawworks_StartUp + end subroutine Drawworks_Init + + subroutine Drawworks_Step + call Drawworks_MainSolver + end subroutine Drawworks_Step + + subroutine DrawworksMainBody + use SimulationVariables !@ + implicit none + Call Drawworks_StartUp + loopdrawsim : do + Call Drawworks_MainSolver + end do loopdrawsim + end subroutine DrawworksMainBody +end module DrawworksMain diff --git a/Equipments/Drawworks/Drawworks_INPUTS.f90 b/Equipments/Drawworks/Drawworks_INPUTS.f90 index ea1fd03..b7f3f87 100644 --- a/Equipments/Drawworks/Drawworks_INPUTS.f90 +++ b/Equipments/Drawworks/Drawworks_INPUTS.f90 @@ -17,9 +17,9 @@ subroutine Drawworks_Inputs - data%State%Drawworks%AssignmentSwitch = data%EquipmentControl%DrillingConsole%AssignmentSwitch - data%State%Drawworks%Switch = data%EquipmentControl%DrillingConsole%DWSwitch - data%State%Drawworks%Throttle = data%EquipmentControl%DrillingConsole%DWThrottle ![RPM] + data%State%Drawworks%AssignmentSwitch = data%Equipments%DrillingConsole%AssignmentSwitch + data%State%Drawworks%Switch = data%Equipments%DrillingConsole%DWSwitch + data%State%Drawworks%Throttle = data%Equipments%DrillingConsole%DWThrottle ![RPM] data%State%Drawworks%DriveType = data%Configuration%Hoisting%DriveType data%State%Drawworks%ShearBopSituation = data%State%RamLine%ShearBop_Situation_forTD !data%State%Drawworks%MotorFaileMalf = ?????? motaghayere voroudi !dar CHoistingProblemsVariables meghdardehi mishavad @@ -60,7 +60,7 @@ subroutine Drawworks_Inputs - data%EquipmentControl%DrillingConsole%ParkingBrakeLed = 0 + data%Equipments%DrillingConsole%ParkingBrakeLed = 0 diff --git a/Equipments/Drawworks/Drawworks_INPUTS.i90 b/Equipments/Drawworks/Drawworks_INPUTS.i90 new file mode 100644 index 0000000..033f5a1 --- /dev/null +++ b/Equipments/Drawworks/Drawworks_INPUTS.i90 @@ -0,0 +1,210 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/Drawworks/Drawworks_INPUTS.f90" +subroutine Drawworks_Inputs + + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables +! Use CSimulationVariables + use OperationScenariosModule + use CWarnings + use SimulationVariables + use SimulationVariables !@ + Use TD_StringConnectionData + Use TD_DrillStemComponents + use SimulationVariables !@ + use SimulationVariables !@ + + IMPLICIT NONE + + + + data%State%Drawworks%AssignmentSwitch = data%Equipments%DrillingConsole%AssignmentSwitch + data%State%Drawworks%Switch = data%Equipments%DrillingConsole%DWSwitch + data%State%Drawworks%Throttle = data%Equipments%DrillingConsole%DWThrottle ![RPM] + data%State%Drawworks%DriveType = data%Configuration%Hoisting%DriveType + data%State%Drawworks%ShearBopSituation = data%State%RamLine%ShearBop_Situation_forTD +!data%State%Drawworks%MotorFaileMalf = ?????? motaghayere voroudi !dar CHoistingProblemsVariables meghdardehi mishavad + + + +!>>> RAM & ToolJoint Collision + data%State%Drawworks%TDBOPElementNo = data%State%TD_BOP%BOPElementNo + data%State%Drawworks%TDBOPHeight = data%State%TD_BOP%BOPHeight + data%State%Drawworks%TDBOPRamDiam = data%State%TD_BOP%BOPRamDiam + data%State%Drawworks%TDBOPThickness = data%State%TD_BOP%BOPThickness + data%State%Drawworks%TDDrillStemBottom = data%State%TD_String%DrillStemBottom + data%State%Drawworks%TDWellTotalLength = data%State%TD_WellGeneral%WellTotalLength + data%State%Drawworks%TDDlMax = data%State%TD_String%DlMax + data%State%Drawworks%TDDrillStemComponentsNumbs = data%State%TD_String%DrillStemComponentsNumbs + if (Allocated(data%State%Drawworks%TDDrillStemsDownDepth)) deAllocate (data%State%Drawworks%TDDrillStemsDownDepth) ! inja gozashtameshun cho momkene tuye startup tedade elemanha dir berese va error bede + Allocate (data%State%Drawworks%TDDrillStemsDownDepth(data%State%Drawworks%TDDrillStemComponentsNumbs+400)) ! +400: because of: Add or Remove DrillStem Components + data%State%Drawworks%TDDrillStemsDownDepth = data%State%TD_DrillStems%DownDepth + if (Allocated(data%State%Drawworks%TDDrillStemsToolJointRange)) deAllocate (data%State%Drawworks%TDDrillStemsToolJointRange) + Allocate (data%State%Drawworks%TDDrillStemsToolJointRange(data%State%Drawworks%TDDrillStemComponentsNumbs+400)) ! +400: because of: Add or Remove DrillStem Components + data%State%Drawworks%TDDrillStemsToolJointRange = data%State%TD_DrillStems%ToolJointRange + if (Allocated(data%State%Drawworks%TDDrillStemsTopDepth)) deAllocate (data%State%Drawworks%TDDrillStemsTopDepth) + Allocate (data%State%Drawworks%TDDrillStemsTopDepth(data%State%Drawworks%TDDrillStemComponentsNumbs+400)) ! +400: because of: Add or Remove DrillStem Components + data%State%Drawworks%TDDrillStemsTopDepth = data%State%TD_DrillStems%TopDepth + if (Allocated(data%State%Drawworks%TDDrillStemsRtoolJoint)) deAllocate (data%State%Drawworks%TDDrillStemsRtoolJoint) + Allocate (data%State%Drawworks%TDDrillStemsRtoolJoint(data%State%Drawworks%TDDrillStemComponentsNumbs+400)) ! +400: because of: Add or Remove DrillStem Components + data%State%Drawworks%TDDrillStemsRtoolJoint = data%State%TD_DrillStems%RtoolJoint + + + +!>>> Warnings + data%State%Drawworks%CrownCollision = data%Warnings%CrownCollision + data%State%Drawworks%FloorCollision = data%Warnings%FloorCollision + + + + data%State%Drawworks%Conv_Ratio = 1.0d0/.380d0 !che meghdari bashad?????????????????? !data%State%Drawworks%FWD_Conv_Ratio(data%State%Drawworks%ClutchMode,data%State%Drawworks%TransMode) + + + + data%Equipments%DrillingConsole%ParkingBrakeLed = 0 + + + +!===> min&max Hook Height + if ( data%State%Drawworks%DriveType==1 .and. Get_OperationCondition()==OPERATION_DRILL ) then + if ( Get_Swing()==SWING_WELL_END .and. Get_KellyConnection()==KELLY_CONNECTION_NOTHING ) then + data%State%Drawworks%DrillModeCond = 1 + data%State%Drawworks%min_Hook_Height = data%State%TD_String%TopJointHeight+data%State%OperationScenario%HKL-data%State%OperationScenario%RE ![ft] HKL=63.76=Kelly Ass. Height , RE=Release + data%State%Drawworks%max_Hook_Height = 120.d0 ![ft] + else if ( Get_Swing()==SWING_WELL_END .and. Get_KellyConnection()==KELLY_CONNECTION_SINGLE ) then + data%State%Drawworks%DrillModeCond = 2 + data%State%Drawworks%min_Hook_Height = data%State%TD_String%TopJointHeight+data%State%OperationScenario%HKL+data%State%OperationScenario%PL-data%State%OperationScenario%RE ![ft] PL=30=Pipe Lenght + data%State%Drawworks%max_Hook_Height = 120.d0 ![ft] + else if ( Get_Swing()==SWING_WELL_END .and. Get_KellyConnection() == KELLY_CONNECTION_STRING ) then + data%State%Drawworks%DrillModeCond = 3 + data%State%Drawworks%min_Hook_Height = 21.44d0-data%State%OperationScenario%RE ![ft] ?????????? check 21.44=(data%State%TD_StConn%KellyConst-data%State%TD_StConn%KellyElementConst) + data%State%Drawworks%max_Hook_Height = 120.d0 ![ft] + else if ( Get_Swing()==SWING_MOUSE_HOLE_END .and. Get_KellyConnection()==KELLY_CONNECTION_NOTHING ) then + data%State%Drawworks%DrillModeCond = 4 + data%State%Drawworks%min_Hook_Height = 66.d0-data%State%OperationScenario%RE ![ft] + data%State%Drawworks%max_Hook_Height = 120.d0 ![ft] + else if ( Get_Swing()==SWING_MOUSE_HOLE_END .and. Get_KellyConnection()==KELLY_CONNECTION_SINGLE ) then + data%State%Drawworks%DrillModeCond = 5 + data%State%Drawworks%min_Hook_Height = 65.1d0-data%State%OperationScenario%RE ![ft] + data%State%Drawworks%max_Hook_Height = 120.d0 ![ft] + else if ( Get_Swing()==SWING_RAT_HOLE_END ) then + data%State%Drawworks%DrillModeCond = 6 + data%State%Drawworks%min_Hook_Height = 66.d0-data%State%OperationScenario%RE ![ft] + data%State%Drawworks%max_Hook_Height = 120.d0 ![ft] + end if + else if ( data%State%Drawworks%DriveType==1 .and. Get_OperationCondition()==OPERATION_TRIP ) then + if ( Get_Swing()==SWING_WELL_END .and. Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING ) then + data%State%Drawworks%DrillModeCond = 7 + data%State%Drawworks%min_Hook_Height = 18.38d0 ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_Swing()==SWING_WELL_END .and. Get_ElevatorConnection() == ELEVATOR_CONNECTION_STAND ) then + data%State%Drawworks%DrillModeCond = 8 + data%State%Drawworks%min_Hook_Height = data%State%TD_String%TopJointHeight+data%State%OperationScenario%HL+data%State%OperationScenario%SL-(3.d0*data%State%OperationScenario%RE) ![ft] HL=17.81=Hook Assy , SL=90=Stand Length , 3: chon meghdari az toole loole(tool joint) dakhele elevator gharar migirad + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_Swing()==SWING_WELL_END .and. Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE ) then + data%State%Drawworks%DrillModeCond = 9 + data%State%Drawworks%min_Hook_Height = data%State%TD_String%TopJointHeight+data%State%OperationScenario%HL+data%State%OperationScenario%PL-(3.d0*data%State%OperationScenario%RE) ![ft] 3: chon meghdari az toole loole(tool joint) balaye elevator mimanad + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_Swing()==SWING_WELL_END .and. Get_ElevatorConnection() == ELEVATOR_CONNECTION_STRING ) then + data%State%Drawworks%DrillModeCond = 10 + data%State%Drawworks%min_Hook_Height = 18.5d0-data%State%OperationScenario%RE ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_Swing()==SWING_MOUSE_HOLE_END .and. Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING ) then + data%State%Drawworks%DrillModeCond = 11 + data%State%Drawworks%min_Hook_Height = 19.38d0-data%State%OperationScenario%RE ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_Swing()==SWING_MOUSE_HOLE_END .and. Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE ) then + data%State%Drawworks%DrillModeCond = 12 + data%State%Drawworks%min_Hook_Height = 17.73d0-data%State%OperationScenario%RE ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_Swing()==SWING_RAT_HOLE_END ) then + data%State%Drawworks%DrillModeCond = 13 + data%State%Drawworks%min_Hook_Height = 27.41d0-data%State%OperationScenario%RE ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_Swing()==SWING_WELL_END .and. Get_ElevatorConnection() == ELEVATOR_LATCH_STRING ) then + data%State%Drawworks%DrillModeCond = 14 + data%State%Drawworks%min_Hook_Height = 18.38d0 ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_Swing()==SWING_WELL_END .and. Get_ElevatorConnection() == ELEVATOR_LATCH_SINGLE ) then + data%State%Drawworks%DrillModeCond = 25 !warning & collision + data%State%Drawworks%min_Hook_Height = 18.38d0 !????????????????? ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_Swing()==SWING_MOUSE_HOLE_END .and. Get_ElevatorConnection() == ELEVATOR_LATCH_SINGLE ) then + data%State%Drawworks%DrillModeCond = 26 + data%State%Drawworks%min_Hook_Height = 10.38d0 !????????????????? ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_Swing()==SWING_WELL_END .and. Get_ElevatorConnection() == ELEVATOR_LATCH_STAND ) then + data%State%Drawworks%DrillModeCond = 27 + data%State%Drawworks%min_Hook_Height = 18.38d0 !????????????????? ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + end if + else if ( data%State%Drawworks%DriveType==0 ) then + if ( Get_TdsSwing()==TDS_SWING_TILT_END ) then + if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_SINGLE ) then + data%State%Drawworks%DrillModeCond = 15 + data%State%Drawworks%min_Hook_Height = 15.0d0 ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_SINGLE ) then + data%State%Drawworks%DrillModeCond = 16 + data%State%Drawworks%min_Hook_Height = 15.0d0 ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_NOTHING ) then + data%State%Drawworks%DrillModeCond = 17 + data%State%Drawworks%min_Hook_Height = 15.0d0 ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + end if + else if ( Get_TdsSwing()==TDS_SWING_OFF_END ) then + if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_STRING ) then + data%State%Drawworks%DrillModeCond = 18 + data%State%Drawworks%min_Hook_Height = max(16.0d0,data%State%TD_String%TopJointHeight) ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_STRING ) then + data%State%Drawworks%DrillModeCond = 19 + data%State%Drawworks%min_Hook_Height = data%State%TD_String%TopJointHeight ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_STRING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_NOTHING ) then + data%State%Drawworks%DrillModeCond = 20 + data%State%Drawworks%min_Hook_Height = data%State%TD_String%TopJointHeight ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_NOTHING ) then + data%State%Drawworks%DrillModeCond = 21 + data%State%Drawworks%min_Hook_Height = max(16.0d0,data%State%TD_String%TopJointHeight) ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_STAND ) then + data%State%Drawworks%DrillModeCond = 22 + data%State%Drawworks%min_Hook_Height = max(16.0d0,data%State%TD_String%TopJointHeight) ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_STAND ) then + data%State%Drawworks%DrillModeCond = 23 + data%State%Drawworks%min_Hook_Height = max(16.0d0,data%State%TD_String%TopJointHeight) ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_SPINE .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_NOTHING ) then + data%State%Drawworks%DrillModeCond = 24 + data%State%Drawworks%min_Hook_Height = data%State%TD_String%TopJointHeight ![ft] + data%State%Drawworks%max_Hook_Height = 140.d0 ![ft] + end if + end if + end if + + + +!===> SLIPS SET , No Motion + if ( data%State%Drawworks%DriveType==1 .and. Get_Slips() == SLIPS_SET_END .and. Get_KellyConnection() == KELLY_CONNECTION_STRING ) then + data%State%Drawworks%Speed = 0.d0 + end if + + if ( data%State%Drawworks%DriveType==0 .and. Get_Slips() == SLIPS_SET_END .and. (Get_TdsConnectionModes()==TDS_CONNECTION_SPINE .or. Get_TdsConnectionModes()==TDS_CONNECTION_STRING) ) then + data%State%Drawworks%Speed = 0.d0 + end if + + + +!===> Closed BOP Rams , No Motion + if ( data%State%Drawworks%ShearBopSituation==1 .and. (any(data%State%Drawworks%DrillModeCond==(/3,10,19,20,24/))) ) then + data%State%Drawworks%Speed = 0.d0 + end if + + + + +end subroutine Drawworks_Inputs diff --git a/Equipments/Drawworks/Drawworks_MainSolver.f90 b/Equipments/Drawworks/Drawworks_MainSolver.f90 index 76f6239..4f32ac5 100644 --- a/Equipments/Drawworks/Drawworks_MainSolver.f90 +++ b/Equipments/Drawworks/Drawworks_MainSolver.f90 @@ -56,7 +56,5 @@ subroutine Drawworks_MainSolver Call Drawworks_Outputs data%State%Drawworks%N_old = data%State%Drawworks%Speed - - end subroutine Drawworks_MainSolver \ No newline at end of file diff --git a/Equipments/Drawworks/Drawworks_MainSolver.i90 b/Equipments/Drawworks/Drawworks_MainSolver.i90 new file mode 100644 index 0000000..a7609ce --- /dev/null +++ b/Equipments/Drawworks/Drawworks_MainSolver.i90 @@ -0,0 +1,61 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/Drawworks/Drawworks_MainSolver.f90" +subroutine Drawworks_MainSolver + + use SimulationVariables !@ + + IMPLICIT NONE + + + + Call Drawworks_Inputs + + if (data%State%Drawworks%Throttle<=0.d0) then + data%State%Drawworks%K_Throttle = 1 + end if + + + if((any(data%State%Drawworks%AssignmentSwitch==(/1,2,3,4,5,7,8,9,10,11/))) .and. (data%State%Drawworks%Switch==-1 .or. data%State%Drawworks%Switch==1) .and. (data%State%Drawworks%CrownCollision==.false. .and. data%State%Drawworks%FloorCollision==.false.) .and. (data%State%Drawworks%K_Throttle==1)) then + + data%State%Drawworks%SoundBlower = .true. + data%State%Drawworks%BLWR = 1 + + Call Drawworks_Solver + + if ( data%State%Drawworks%motion==+1 ) then + data%State%Drawworks%SoundRev = 0 ![rpm or rad/s????????????????] , Integer + data%State%Drawworks%SoundFw = INT(data%State%Drawworks%w_drum) ![rpm] , Integer + else + data%State%Drawworks%SoundFw = 0 ![rpm] , Integer + data%State%Drawworks%SoundRev = INT(data%State%Drawworks%w_drum) ![rpm] , Integer + end if + + else + + if((any(data%State%Drawworks%AssignmentSwitch==(/1,2,3,4,5,7,8,9,10,11/))) .and. (data%State%Drawworks%Switch==-1 .or. data%State%Drawworks%Switch==1)) then + data%State%Drawworks%SoundBlower = .true. + data%State%Drawworks%BLWR = 1 + else + data%State%Drawworks%SoundBlower = .false. + data%State%Drawworks%BLWR = 0 + end if + + Call Drawworks_Solver_OffMode + + if ( data%State%Drawworks%motion==+1 ) then + data%State%Drawworks%SoundRev = 0 ![rpm] , Integer + data%State%Drawworks%SoundFw = INT(data%State%Drawworks%w_drum) ![rpm] , Integer + else + data%State%Drawworks%SoundFw = 0 ![rpm] , Integer + data%State%Drawworks%SoundRev = INT(data%State%Drawworks%w_drum) ![rpm] , Integer + end if + + data%State%Drawworks%K_Throttle = 0 + + end if + + + Call Drawworks_Outputs + + data%State%Drawworks%N_old = data%State%Drawworks%Speed + +end subroutine Drawworks_MainSolver diff --git a/Equipments/Drawworks/Drawworks_Outputs.f90 b/Equipments/Drawworks/Drawworks_Outputs.f90 index 303f8c6..9681b4c 100644 --- a/Equipments/Drawworks/Drawworks_Outputs.f90 +++ b/Equipments/Drawworks/Drawworks_Outputs.f90 @@ -13,7 +13,7 @@ subroutine Drawworks_Outputs - data%EquipmentControl%DrillingConsole%DWBLWR = data%State%Drawworks%BLWR + data%Equipments%DrillingConsole%DWBLWR = data%State%Drawworks%BLWR Call SetSoundBlowerDW( data%State%Drawworks%SoundBlower ) !.true. or .false. Call SetSoundDwRev( data%State%Drawworks%SoundRev ) ![rpm] ??? or rad/s, Integer @@ -32,7 +32,7 @@ subroutine Drawworks_Outputs data%State%Drawworks%TDHookHeight = data%State%Drawworks%Hook_Height_final ![ft] !!data%State%Drawworks%HookHeight_graph_output - !data%EquipmentControl%DrillingConsole%ParkingBrakeLed = 0 ! in Drawworks_Inputs + !data%Equipments%DrillingConsole%ParkingBrakeLed = 0 ! in Drawworks_Inputs diff --git a/Equipments/Drawworks/Drawworks_Outputs.i90 b/Equipments/Drawworks/Drawworks_Outputs.i90 new file mode 100644 index 0000000..faceeff --- /dev/null +++ b/Equipments/Drawworks/Drawworks_Outputs.i90 @@ -0,0 +1,41 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/Drawworks/Drawworks_Outputs.f90" +subroutine Drawworks_Outputs + + Use CSounds + use CHook + use SimulationVariables + use CWarnings + use SimulationVariables !@ + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables + + IMPLICIT NONE + + + + data%Equipments%DrillingConsole%DWBLWR = data%State%Drawworks%BLWR + + Call SetSoundBlowerDW( data%State%Drawworks%SoundBlower ) !.true. or .false. + Call SetSoundDwRev( data%State%Drawworks%SoundRev ) ![rpm] ??? or rad/s, Integer + Call SetSoundDwFw( data%State%Drawworks%SoundFw ) ![rpm] , Integer + Call SetSoundCrownCollision( data%State%Drawworks%SoundCrownCollision ) !.true. or .false. + Call SetSoundFloorCollision( data%State%Drawworks%SoundFloorCollision ) !.true. or .false. + + if (data%State%Drawworks%CrownCollision==1) then + Call Activate_CrownCollision() + end if + if (data%State%Drawworks%FloorCollision==1) then + Call Activate_FloorCollision() + end if + + Call Set_HookHeight( real(data%State%Drawworks%Hook_Height_final) ) ![ft] + data%State%Drawworks%TDHookHeight = data%State%Drawworks%Hook_Height_final ![ft] +!!data%State%Drawworks%HookHeight_graph_output + +!data%Equipments%DrillingConsole%ParkingBrakeLed = 0 ! in Drawworks_Inputs + + + + +end subroutine Drawworks_Outputs diff --git a/Equipments/DrillingConsole_ScrLEDs.f90 b/Equipments/DrillingConsole_ScrLEDs.f90 index 829b18d..83544b8 100644 --- a/Equipments/DrillingConsole_ScrLEDs.f90 +++ b/Equipments/DrillingConsole_ScrLEDs.f90 @@ -10,38 +10,38 @@ subroutine DrillingConsole_ScrLEDs !===> Torque Limit - data%EquipmentControl%DrillingConsole%RTTorqueLimitGauge = sngl(1-data%State%RTable%TorqueLimitGaugeMalf)*(data%EquipmentControl%DrillingConsole%RTTorqueLimitKnob/10.d0)*7000.d0 !tabdile bazeye 0-10 be 0-7000 taghribi anjam shode, baadan eslah shavad ?????? + data%Equipments%DrillingConsole%RTTorqueLimitGauge = sngl(1-data%State%RTable%TorqueLimitGaugeMalf)*(data%Equipments%DrillingConsole%RTTorqueLimitKnob/10.d0)*7000.d0 !tabdile bazeye 0-10 be 0-7000 taghribi anjam shode, baadan eslah shavad ?????? - if((any(data%EquipmentControl%DrillingConsole%AssignmentSwitch==(/1,2,3,4,8,9,10,11/)))) then + if((any(data%Equipments%DrillingConsole%AssignmentSwitch==(/1,2,3,4,8,9,10,11/)))) then - data%EquipmentControl%DrillingConsole%SCR1LED=1 - data%EquipmentControl%DrillingConsole%SCR2LED=1 - data%EquipmentControl%DrillingConsole%SCR3LED=1 - data%EquipmentControl%DrillingConsole%SCR4LED=1 + data%Equipments%DrillingConsole%SCR1LED=1 + data%Equipments%DrillingConsole%SCR2LED=1 + data%Equipments%DrillingConsole%SCR3LED=1 + data%Equipments%DrillingConsole%SCR4LED=1 - else if (data%EquipmentControl%DrillingConsole%AssignmentSwitch == 5) then + else if (data%Equipments%DrillingConsole%AssignmentSwitch == 5) then - data%EquipmentControl%DrillingConsole%SCR1LED=1 - data%EquipmentControl%DrillingConsole%SCR2LED=1 - data%EquipmentControl%DrillingConsole%SCR3LED=0 - data%EquipmentControl%DrillingConsole%SCR4LED=1 + data%Equipments%DrillingConsole%SCR1LED=1 + data%Equipments%DrillingConsole%SCR2LED=1 + data%Equipments%DrillingConsole%SCR3LED=0 + data%Equipments%DrillingConsole%SCR4LED=1 - else if (data%EquipmentControl%DrillingConsole%AssignmentSwitch == 7) then + else if (data%Equipments%DrillingConsole%AssignmentSwitch == 7) then - data%EquipmentControl%DrillingConsole%SCR1LED=1 - data%EquipmentControl%DrillingConsole%SCR2LED=1 - data%EquipmentControl%DrillingConsole%SCR3LED=1 - data%EquipmentControl%DrillingConsole%SCR4LED=0 + data%Equipments%DrillingConsole%SCR1LED=1 + data%Equipments%DrillingConsole%SCR2LED=1 + data%Equipments%DrillingConsole%SCR3LED=1 + data%Equipments%DrillingConsole%SCR4LED=0 else - data%EquipmentControl%DrillingConsole%SCR1LED=0 - data%EquipmentControl%DrillingConsole%SCR2LED=0 - data%EquipmentControl%DrillingConsole%SCR3LED=0 - data%EquipmentControl%DrillingConsole%SCR4LED=0 + data%Equipments%DrillingConsole%SCR1LED=0 + data%Equipments%DrillingConsole%SCR2LED=0 + data%Equipments%DrillingConsole%SCR3LED=0 + data%Equipments%DrillingConsole%SCR4LED=0 end if diff --git a/Equipments/DrillingConsole_ScrLEDs.i90 b/Equipments/DrillingConsole_ScrLEDs.i90 new file mode 100644 index 0000000..7b9763f --- /dev/null +++ b/Equipments/DrillingConsole_ScrLEDs.i90 @@ -0,0 +1,52 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/DrillingConsole_ScrLEDs.f90" +subroutine DrillingConsole_ScrLEDs + + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables + use SimulationVariables !@ + + IMPLICIT NONE + + + +!===> Torque Limit + data%Equipments%DrillingConsole%RTTorqueLimitGauge = sngl(1-data%State%RTable%TorqueLimitGaugeMalf)*(data%Equipments%DrillingConsole%RTTorqueLimitKnob/10.d0)*7000.d0 !tabdile bazeye 0-10 be 0-7000 taghribi anjam shode, baadan eslah shavad ?????? + + + + + + if((any(data%Equipments%DrillingConsole%AssignmentSwitch==(/1,2,3,4,8,9,10,11/)))) then + + data%Equipments%DrillingConsole%SCR1LED=1 + data%Equipments%DrillingConsole%SCR2LED=1 + data%Equipments%DrillingConsole%SCR3LED=1 + data%Equipments%DrillingConsole%SCR4LED=1 + + else if (data%Equipments%DrillingConsole%AssignmentSwitch == 5) then + + data%Equipments%DrillingConsole%SCR1LED=1 + data%Equipments%DrillingConsole%SCR2LED=1 + data%Equipments%DrillingConsole%SCR3LED=0 + data%Equipments%DrillingConsole%SCR4LED=1 + + else if (data%Equipments%DrillingConsole%AssignmentSwitch == 7) then + + data%Equipments%DrillingConsole%SCR1LED=1 + data%Equipments%DrillingConsole%SCR2LED=1 + data%Equipments%DrillingConsole%SCR3LED=1 + data%Equipments%DrillingConsole%SCR4LED=0 + + else + data%Equipments%DrillingConsole%SCR1LED=0 + data%Equipments%DrillingConsole%SCR2LED=0 + data%Equipments%DrillingConsole%SCR3LED=0 + data%Equipments%DrillingConsole%SCR4LED=0 + + end if + + + + +end subroutine DrillingConsole_ScrLEDs diff --git a/Equipments/MudSystem/Disconnecting_Pipe.f90 b/Equipments/MudSystem/Disconnecting_Pipe.f90 index 9acd7d4..5baf6fe 100644 --- a/Equipments/MudSystem/Disconnecting_Pipe.f90 +++ b/Equipments/MudSystem/Disconnecting_Pipe.f90 @@ -7,7 +7,7 @@ use SimulationVariables !@@@ use SimulationVariables use SimulationVariables !@ ! !use CTanks - !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables use KickVARIABLESModule diff --git a/Equipments/MudSystem/Disconnecting_Pipe.i90 b/Equipments/MudSystem/Disconnecting_Pipe.i90 new file mode 100644 index 0000000..247886b --- /dev/null +++ b/Equipments/MudSystem/Disconnecting_Pipe.i90 @@ -0,0 +1,111 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/Disconnecting_Pipe.f90" +subroutine DisconnectingPipe ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + use SimulationVariables !@ +! !use CTanks +!@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + USE TD_DrillStemComponents + use OperationScenariosModule + Use CUnityOutputs + USE CManifolds + + implicit none + + Real(8) ExcessMudVolume, ExcessMudVolume_Remained + write(*,*) 'DisconnectingPipe' + +!TD_RemoveVolume= TD_RemoveVolume* 7.48051948 ! ft^3 to gal + + ExcessMudVolume= sum(data%State%MudSystem%St_MudDischarged_Volume%Array(:)) - sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:data%State%F_Counts%StringIntervalCounts)) + + +! ======if(ExcessMudVolume <= 0.) No Modification Needed Because Removed Pipe was Empty===== + + if (Get_KellyConnection() == KELLY_CONNECTION_NOTHING .and. Manifold%Valve(56)%Status == .False.) ExcessMudVolume= 0.d0 !Valve(56)%Status == .False. :: safety valve installed + + if (ExcessMudVolume > 0.) then + + if ( Manifold%Valve(53)%Status == .true. ) then + data%State%MudSystem%MudBucketVolume= ExcessMudVolume + else + data%State%MudSystem%MudBucketVolume= 0.0 + endif + + + + + +!========================Flow Disconnect Unity Input Signals================= + +!if ( Get_JointConnectionPossible() == .false. ) then + if (Get_KellyConnection() == KELLY_CONNECTION_NOTHING) then + Call Set_FlowKellyDisconnect(.true.) + else + Call Set_FlowPipeDisconnect(.true.) + endif +!endif + + + +!====================Flow Disconnect Unity Input Signals-End================= + + + + +!========================Disconnecting Pipe from the String================= + + ExcessMudVolume_Remained= ExcessMudVolume ! ft^3 to gal + + + imud=1 + + Do + + if(data%State%MudSystem%St_MudDischarged_Volume%Array(imud) < ExcessMudVolume_Remained) then + ExcessMudVolume_Remained= ExcessMudVolume_Remained- data%State%MudSystem%St_MudDischarged_Volume%Array(imud) + call data%State%MudSystem%St_MudDischarged_Volume%Remove (imud) + call data%State%MudSystem%St_Mud_Backhead_X%Remove (imud) + call data%State%MudSystem%St_Mud_Backhead_section%Remove (imud) + call data%State%MudSystem%St_Mud_Forehead_X%Remove (imud) + call data%State%MudSystem%St_Mud_Forehead_section%Remove (imud) + call data%State%MudSystem%St_Density%Remove (imud) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%Remove (imud) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Remove (imud) + call data%State%MudSystem%St_MudOrKick%Remove (imud) + + elseif(data%State%MudSystem%St_MudDischarged_Volume%Array(imud) > ExcessMudVolume_Remained) then + data%State%MudSystem%St_MudDischarged_Volume%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- ExcessMudVolume_Remained + exit + + else !(St_MudDischarged_Volume%Array(imud) == ExcessMudVolume_Remained) + call data%State%MudSystem%St_MudDischarged_Volume%Remove (imud) + call data%State%MudSystem%St_Mud_Backhead_X%Remove (imud) + call data%State%MudSystem%St_Mud_Backhead_section%Remove (imud) + call data%State%MudSystem%St_Mud_Forehead_X%Remove (imud) + call data%State%MudSystem%St_Mud_Forehead_section%Remove (imud) + call data%State%MudSystem%St_Density%Remove (imud) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%Remove (imud) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Remove (imud) + call data%State%MudSystem%St_MudOrKick%Remove (imud) + exit + + endif + + enddo + + + + +!=================Disconnecting Pipe from the String - End=================== + endif + + + end subroutine DisconnectingPipe diff --git a/Equipments/MudSystem/Elements_Creation.f90 b/Equipments/MudSystem/Elements_Creation.f90 index cad138b..640d8f7 100644 --- a/Equipments/MudSystem/Elements_Creation.f90 +++ b/Equipments/MudSystem/Elements_Creation.f90 @@ -16,7 +16,7 @@ use SimulationVariables !@@@ !use CChokeManifoldVariables use SimulationVariables ! !use CTanks - !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables use KickVARIABLESModule diff --git a/Equipments/MudSystem/Elements_Creation.i90 b/Equipments/MudSystem/Elements_Creation.i90 new file mode 100644 index 0000000..00c07b0 --- /dev/null +++ b/Equipments/MudSystem/Elements_Creation.i90 @@ -0,0 +1,281 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/Elements_Creation.f90" +subroutine ElementsCreation ! is called in subroutine Fluid_Flow_Solver + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!use CDataDisplayConsole +!@ use ConfigurationVariables , StandPipePressureDataDisplay=>StandPipePressure +!use CManifolds + use SimulationVariables !@ + USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!use CChokeManifoldVariables + use SimulationVariables +! !use CTanks +!@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + use CError + + implicit none + + integer jelement, jmud, jsection,ielement,i + integer jopelement,jopmud,jopsection,iisection,isection,OpSection + +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + + if(allocated(data%State%MudSystem%Xstart_PipeSection)) deallocate(data%State%MudSystem%Xstart_PipeSection) + if(allocated(data%State%MudSystem%Xend_PipeSection)) deallocate(data%State%MudSystem%Xend_PipeSection) + if(allocated(data%State%MudSystem%PipeSection_VolumeCapacity)) deallocate(data%State%MudSystem%PipeSection_VolumeCapacity) + if(allocated(data%State%MudSystem%Area_PipeSectionFt)) deallocate(data%State%MudSystem%Area_PipeSectionFt) + if(allocated(data%State%MudSystem%GeoType)) deallocate(data%State%MudSystem%GeoType) + if(allocated(data%State%MudSystem%OD_PipeSectionInch)) deallocate(data%State%MudSystem%OD_PipeSectionInch) + if(allocated(data%State%MudSystem%ID_PipeSectionInch)) deallocate(data%State%MudSystem%ID_PipeSectionInch) + if(allocated(data%State%MudSystem%Angle_PipeSection)) deallocate(data%State%MudSystem%Angle_PipeSection) + + if(allocated(data%State%MudSystem%Xstart_OpSection)) deallocate(data%State%MudSystem%Xstart_OpSection) + if(allocated(data%State%MudSystem%Xend_OpSection)) deallocate(data%State%MudSystem%Xend_OpSection) + if(allocated(data%State%MudSystem%OpSection_VolumeCapacity)) deallocate(data%State%MudSystem%OpSection_VolumeCapacity) + if(allocated(data%State%MudSystem%Area_OpSectionFt)) deallocate(data%State%MudSystem%Area_OpSectionFt) + if(allocated(data%State%MudSystem%GeoTypeOp)) deallocate(data%State%MudSystem%GeoTypeOp) + if(allocated(data%State%MudSystem%OD_OpSectionInch)) deallocate(data%State%MudSystem%OD_OpSectionInch) + if(allocated(data%State%MudSystem%ID_OpSectionInch)) deallocate(data%State%MudSystem%ID_OpSectionInch) + if(allocated(data%State%MudSystem%Angle_OpSection)) deallocate(data%State%MudSystem%Angle_OpSection) + + + +ALLOCATE (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+data%State%F_Counts%AnnulusIntervalCounts),data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts+data%State%F_Counts%AnnulusIntervalCounts) & + ,data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+data%State%F_Counts%AnnulusIntervalCounts),data%State%MudSystem%Area_PipeSectionFt(data%State%F_Counts%StringIntervalCounts+data%State%F_Counts%AnnulusIntervalCounts), & + data%State%MudSystem%GeoType(data%State%F_Counts%StringIntervalCounts+data%State%F_Counts%AnnulusIntervalCounts),data%State%MudSystem%OD_PipeSectionInch(data%State%F_Counts%StringIntervalCounts+data%State%F_Counts%AnnulusIntervalCounts),data%State%MudSystem%ID_PipeSectionInch(data%State%F_Counts%StringIntervalCounts+data%State%F_Counts%AnnulusIntervalCounts)) + + +ALLOCATE (data%State%MudSystem%Xstart_OpSection(data%State%F_Counts%BottomHoleIntervalCounts),data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts) & + ,data%State%MudSystem%OpSection_VolumeCapacity(data%State%F_Counts%BottomHoleIntervalCounts),data%State%MudSystem%Area_OpSectionFt(data%State%F_Counts%BottomHoleIntervalCounts), & + data%State%MudSystem%GeoTypeOp(data%State%F_Counts%BottomHoleIntervalCounts),data%State%MudSystem%OD_OpSectionInch(data%State%F_Counts%BottomHoleIntervalCounts),data%State%MudSystem%ID_OpSectionInch(data%State%F_Counts%BottomHoleIntervalCounts)) + + data%State%MudSystem%OpSection=0 + data%State%MudSystem%isection=0 + + + DO iisection=1, data%State%F_Counts%IntervalsTotalCounts + IF (data%State%F_Interval(iisection)%GeoType == 1) THEN + data%State%MudSystem%OpSection= data%State%MudSystem%OpSection+1 + data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%OpSection)= (data%State%F_Interval(iisection)%StartDepth) + data%State%MudSystem%Xend_OpSection(data%State%MudSystem%OpSection)= (data%State%F_Interval(iisection)%EndDepth) + data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%OpSection)= PII*((data%State%F_Interval(iisection)%OD/12.0d0)**2-(data%State%F_Interval(iisection)%ID/12.0d0)**2)/4.0d0 !D(in), AREA(ft^2) + data%State%MudSystem%OD_OpSectionInch(data%State%MudSystem%OpSection)= (data%State%F_Interval(iisection)%OD) + data%State%MudSystem%ID_OpSectionInch(data%State%MudSystem%OpSection)= (data%State%F_Interval(iisection)%ID) !REAL(data%State%F_Interval(iisection)%Volume) + data%State%MudSystem%GeoTypeOp(data%State%MudSystem%OpSection)= data%State%F_Interval(iisection)%GeoType ! niaz nist ehtemalan +!Angle_OpSection(OpSection)= data%State%F_Interval(iisection)%Angle +!write(*,*) 'iisection=' , iisection +!write(*,*) 'StartDepth=' , data%State%F_Interval(iisection)%StartDepth +!write(*,*) 'EndDepth=' , data%State%F_Interval(iisection)%EndDepth +!write(*,*) 'OD=' , data%State%F_Interval(iisection)%OD +!write(*,*) 'ID=' , data%State%F_Interval(iisection)%ID + ELSE + data%State%MudSystem%isection= data%State%MudSystem%isection+1 + data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)= (data%State%F_Interval(iisection)%StartDepth) +!write(*,*) 'data%State%F_Interval(iisection)%StartDepth=' , data%State%F_Interval(iisection)%StartDepth + data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)= (data%State%F_Interval(iisection)%EndDepth) +!write(*,*) 'data%State%F_Interval(iisection)%EndDepth=' , data%State%F_Interval(iisection)%EndDepth + + data%State%MudSystem%OD_PipeSectionInch(data%State%MudSystem%isection)= (data%State%F_Interval(iisection)%OD) + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%isection)= PII*((data%State%F_Interval(iisection)%OD/12.0d0)**2-(data%State%F_Interval(iisection)%ID/12.0d0)**2)/4.0d0 !D(in), AREA(ft^2) + data%State%MudSystem%ID_PipeSectionInch(data%State%MudSystem%isection)= (data%State%F_Interval(iisection)%ID) +!PipeSection_VolumeCapacity(isection)= Area_PipeSectionFt(isection)* ABS(Xend_PipeSection(isection)-Xstart_PipeSection(isection))* 7.48051948 !REAL(data%State%F_Interval(iisection)%Volume) ! (gal) + data%State%MudSystem%GeoType(data%State%MudSystem%isection)= data%State%F_Interval(iisection)%GeoType +!Angle_PipeSection(isection)= data%State%F_Interval(iisection)%Angle + ENDIF + + ENDDO + + + + call data%State%MudSystem%Xstart_MudElement%Empty() + call data%State%MudSystem%Xstart_MudElement%Add(data%State%MudSystem%Xstart_PipeSection(1)) + + + call data%State%MudSystem%Xstart_OpMudElement%Empty() + call data%State%MudSystem%Xstart_OpMudElement%Add(data%State%MudSystem%Xstart_OpSection(1)) + + + call data%State%MudSystem%TVDstart_MudElement%Empty() + call TVD_Calculator(data%State%MudSystem%Xstart_PipeSection(1),data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%TVDstart_MudElement%Add(data%State%MudSystem%MudCircVerticalDepth) + + + call data%State%MudSystem%TVDstart_OpMudElement%Empty() + call TVD_Calculator(data%State%MudSystem%Xstart_OpSection(1),data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%TVDstart_OpMudElement%Add(data%State%MudSystem%MudCircVerticalDepth) + + + + data%State%MudSystem%NoPipeSections= data%State%MudSystem%isection ! sections in string and annulus(GeoType 0 & 2) + + + DO OpSection= 1,data%State%F_Counts%BottomHoleIntervalCounts + data%State%MudSystem%OpSection_VolumeCapacity(OpSection)= data%State%MudSystem%Area_OpSectionFt(OpSection)* ABS(data%State%MudSystem%Xend_OpSection(OpSection)-data%State%MudSystem%Xstart_OpSection(OpSection))* 7.48051948d0 !REAL(data%State%F_Interval(iisection)%Volume) + ENDDO + data%State%MudSystem%OpSection=OpSection + DO isection= 1,data%State%MudSystem%NoPipeSections + data%State%MudSystem%PipeSection_VolumeCapacity(isection)= data%State%MudSystem%Area_PipeSectionFt(isection)* ABS(data%State%MudSystem%Xend_PipeSection(isection)-data%State%MudSystem%Xstart_PipeSection(isection))* 7.48051948d0 !REAL(data%State%F_Interval(iisection)%Volume) ! (gal) + ENDDO + data%State%MudSystem%isection = isection + + + +!types: Mud= 0 Kick=1 + +!=========================================== + if (data%State%MudSystem%FirstMudSet==0) then + call data%State%MudSystem%Hz_MudDischarged_Volume%AddToFirst(data%State%MudSystem%PipeSection_VolumeCapacity(1)) !startup initial + call data%State%MudSystem%Hz_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(1)) + call data%State%MudSystem%Hz_Mud_Backhead_section%AddToFirst (1) + call data%State%MudSystem%Hz_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xend_PipeSection(1)) + call data%State%MudSystem%Hz_Mud_Forehead_section%AddToFirst (1) + call data%State%MudSystem%Hz_Density%AddToFirst (data%Configuration%Mud%ActiveDensity) ! initial(ppg) + call data%State%MudSystem%Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Hz_MudOrKick%AddToFirst (0) + + + call data%State%MudSystem%St_MudDischarged_Volume%AddToFirst(sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:data%State%F_Counts%StringIntervalCounts))) !startup initial + call data%State%MudSystem%St_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Backhead_section%AddToFirst (2) + call data%State%MudSystem%St_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts)) + call data%State%MudSystem%St_Mud_Forehead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts) + call data%State%MudSystem%St_Density%AddToFirst (data%Configuration%Mud%ActiveDensity) ! initial(ppg) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%St_MudOrKick%AddToFirst (0) + + + call data%State%MudSystem%Ann_MudDischarged_Volume%AddToFirst(sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections))) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections)) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddToFirst (data%State%MudSystem%NoPipeSections) + call data%State%MudSystem%Ann_Density%AddToFirst (data%Configuration%Mud%ActiveDensity) ! initial(ppg) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddToFirst (0) + call data%State%MudSystem%Ann_CuttingMud%AddToFirst (0) + + data%State%MudSystem%OldPosition= data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts) + + data%State%MudSystem%OldAnnulusCapacity= sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + + + call data%State%MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst(data%State%MudSystem%ChokeLine_VolumeCapacity) + call data%State%MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1) + call data%State%MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (data%Configuration%BopStack%ChokeLineLength) + call data%State%MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1) + call data%State%MudSystem%ChokeLine_Density%AddToFirst (data%Configuration%Mud%ActiveDensity) ! initial(ppg) + call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_MudOrKick%AddToFirst (0) + + + call data%State%MudSystem%Op_MudDischarged_Volume%AddToFirst (sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts))) + call data%State%MudSystem%Op_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_OpSection(1)) + call data%State%MudSystem%Op_Mud_Backhead_section%AddToFirst (1) + call data%State%MudSystem%Op_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts)) + call data%State%MudSystem%Op_Mud_Forehead_section%AddToFirst (data%State%F_Counts%BottomHoleIntervalCounts) + call data%State%MudSystem%Op_Density%AddToFirst (data%Configuration%Mud%ActiveDensity) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddToFirst (0) + +!F_StringIntervalCountsOld= F_StringIntervalCounts ! is used for adding new pipe to string + data%State%MudSystem%F_StringIntervalCounts_Old= data%State%F_Counts%StringIntervalCounts ! is used for adding new pipe to string + + + data%State%MudSystem%FirstMudSet= 1 + endif + + +!===================== Trip Detection ================ + +!DeltaVolumeOp > 0 : Trip in +!DeltaVolumeOp < 0 : Trip out + + + data%State%MudSystem%DeltaVolumeOp= ((data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts)-data%State%MudSystem%OldPosition)*PII*((data%State%MudSystem%OD_PipeSectionInch(data%State%F_Counts%StringIntervalCounts+1)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal ! D(in) + data%State%MudSystem%DeltaVolumeOp = INT(data%State%MudSystem%DeltaVolumeOp * 100000.d0) / 100000.d0 + + data%State%MudSystem%DeltaVolumePipe= ((data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts)-data%State%MudSystem%OldPosition)*PII*((data%State%MudSystem%ID_PipeSectionInch(data%State%F_Counts%StringIntervalCounts+data%State%F_Counts%AnnulusIntervalCounts)/12.0d0)**2)/4.0d0)* 7.48051948d0! ft^3 to gal + data%State%MudSystem%DeltaVolumePipe = INT(data%State%MudSystem%DeltaVolumePipe * 100000.d0) / 100000.d0 + +!DeltaVolumeAnnulusCapacity= ((Xend_PipeSection(data%State%F_Counts%StringIntervalCounts)-OldPosition))*Area_PipeSectionFt(NoPipeSections)* 7.48051948d0! ft^3 to gal + KickVARIABLES%DrillStringSpeed = (data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts)-data%State%MudSystem%OldPosition) / 0.1 + + data%State%MudSystem%DeltaVolumeAnnulusCapacity= sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) - data%State%MudSystem%OldAnnulusCapacity + + +!write(*,*) 'DeltaVolumeAnnulusCapacity= ' , DeltaVolumeAnnulusCapacity + +!write(*,*) 'DeltaVolumePipe=' , DeltaVolumePipe +!write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp +! +! +!write(*,*) 'Bit here=' , Xend_PipeSection(data%State%F_Counts%StringIntervalCounts) + + + + + data%State%MudSystem%OldAnnulusCapacity= sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + + data%State%MudSystem%OldPosition= data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts) + +! Needed for trip in or out: + if (data%State%MudSystem%Hz_Mud_Backhead_X%Length() == 0) then + + CALL ErrorStop('Hz_Mud_Backhead_X Length is 0') + endif + + + data%State%MudSystem%Hz_Mud_Backhead_X%Array(1)= data%State%MudSystem%Xstart_PipeSection(1) + data%State%MudSystem%Hz_Mud_Backhead_section%Array(1)= 1 + + data%State%MudSystem%AddedElementsToString = data%State%F_Counts%StringIntervalCounts - data%State%MudSystem%F_StringIntervalCounts_Old + data%State%MudSystem%St_Mud_Backhead_X%Array(1)= data%State%MudSystem%Xstart_PipeSection(2) + data%State%MudSystem%St_Mud_Backhead_section%Array(1)= 2 + data%State%MudSystem%Ann_Mud_Backhead_X%Array(1)= data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1) + data%State%MudSystem%Ann_Mud_Backhead_section%Array(1)= data%State%F_Counts%StringIntervalCounts+1 + data%State%MudSystem%Op_Mud_Backhead_X%Array(1)= data%State%MudSystem%Xstart_OpSection(1) + data%State%MudSystem%Op_Mud_Backhead_section%Array(1)= 1 + data%State%MudSystem%ChokeLine_Mud_Backhead_X%Array(1)= 0. + data%State%MudSystem%ChokeLine_Mud_Backhead_section%Array(1)= 1 + + + data%State%MudSystem%F_StringIntervalCounts_Old= data%State%F_Counts%StringIntervalCounts +!write(*,*) 'Xstart_PipeSection(2)' , Xstart_PipeSection(2) +!write(*,*) 'Xend_PipeSection(1)' , Xend_PipeSection(1) + + +!=================================================== + +! +!DeltaWellCap= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) - WellCapOld +!WellCapOld= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) + sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) +!write(*,*) 'DeltaWellCap=' , DeltaWellCap +! +! +! +!DeltaAnnCap= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) - AnnCapOld +!AnnCapOld= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +!write(*,*) 'DeltaAnnCap=' , DeltaAnnCap + + end subroutine ElementsCreation + + + + diff --git a/Equipments/MudSystem/FillingWell_By_BellNipple.f90 b/Equipments/MudSystem/FillingWell_By_BellNipple.f90 index 7786f70..d3ec6fe 100644 --- a/Equipments/MudSystem/FillingWell_By_BellNipple.f90 +++ b/Equipments/MudSystem/FillingWell_By_BellNipple.f90 @@ -10,7 +10,7 @@ use SimulationVariables !@@@ use SimulationVariables use SimulationVariables !@ !use CTanks - !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables use KickVARIABLESModule diff --git a/Equipments/MudSystem/FillingWell_By_BellNipple.i90 b/Equipments/MudSystem/FillingWell_By_BellNipple.i90 new file mode 100644 index 0000000..b2363d9 --- /dev/null +++ b/Equipments/MudSystem/FillingWell_By_BellNipple.i90 @@ -0,0 +1,218 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/FillingWell_By_BellNipple.f90" +subroutine FillingWell_By_BellNipple ! is called in subroutine CirculationCodeSelect + +! this subroutine is for lines: 1) BellNippleToWell-NonFullWell : data%State%MUD(8)%Q +! 2) PumpsToWell_KillLine : data%State%MUD(10)%Q + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + use SimulationVariables !@ +!use CTanks +!@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + + implicit none + + real(8) deltaV,Xposition,FillingDensity + + integer kloc,SectionPosition + + + + +! Well Is Not Full + + + + if (data%State%MudSystem%Ann_MudOrKick%Last() == 104) then ! Last Element is air we must observe: Ann_Mud_Forehead_X%Last()=0.0 + + write(*,*) 'FillingWell_By_BellNipple-Last Element is air' + +!write(*,*) '*Ann_Mud_Forehead_X%Last()=' , Ann_Mud_Forehead_X%Last() +!write(*,*) '*Ann_MudOrKick%Last()=' , Ann_MudOrKick%Last() + + + + FillingDensity= data%State%MudSystem%BellNippleDensity + +!**************************** + if ( data%State%MudSystem%Ann_MudDischarged_Volume%Last() > (((data%State%MUD(8)%Q+data%State%MUD(10)%Q)/60.)*data%State%MudSystem%DeltaT_Mudline)) then ! air baghi mimune + + kloc= data%State%MudSystem%Ann_MudDischarged_Volume%Length()-1 + + + + deltaV= ((data%State%MUD(8)%Q+data%State%MUD(10)%Q)/60.)*data%State%MudSystem%DeltaT_Mudline + + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_MudDischarged_Volume%Length())= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_MudDischarged_Volume%Length()) - deltaV + + +!========================ANNULUS ENTRANCE==================== + + if (ABS(data%State%MudSystem%Ann_Density%Array(kloc) - FillingDensity) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped + call data%State%MudSystem%Ann_Density%AddTo (kloc, FillingDensity) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (kloc, 0.0d0) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (kloc, 0.0d0) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (kloc, 1) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (kloc, 0.0d0) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (kloc, data%State%MudSystem%NoPipeSections) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (kloc, 0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (kloc, 0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddTo (kloc, 0) + call data%State%MudSystem%Ann_CuttingMud%AddTo (kloc,0) + +!AnnulusSuctionDensity_Old= Hz_Density_Utube + endif + +!========================ANNULUS==================== + + data%State%MudSystem%Ann_MudDischarged_Volume%Array(kloc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(kloc)+ deltaV !(gal) + + + + else ! ( Ann_MudDischarged_Volume%Last() <= (((data%State%MUD(8)%Q+data%State%MUD(10)%Q)/60.)*DeltaT_Mudline)) then ! air baghi namune + + + + + kloc= data%State%MudSystem%Ann_MudDischarged_Volume%Length()-1 + + deltaV= data%State%MudSystem%Ann_MudDischarged_Volume%Last() + + + + if (ABS(data%State%MudSystem%Ann_Density%Array(kloc)-FillingDensity)< data%State%MudSystem%DensityMixTol .and. data%State%MudSystem%Ann_CuttingMud%Array(kloc)==0) then ! .OR. (Ann_MudDischarged_Volume%Array(kloc)< 42.) ) then ! 1-Pockets are Merged + data%State%MudSystem%Ann_Density%Array(kloc)= (data%State%MudSystem%Ann_Density%Array(kloc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(kloc)+FillingDensity*deltaV)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(kloc)+deltaV) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(kloc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(kloc)+deltaV + data%State%MudSystem%Ann_Mud_Forehead_X%Array(kloc)= data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections) + data%State%MudSystem%Ann_Mud_Forehead_section%Array(kloc)= data%State%MudSystem%NoPipeSections +!Ann_Mud_Backhead_X%Array(kloc)= no change +!Ann_Mud_Backhead_section%Array(kloc)= no change + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(kloc)= (0.0) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(kloc)= (0.0) + + call data%State%MudSystem%Ann_MudDischarged_Volume%Remove (kloc+1) + call data%State%MudSystem%Ann_Mud_Backhead_X%Remove (kloc+1) + call data%State%MudSystem%Ann_Mud_Backhead_section%Remove (kloc+1) + call data%State%MudSystem%Ann_Mud_Forehead_X%Remove (kloc+1) + call data%State%MudSystem%Ann_Mud_Forehead_section%Remove (kloc+1) + call data%State%MudSystem%Ann_Density%Remove (kloc+1) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Remove (kloc+1) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (kloc+1) + call data%State%MudSystem%Ann_MudOrKick%Remove (kloc+1) + call data%State%MudSystem%Ann_CuttingMud%Remove (kloc+1) + + + else ! 2-Merging conditions are not meeted, so new pocket== air is replaced with filling mud + data%State%MudSystem%Ann_Density%Array(kloc+1) =FillingDensity + data%State%MudSystem%Ann_MudOrKick%Array(kloc+1)= 0 + + endif + + + endif + +! end condition (Ann_MudOrKick%Last() == 104) ! Last Element is air + +!********************************************************************************************************************************************************** + + + + + else ! (Ann_MudOrKick%Last() == 0) then ! Last Element is NOT air- so we must observe: Ann_Mud_Forehead_X%Last()/=0.0 + +!write(*,*) 'FillingWell_By_BellNipple-Last Element is NOT air' +! +!write(*,*) '*Ann_Mud_Forehead_X%Last()=' , Ann_Mud_Forehead_X%Last() +!write(*,*) '*Ann_MudOrKick%Last()=' , Ann_MudOrKick%Last() + + + deltaV= ((data%State%MUD(8)%Q+data%State%MUD(10)%Q)/60.)*data%State%MudSystem%DeltaT_Mudline + + kloc= data%State%MudSystem%Ann_MudDischarged_Volume%Length() + + + + + +!========================ANNULUS ENTRANCE==================== + + if (ABS(data%State%MudSystem%Ann_Density%Last() - FillingDensity) >= data%State%MudSystem%DensityMixTol .or. data%State%MudSystem%Ann_CuttingMud%Last()==1) then ! .OR. (Ann_MudDischarged_Volume%Array(kloc)>42.) ) then ! new mud is pumped + Xposition= data%State%MudSystem%Ann_Mud_Forehead_X%Last() + SectionPosition= data%State%MudSystem%Ann_Mud_Forehead_section%Last() + call data%State%MudSystem%Ann_Density%Add (FillingDensity) + call data%State%MudSystem%Ann_MudDischarged_Volume%Add (0.0d0) + call data%State%MudSystem%Ann_Mud_Forehead_X%Add (Xposition) + call data%State%MudSystem%Ann_Mud_Forehead_section%Add (SectionPosition) + call data%State%MudSystem%Ann_Mud_Backhead_X%Add (Xposition) + call data%State%MudSystem%Ann_Mud_Backhead_section%Add (SectionPosition) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Add (0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Add (0.0d0) + call data%State%MudSystem%Ann_MudOrKick%Add (0) + call data%State%MudSystem%Ann_CuttingMud%Add (0) + +!AnnulusSuctionDensity_Old= Hz_Density_Utube +!endif + +!========================ANNULUS==================== + + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_MudDischarged_Volume%Length())= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_MudDischarged_Volume%Length())+ deltaV !(gal) + + + else ! Merged with last Mud + data%State%MudSystem%Ann_Density%Array(kloc)= (data%State%MudSystem%Ann_Density%Array(kloc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(kloc)+FillingDensity*deltaV)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(kloc)+deltaV) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(kloc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(kloc)+deltaV +!Ann_Mud_Forehead_X%Array(kloc)= Xend_PipeSection(NoPipeSections) +!Ann_Mud_Forehead_section%Array(kloc)= NoPipeSections +!Ann_Mud_Backhead_X%Array(kloc)= no change +!Ann_Mud_Backhead_section%Array(kloc)= no change + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(kloc)= (0.0) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(kloc)= (0.0) + endif + + + + + + + endif + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + end subroutine FillingWell_By_BellNipple diff --git a/Equipments/MudSystem/Kick_Expansion_and_Contraction.f90 b/Equipments/MudSystem/Kick_Expansion_and_Contraction.f90 index 3540ffa..2aa01c7 100644 --- a/Equipments/MudSystem/Kick_Expansion_and_Contraction.f90 +++ b/Equipments/MudSystem/Kick_Expansion_and_Contraction.f90 @@ -6,7 +6,7 @@ subroutine Kick_Expansion ! is called in subroutine CirculationCodeSelect use SimulationVariables !@@@ use SimulationVariables use SimulationVariables !@ - !use CTanks !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !use CTanks !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables USE CReservoirVariables @@ -130,7 +130,7 @@ subroutine Kick_Contraction ! is called in subroutine CirculationCodeSelect use SimulationVariables !@@@ use SimulationVariables use SimulationVariables !@ - !use CTanks !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !use CTanks !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables USE CReservoirVariables diff --git a/Equipments/MudSystem/Kick_Expansion_and_Contraction.i90 b/Equipments/MudSystem/Kick_Expansion_and_Contraction.i90 new file mode 100644 index 0000000..9fd18d1 --- /dev/null +++ b/Equipments/MudSystem/Kick_Expansion_and_Contraction.i90 @@ -0,0 +1,237 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/Kick_Expansion_and_Contraction.f90" +subroutine Kick_Expansion ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + use SimulationVariables !@ +!use CTanks !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + USE CReservoirVariables + use KickVARIABLESModule + + + implicit none + real(8) ExpansionVolume + +!write(*,*) 'Kick Expansion' + + ExpansionVolume= GasPocketDeltaVol%Array(data%State%MudSystem%NewInfluxNumber - data%State%MudSystem%KickNumber + 1) * 7.48 + +IF ( data%State%MudSystem%Kickexpansion_DueToMudLost ) ExpansionVolume = ((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) + + +!============================== kick zire mate bashad ============================== + + if (data%State%MudSystem%Op_KickLoc > 0 .and. data%State%MudSystem%Ann_KickLoc==0) then ! .and. Op_KickLoc /= Op_MudOrKick%Length ()) then + +!write(*,*) 'expansion (1)' + + + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc)+ ExpansionVolume + + +!if (data%State%MUD(4)%Q > 0.) then +! +! if (abs(ChokeLine_Density%Array(1)-Ann_Density%Last())< DensityMixTol) then +! ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1) + ExpansionVolume +! else +! call ChokeLine_Density%AddToFirst (Ann_Density%Last()) +! call ChokeLine_MudDischarged_Volume%AddToFirst (ExpansionVolume) ! farz kardam ke hameye hajm ro ba yek density ezafe konim +! call ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) +! call ChokeLine_Mud_Forehead_section%AddToFirst (1) +! call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) +! call ChokeLine_Mud_Backhead_section%AddToFirst (1) +! call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call ChokeLine_MudOrKick%AddToFirst (Ann_MudOrKick%Last()) +! endif +! +!endif + + endif +!======================================================================================== + + + +!============================= foreheade dar fazaye annulus bashad =========================== +! agar kick be entehaye annulus reside bashe, expansion ra emaal nemikonim + if (data%State%MudSystem%Ann_KickLoc > 0) then ! .and. Ann_KickLoc /= Ann_MudOrKick%Length ()) then +!write(*,*) 'expansion (2)' + +!if ( sum(Ann_MudDischarged_Volume%Array(1:Ann_KickLoc)) + ExpansionVolume > sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) ) then ! agar khast az mate rad kone +! ExpansionVolume= sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) - sum(Ann_MudDischarged_Volume%Array(1:Ann_KickLoc)) +!endif + + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc)+ ExpansionVolume + +!if (data%State%MUD(4)%Q > 0.) then +! +! +! if (abs(ChokeLine_Density%Array(1)-Ann_Density%Last())< DensityMixTol) then +! ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1) + ExpansionVolume +! else +! call ChokeLine_Density%AddToFirst (Ann_Density%Last()) +! call ChokeLine_MudDischarged_Volume%AddToFirst (ExpansionVolume) ! farz kardam ke hameye hajm ro ba yek density ezafe konim +! call ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) +! call ChokeLine_Mud_Forehead_section%AddToFirst (1) +! call ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) +! call ChokeLine_Mud_Backhead_section%AddToFirst (1) +! call ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call ChokeLine_MudOrKick%AddToFirst (Ann_MudOrKick%Last()) +! endif +! +!endif + + endif +!======================================================================================== + + + + + +!=============================== foreheade dar choke line bashad ============================= + + if (data%State%MudSystem%ChokeLine_KickLoc > 0 .and. data%State%MudSystem%Ann_KickLoc==0) then + + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(data%State%MudSystem%ChokeLine_KickLoc)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(data%State%MudSystem%ChokeLine_KickLoc)+ ExpansionVolume + + endif + + +!======================================================================================== + +!write(*,*) 'Expansion======0' +! !do imud=1, Ann_MudDischarged_Volume%Length() +! ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! !enddo +! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +!write(*,*) '0======expansion' + + + + end subroutine Kick_Expansion + + + + + +subroutine Kick_Contraction ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + use SimulationVariables !@ +!use CTanks !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + USE CReservoirVariables + use KickVARIABLESModule + USE CError + + + implicit none + + integer jelement, jmud, jsection,ielement,i + integer jopelement,jopmud,jopsection + real(8) ContractionVolume + + +!********************************************************* + +! contraction is always with pump flow + +!********************************************************* +!write(*,*) 'Kick Contraction' + +!data%State%MUD(2)%Q= data%State%MPumps%Total_Pump_GPM + data%State%MudSystem%StringFlowRate= data%State%MUD(2)%Q + data%State%MudSystem%AnnulusFlowRate= data%State%MUD(2)%Q + + if (data%State%MudSystem%NewPipeFilling == 0) then + data%State%MudSystem%StringFlowRate= 0. + data%State%MudSystem%AnnulusFlowRate= 0. + endif + + + + + +!if (WellHeadIsOpen) then + ContractionVolume= - GasPocketDeltaVol%Array(data%State%MudSystem%NewInfluxNumber - data%State%MudSystem%KickNumber + 1) * 7.48 +!else +!ContractionVolume = (data%State%MudSystem%StringFlowRate/60.0d0)*DeltaT_Mudline + DeltaVolumePipe + if (data%State%MudSystem%KickNumber == 1 .and. data%State%MudSystem%WellHeadIsOpen==.false.) ContractionVolume = ContractionVolume + (data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline + data%State%MudSystem%DeltaVolumePipe +!endif + + +!************************************************************************************************************************************************************************** + +! pump mud is added in "pump&TripIn" code + + IF (data%State%MudSystem%Op_KickLoc > 0 .and. data%State%MudSystem%Ann_KickLoc == 0) then ! All of kick is under bit (iloc == 1) + + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc) - ( ContractionVolume ) + + ELSE IF (data%State%MudSystem%Op_KickLoc == 0 .AND. data%State%MudSystem%Ann_KickLoc > 0 .AND. data%State%MudSystem%ChokeLine_KickLoc == 0) THEN ! All of kick is an Annulus (iloc == 1) + + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc) - ( ContractionVolume ) + + ELSE IF (data%State%MudSystem%Ann_KickLoc == 0 .AND. data%State%MudSystem%ChokeLine_KickLoc > 0) THEN ! kick is in chokeline only + + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(data%State%MudSystem%ChokeLine_KickLoc)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(data%State%MudSystem%ChokeLine_KickLoc) - ( ContractionVolume ) + + ELSE IF (data%State%MudSystem%Op_KickLoc > 0 .AND. data%State%MudSystem%Ann_KickLoc > 0) THEN ! Kick is around bit (iloc==2) + + if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) > ContractionVolume ) then + + data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) - ( ContractionVolume ) + + + elseif (data%State%MudSystem%Op_MudDischarged_Volume%Last() > ContractionVolume ) then + + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_MudDischarged_Volume%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_MudDischarged_Volume%Length()) - ( ContractionVolume ) + + else + Call ErrorStop ('kick contraction error 1') + endif + + ELSE IF (data%State%MudSystem%Ann_KickLoc > 0 .AND. data%State%MudSystem%ChokeLine_KickLoc > 0) THEN + + if (data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1) > ContractionVolume ) then + + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1) = data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1) - ( ContractionVolume ) + + + elseif (data%State%MudSystem%Ann_MudDischarged_Volume%Last() > ContractionVolume ) then + + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_MudDischarged_Volume%Length())= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_MudDischarged_Volume%Length()) - ( ContractionVolume ) + + else + Call ErrorStop ('kick contraction error 2') + endif + + + + endif + +! write(*,*) 'contract======0' +!! !do imud=1, Ann_MudDischarged_Volume%Length() +!! ! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +!! !enddo +!! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +!write(*,*) '0======contract' + +end subroutine Kick_Contraction diff --git a/Equipments/MudSystem/Kick_Influx.f90 b/Equipments/MudSystem/Kick_Influx.f90 index 347acca..cea8854 100644 --- a/Equipments/MudSystem/Kick_Influx.f90 +++ b/Equipments/MudSystem/Kick_Influx.f90 @@ -7,7 +7,7 @@ use SimulationVariables !@@@ use SimulationVariables use SimulationVariables !@ !use CTanks - ! !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + ! !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables use KickVARIABLESModule @@ -82,7 +82,7 @@ use SimulationVariables !@@@ - if ( DownHole%AnnDrillMud == .true. .and. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%DeltaVolumeOp>0.0) ) then + if ( data%Equipments%DownHole%AnnDrillMud == .true. .and. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%DeltaVolumeOp>0.0) ) then do imud= 1, data%State%MudSystem%Ann_Density%Length() @@ -96,7 +96,7 @@ use SimulationVariables !@@@ endif - if ( DownHole%AnnCirculateMud == .true. ) then + if ( data%Equipments%DownHole%AnnCirculateMud == .true. ) then do imud= 1, data%State%MudSystem%Ann_Density%Length() @@ -151,7 +151,7 @@ use SimulationVariables !@@@ data%State%MudSystem%UGBOSuccessionCounter = data%State%MudSystem%UGBOSuccessionCounter + 1 !write(*,*) 'check point 1' - if (Shoe%InactiveFracture == .FALSE. .AND. ((data%State%MudSystem%ShoeMudPressure >= data%State%MudSystem%FormationLostPressure) .or. data%State%MudSystem%ShoeFractured )) then + if (data%Configuration%Shoe%InactiveFracture == .FALSE. .AND. ((data%State%MudSystem%ShoeMudPressure >= data%State%MudSystem%FormationLostPressure) .or. data%State%MudSystem%ShoeFractured )) then !write(*,*) 'check point 2 ,UGBOSuccessionCounter' , UGBOSuccessionCounter ! if ShoeFractured changed to true , then time counter is not needed more @@ -191,7 +191,7 @@ use SimulationVariables !@@@ do imud= 1, data%State%MudSystem%Ann_Mud_Forehead_X%Length() - IF ( data%State%MudSystem%ShoeLost .and. Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) & + IF ( data%State%MudSystem%ShoeLost .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) & .and. data%State%MudSystem%Ann_MudOrKick%Array(imud) == 0 .and. data%State%MudSystem%WellHeadIsOpen == .FALSE. ) then data%State%MudSystem%Kickexpansion_DueToMudLost= .true. diff --git a/Equipments/MudSystem/Kick_Influx.i90 b/Equipments/MudSystem/Kick_Influx.i90 new file mode 100644 index 0000000..3e1669f --- /dev/null +++ b/Equipments/MudSystem/Kick_Influx.i90 @@ -0,0 +1,220 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/Kick_Influx.f90" +subroutine Kick_Influx ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + use SimulationVariables !@ +!use CTanks +! !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + + + implicit none + + +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + +!write(*,*) 'Kick Influx' + + +!=================== Bottom Hole Kick Influx ENTRANCE(due to Kick) =================== + + data%State%MudSystem%Kick_Density= 2 + data%State%MudSystem%NewInflux_Density= data%State%MudSystem%Kick_Density + + + if ( data%State%MudSystem%NewInfluxElementCreated==0 ) then ! new kick is pumped- (it is set to zero in sheykh subroutine after a new kick influx) + call data%State%MudSystem%Op_Density%AddToFirst (data%State%MudSystem%NewInflux_Density) + call data%State%MudSystem%Op_MudDischarged_Volume%AddToFirst (0.0d0) + call data%State%MudSystem%Op_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_OpSection(1)) + call data%State%MudSystem%Op_Mud_Forehead_section%AddToFirst (1) + call data%State%MudSystem%Op_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_OpSection(1)) + call data%State%MudSystem%Op_Mud_Backhead_section%AddToFirst (1) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddToFirst (data%State%MudSystem%NewInfluxNumber) ! KickNumber= NewInfluxNumber + + + data%State%MudSystem%NewInfluxElementCreated= 1 + endif + + + data%State%MudSystem%Op_MudDischarged_Volume%Array(1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(1)+ ((KickVARIABLES%GasKickPumpFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) due to KickFlux +!write(*,*) 'kick volume ok=' , Op_MudDischarged_Volume%Array(1) + + + + end subroutine Kick_Influx + + + + + + + + + + + +subroutine Instructor_CirculationMud_Edit ! is called in subroutine CirculationCodeSelect + + use KickVARIABLESModule + USE MudSystemVARIABLES +use SimulationVariables !@@@ + USE TD_DrillStemComponents + Use CUnityInputs + Use CUnityOutputs + use OperationScenariosModule + use UTUBEVARSModule + use sROP_Variables + use sROP_Other_Variables + use CDownHoleVariables + + + implicit none + + + + + + if ( data%Equipments%DownHole%AnnDrillMud == .true. .and. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%DeltaVolumeOp>0.0) ) then + + do imud= 1, data%State%MudSystem%Ann_Density%Length() + + if ( data%State%MudSystem%Ann_MudOrKick%Array(imud) == 0 ) then + data%State%MudSystem%Ann_Density%Array(imud)= (data%State%MudSystem%St_Density%Last() * data%State%MudSystem%AnnulusFlowRate + 141.4296E-4*data%State%ROP_Bit%RateOfPenetration*data%State%ROP_Spec%DiameterOfBit**2)/(data%State%MudSystem%AnnulusFlowRate+6.7995E-4*data%State%ROP_Bit%RateOfPenetration*data%State%ROP_Spec%DiameterOfBit**2) + data%State%MudSystem%Ann_CuttingMud%Array(imud)= 1 + endif + + enddo + + endif + + + if ( data%Equipments%DownHole%AnnCirculateMud == .true. ) then + + do imud= 1, data%State%MudSystem%Ann_Density%Length() + + if ( data%State%MudSystem%Ann_MudOrKick%Array(imud) == 0 ) then + data%State%MudSystem%Ann_Density%Array(imud)= data%State%MudSystem%ActiveTankDensity + data%State%MudSystem%Ann_CuttingMud%Array(imud)= 0 + endif + + enddo + + do imud= 1, data%State%MudSystem%St_Density%Length() + + data%State%MudSystem%St_Density%Array(imud)= data%State%MudSystem%ActiveTankDensity + + enddo + + endif + + + + + end subroutine Instructor_CirculationMud_Edit + + + +subroutine ShoeLostSub ! is called in subroutine CirculationCodeSelect + + use KickVARIABLESModule + USE MudSystemVARIABLES +use SimulationVariables !@@@ + USE TD_DrillStemComponents + Use CUnityInputs + Use CUnityOutputs + use OperationScenariosModule + use UTUBEVARSModule + use sROP_Variables + use sROP_Other_Variables + use CDownHoleVariables + use CShoeVariables + use PressureDisplayVARIABLESModule + use CWarnings + + + implicit none + + data%State%MudSystem%ShoeLost= .false. + data%State%MudSystem%Kickexpansion_DueToMudLost= .false. + + data%State%MudSystem%ShoeMudPressure= data%State%PressureDisplay%PressureGauges(5) + + + data%State%MudSystem%UGBOSuccessionCounter = data%State%MudSystem%UGBOSuccessionCounter + 1 +!write(*,*) 'check point 1' + + if (data%Configuration%Shoe%InactiveFracture == .FALSE. .AND. ((data%State%MudSystem%ShoeMudPressure >= data%State%MudSystem%FormationLostPressure) .or. data%State%MudSystem%ShoeFractured )) then +!write(*,*) 'check point 2 ,UGBOSuccessionCounter' , UGBOSuccessionCounter + +! if ShoeFractured changed to true , then time counter is not needed more + if ( data%State%MudSystem%UGBOSuccessionCounter /= data%State%MudSystem%UGBOSuccessionCounterOld+1 .and. data%State%MudSystem%ShoeFractured==.false. ) then + data%State%MudSystem%UGBOSuccessionCounter = 0 ! also in starup + data%State%MudSystem%UGBOSuccessionCounterOld = 0 ! also in starup + return + else + data%State%MudSystem%UGBOSuccessionCounterOld= data%State%MudSystem%UGBOSuccessionCounter + endif + + if ( data%State%MudSystem%UGBOSuccessionCounter < 10 .and. data%State%MudSystem%ShoeFractured==.false.) then + return + endif + +!write(*,*) 'check point 3 ,UGBOSuccessionCounter' , UGBOSuccessionCounter + + + + data%State%MudSystem%ShoeFractured= .true. + + data%State%MudSystem%ShoeMudViscosity= MAX(data%State%MudSystem%ShoeMudViscosity, 12.d0) +!write(*,*) 'ShoeMudDensity , ShoeMudViscosity' , ShoeMudDensity , ShoeMudViscosity + data%State%MudSystem%ShoeLostCoef = 10.**(-8) * 1.15741d0 * 7.08d0 * 1000000.d0 * 1.d0 * data%State%MudSystem%ShoeMudDensity / & + (data%State%MudSystem%ShoeMudViscosity * LOG(10000.d0)) +!write(*,*) 'lost parameters 1' , ShoeMudPressure , FormationLostPressure + data%State%MudSystem%Qlost = MAX( (data%State%MudSystem%ShoeLostCoef * (data%State%MudSystem%ShoeMudPressure - (data%State%MudSystem%FormationLostPressure/2.0))) , 0.d0 ) + if (data%State%MudSystem%Qlost > 0.0) then + data%State%MudSystem%ShoeLost= .true. + else + data%State%MudSystem%ShoeLost= .false. + endif + +!write(*,*) 'Qlost=' , Qlost, ShoeMudPressure, FormationLostPressure + call Activate_UndergroundBlowout() + + + do imud= 1, data%State%MudSystem%Ann_Mud_Forehead_X%Length() + + IF ( data%State%MudSystem%ShoeLost .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) & + .and. data%State%MudSystem%Ann_MudOrKick%Array(imud) == 0 .and. data%State%MudSystem%WellHeadIsOpen == .FALSE. ) then + + data%State%MudSystem%Kickexpansion_DueToMudLost= .true. + write(*,*) 'Kickexpansion_DueToMudLost' + + EXIT + + ENDIF + + + enddo + + + + endif + + if (data%Warnings%UndergroundBlowout == .false.) data%State%MudSystem%ShoeLost= .false. + + + + end subroutine ShoeLostSub + + + + diff --git a/Equipments/MudSystem/Kick_Migration.f90 b/Equipments/MudSystem/Kick_Migration.f90 index 56f60a6..5c6f58d 100644 --- a/Equipments/MudSystem/Kick_Migration.f90 +++ b/Equipments/MudSystem/Kick_Migration.f90 @@ -7,7 +7,7 @@ use SimulationVariables !@@@ use SimulationVariables use SimulationVariables !@ !use CTanks - !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables USE CReservoirVariables diff --git a/Equipments/MudSystem/Kick_Migration.i90 b/Equipments/MudSystem/Kick_Migration.i90 new file mode 100644 index 0000000..f443ee0 --- /dev/null +++ b/Equipments/MudSystem/Kick_Migration.i90 @@ -0,0 +1,1179 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/Kick_Migration.f90" +subroutine Kick_Migration ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + use SimulationVariables !@ +!use CTanks +!@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + USE CReservoirVariables + use KickVARIABLESModule + + + implicit none + + integer jelement, jmud, jsection,ielement,i,kickNumber + integer jopelement,jopmud,jopsection,CuttingValue + + +!data%State%MUD(2)%Q= data%State%MPumps%Total_Pump_GPM +!data%State%MudSystem%StringFlowRate= data%State%MUD(2)%Q +!data%State%MudSystem%AnnulusFlowRate= data%State%MUD(2)%Q +! +!if (NewPipeFilling == 0) then +! data%State%MudSystem%StringFlowRate= 0. +! data%State%MudSystem%AnnulusFlowRate= 0. +!endif + +!StringFlowRateFinal= data%State%MudSystem%StringFlowRate +!AnnulusFlowRateFinal= data%State%MudSystem%AnnulusFlowRate + + + +!write(*,*) 'data%State%MUD(2)%Q=====' , data%State%MUD(2)%Q +!write(*,*) 'Kick Migration,NewInfluxNumber:' , NewInfluxNumber + + + +!FirstSetKickMigration +!write(*,*) 'NewInfluxNumber=' , NewInfluxNumber +DO KickNumber= data%State%MudSystem%NewInfluxNumber-KickVARIABLES%NoGasPocket+1 , data%State%MudSystem%NewInfluxNumber +!write(*,*) 'KickNumber=' , KickNumber + if (KickVARIABLES%KickFlux .AND. NOT(KickVARIABLES%KickOffBottom) .and. KickNumber == data%State%MudSystem%NewInfluxNumber) cycle + if ( KickNumber == data%State%MudSystem%Ann_MudOrKick%Last() ) cycle ! when the last element in Annulus is kick, Migration is not called +!write(*,*) 'Migration will be done for,KickNumber=' ,KickNumber + +!=================== Bottom Hole ENTRANCE(due to Kick) =================== +!KickDx= (AutoMigrationRate/60.)*DeltaT_Mudline !3600 (ft/min)= 6 ft set in start up + + + data%State%MudSystem%Op_KickLoc= 0 + data%State%MudSystem%Ann_KickLoc= 0 + data%State%MudSystem%ChokeLine_KickLoc= 0 + + do i = 1, data%State%MudSystem%Op_MudOrKick%Length () + if (data%State%MudSystem%Op_MudOrKick%Array(i) == KickNumber) then + data%State%MudSystem%Op_KickLoc = i + exit + endif + end do + + do i = 1, data%State%MudSystem%Ann_MudOrKick%Length () + if (data%State%MudSystem%Ann_MudOrKick%Array(i) == KickNumber) then + data%State%MudSystem%Ann_KickLoc = i + exit + endif + end do + + do i = 1, data%State%MudSystem%ChokeLine_MudOrKick%Length () + if (data%State%MudSystem%ChokeLine_MudOrKick%Array(i) == KickNumber) then + data%State%MudSystem%ChokeLine_KickLoc = i + exit + endif + end do + +!write(*,*) 'Op_KickLoc=' , Op_KickLoc +!write(*,*) 'Ann_KickLoc=' , Ann_KickLoc +!!write(*,*) 'ChokeLine_KickLoc=' , ChokeLine_KickLoc +! +! +!write(*,*) 'Op_MudOrKick%Length ()=' , Op_MudOrKick%Length () +! +! + + + + +!============================== foreheade kick be mate reside bashad *3 ============================== + +if (data%State%MudSystem%Op_KickLoc == data%State%MudSystem%Op_MudOrKick%Length () .and. data%State%MudSystem%Ann_KickLoc==0 ) then +!write(*,*) '****3' + + data%State%MudSystem%iLoc= 2 + + data%State%MudSystem%KickDv= data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Forehead_section%Array(data%State%MudSystem%Op_KickLoc)) * data%State%MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal + + + data%State%MudSystem%MinKickDv= min( data%State%MudSystem%KickDv,data%State%MudSystem%Ann_MudDischarged_Volume%Array (1), data%State%MudSystem%Op_MudDischarged_Volume%Last () ) + + data%State%MudSystem%NewDensity= data%State%MudSystem%Ann_Density%Array (1) + data%State%MudSystem%NewVolume= data%State%MudSystem%MinKickDv + + if ( data%State%MudSystem%MinKickDv == data%State%MudSystem%KickDv ) then !eleman bala sari baghi mimund, paeeni(kick) ham baghi mimund + + data%State%MudSystem%Ann_MudDischarged_Volume%Array (1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array (1) - data%State%MudSystem%MinKickDv + + call data%State%MudSystem%Ann_Density%AddToFirst (data%State%MudSystem%Op_Density%Last()) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddToFirst (data%State%MudSystem%MinKickDv) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddToFirst (KickNumber) + call data%State%MudSystem%Ann_CuttingMud%AddToFirst (0) + + data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc)= data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc) - data%State%MudSystem%MinKickDv + +! backheade kick zire mate bashad + if (data%State%MudSystem%Op_KickLoc > 1) then +!if ( Op_Density%Array (Op_KickLoc-1) /= data%State%MudSystem%NewDensity ) then + + if ( ABS(data%State%MudSystem%Op_Density%Array (data%State%MudSystem%Op_KickLoc-1) - data%State%MudSystem%NewDensity) >= data%State%MudSystem%DensityMixTol ) then + + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Op_Mud_Backhead_X%Array (data%State%MudSystem%Op_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Op_Mud_Backhead_section%Array (data%State%MudSystem%Op_KickLoc) + + call data%State%MudSystem%Op_Density%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddTo (data%State%MudSystem%Op_KickLoc,0) + + + else !Op_Density%Array (imudKick-1) == data%State%MudSystem%NewDensity + + data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)= (data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)*data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1) + data%State%MudSystem%NewVolume + + endif + else !if Op_KickLoc == 1 (*****Migration Start*****) *3-1=============================== +!write(*,*) '****3-1' + + + call data%State%MudSystem%Op_Density%AddToFirst (data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddToFirst (data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + + elseif ( data%State%MudSystem%MinKickDv == data%State%MudSystem%Ann_MudDischarged_Volume%Array (1) ) then ! eleman bala sari baghi nemimund + + data%State%MudSystem%Ann_Density%Array(1)= data%State%MudSystem%Op_Density%Last() + data%State%MudSystem%Ann_MudOrKick%Array(1)= KickNumber + + data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc)= data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc) - data%State%MudSystem%MinKickDv + +! backheade kick zire mate bashad + if (data%State%MudSystem%Op_KickLoc > 1) then + +!if ( Op_Density%Array (Op_KickLoc-1) /= data%State%MudSystem%NewDensity ) then + + if ( ABS(data%State%MudSystem%Op_Density%Array (data%State%MudSystem%Op_KickLoc-1) - data%State%MudSystem%NewDensity) >= data%State%MudSystem%DensityMixTol ) then + + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Op_Mud_Backhead_X%Array (data%State%MudSystem%Op_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Op_Mud_Backhead_section%Array (data%State%MudSystem%Op_KickLoc) + + call data%State%MudSystem%Op_Density%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddTo (data%State%MudSystem%Op_KickLoc,0) + + + else !Op_Density%Array (imudKick-1) == data%State%MudSystem%NewDensity + + data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)= (data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)*data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1) + data%State%MudSystem%NewVolume + + endif + + else !if Op_KickLoc == 1 (*****Migration Start*****) *3-2=============================== +!write(*,*) '****3-2' + + + call data%State%MudSystem%Op_Density%AddToFirst (data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddToFirst (data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + +! + elseif ( data%State%MudSystem%MinKickDv == data%State%MudSystem%Op_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick hazf mishod + + data%State%MudSystem%Ann_MudDischarged_Volume%Array (1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array (1) - data%State%MudSystem%MinKickDv + + call data%State%MudSystem%Ann_Density%AddToFirst (data%State%MudSystem%Op_Density%Last()) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddToFirst (data%State%MudSystem%MinKickDv) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddToFirst (KickNumber) + call data%State%MudSystem%Ann_CuttingMud%AddToFirst (0) + + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Op_Mud_Backhead_X%Array (data%State%MudSystem%Op_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Op_Mud_Backhead_section%Array (data%State%MudSystem%Op_KickLoc) + + call data%State%MudSystem%Op_MudDischarged_Volume%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_Mud_Backhead_X%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_Mud_Backhead_section%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_Mud_Forehead_X%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_Mud_Forehead_section%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_Density%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_MudOrKick%Remove (data%State%MudSystem%Op_KickLoc) + + +! backheade kick zire mate bashad + if (data%State%MudSystem%Op_KickLoc > 1) then +!if ( Op_Density%Array (Op_KickLoc-1) /= data%State%MudSystem%NewDensity ) then + + if ( ABS(data%State%MudSystem%Op_Density%Array (data%State%MudSystem%Op_KickLoc-1) - data%State%MudSystem%NewDensity) >= data%State%MudSystem%DensityMixTol ) then + + + + call data%State%MudSystem%Op_Density%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddTo (data%State%MudSystem%Op_KickLoc,0) + + + else !Op_Density%Array (imudKick-1) == data%State%MudSystem%NewDensity + + data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)= (data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)*data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1) + data%State%MudSystem%NewVolume + + endif + + else !if Op_KickLoc == 1 (*****Migration Start*****) *3-3=============================== +!write(*,*) '****3-3' + + call data%State%MudSystem%Op_Density%AddToFirst (data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddToFirst (data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + + + endif + + + endif + +!======================================================================================== + + +!============================== foreheade kick be mate reside bashad *3 with pump ============================== + +! if (Op_KickLoc == Op_MudOrKick%Length () .and. Ann_KickLoc==0 .and. data%State%MudSystem%AnnulusFlowRate /= 0.0 ) then +! write(*,*) '****3 with pump' +! +! KickMigration_2SideBit= .true. +! !iloc= 2 +! +! !KickDv= Area_OpSectionFt(Op_Mud_Forehead_section%Array(Op_KickLoc)) * KickDx * 7.48051948 ! ft^3 to gal +! +!!farz mikonam baraye in yek iteration kick az OP hazf nemishavad va hajme aan bishtar az pump flow ast +! +! KickDv= ((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) +! +! call Ann_Density%AddToFirst (Kick_Density) +! call Ann_MudDischarged_Volume%AddToFirst (KickDv) +! call Ann_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) +! call Ann_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts+1) +! call Ann_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1)) +! call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1) +! call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call Ann_MudOrKick%AddToFirst (KickNumber) +! call Ann_CuttingMud%AddToFirst (0) +! +! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv +! +! ! +! !if ( ((data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) >= KickDv ) then ! sorate pump bishtar az kick bashad +! ! +! ! KickDv= ((data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) +! +! +! +! ! BackHead: +! if ( Op_Density%Array (Op_KickLoc-1) /=data%State%MudSystem%St_Density%Last() ) then +! +! +! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! call Op_Density%AddTo (Op_KickLocMudSystem%St_Density%Last()) +! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,KickDv) +! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) +! call Op_MudOrKick%AddTo (Op_KickLoc,0) +! +! +! else !Op_Density%Array (imudKick-1) == data%State%MudSystem%NewDensity +! +! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + KickDv +! +! endif +! +! +! +! +! endif + +!======================================================================================== + + +!============================= tamame kick zire mate bashad *1 ================================ + if ( data%State%MudSystem%Op_KickLoc>0 .and. data%State%MudSystem%Op_KickLoc < data%State%MudSystem%Op_MudOrKick%Length () ) then +!write(*,*) '****1' +!iloc= 1 + + data%State%MudSystem%KickDv= data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Forehead_section%Array(data%State%MudSystem%Op_KickLoc)) * data%State%MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal + + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Op_Mud_Backhead_X%Array (data%State%MudSystem%Op_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Op_Mud_Backhead_section%Array (data%State%MudSystem%Op_KickLoc) + + if ( data%State%MudSystem%KickDv < data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc+1) ) then !eleman bala sari baghi mimund + +!write(*,*) 'cond 11111111111111' + + data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc+1)= data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc+1) - data%State%MudSystem%KickDv + + data%State%MudSystem%NewDensity= data%State%MudSystem%Op_Density%Array (data%State%MudSystem%Op_KickLoc+1) + data%State%MudSystem%NewVolume= data%State%MudSystem%KickDv + + else !KickDv > Op_MudDischarged_Volume%Array (imudKick+1) eleman baghi nemimund + +! write(*,*) 'cond 22222222222222222' + + + data%State%MudSystem%KickDv= data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc+1) + + data%State%MudSystem%NewVolume= data%State%MudSystem%KickDv + data%State%MudSystem%NewDensity= data%State%MudSystem%Op_Density%Array (data%State%MudSystem%Op_KickLoc+1) + + + + + call data%State%MudSystem%Op_MudDischarged_Volume%Remove (data%State%MudSystem%Op_KickLoc+1) + call data%State%MudSystem%Op_Mud_Backhead_X%Remove (data%State%MudSystem%Op_KickLoc+1) + call data%State%MudSystem%Op_Mud_Backhead_section%Remove (data%State%MudSystem%Op_KickLoc+1) + call data%State%MudSystem%Op_Mud_Forehead_X%Remove (data%State%MudSystem%Op_KickLoc+1) + call data%State%MudSystem%Op_Mud_Forehead_section%Remove (data%State%MudSystem%Op_KickLoc+1) + call data%State%MudSystem%Op_Density%Remove (data%State%MudSystem%Op_KickLoc+1) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%Remove (data%State%MudSystem%Op_KickLoc+1) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (data%State%MudSystem%Op_KickLoc+1) + call data%State%MudSystem%Op_MudOrKick%Remove (data%State%MudSystem%Op_KickLoc+1) + + endif + +! backheade kick zire mate bashad + if (data%State%MudSystem%Op_KickLoc > 1) then +!if ( Op_Density%Array (Op_KickLoc-1) /= data%State%MudSystem%NewDensity ) then + + if ( ABS(data%State%MudSystem%Op_Density%Array (data%State%MudSystem%Op_KickLoc-1) - data%State%MudSystem%NewDensity) >= data%State%MudSystem%DensityMixTol ) then + + + + + call data%State%MudSystem%Op_Density%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddTo (data%State%MudSystem%Op_KickLoc,0) + + else !Op_Density%Array (Op_KickLoc-1) == data%State%MudSystem%NewDensity + + data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)= (data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)*data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1) + data%State%MudSystem%NewVolume + + endif + else !if Op_KickLoc == 1 (*****Migration Start*****) *5-1=============================== +!write(*,*) '****5-1' + + call data%State%MudSystem%Op_Density%AddToFirst (data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddToFirst (data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + endif + +!======================================================================================== + +!write(*,*) 'a) density and cutting:' , Ann_Density%Length() , Ann_CuttingMud%Length() + + +!=========================== tamame kick balaye mate bashad *2 ================================== + + if ( data%State%MudSystem%Ann_KickLoc > 0 .and. data%State%MudSystem%Op_KickLoc==0 ) then +!write(*,*) '****2' + +!iloc= 1 + + data%State%MudSystem%KickDv= data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%Ann_KickLoc)) * data%State%MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal + + data%State%MudSystem%NewDensity= data%State%MudSystem%Ann_Density%Array (data%State%MudSystem%Ann_KickLoc+1) + data%State%MudSystem%NewVolume= data%State%MudSystem%KickDv + CuttingValue= data%State%MudSystem%Ann_CuttingMud%Array (data%State%MudSystem%Ann_KickLoc+1) + + if ( data%State%MudSystem%KickDv < data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc+1) ) then !eleman bala sari baghi mimund + + data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc+1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc+1) - data%State%MudSystem%KickDv + + else !KickDv > Ann_MudDischarged_Volume%Array (imudKick+1) eleman baghi nemimund + + data%State%MudSystem%KickDv= data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc+1) + data%State%MudSystem%NewVolume= data%State%MudSystem%KickDv + + call data%State%MudSystem%Ann_MudDischarged_Volume%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_Mud_Backhead_X%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_Mud_Backhead_section%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_Mud_Forehead_X%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_Mud_Forehead_section%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_Density%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_MudOrKick%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_CuttingMud%Remove (data%State%MudSystem%Ann_KickLoc+1) + + endif + +! backheade kick balaye mate bashad + + if (data%State%MudSystem%Ann_KickLoc > 1) then +!if ( Ann_Density%Array (Ann_KickLoc-1) /= data%State%MudSystem%NewDensity ) then + + if ( ABS(data%State%MudSystem%Ann_Density%Array (data%State%MudSystem%Ann_KickLoc-1) - data%State%MudSystem%NewDensity) >= data%State%MudSystem%DensityMixTol ) then + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Ann_Mud_Backhead_X%Array (data%State%MudSystem%Ann_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Ann_Mud_Backhead_section%Array (data%State%MudSystem%Ann_KickLoc) + + + call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%Ann_KickLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%Ann_KickLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%Ann_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%Ann_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%Ann_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%Ann_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%Ann_KickLoc,0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%Ann_KickLoc,0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%Ann_KickLoc,0) + call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%Ann_KickLoc,0) + + else !Op_Density%Array (imudKick-1) == data%State%MudSystem%NewDensity + + data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%Ann_KickLoc-1)= (data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%Ann_KickLoc-1)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc-1)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc-1)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc-1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_KickLoc-1) + data%State%MudSystem%NewVolume + + + endif + + else !if Ann_KickLoc == 1 *6 =============================== +!write(*,*) '****6' + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Ann_Mud_Backhead_X%Array (data%State%MudSystem%Ann_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Ann_Mud_Backhead_section%Array (data%State%MudSystem%Ann_KickLoc) + + + call data%State%MudSystem%Ann_Density%AddToFirst (data%State%MudSystem%NewDensity) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddToFirst (data%State%MudSystem%NewVolume) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddToFirst (0) + call data%State%MudSystem%Ann_CuttingMud%AddToFirst (CuttingValue) + + endif + + endif + +!======================================================================================== + + + + + + + +!============================== kick 2 tarafe mate bashad *4 ============================== + + if ( data%State%MudSystem%Ann_KickLoc > 0 .and. data%State%MudSystem%Op_KickLoc > 0 ) then +!write(*,*) '****4' + + data%State%MudSystem%iLoc= 2 + + data%State%MudSystem%KickDv= data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%Ann_KickLoc)) * data%State%MudSystem%KickDx * 7.48051948d0 ! ft^3 to gal + + + data%State%MudSystem%MinKickDv= min( data%State%MudSystem%KickDv,data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc+1), data%State%MudSystem%Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick + + data%State%MudSystem%NewDensity= data%State%MudSystem%Ann_Density%Array (data%State%MudSystem%Ann_KickLoc+1) + data%State%MudSystem%NewVolume= data%State%MudSystem%MinKickDv + + if ( data%State%MudSystem%MinKickDv == data%State%MudSystem%KickDv ) then !eleman bala sari baghi mimund, paeeni(kick) dar OP ham baghi mimund +!write(*,*) '****4----1' + + + data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc+1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc+1) - data%State%MudSystem%MinKickDv + + data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc) + data%State%MudSystem%MinKickDv ! Ann_KickLoc= 1 + + data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc)= data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc) - data%State%MudSystem%MinKickDv ! Op_KickLoc= last + + +! backheade kick zire mate bashad + if ( data%State%MudSystem%Op_KickLoc>1) then + +!if ( Op_Density%Array (Op_KickLoc-1) /= data%State%MudSystem%NewDensity ) then + + if ( ABS(data%State%MudSystem%Op_Density%Array (data%State%MudSystem%Op_KickLoc-1) - data%State%MudSystem%NewDensity) >= data%State%MudSystem%DensityMixTol ) then + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Op_Mud_Backhead_X%Array (data%State%MudSystem%Op_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Op_Mud_Backhead_section%Array (data%State%MudSystem%Op_KickLoc) + + call data%State%MudSystem%Op_Density%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddTo (data%State%MudSystem%Op_KickLoc,0) + + + else ! merge + + data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)= (data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)*data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1) + data%State%MudSystem%NewVolume + + endif + + else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== +!write(*,*) '****5-2' + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Op_Mud_Backhead_X%Array (data%State%MudSystem%Op_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Op_Mud_Backhead_section%Array (data%State%MudSystem%Op_KickLoc) + + + call data%State%MudSystem%Op_Density%AddToFirst (data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddToFirst (data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + + elseif ( data%State%MudSystem%MinKickDv == data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc+1) ) then ! eleman bala sari baghi nemimund +!write(*,*) '****4----2' + + call data%State%MudSystem%Ann_MudDischarged_Volume%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_Mud_Backhead_X%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_Mud_Backhead_section%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_Mud_Forehead_X%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_Mud_Forehead_section%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_Density%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_MudOrKick%Remove (data%State%MudSystem%Ann_KickLoc+1) + call data%State%MudSystem%Ann_CuttingMud%Remove (data%State%MudSystem%Ann_KickLoc+1) + + data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc) + data%State%MudSystem%MinKickDv ! Ann_KickLoc= 1 + + data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc)= data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_KickLoc) - data%State%MudSystem%MinKickDv ! Op_KickLoc= last + +! backheade kick zire mate bashad + if (data%State%MudSystem%Op_KickLoc > 1) then + +!if ( Op_Density%Array (Op_KickLoc-1) /= data%State%MudSystem%NewDensity ) then + + if ( ABS(data%State%MudSystem%Op_Density%Array (data%State%MudSystem%Op_KickLoc-1) - data%State%MudSystem%NewDensity) >= data%State%MudSystem%DensityMixTol ) then + + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Op_Mud_Backhead_X%Array (data%State%MudSystem%Op_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Op_Mud_Backhead_section%Array (data%State%MudSystem%Op_KickLoc) + + call data%State%MudSystem%Op_Density%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddTo (data%State%MudSystem%Op_KickLoc,0) + + + else !Op_Density%Array (imudKick-1) == data%State%MudSystem%NewDensity + data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)= (data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)*data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1) + data%State%MudSystem%NewVolume + + endif + + else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Op_Mud_Backhead_X%Array (data%State%MudSystem%Op_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Op_Mud_Backhead_section%Array (data%State%MudSystem%Op_KickLoc) + + + call data%State%MudSystem%Op_Density%AddToFirst (data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddToFirst (data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + + elseif ( data%State%MudSystem%MinKickDv == data%State%MudSystem%Op_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick az OP kamel kharej mishod +!write(*,*) '****4----3' + + + + data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc+1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc+1) - data%State%MudSystem%MinKickDv + + data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array (data%State%MudSystem%Ann_KickLoc) + data%State%MudSystem%MinKickDv ! Ann_KickLoc= 1 + + + + data%State%MudSystem%Old_KickBackHead_X= data%State%MudSystem%Op_Mud_Backhead_X%Array (data%State%MudSystem%Op_KickLoc) + data%State%MudSystem%Old_KickBackHead_Section= data%State%MudSystem%Op_Mud_Backhead_section%Array (data%State%MudSystem%Op_KickLoc) + + + call data%State%MudSystem%Op_MudDischarged_Volume%Remove (data%State%MudSystem%Op_KickLoc) ! Op_KickLoc= last + call data%State%MudSystem%Op_Mud_Backhead_X%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_Mud_Backhead_section%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_Mud_Forehead_X%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_Mud_Forehead_section%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_Density%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (data%State%MudSystem%Op_KickLoc) + call data%State%MudSystem%Op_MudOrKick%Remove (data%State%MudSystem%Op_KickLoc) + +! backheade kick zire mate bashad + if (data%State%MudSystem%Op_KickLoc > 1) then + +!if ( Op_Density%Array (Op_KickLoc-1) /= data%State%MudSystem%NewDensity ) then + + if ( ABS(data%State%MudSystem%Op_Density%Array (data%State%MudSystem%Op_KickLoc-1) - data%State%MudSystem%NewDensity) >= data%State%MudSystem%DensityMixTol ) then + + + call data%State%MudSystem%Op_Density%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddTo (data%State%MudSystem%Op_KickLoc,data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%Op_KickLoc,0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddTo (data%State%MudSystem%Op_KickLoc,0) + + else !Op_Density%Array (imudKick-1) == data%State%MudSystem%NewDensity + data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)= (data%State%MudSystem%Op_Density%Array(data%State%MudSystem%Op_KickLoc-1)*data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_KickLoc-1) + data%State%MudSystem%NewVolume + + endif + + else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== + + call data%State%MudSystem%Op_Density%AddToFirst (data%State%MudSystem%NewDensity) + call data%State%MudSystem%Op_MudDischarged_Volume%AddToFirst (data%State%MudSystem%NewVolume) + call data%State%MudSystem%Op_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Forehead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Old_KickBackHead_X) + call data%State%MudSystem%Op_Mud_Backhead_section%AddToFirst (data%State%MudSystem%Old_KickBackHead_Section) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddToFirst (0) + + endif + + data%State%MudSystem%iLoc= 1 ! ok + + endif + + + endif + +!======================================================================================== + + + +!============================== kick 2 tarafe mate bashad *4 with pump ============================== + +! +!if ( Ann_KickLoc > 0 .and. Op_KickLoc > 0 .and. data%State%MudSystem%AnnulusFlowRate /= 0.0 ) then +! write(*,*) '****4 with pump' +! +! KickMigration_2SideBit= .true. +! +! !iloc= 2 +! +! KickDv= Area_PipeSectionFt(Ann_Mud_Forehead_section%Array(Ann_KickLoc)) * KickDx * 7.48051948d0 ! ft^3 to gal +! !MinKickDv= min( KickDv,Ann_MudDischarged_Volume%Array (Ann_KickLoc+1), Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick +! +! +! !MinKickDv= min( KickDv,Ann_MudDischarged_Volume%Array (Ann_KickLoc+1), Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick +! ! +! !data%State%MudSystem%NewDensity= Ann_Density%Array (Ann_KickLoc+1) +! !NewVolume= MinKickDv +! +! +! if ( ((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) >= KickDv ) then ! sorate pump bishtar az kick bashad---tu in halat aslan kari be elemane balaiye kick tuye Ann nadarim +! !WRITE(*,*) '*****sorate pump bishtar az kick*******' +! MinKickDv= ((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) ! dar asl maxKickDv ast +! +! +! +! +! +! +! +! +! if ( Op_MudDischarged_Volume%Last () > MinKickDv ) then !eleman paeeni(kick) dar OP baghi mimund +! +! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1 +! +! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv ! Op_KickLoc= last +! +! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! ! backheade kick zire mate bashad +! if ( Op_KickLoc>1) then +! +! if ( Op_Density%Array (Op_KickLoc-1) /=data%State%MudSystem%St_Density%Last() ) then +! +! +! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! call Op_Density%AddTo (Op_KickLocMudSystem%St_Density%Last()) +! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,MinKickDv) +! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) +! call Op_MudOrKick%AddTo (Op_KickLoc,0) +! +! +! else !Op_Density%Array (imudKick-1) == data%State%MudSystem%NewDensity +! +! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume +! +! endif +! +! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== +! write(*,*) '****5-2 with pump' +! +! +! !Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! !Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! +! call Op_Density%AddToFirst data%State%MudSystem%St_Density%Last()) +! call Op_MudDischarged_Volume%AddToFirst (MinKickDv) +! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call Op_MudOrKick%AddToFirst (0) +! +! endif +! +! elseif ( Op_MudDischarged_Volume%Last () <= MinKickDv ) then !eleman paeeni(kick) dar OP baghi nemimund yani kick az OP kamel kharej mishod +! +! MinKickDv= Op_MudDischarged_Volume%Last () +! +! +! write(*,*) '****4----3 with pump a' +! +! +! Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)= Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) + ((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline)-MinKickDv +! +! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1 +! +! call Op_MudDischarged_Volume%Remove (Op_KickLoc) ! Op_KickLoc= last +! call Op_Mud_Backhead_X%Remove (Op_KickLoc) +! call Op_Mud_Backhead_section%Remove (Op_KickLoc) +! call Op_Mud_Forehead_X%Remove (Op_KickLoc) +! call Op_Mud_Forehead_section%Remove (Op_KickLoc) +! call Op_Density%Remove (Op_KickLoc) +! call Op_RemainedVolume_in_LastSection%Remove (Op_KickLoc) +! call Op_EmptyVolume_inBackheadLocation%Remove (Op_KickLoc) +! call Op_MudOrKick%Remove (Op_KickLoc) +! +! +! ! backheade kick zire mate bashad +! if (Op_KickLoc > 1) then +! +! if ( Op_Density%Array (Op_KickLoc-1) /=data%State%MudSystem%St_Density%Last() ) then +! +! +! !Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! !Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! call Op_Density%AddTo (Op_KickLocMudSystem%St_Density%Last()) +! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,MinKickDv) +! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) +! call Op_MudOrKick%AddTo (Op_KickLoc,0) +! +! +! +! else !Op_Density%Array (imudKick-1) == data%State%MudSystem%NewDensity +! +! +! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + MinKickDv +! +! endif +! +! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== +! +! +! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! +! call Op_Density%AddToFirst data%State%MudSystem%St_Density%Last()) +! call Op_MudDischarged_Volume%AddToFirst (MinKickDv) +! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call Op_MudOrKick%AddToFirst (0) +! +! endif +! +! +! endif ! ende 2 halat ke kick tuye Op baghi bemune ya namune- dar halati ke ((data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) >= KickDv ) ! sorate pump bishtar az kick bashad +! +! +! +! +! else !if( ((data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) < KickDv ) then ! sorate pump kamtar az kick bashad +! !WRITE(*,*) '*****sorate pump kamtar az kick*******' +! +! +! +! +! MinKickDv= min( KickDv,Ann_MudDischarged_Volume%Array (Ann_KickLoc+1), Op_MudDischarged_Volume%Last () ) ! Ann_KickLoc+1=2 Op_MudDischarged_Volume%Last ()=kick +! +! +! +! !write(*,*) 'MinKickDv=' , MinKickDv +! +! +! if ( MinKickDv == KickDv ) then !eleman bala sari baghi mimund, paeeni(kick) dar OP ham baghi mimund +! !write(*,*) '****4----1 with pump' +! !write(*,*) data%State%MudSystem%St_Density%Last()=' ,data%State%MudSystem%St_Density%Last() +! !write(*,*) '((data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline)=' , ((data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) +! !write(*,*) 'Ann_Density%Array(Ann_KickLoc+1)=' , Ann_Density%Array(Ann_KickLoc+1) +! !write(*,*) '(MinKickDv-((data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline))=' , (MinKickDv-((data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline)) +! +! +! data%State%MudSystem%NewDensity= data%State%MudSystem%St_Density%Last()*((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_Density%Array(Ann_KickLoc+1)*(MinKickDv-((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline))) & +! / (((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + (MinKickDv-((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline))) +! NewVolume= MinKickDv +! +! +! Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)= Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) - (MinKickDv-((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline)) +! +! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1 +! +! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv ! Op_KickLoc= last +! +! +! ! backheade kick zire mate bashad +! if ( Op_KickLoc>1) then +! +! +! +! if ( ABS(Op_Density%Array (Op_KickLoc-1) - data%State%MudSystem%NewDensity) > DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Array (Op_KickLoc-1)>42.) ) then +! +! +! +! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! call Op_Density%AddTo (Op_KickLoc,data%State%MudSystem%NewDensity) +! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,NewVolume) +! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) +! call Op_MudOrKick%AddTo (Op_KickLoc,0) +! +! +! else !Merge Condition +! +! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume +! Op_Density%Array (Op_KickLoc-1)= (Op_MudDischarged_Volume%Array (Op_KickLoc-1)*Op_Density%Array (Op_KickLoc-1)+NewVolume*data%State%MudSystem%NewDensity) / & +! (Op_MudDischarged_Volume%Array (Op_KickLoc-1)+NewVolume) +! +! +! endif +! +! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== +! write(*,*) '****5-2 with pump' +! +! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! +! call Op_Density%AddToFirst (data%State%MudSystem%NewDensity) +! call Op_MudDischarged_Volume%AddToFirst (NewVolume) +! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call Op_MudOrKick%AddToFirst (0) +! +! endif +! +! +! +! elseif ( MinKickDv == Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) ) then ! eleman bala sari baghi nemimund +! write(*,*) '****4----2 with pump' +! +! data%State%MudSystem%NewDensity= data%State%MudSystem%St_Density%Last()*((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_Density%Array(Ann_KickLoc+1)*(MinKickDv-((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline))) & +! / (((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) + Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)) +! NewVolume= MinKickDv +! +! call RemoveAnnulusMudArrays(Ann_KickLoc+1) +! +! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1 +! +! Op_MudDischarged_Volume%Array (Op_KickLoc)= Op_MudDischarged_Volume%Array (Op_KickLoc) - MinKickDv ! Op_KickLoc= last +! +! ! backheade kick zire mate bashad +! if (Op_KickLoc > 1) then +! +! if ( ABS(Op_Density%Array (Op_KickLoc-1) - data%State%MudSystem%NewDensity) > DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Array (Op_KickLoc-1)>42.) ) then +! +! ! +! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! call Op_Density%AddTo (Op_KickLoc,data%State%MudSystem%NewDensity) +! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,NewVolume) +! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) +! call Op_MudOrKick%AddTo (Op_KickLoc,0) +! +! +! else !Merge Condition +! +! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume +! Op_Density%Array (Op_KickLoc-1)= (Op_MudDischarged_Volume%Array (Op_KickLoc-1)*Op_Density%Array (Op_KickLoc-1)+NewVolume*data%State%MudSystem%NewDensity) / & +! (Op_MudDischarged_Volume%Array (Op_KickLoc-1)+NewVolume) +! +! +! +! endif +! +! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== +! +! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! +! call Op_Density%AddToFirst (data%State%MudSystem%NewDensity) +! call Op_MudDischarged_Volume%AddToFirst (NewVolume) +! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call Op_MudOrKick%AddToFirst (0) +! +! endif +! +! +! elseif ( MinKickDv == Op_MudDischarged_Volume%Last () ) then ! eleman balaee baghi mimund, kick az OP kamel kharej mishod +! write(*,*) '****4----3 with pump b' +! +! data%State%MudSystem%NewDensity=data%State%MudSystem%St_Density%Last() +! NewVolume= MinKickDv +! +! +! Old_KickBackHead_X= Op_Mud_Backhead_X%Array (Op_KickLoc) +! Old_KickBackHead_Section= Op_Mud_Backhead_section%Array (Op_KickLoc) +! +! +! !Ann_MudDischarged_Volume%Array (Ann_KickLoc+1)= Ann_MudDischarged_Volume%Array (Ann_KickLoc+1) - MinKickDv farz kardam dast be elemane balaee nazanam +! +! Ann_MudDischarged_Volume%Array (Ann_KickLoc)= Ann_MudDischarged_Volume%Array (Ann_KickLoc) + MinKickDv ! Ann_KickLoc= 1 +! !write(*,*) 'pointer 1' +! call Op_MudDischarged_Volume%Remove (Op_KickLoc) ! Op_KickLoc= last +! call Op_Mud_Backhead_X%Remove (Op_KickLoc) +! call Op_Mud_Backhead_section%Remove (Op_KickLoc) +! call Op_Mud_Forehead_X%Remove (Op_KickLoc) +! call Op_Mud_Forehead_section%Remove (Op_KickLoc) +! call Op_Density%Remove (Op_KickLoc) +! call Op_RemainedVolume_in_LastSection%Remove (Op_KickLoc) +! call Op_EmptyVolume_inBackheadLocation%Remove (Op_KickLoc) +! call Op_MudOrKick%Remove (Op_KickLoc) +! +! !write(*,*) 'pointer 2' +! +! ! backheade kick zire mate bashad +! if (Op_KickLoc > 1) then +! +! if ( ABS(Op_Density%Array (Op_KickLoc-1) - data%State%MudSystem%NewDensity) > DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Array (Op_KickLoc-1)>42.) ) then +! !write(*,*) 'pointer 3' +! +! +! +! +! call Op_Density%AddTo (Op_KickLoc,data%State%MudSystem%NewDensity) +! call Op_MudDischarged_Volume%AddTo (Op_KickLoc,NewVolume) +! call Op_Mud_Forehead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddTo (Op_KickLoc,Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddTo (Op_KickLoc,Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddTo (Op_KickLoc,0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddTo (Op_KickLoc,0.0d0) +! call Op_MudOrKick%AddTo (Op_KickLoc,0) +! +! !write(*,*) 'pointer 4' +! +! else !Merge Condition +! +! Op_MudDischarged_Volume%Array (Op_KickLoc-1)= Op_MudDischarged_Volume%Array (Op_KickLoc-1) + NewVolume +! Op_Density%Array (Op_KickLoc-1)= (Op_MudDischarged_Volume%Array (Op_KickLoc-1)*Op_Density%Array (Op_KickLoc-1)+NewVolume*data%State%MudSystem%NewDensity) / & +! (Op_MudDischarged_Volume%Array (Op_KickLoc-1)+NewVolume) +! +! endif +! +! else !if Op_KickLoc == 1 (*****Migration Start*****) *5-2=============================== +! !write(*,*) 'pointer 5' +! +! +! !write(*,*) 'pointer 6' +! +! +! call Op_Density%AddToFirst (data%State%MudSystem%NewDensity) +! call Op_MudDischarged_Volume%AddToFirst (NewVolume) +! call Op_Mud_Forehead_X%AddToFirst (Old_KickBackHead_X) +! call Op_Mud_Forehead_section%AddToFirst (Old_KickBackHead_Section) +! call Op_Mud_Backhead_X%AddToFirst (Old_KickBackHead_X) +! call Op_Mud_Backhead_section%AddToFirst (Old_KickBackHead_Section) +! call Op_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Op_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call Op_MudOrKick%AddToFirst (0) +! !write(*,*) 'pointer 7' +! +! endif +! +! +! endif +! +! +! +! endif !( ((data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) < KickDv ) ! sorate pump kamtar az kick bashad +! +! +! +! +! endif + +!======================================================================================== + +ENDDO ! KickNumber= 1, NewInfluxNumber +data%State%MudSystem%KickNumber = kickNumber + +!write(*,*) 'c)Ann_MudDischarged_Volume%Array(:)=' , sum(Ann_MudDischarged_Volume%Array(:)) + + + + end subroutine Kick_Migration diff --git a/Equipments/MudSystem/MudSystem.f90 b/Equipments/MudSystem/MudSystem.f90 index 9ccd467..6167e04 100644 --- a/Equipments/MudSystem/MudSystem.f90 +++ b/Equipments/MudSystem/MudSystem.f90 @@ -649,7 +649,7 @@ use SimulationVariables !@ Integer I data%State%MudSystem%MudSys_timeCounter = data%State%MudSystem%MudSys_timeCounter + 1 - if (data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then data%State%MudSystem%MudSys_timeCounter= 0 endif @@ -973,7 +973,7 @@ use SimulationVariables !@ !write(*,*) 'data%State%MudSystem%MudVolume_InjectedFromAnn-WellToBellNipple=' , data%State%MudSystem%MudVolume_InjectedFromAnn !write(*,*) 'Ann_Kick_Saved_Volume=' , Ann_Kick_Saved_Volume sys_total_injected= sys_total_injected+ data%State%MudSystem%MudVolume_InjectedFromAnn - if (data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then sys_total_injected= 0. endif !write(*,*) 'sys_total_injected=' , sys_total_injected @@ -1166,7 +1166,7 @@ use SimulationVariables !@ total_active_increase= total_active_increase + active_increase - if (data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then total_active_increase= 0. endif @@ -1601,7 +1601,7 @@ use SimulationVariables !@ endif - data%EquipmentControl%StandPipeManifold%StandPipeGauge1= (1 - data%State%MudSystem%StandPipeGauge1Malf) * data%State%MudSystem%PressureGauge75 ! for STManifold Display + data%Equipments%StandPipeManifold%StandPipeGauge1= (1 - data%State%MudSystem%StandPipeGauge1Malf) * data%State%MudSystem%PressureGauge75 ! for STManifold Display !write(*,*) 'PressureGauge75=' , PressureGauge75 !P1toSt= jj2*(1-H82)*(1-DumpPump1)*G82 !P2toSt= jj12*(1-H83)*(1-DumpPump2)*G83 @@ -1633,7 +1633,7 @@ use SimulationVariables !@ !if (L78 == 1) PressureGauge76= 0. !Dump to Gauge76 endif - data%EquipmentControl%StandPipeManifold%StandPipeGauge2= (1 - data%State%MudSystem%StandPipeGauge2Malf) * data%State%MudSystem%PressureGauge76 ! for STManifold Display + data%Equipments%StandPipeManifold%StandPipeGauge2= (1 - data%State%MudSystem%StandPipeGauge2Malf) * data%State%MudSystem%PressureGauge76 ! for STManifold Display !=========================================================================================================================== !=========================================================================================================================== ! @@ -1658,10 +1658,10 @@ use SimulationVariables !@ if (data%State%StudentStation%TapSelector == .false.) then - data%EquipmentControl%DrillingWatch%PumpPressure= data%State%MudSystem%PressureGauge75 !for DrillWatch Display + data%Equipments%DrillingWatch%PumpPressure= data%State%MudSystem%PressureGauge75 !for DrillWatch Display CALL Set_StandPipePressure(real((1-data%State%MudSystem%DrillPipePressureMalf)*data%State%MudSystem%PressureGauge75 , 8)) !for Data Display Console else - data%EquipmentControl%DrillingWatch%PumpPressure= data%State%MudSystem%PressureGauge76 !for DrillWatch Display + data%Equipments%DrillingWatch%PumpPressure= data%State%MudSystem%PressureGauge76 !for DrillWatch Display CALL Set_StandPipePressure(real((1-data%State%MudSystem%DrillPipePressureMalf)*data%State%MudSystem%PressureGauge76 , 8)) !for Data Display Console endif @@ -1705,7 +1705,7 @@ use SimulationVariables !@ !write(*,*) 'Active-decline=' , A71*(((1./RealJ2)*data%State%Pump(1)%Flow_Rate/60.)*DeltaT_Mudline) total_decrease= total_decrease+ A71*(((1./RealJ2)*data%State%Pump(1)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) - if (data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then total_decrease= 0. endif !write(*,*) 'total_decrease=' , total_decrease @@ -1865,7 +1865,7 @@ use SimulationVariables !@ data%State%MudSystem%CompressedMudDensity= data%State%MudSystem%Suction_Density_MudSystem - data%EquipmentControl%DrillingWatch%MudWeightIn= data%State%MudSystem%Suction_Density_MudSystem !for drillwatch display + data%Equipments%DrillingWatch%MudWeightIn= data%State%MudSystem%Suction_Density_MudSystem !for drillwatch display data%State%MUD(2)%Q= jj2*(1-H82)*(1-DumpPump1)*G82*data%State%Pump(1)%Flow_Rate + jj12*(1-H83)*(1-DumpPump2)*G83*data%State%Pump(2)%Flow_Rate + jj13*(1-H84)*(1-DumpCementPump)*G84*data%State%Pump(3)%Flow_Rate @@ -2021,7 +2021,7 @@ use SimulationVariables !@ call Set_ActiveDensity_StudentStation(real(data%State%MudSystem%ActiveTankDensity,8)) call Set_ReserveMudVolume_StudentStation(real(data%State%MudSystem%ReserveTankVolume/42.,8)) ! 42: gal to bbl call Set_ReserveDensity_StudentStation(real(data%State%MudSystem%ReserveTankDensity,8)) - data%EquipmentControl%DrillingWatch%KillMudVolume= data%State%MudSystem%ReserveTankVolume/42. ! for DrillWatch + data%Equipments%DrillingWatch%KillMudVolume= data%State%MudSystem%ReserveTankVolume/42. ! for DrillWatch !PitGainLose= @@ -2030,32 +2030,32 @@ use SimulationVariables !@ !!====================================================================== - IF (data%EquipmentControl%DataDisplayConsole%TotalStrokeCounterResetSwitch == 1) then !for drilling data display + IF (data%Equipments%DataDisplayConsole%TotalStrokeCounterResetSwitch == 1) then !for drilling data display data%State%MudSystem%TotalStrokesPump1=0. data%State%MudSystem%TotalStrokesPump2=0. ENDIF - data%State%MudSystem%TotalStrokesPump1=data%State%MudSystem%TotalStrokesPump1+((data%EquipmentControl%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline !for drilling data display - data%State%MudSystem%TotalStrokesPump2=data%State%MudSystem%TotalStrokesPump2+((data%EquipmentControl%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline !for drilling data display - data%State%MudSystem%GraphTotalStrokes=data%State%MudSystem%GraphTotalStrokes+((data%EquipmentControl%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline+((data%EquipmentControl%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + data%State%MudSystem%TotalStrokesPump1=data%State%MudSystem%TotalStrokesPump1+((data%Equipments%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline !for drilling data display + data%State%MudSystem%TotalStrokesPump2=data%State%MudSystem%TotalStrokesPump2+((data%Equipments%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline !for drilling data display + data%State%MudSystem%GraphTotalStrokes=data%State%MudSystem%GraphTotalStrokes+((data%Equipments%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline+((data%Equipments%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline - data%State%MPumps%Total_Stroke_Counter_For_Plot = data%State%MPumps%Total_Stroke_Counter_For_Plot + ((data%EquipmentControl%DataDisplayConsole%MP1SPMGauge + data%EquipmentControl%DataDisplayConsole%MP2SPMGauge) / 60.0) * data%State%MudSystem%DeltaT_Mudline + data%State%MPumps%Total_Stroke_Counter_For_Plot = data%State%MPumps%Total_Stroke_Counter_For_Plot + ((data%Equipments%DataDisplayConsole%MP1SPMGauge + data%Equipments%DataDisplayConsole%MP2SPMGauge) / 60.0) * data%State%MudSystem%DeltaT_Mudline ! CALL SetTotalStrokes(INT(data%State%MPumps%Total_Stroke_Counter_For_Plot)) - data%EquipmentControl%DataDisplayConsole%TotalStrokeCounter= real(nint(data%State%MudSystem%TotalStrokesPump1+data%State%MudSystem%TotalStrokesPump2)) !for drilling data display + data%Equipments%DataDisplayConsole%TotalStrokeCounter= real(nint(data%State%MudSystem%TotalStrokesPump1+data%State%MudSystem%TotalStrokesPump2)) !for drilling data display !=========================================================================== ! MUD PUMP STROKES ! & TOTAL STROKE- CHOKE CONTROL PANEL !=========================================================================== !write(*,*) 'a)))' , ChokePanelStrokeResetSwitch - if (data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then - IF (data%EquipmentControl%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 1) THEN + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + IF (data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 1) THEN !write(*,*) '1 reset' data%State%Choke%TotalStrokes1 =0. - elseif (data%EquipmentControl%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 2) THEN + elseif (data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 2) THEN !write(*,*) '2 reset' data%State%Choke%TotalStrokes2 =0. else @@ -2069,20 +2069,20 @@ use SimulationVariables !@ !write(*,*) 'b)))' , ChokePanelStrokeResetSwitch - data%State%Choke%TotalStrokes1= data%State%Choke%TotalStrokes1+((data%EquipmentControl%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline - data%State%Choke%TotalStrokes2= data%State%Choke%TotalStrokes2+((data%EquipmentControl%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + data%State%Choke%TotalStrokes1= data%State%Choke%TotalStrokes1+((data%Equipments%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + data%State%Choke%TotalStrokes2= data%State%Choke%TotalStrokes2+((data%Equipments%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline - IF (data%EquipmentControl%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 1) THEN - data%EquipmentControl%ChokeControlPanel%ChokePanelSPMCounter = real(nint(data%EquipmentControl%DataDisplayConsole%MP1SPMGauge)) - data%EquipmentControl%ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(data%State%Choke%TotalStrokes1)) - ELSEIF (data%EquipmentControl%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 2) THEN - data%EquipmentControl%ChokeControlPanel%ChokePanelSPMCounter = real(nint(data%EquipmentControl%DataDisplayConsole%MP2SPMGauge)) - data%EquipmentControl%ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(data%State%Choke%TotalStrokes2)) + IF (data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 1) THEN + data%Equipments%ChokeControlPanel%ChokePanelSPMCounter = real(nint(data%Equipments%DataDisplayConsole%MP1SPMGauge)) + data%Equipments%ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(data%State%Choke%TotalStrokes1)) + ELSEIF (data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 2) THEN + data%Equipments%ChokeControlPanel%ChokePanelSPMCounter = real(nint(data%Equipments%DataDisplayConsole%MP2SPMGauge)) + data%Equipments%ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(data%State%Choke%TotalStrokes2)) ELSE - data%EquipmentControl%ChokeControlPanel%ChokePanelSPMCounter= real(nint(data%EquipmentControl%DataDisplayConsole%MP1SPMGauge+data%EquipmentControl%DataDisplayConsole%MP2SPMGauge)) - data%EquipmentControl%ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(data%State%Choke%TotalStrokes1+data%State%Choke%TotalStrokes2)) + data%Equipments%ChokeControlPanel%ChokePanelSPMCounter= real(nint(data%Equipments%DataDisplayConsole%MP1SPMGauge+data%Equipments%DataDisplayConsole%MP2SPMGauge)) + data%Equipments%ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(data%State%Choke%TotalStrokes1+data%State%Choke%TotalStrokes2)) ENDIF ! ChokePanelStrokeResetSwitch = 0 @@ -2093,7 +2093,7 @@ use SimulationVariables !@ !!====================================================================== - data%EquipmentControl%DrillingWatch%PitVolume= data%State%MudSystem%ActiveTankVolume/42.d0 !(bbl) For DrillWatch Display + data%Equipments%DrillingWatch%PitVolume= data%State%MudSystem%ActiveTankVolume/42.d0 !(bbl) For DrillWatch Display !write(*,*) 'PitVolume,ActiveTankVolume=' ,PitVolume,ActiveTankVolume @@ -2107,11 +2107,11 @@ use SimulationVariables !@ - IF (data%EquipmentControl%DataDisplayConsole%MVTPowerSwitch==1) THEN - data%EquipmentControl%DataDisplayConsole%MudTanksVolumeGauge= (1 - data%State%MudSystem%MudTanksVolumeGaugeMalf) *((data%State%MudSystem%MudTank1_vol*data%EquipmentControl%DataDisplayConsole%MudTank1Switch)+(data%State%MudSystem%MudTank2_vol*data%EquipmentControl%DataDisplayConsole%MudTank2Switch)+ & - (data%State%MudSystem%MudTank3_vol*data%EquipmentControl%DataDisplayConsole%MudTank3Switch)+(data%State%MudSystem%MudTank4_vol*data%EquipmentControl%DataDisplayConsole%MudTank4Switch)+data%State%MudSystem%ActiveTankSettled) !(gal) - ELSEIF (data%EquipmentControl%DataDisplayConsole%MVTPowerSwitch==0) THEN - data%EquipmentControl%DataDisplayConsole%MudTanksVolumeGauge= (1 - data%State%MudSystem%MudTanksVolumeGaugeMalf) *0. + IF (data%Equipments%DataDisplayConsole%MVTPowerSwitch==1) THEN + data%Equipments%DataDisplayConsole%MudTanksVolumeGauge= (1 - data%State%MudSystem%MudTanksVolumeGaugeMalf) *((data%State%MudSystem%MudTank1_vol*data%Equipments%DataDisplayConsole%MudTank1Switch)+(data%State%MudSystem%MudTank2_vol*data%Equipments%DataDisplayConsole%MudTank2Switch)+ & + (data%State%MudSystem%MudTank3_vol*data%Equipments%DataDisplayConsole%MudTank3Switch)+(data%State%MudSystem%MudTank4_vol*data%Equipments%DataDisplayConsole%MudTank4Switch)+data%State%MudSystem%ActiveTankSettled) !(gal) + ELSEIF (data%Equipments%DataDisplayConsole%MVTPowerSwitch==0) THEN + data%Equipments%DataDisplayConsole%MudTanksVolumeGauge= (1 - data%State%MudSystem%MudTanksVolumeGaugeMalf) *0. ENDIF !!====================================================================== @@ -2121,27 +2121,27 @@ use SimulationVariables !@ - ! IF (data%EquipmentControl%DataDisplayConsole%MVTPowerSwitch==1 .and. IsPortable==.false.) THEN + ! IF (data%Equipments%DataDisplayConsole%MVTPowerSwitch==1 .and. IsPortable==.false.) THEN - ! IF (data%EquipmentControl%DataDisplayConsole%MVTSetAlarmSwitch==0) THEN + ! IF (data%Equipments%DataDisplayConsole%MVTSetAlarmSwitch==0) THEN - ! data%EquipmentControl%DataDisplayConsole%PitGainLossGauge= ( ((ActiveTankVolume/42.) - RefrencePitVolume)) - PitGainLossGaugeMalf*(( ((ActiveTankVolume/42.) - RefrencePitVolume))+50) !(bbl) + ! data%Equipments%DataDisplayConsole%PitGainLossGauge= ( ((ActiveTankVolume/42.) - RefrencePitVolume)) - PitGainLossGaugeMalf*(( ((ActiveTankVolume/42.) - RefrencePitVolume))+50) !(bbl) - ! ELSEIF (data%EquipmentControl%DataDisplayConsole%MVTSetAlarmSwitch==-1) THEN + ! ELSEIF (data%Equipments%DataDisplayConsole%MVTSetAlarmSwitch==-1) THEN - ! MVT_MinVol_Allowded= PitGainLossZero+ MIN(0.,(data%EquipmentControl%DataDisplayConsole%MVTSetAlarmLowKnob-50))-0.1 - ! data%EquipmentControl%DataDisplayConsole%PitGainLossGauge= MVT_MinVol_Allowded - PitGainLossGaugeMalf*(MVT_MinVol_Allowded+50) + ! MVT_MinVol_Allowded= PitGainLossZero+ MIN(0.,(data%Equipments%DataDisplayConsole%MVTSetAlarmLowKnob-50))-0.1 + ! data%Equipments%DataDisplayConsole%PitGainLossGauge= MVT_MinVol_Allowded - PitGainLossGaugeMalf*(MVT_MinVol_Allowded+50) ! ! - PitGainLossGaugeMalf*(MVT_MinVol_Allowded+50) : Malf effect ! !PitGainLose=(MVT_MinVol_Allowded) ! DrillWatch (incorrect) ! !RefrencePitVolume= ActiveTankVolume/42. !(bbl) ! ELSE !(MVTSetAlarmSwitch==1) - ! MVT_MaxVol_Allowded= PitGainLossZero+ MAX(0., (data%EquipmentControl%DataDisplayConsole%MVTSetAlarmHighKnob-50.))+0.1 - ! data%EquipmentControl%DataDisplayConsole%PitGainLossGauge= MVT_MaxVol_Allowded - PitGainLossGaugeMalf*(MVT_MaxVol_Allowded+50) + ! MVT_MaxVol_Allowded= PitGainLossZero+ MAX(0., (data%Equipments%DataDisplayConsole%MVTSetAlarmHighKnob-50.))+0.1 + ! data%Equipments%DataDisplayConsole%PitGainLossGauge= MVT_MaxVol_Allowded - PitGainLossGaugeMalf*(MVT_MaxVol_Allowded+50) ! ! - PitGainLossGaugeMalf*(MVT_MaxVol_Allowded+50) : Malf effect ! !PitGainLose=(MVT_MaxVol_Allowded) ! DrillWatch (incorrect) ! !RefrencePitVolume= ActiveTankVolume/42. !(bbl) @@ -2156,25 +2156,25 @@ use SimulationVariables !@ ! IF ( ActiveTankVolume/42. < (RefrencePitVolume-ABS(MVT_MinVol_Allowded)) .OR. ActiveTankVolume/42. > (RefrencePitVolume+ABS(MVT_MaxVol_Allowded)) ) THEN - ! data%EquipmentControl%DataDisplayConsole%MVTAlarmLED = 1 !(blinking) - ! IF (data%EquipmentControl%DataDisplayConsole%MVTHornSwitch) THEN - ! data%EquipmentControl%DataDisplayConsole%Buzzer2= .TRUE. + ! data%Equipments%DataDisplayConsole%MVTAlarmLED = 1 !(blinking) + ! IF (data%Equipments%DataDisplayConsole%MVTHornSwitch) THEN + ! data%Equipments%DataDisplayConsole%Buzzer2= .TRUE. ! ELSE - ! data%EquipmentControl%DataDisplayConsole%Buzzer2= .FALSE. + ! data%Equipments%DataDisplayConsole%Buzzer2= .FALSE. ! ENDIF ! ELSE - ! data%EquipmentControl%DataDisplayConsole%MVTAlarmLED = 0 !(OFF) - ! data%EquipmentControl%DataDisplayConsole%Buzzer2= .false. + ! data%Equipments%DataDisplayConsole%MVTAlarmLED = 0 !(OFF) + ! data%Equipments%DataDisplayConsole%Buzzer2= .false. ! ENDIF - ! ELSEIF (data%EquipmentControl%DataDisplayConsole%MVTPowerSwitch==0) THEN + ! ELSEIF (data%Equipments%DataDisplayConsole%MVTPowerSwitch==0) THEN ! !MudTanksVolumeGauge= 0. - ! data%EquipmentControl%DataDisplayConsole%PitGainLossGauge= -50 - ! data%EquipmentControl%DataDisplayConsole%MVTAlarmLED= 0 - ! data%EquipmentControl%DataDisplayConsole%Buzzer2= .false. + ! data%Equipments%DataDisplayConsole%PitGainLossGauge= -50 + ! data%Equipments%DataDisplayConsole%MVTAlarmLED= 0 + ! data%Equipments%DataDisplayConsole%Buzzer2= .false. ! ENDIF @@ -2186,10 +2186,10 @@ use SimulationVariables !@ - data%EquipmentControl%DrillingWatch%PercentFlow= (data%State%MudSystem%ReturnFlowRate/data%State%MudSystem%PedalMeter) *100. !(percent) ! for DrillWatch display - if (abs(data%EquipmentControl%DrillingWatch%PercentFlow - unityreturn) > 1.0) then + data%Equipments%DrillingWatch%PercentFlow= (data%State%MudSystem%ReturnFlowRate/data%State%MudSystem%PedalMeter) *100. !(percent) ! for DrillWatch display + if (abs(data%Equipments%DrillingWatch%PercentFlow - unityreturn) > 1.0) then - write(*,*) 'PercentFlow,ReturnFlowRate,PedalMeter=' , data%EquipmentControl%DrillingWatch%PercentFlow,data%State%MudSystem%ReturnFlowRate,data%State%MudSystem%PedalMeter + write(*,*) 'PercentFlow,ReturnFlowRate,PedalMeter=' , data%Equipments%DrillingWatch%PercentFlow,data%State%MudSystem%ReturnFlowRate,data%State%MudSystem%PedalMeter write(*,*) 'unityreturn=' , unityreturn endif @@ -2204,27 +2204,27 @@ use SimulationVariables !@ !! DRILL WATCH !!====================================================================== - data%EquipmentControl%DrillingWatch%PitGainLose= ((data%State%MudSystem%ActiveTankVolume/42.) - data%State%MudSystem%RefrencePitVolume_DrillWatch) ! DrillWatch + data%Equipments%DrillingWatch%PitGainLose= ((data%State%MudSystem%ActiveTankVolume/42.) - data%State%MudSystem%RefrencePitVolume_DrillWatch) ! DrillWatch !write(*,*) 'PitGainLose galon' , PitGainLose*42. ! if (IsPortable) then - ! MVT_MinVol_Allowded= data%EquipmentControl%DataDisplayConsole%PitAlarmLow - ! MVT_MaxVol_Allowded= data%EquipmentControl%DataDisplayConsole%PitAlarmHigh + ! MVT_MinVol_Allowded= data%Equipments%DataDisplayConsole%PitAlarmLow + ! MVT_MaxVol_Allowded= data%Equipments%DataDisplayConsole%PitAlarmHigh ! IF ( ActiveTankVolume/42. < (RefrencePitVolume-ABS(MVT_MinVol_Allowded)) .OR. ActiveTankVolume/42. > (RefrencePitVolume+ABS(MVT_MaxVol_Allowded)) ) THEN - ! data%EquipmentControl%DataDisplayConsole%MVTAlarmLED = 1 !(blinking) - ! IF (data%EquipmentControl%DataDisplayConsole%MVTHornSwitch) THEN - ! data%EquipmentControl%DataDisplayConsole%Buzzer2= .TRUE. + ! data%Equipments%DataDisplayConsole%MVTAlarmLED = 1 !(blinking) + ! IF (data%Equipments%DataDisplayConsole%MVTHornSwitch) THEN + ! data%Equipments%DataDisplayConsole%Buzzer2= .TRUE. ! ELSE - ! data%EquipmentControl%DataDisplayConsole%Buzzer2= .FALSE. + ! data%Equipments%DataDisplayConsole%Buzzer2= .FALSE. ! ENDIF ! ELSE - ! data%EquipmentControl%DataDisplayConsole%MVTAlarmLED = 0 !(OFF) - ! data%EquipmentControl%DataDisplayConsole%Buzzer2= .false. + ! data%Equipments%DataDisplayConsole%MVTAlarmLED = 0 !(OFF) + ! data%Equipments%DataDisplayConsole%Buzzer2= .false. ! ENDIF ! endif @@ -2232,11 +2232,11 @@ use SimulationVariables !@ if (data%State%StudentStation%PitGainLossZero) then - data%EquipmentControl%DrillingWatch%PitGainLose= 0.d0 !DrillWatch + data%Equipments%DrillingWatch%PitGainLose= 0.d0 !DrillWatch data%State%MudSystem%RefrencePitVolume_DrillWatch= data%State%MudSystem%ActiveTankVolume/42. !(bbl) !DrillWatch !********************************************* - data%EquipmentControl%DataDisplayConsole%PitGainLossGauge= 0. !MFF Indicator + data%Equipments%DataDisplayConsole%PitGainLossGauge= 0. !MFF Indicator data%State%MudSystem%RefrencePitVolume= data%State%MudSystem%ActiveTankVolume/42. !(bbl) !MFF Indicator endif @@ -2251,28 +2251,28 @@ use SimulationVariables !@ !! MUD FLOW-FILL INDICATOR !!====================================================================== - IF (data%EquipmentControl%DataDisplayConsole%MFFIPowerSwitch==1 ) THEN !.and. IsPortable==.false. + IF (data%Equipments%DataDisplayConsole%MFFIPowerSwitch==1 ) THEN !.and. IsPortable==.false. !====================TotalStrokes Reset and Calculate====================== - if (data%EquipmentControl%DataDisplayConsole%MFFIResetTotalStrokes == 1) then - IF (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN + if (data%Equipments%DataDisplayConsole%MFFIResetTotalStrokes == 1) then + IF (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN data%State%MudSystem%TotalStrokes1MFFI =0. - elseif (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) THEN + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) THEN data%State%MudSystem%TotalStrokes2MFFI =0. else data%State%MudSystem%TotalStrokes1MFFI =0. data%State%MudSystem%TotalStrokes2MFFI =0. endif endif - data%State%MudSystem%TotalStrokes1MFFI= data%State%MudSystem%TotalStrokes1MFFI+((data%EquipmentControl%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline - data%State%MudSystem%TotalStrokes2MFFI= data%State%MudSystem%TotalStrokes2MFFI+((data%EquipmentControl%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + data%State%MudSystem%TotalStrokes1MFFI= data%State%MudSystem%TotalStrokes1MFFI+((data%Equipments%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + data%State%MudSystem%TotalStrokes2MFFI= data%State%MudSystem%TotalStrokes2MFFI+((data%Equipments%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline !==================FillStrokes Reset and Calculate========================= - if (data%EquipmentControl%DataDisplayConsole%MFFIResetFillCounter == 1) then - IF (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN + if (data%Equipments%DataDisplayConsole%MFFIResetFillCounter == 1) then + IF (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN data%State%MudSystem%TotalFillStrokes1MFFI =0. - elseif (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) THEN + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) THEN data%State%MudSystem%TotalFillStrokes2MFFI =0. else data%State%MudSystem%TotalFillStrokes1MFFI =0. @@ -2281,37 +2281,37 @@ use SimulationVariables !@ endif - data%State%MudSystem%TotalFillStrokes1MFFI= data%State%MudSystem%TotalFillStrokes1MFFI+((data%EquipmentControl%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline - data%State%MudSystem%TotalFillStrokes2MFFI= data%State%MudSystem%TotalFillStrokes2MFFI+((data%EquipmentControl%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + data%State%MudSystem%TotalFillStrokes1MFFI= data%State%MudSystem%TotalFillStrokes1MFFI+((data%Equipments%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + data%State%MudSystem%TotalFillStrokes2MFFI= data%State%MudSystem%TotalFillStrokes2MFFI+((data%Equipments%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline !=================================================================== - if (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then - data%EquipmentControl%DataDisplayConsole%MFFITotalStrokeCounter = real(nint(data%State%MudSystem%TotalStrokes1MFFI)) !TotalStroke LED - elseif (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then - data%EquipmentControl%DataDisplayConsole%MFFITotalStrokeCounter = real(nint(data%State%MudSystem%TotalStrokes2MFFI)) !TotalStroke LED - elseif (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then - data%EquipmentControl%DataDisplayConsole%MFFITotalStrokeCounter = real(nint(data%State%MudSystem%TotalStrokes1MFFI+data%State%MudSystem%TotalStrokes2MFFI)) !TotalStroke LED + if (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter = real(nint(data%State%MudSystem%TotalStrokes1MFFI)) !TotalStroke LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter = real(nint(data%State%MudSystem%TotalStrokes2MFFI)) !TotalStroke LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter = real(nint(data%State%MudSystem%TotalStrokes1MFFI+data%State%MudSystem%TotalStrokes2MFFI)) !TotalStroke LED endif - IF (data%EquipmentControl%DataDisplayConsole%MFFIFillSPMSelectorSwitch== .false.) THEN !(spm mode) - if (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then - data%EquipmentControl%DataDisplayConsole%FillStrokeCounter = real(nint(data%EquipmentControl%DataDisplayConsole%MP1SPMGauge)) !Fill or SPM LED - elseif (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then - data%EquipmentControl%DataDisplayConsole%FillStrokeCounter = real(nint(data%EquipmentControl%DataDisplayConsole%MP2SPMGauge)) !Fill or SPM LED - elseif (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then - data%EquipmentControl%DataDisplayConsole%FillStrokeCounter= real(nint(data%EquipmentControl%DataDisplayConsole%MP1SPMGauge+data%EquipmentControl%DataDisplayConsole%MP2SPMGauge)) !Fill or SPM LED + IF (data%Equipments%DataDisplayConsole%MFFIFillSPMSelectorSwitch== .false.) THEN !(spm mode) + if (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = real(nint(data%Equipments%DataDisplayConsole%MP1SPMGauge)) !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = real(nint(data%Equipments%DataDisplayConsole%MP2SPMGauge)) !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + data%Equipments%DataDisplayConsole%FillStrokeCounter= real(nint(data%Equipments%DataDisplayConsole%MP1SPMGauge+data%Equipments%DataDisplayConsole%MP2SPMGauge)) !Fill or SPM LED endif ELSE ! (MFFIFillSPMSelectorSwitch== .true.) then !(fill mode) if (data%State%MudSystem%ReturnFlowRate== 0) then - if (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then - data%EquipmentControl%DataDisplayConsole%FillStrokeCounter = real(nint(data%State%MudSystem%TotalFillStrokes1MFFI)) !Fill or SPM LED - elseif (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then - data%EquipmentControl%DataDisplayConsole%FillStrokeCounter = real(nint(data%State%MudSystem%TotalFillStrokes2MFFI)) !Fill or SPM LED - elseif (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then - data%EquipmentControl%DataDisplayConsole%FillStrokeCounter= real(nint(data%State%MudSystem%TotalFillStrokes1MFFI+data%State%MudSystem%TotalFillStrokes2MFFI)) !Fill or SPM LED + if (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = real(nint(data%State%MudSystem%TotalFillStrokes1MFFI)) !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = real(nint(data%State%MudSystem%TotalFillStrokes2MFFI)) !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + data%Equipments%DataDisplayConsole%FillStrokeCounter= real(nint(data%State%MudSystem%TotalFillStrokes1MFFI+data%State%MudSystem%TotalFillStrokes2MFFI)) !Fill or SPM LED endif @@ -2324,12 +2324,12 @@ use SimulationVariables !@ else !(ReturnFlowRate>0) ! these values=fix on LED after the well filled - if (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then - data%EquipmentControl%DataDisplayConsole%FillStrokeCounter = data%State%MudSystem%TotalFilledStrokesBy1MFFI !Fill or SPM LED - elseif (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then - data%EquipmentControl%DataDisplayConsole%FillStrokeCounter = data%State%MudSystem%TotalFilledStrokesBy2MFFI !Fill or SPM LED - elseif (data%EquipmentControl%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then - data%EquipmentControl%DataDisplayConsole%FillStrokeCounter= data%State%MudSystem%TotalFilledStrokesBy1and2MFFI !Fill or SPM LED + if (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = data%State%MudSystem%TotalFilledStrokesBy1MFFI !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = data%State%MudSystem%TotalFilledStrokesBy2MFFI !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + data%Equipments%DataDisplayConsole%FillStrokeCounter= data%State%MudSystem%TotalFilledStrokesBy1and2MFFI !Fill or SPM LED endif endif @@ -2344,69 +2344,69 @@ use SimulationVariables !@ if (data%State%MudSystem%ReturnFlowRate>0) then - data%EquipmentControl%DataDisplayConsole%MFFIPumpLED=1 !(Returns Lamp) + data%Equipments%DataDisplayConsole%MFFIPumpLED=1 !(Returns Lamp) else - data%EquipmentControl%DataDisplayConsole%MFFIPumpLED=0 !(Returns Lamp) + data%Equipments%DataDisplayConsole%MFFIPumpLED=0 !(Returns Lamp) endif - IF (data%EquipmentControl%DataDisplayConsole%MFFISetAlarmSwitch==0) THEN + IF (data%Equipments%DataDisplayConsole%MFFISetAlarmSwitch==0) THEN - data%EquipmentControl%DataDisplayConsole%ReturnMudFlowGauge= (1 - data%State%MudSystem%ReturnMudFlowGaugeMalf)*data%State%MudSystem%ReturnFlowPercent !(percent) + data%Equipments%DataDisplayConsole%ReturnMudFlowGauge= (1 - data%State%MudSystem%ReturnMudFlowGaugeMalf)*data%State%MudSystem%ReturnFlowPercent !(percent) - ELSEIF (data%EquipmentControl%DataDisplayConsole%MFFISetAlarmSwitch==-1) THEN - data%State%MudSystem%MFFI_MinPercent_Allowded=data%EquipmentControl%DataDisplayConsole%MFFISetAlarmLowKnob - data%EquipmentControl%DataDisplayConsole%ReturnMudFlowGauge= (1 - data%State%MudSystem%ReturnMudFlowGaugeMalf)*data%State%MudSystem%MFFI_MinPercent_Allowded + ELSEIF (data%Equipments%DataDisplayConsole%MFFISetAlarmSwitch==-1) THEN + data%State%MudSystem%MFFI_MinPercent_Allowded=data%Equipments%DataDisplayConsole%MFFISetAlarmLowKnob + data%Equipments%DataDisplayConsole%ReturnMudFlowGauge= (1 - data%State%MudSystem%ReturnMudFlowGaugeMalf)*data%State%MudSystem%MFFI_MinPercent_Allowded ELSE !(MFFISetAlarmSwitch==1) - data%State%MudSystem%MFFI_MaxPercent_Allowded=data%EquipmentControl%DataDisplayConsole%MFFISetAlarmHighKnob - data%EquipmentControl%DataDisplayConsole%ReturnMudFlowGauge= (1 - data%State%MudSystem%ReturnMudFlowGaugeMalf)*data%State%MudSystem%MFFI_MaxPercent_Allowded + data%State%MudSystem%MFFI_MaxPercent_Allowded=data%Equipments%DataDisplayConsole%MFFISetAlarmHighKnob + data%Equipments%DataDisplayConsole%ReturnMudFlowGauge= (1 - data%State%MudSystem%ReturnMudFlowGaugeMalf)*data%State%MudSystem%MFFI_MaxPercent_Allowded ENDIF IF (data%State%MudSystem%ReturnFlowPercentdata%State%MudSystem%MFFI_MaxPercent_Allowded) THEN !write(*,*) 'alarm return:' , ReturnFlowRate - data%EquipmentControl%DataDisplayConsole%MFFIAlarmLED = 2 !(blinking) - IF (data%EquipmentControl%DataDisplayConsole%MFFIHornSwitch) THEN - data%EquipmentControl%DataDisplayConsole%Buzzer3= .true. + data%Equipments%DataDisplayConsole%MFFIAlarmLED = 2 !(blinking) + IF (data%Equipments%DataDisplayConsole%MFFIHornSwitch) THEN + data%Equipments%DataDisplayConsole%Buzzer3= .true. ELSE - data%EquipmentControl%DataDisplayConsole%Buzzer3= .FALSE. + data%Equipments%DataDisplayConsole%Buzzer3= .FALSE. ENDIF ELSE - data%EquipmentControl%DataDisplayConsole%MFFIAlarmLED = 0 !(OFF) - data%EquipmentControl%DataDisplayConsole%Buzzer3= .false. + data%Equipments%DataDisplayConsole%MFFIAlarmLED = 0 !(OFF) + data%Equipments%DataDisplayConsole%Buzzer3= .false. ENDIF !=================================================================================== - ELSEIF (data%EquipmentControl%DataDisplayConsole%MFFIPowerSwitch==0) THEN - data%EquipmentControl%DataDisplayConsole%ReturnMudFlowGauge= 0. - data%EquipmentControl%DataDisplayConsole%FillStrokeCounter= 0 - data%EquipmentControl%DataDisplayConsole%MFFITotalStrokeCounter= 0 - data%EquipmentControl%DataDisplayConsole%MFFIAlarmLED= 0 - data%EquipmentControl%DataDisplayConsole%Buzzer3= .false. + ELSEIF (data%Equipments%DataDisplayConsole%MFFIPowerSwitch==0) THEN + data%Equipments%DataDisplayConsole%ReturnMudFlowGauge= 0. + data%Equipments%DataDisplayConsole%FillStrokeCounter= 0 + data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter= 0 + data%Equipments%DataDisplayConsole%MFFIAlarmLED= 0 + data%Equipments%DataDisplayConsole%Buzzer3= .false. ENDIF ! if ( IsPortable ) then - ! MFFI_MinPercent_Allowded=data%EquipmentControl%DataDisplayConsole%RetFlowAlarmLow - ! MFFI_MaxPercent_Allowded=data%EquipmentControl%DataDisplayConsole%RetFlowAlarmHigh + ! MFFI_MinPercent_Allowded=data%Equipments%DataDisplayConsole%RetFlowAlarmLow + ! MFFI_MaxPercent_Allowded=data%Equipments%DataDisplayConsole%RetFlowAlarmHigh ! IF (ReturnFlowPercentMFFI_MaxPercent_Allowded) THEN - ! data%EquipmentControl%DataDisplayConsole%MFFIAlarmLED = 1 !(blinking) - ! IF (data%EquipmentControl%DataDisplayConsole%MFFIHornSwitch) THEN - ! data%EquipmentControl%DataDisplayConsole%Buzzer3= .true. + ! data%Equipments%DataDisplayConsole%MFFIAlarmLED = 1 !(blinking) + ! IF (data%Equipments%DataDisplayConsole%MFFIHornSwitch) THEN + ! data%Equipments%DataDisplayConsole%Buzzer3= .true. ! ELSE - ! data%EquipmentControl%DataDisplayConsole%Buzzer3= .FALSE. + ! data%Equipments%DataDisplayConsole%Buzzer3= .FALSE. ! ENDIF ! ELSE - ! data%EquipmentControl%DataDisplayConsole%MFFIAlarmLED = 0 !(OFF) - ! data%EquipmentControl%DataDisplayConsole%Buzzer3= .false. + ! data%Equipments%DataDisplayConsole%MFFIAlarmLED = 0 !(OFF) + ! data%Equipments%DataDisplayConsole%Buzzer3= .false. ! ENDIF ! endif @@ -2416,66 +2416,66 @@ use SimulationVariables !@ !! TRIP TANK PANEL DISPLAY VALUES !!====================================================================== - data%EquipmentControl%Tank%TripTankVolume = data%State%MudSystem%TripTankVolumeCalc/42. !(Drill Watch display) - data%EquipmentControl%Tank%TripTankDensity= data%State%MudSystem%TripTankDensityCalc !(display) + data%Equipments%Tank%TripTankVolume = data%State%MudSystem%TripTankVolumeCalc/42. !(Drill Watch display) + data%Equipments%Tank%TripTankDensity= data%State%MudSystem%TripTankDensityCalc !(display) - IF (data%EquipmentControl%DataDisplayConsole%TripTankPowerSwitch==1 ) THEN !.and. IsPortable==.false. + IF (data%Equipments%DataDisplayConsole%TripTankPowerSwitch==1 ) THEN !.and. IsPortable==.false. - IF (data%EquipmentControl%DataDisplayConsole%TripTankSetAlarmSwitch==0) THEN + IF (data%Equipments%DataDisplayConsole%TripTankSetAlarmSwitch==0) THEN - data%EquipmentControl%DataDisplayConsole%TripTankGauge= (1 - data%State%MudSystem%TripTankPressure_DataDisplayMalf) * data%State%MudSystem%TripTankVolumeCalc ! (gal) - ELSEIF (data%EquipmentControl%DataDisplayConsole%TripTankSetAlarmSwitch==-1) THEN + data%Equipments%DataDisplayConsole%TripTankGauge= (1 - data%State%MudSystem%TripTankPressure_DataDisplayMalf) * data%State%MudSystem%TripTankVolumeCalc ! (gal) + ELSEIF (data%Equipments%DataDisplayConsole%TripTankSetAlarmSwitch==-1) THEN - data%State%MudSystem%TripTank_MinVol_Allowded= data%EquipmentControl%DataDisplayConsole%TripTankSetAlarmLow/2. ! 2: because knob input is 0-100 but gauge is 0-50 - data%EquipmentControl%DataDisplayConsole%TripTankGauge= (1 - data%State%MudSystem%TripTankPressure_DataDisplayMalf) * data%State%MudSystem%TripTank_MinVol_Allowded + data%State%MudSystem%TripTank_MinVol_Allowded= data%Equipments%DataDisplayConsole%TripTankSetAlarmLow/2. ! 2: because knob input is 0-100 but gauge is 0-50 + data%Equipments%DataDisplayConsole%TripTankGauge= (1 - data%State%MudSystem%TripTankPressure_DataDisplayMalf) * data%State%MudSystem%TripTank_MinVol_Allowded ELSE !(TripTankSetAlarmSwitch==1) - data%State%MudSystem%TripTank_MaxVol_Allowded= data%EquipmentControl%DataDisplayConsole%TripTankSetAlarmHigh/2. ! 2: because knob input is 0-100 but gauge is 0-50 - data%EquipmentControl%DataDisplayConsole%TripTankGauge= (1 - data%State%MudSystem%TripTankPressure_DataDisplayMalf) * data%State%MudSystem%TripTank_MaxVol_Allowded + data%State%MudSystem%TripTank_MaxVol_Allowded= data%Equipments%DataDisplayConsole%TripTankSetAlarmHigh/2. ! 2: because knob input is 0-100 but gauge is 0-50 + data%Equipments%DataDisplayConsole%TripTankGauge= (1 - data%State%MudSystem%TripTankPressure_DataDisplayMalf) * data%State%MudSystem%TripTank_MaxVol_Allowded ENDIF IF ((data%State%MudSystem%TripTankVolumeCalc < data%State%MudSystem%TripTank_MinVol_Allowded) .OR. (data%State%MudSystem%TripTankVolumeCalc > data%State%MudSystem%TripTank_MaxVol_Allowded)) THEN - data%EquipmentControl%DataDisplayConsole%TripTankAlarmLED = 2 !(blinking) - IF (data%EquipmentControl%DataDisplayConsole%TripTankHornSwitch) THEN - data%EquipmentControl%DataDisplayConsole%Buzzer1= .true. + data%Equipments%DataDisplayConsole%TripTankAlarmLED = 2 !(blinking) + IF (data%Equipments%DataDisplayConsole%TripTankHornSwitch) THEN + data%Equipments%DataDisplayConsole%Buzzer1= .true. ELSE - data%EquipmentControl%DataDisplayConsole%Buzzer1= .false. + data%Equipments%DataDisplayConsole%Buzzer1= .false. ENDIF ELSE - data%EquipmentControl%DataDisplayConsole%TripTankAlarmLED = 0 !(OFF) - data%EquipmentControl%DataDisplayConsole%Buzzer1= .false. + data%Equipments%DataDisplayConsole%TripTankAlarmLED = 0 !(OFF) + data%Equipments%DataDisplayConsole%Buzzer1= .false. ENDIF - data%EquipmentControl%DataDisplayConsole%TripTankPumpLED= data%EquipmentControl%DataDisplayConsole%TripTankPumpSwitch + data%Equipments%DataDisplayConsole%TripTankPumpLED= data%Equipments%DataDisplayConsole%TripTankPumpSwitch - ELSEIF (data%EquipmentControl%DataDisplayConsole%TripTankPowerSwitch==0) THEN - data%EquipmentControl%DataDisplayConsole%TripTankGauge= 0. !(gal) - data%EquipmentControl%DataDisplayConsole%TripTankAlarmLED= 0 - data%EquipmentControl%DataDisplayConsole%TripTankPumpLED= 0 - data%EquipmentControl%DataDisplayConsole%Buzzer1= .false. + ELSEIF (data%Equipments%DataDisplayConsole%TripTankPowerSwitch==0) THEN + data%Equipments%DataDisplayConsole%TripTankGauge= 0. !(gal) + data%Equipments%DataDisplayConsole%TripTankAlarmLED= 0 + data%Equipments%DataDisplayConsole%TripTankPumpLED= 0 + data%Equipments%DataDisplayConsole%Buzzer1= .false. ENDIF ! if ( IsPortable ) then - ! TripTank_MinVol_Allowded= data%EquipmentControl%DataDisplayConsole%TripAlarmLow - ! TripTank_MaxVol_Allowded= data%EquipmentControl%DataDisplayConsole%TripAlarmHigh + ! TripTank_MinVol_Allowded= data%Equipments%DataDisplayConsole%TripAlarmLow + ! TripTank_MaxVol_Allowded= data%Equipments%DataDisplayConsole%TripAlarmHigh ! IF ((TripTankVolumeCalc < TripTank_MinVol_Allowded) .OR. (TripTankVolumeCalc > TripTank_MaxVol_Allowded)) THEN - ! data%EquipmentControl%DataDisplayConsole%TripTankAlarmLED = 1 !(blinking) - ! IF (data%EquipmentControl%DataDisplayConsole%TripTankHornSwitch) THEN - ! data%EquipmentControl%DataDisplayConsole%Buzzer1= .true. + ! data%Equipments%DataDisplayConsole%TripTankAlarmLED = 1 !(blinking) + ! IF (data%Equipments%DataDisplayConsole%TripTankHornSwitch) THEN + ! data%Equipments%DataDisplayConsole%Buzzer1= .true. ! ELSE - ! data%EquipmentControl%DataDisplayConsole%Buzzer1= .false. + ! data%Equipments%DataDisplayConsole%Buzzer1= .false. ! ENDIF ! ELSE - ! data%EquipmentControl%DataDisplayConsole%TripTankAlarmLED = 0 !(OFF) - ! data%EquipmentControl%DataDisplayConsole%Buzzer1= .false. + ! data%Equipments%DataDisplayConsole%TripTankAlarmLED = 0 !(OFF) + ! data%Equipments%DataDisplayConsole%Buzzer1= .false. ! ENDIF ! endif diff --git a/Equipments/MudSystem/MudSystem.i90 b/Equipments/MudSystem/MudSystem.i90 new file mode 100644 index 0000000..8d1ef2d --- /dev/null +++ b/Equipments/MudSystem/MudSystem.i90 @@ -0,0 +1,3319 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/MudSystem.f90" +module MudSystemModule + + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use PressureDisplayVARIABLESModule + USE FricPressDropVarsModule + USE Fluid_Flow_Startup_Vars +! USE CMudPropertiesVariables + USE CManifolds + use CPumpsVariables + use CPumps + USE CUnityOutputs + use CWarnings + use DynamicIntegerArray,only: DynamicIntegerArrayType + use CError + use CLog1 + use CDataDisplayConsole + use SimulationVariables + use CStudentStationVariables !, PitGainLossReset=>PitGainLossZero + use MudPropertiesModule + + + implicit none + + real j2,j12,j13,jj2,jj12,jj13 + real A71,A72,A73 + integer j3,B71,B77,B78 + integer j4 + real C71,C77,C78 + integer j5 + integer j6,D71,D80 + integer j7,j8,j9,j10,j11 + real E71,E72,E73 + real F71,F72,F73 + integer j14 + real G82,G83,G84 + integer j15 + real H82,H83,H84 + integer j16,K82,K83,K84,K79,K78 + integer j17,L82,L83,L84,L79,L78 + integer j18 + real M71,M77,M78, Pump1toCh,Pump2toCh,Pump3toCh,Denominator_a + integer j19 + real N82,N83,N84 + integer j20 + integer j21 + real unityreturn + + + + real(8) DumpPump1,DumpPump2,DumpCementPump,Denominator + real(8) Mp1Coef,Mp2Coef,CpCoef + real(8) PumpPressure1,PumpPressure2,PumpPressure3 + integer Mp1_NoPath,Mp2_NoPath,Cp_NoPath + real P1toSt,P2toSt,CptoSt + real(8) MaxWorkingPressure1,MaxWorkingPressure2,MaxWorkingPressure3,MaxWorkingPressure + + REAL(8) DumpFromKelly, DumpFromFillupHead + real(8) AddedVolumeToTank,PUMP1_Flow_Rate_Old,PUMP2_Flow_Rate_Old,PUMP3_Flow_Rate_Old + real(8) VolumeToActive,VolumeToBellNipple,BellNipple_FlowCoef,ChokeLine_FlowCoef + + + REAL RealJ2,RealJ12,RealJ13,RealJ4,RealJ18 + INTEGER active32,active33,active34,active35,active29 + + logical condition1, condition2, condition3, condition4, condition5, condition6, condition7, condition8, condition9, condition10, condition11, condition12, condition13, condition14, condition15 + logical condition16,condition17,condition18,condition19,condition20,condition21,condition22,condition23,condition24,condition25,condition26,condition27,condition28,condition29,condition30,condition31 + logical condition32,condition33,condition34,condition35,condition36,condition37,condition38,condition39,condition40,condition41,condition42,condition43,condition44,condition45 + logical condition46,condition47,condition48,condition49,condition50,condition51,condition52,condition53,condition54,condition55,condition56,condition57,condition58 + logical condition59,condition60,condition61 + logical ac32, ac33, ac34, ac35, ac29 + logical ThereIsPathFrom_71_72_73_To_82, ThereIsPathFrom_71_72_73_To_83, ThereIsPathFrom_71_72_73_To_84 + logical DumpFromKelly_Pump1, DumpFromKelly_Pump2, DumpFromKelly_Pump3 + logical DumpFromTopDrive_Pump1,DumpFromTopDrive_Pump2,DumpFromTopDrive_Pump3 + logical DumpFromFillupHead_Pump1, DumpFromFillupHead_Pump2, DumpFromFillupHead_Pump3 + logical State1,State2, State3, State4 + type(DynamicIntegerArrayType) Pump1_Lasts,Pump2_Lasts, Pump3_Lasts + REAL MP1_Q, MP2_Q, MP3_Q + real TimePassed + + real(8) active_after, active_before, active_increase, total_active_increase,total_decrease,sys_total_injected + real(8) total_annFlow,total_DeltaVPipe + contains + + subroutine LineupAndPath() + implicit none + +!=========================================================================== +! MUDLINE CODE +!=========================================================================== +! Initialize + j2=0 + jj2=0 + A71=0 + A72=0 + A73=0 + RealJ2=0.0 + + j3=0 + B71=0 + B77=0 + B78=0 + + j4=0 + C71=0. + C77=0. + C78=0. + active32=0 + active33=0 + active34=0 + active35=0 + active29=0 + + + j5=0 + + j6=0 + D71=0 + D80=0 + + j7=0 + + j8=0 + + j9=0 + j10=0 + j11=0 + + j12=0 + jj12=0 + E71=0 + E72=0 + E73=0 + RealJ12=0.0 + + j13=0 + jj13=0 + F71=0 + F72=0 + F73=0 + RealJ13=0.0 + + j14=0 + G82=0 + G83=0 + G84=0 + + DumpPump1=0. + DumpPump2=0. + DumpCementPump=0. + + j15=0 + H82=0.0 + H83=0.0 + H84=0.0 + + Mp1Coef= 0.0 + Mp1Coef= 0.0 + CpCoef= 0.0 + + Mp1_NoPath= 0 + Mp2_NoPath= 0 + Cp_NoPath= 0 + + j16=0 + K82=0 + K83=0 + K84=0 + K78=0 + K79=0 + + + j17=0 + L82=0 + L83=0 + L84=0 + L78=0 + L79=0 + + j18=0 + M71=0. + M77=0. + M78=0. + Pump1toCh=0. + Pump2toCh=0. + Pump3toCh=0. + + + j19=0 + N82=0 + N83=0 + N84=0 + + j20=0 + + j21=0 + + + +!=========================================================================== + +!===============TanksToMudPump1================= + if(condition1) then + j2=j2+1 + A71=1 + jj2=1 + endif + + if(condition2) then + j2=j2+1 + A72=1 + jj2=1 + endif + + if(condition3) then + j2=j2+1 + A73=1 + jj2=1 + endif + +!================================================ + +!============BellNippleToPits-FullWell============== + if(data%State%MudSystem%FirstMudSet== 1 ) then !.and. WellisNOTFull== .false.) then ! Well Must Be Full !Ann_Mud_Forehead_X%Last()==AboveAnnularHeight .and. Ann_Density%Last()/=0.0) + if(condition4) then + j3=j3+1 + B71=1 + endif + + if(condition5) then + j3=j3+1 + B77=1 + endif + + if(condition6) then + j3=j3+1 + B78=1 + endif + + endif + +!================================================ + +!============WellToChokeManifold(Through 26)============== + if(condition7) then + j4=j4+1 + C71=1. + endif + + if(condition8) then + j4=j4+1 + C77=1. + endif + + if(condition45) then + j4=j4+1 + C78=1. + endif + if (ac32) active32=1 + if (ac33) active33=1 + if (ac34) active34=1 + if (ac35) active35=1 + if (ac29) active29=1 !BYPASS VALVE + + + +!================================================ + + +!============ActiveTankToTripTank============== + if(condition9) then + j5=j5+1 + endif +!================================================ + +!write(*,*) 'j5====' , j5 +!============TripTankToActiveTank And BellNipple============== + if(condition10) then + j6=j6+1 + D71=1 + endif + + if(condition11) then + j6=j6+1 + D80=1 + endif +!================================================ + +!============ActiveTankToDump============== + if(condition12) then + j7=j7+1 + endif +!================================================ + +!============TripTankToDump============== + if(condition13) then + j8=j8+1 + endif +!================================================ + +!============WellToBellNipple============== + if(condition14) then + j9=j9+1 + endif +!================================================ + +!============MudBucketToBellNipple============== + if(condition15) then + j10=j10+1 + endif +!================================================ + +!============BellNippleToWell-NonFullWell============== + + + if(condition16 .and. data%State%MudSystem%FirstMudSet== 1 .and. data%State%MudSystem%BellNippleVolume > 0.0001 .and. data%State%MudSystem%WellisNOTFull) then + + write(*,*) 'data%State%MUD(7)%Q=' , data%State%MUD(7)%Q + write(*,*) 'BellNippleVolume=' , data%State%MudSystem%BellNippleVolume + + + write(*,*) 'data%State%MudSystem%MudVolume_InjectedFromAnn-WellToBellNipple=' , data%State%MudSystem%MudVolume_InjectedFromAnn + + write(*,*) 'int:::=' , (data%State%MudSystem%Ann_Mud_Forehead_X%Last() - data%Configuration%BopStack%AboveAnnularHeight) + write(*,*) 'Ann_Mud_Forehead_X%Last()=' , data%State%MudSystem%Ann_Mud_Forehead_X%Last() + write(*,*) 'AboveAnnularHeight=' , data%Configuration%BopStack%AboveAnnularHeight + write(*,*) 'Ann_Density%Last()=' , data%State%MudSystem%Ann_Density%Last() + CALL ErrorStop('error stop1') + + j11=j11+1 + endif +!================================================ + +!===============TanksToMudPump2=================== + + if(condition17) then + j12=j12+1 + E71=1 + jj12=1 + endif + + if(condition18) then + j12=j12+1 + E72=1 + jj12=1 + endif + + if(condition19) then + j12=j12+1 + E73=1 + jj12=1 + endif + +!================================================ + +!===============TanksToCementPump=================== + if(condition20) then + j13=j13+1 + F71=1 + jj13=1 + endif + + if(condition21) then + j13=j13+1 + F72=1 + jj13=1 + endif + + if(condition22) then + j13=j13+1 + F73=1 + jj13=1 + endif + +!================================================ + +!===============PumpsToString=================== + if(condition23) then + j14=j14+1 + G82=1 + endif + + if(condition24) then + j14=j14+1 + G83=1 + endif + + if(condition25) then + j14=j14+1 + G84=1 + endif +!================================================ + + +!===============PumpsToDump=================== + if(condition26) then + DumpPump1=1.0 + endif + + if(condition27) then + DumpPump2=1.0 + endif + + if(condition28) then + DumpCementPump=1.0 + endif +!================================================ + + +!=======MudPumps1&2ToActiveTank_Through65&66========== + if(condition29) then +!write(*,*) 'condition 29' + j15=j15+1 + H82=1.0 + endif + + if(condition30) then + j15=j15+1 + H83=1.0 + endif + +!================================================ + + +!=======CementPumpToActiveTank_Through65========== + + if(condition31) then + + H84=1.0 + + endif +!================================================ + +!write(*,*) 'condition32===' , condition32 + +!============MudPump1HasNoPath=================== + if(data%State%MudSystem%condition32Final) then +!write(*,*) 'MudPump1HasNoPath' + Mp1_NoPath = 1 + endif +!================================================ + +!============MudPump2HasNoPath=================== + if(data%State%MudSystem%condition33Final) then +!write(*,*) 'MudPump2HasNoPath' + Mp2_NoPath = 1 + endif +!================================================ + + +!============CementPumpHasNoPath=================== + if(data%State%MudSystem%condition34Final) then + Cp_NoPath = 1 + endif +!================================================ + +!===============PathsToGauge75=================== + if(condition35) then !Pump1 to Gauge75 + j16=j16+1 + K82=1 + endif + + if(condition36) then !Pump2 to Gauge75 + j16=j16+1 + K83=1 + endif + + if(condition37) then !Pump3 to Gauge75 + j16=j16+1 + K84=1 + endif + + if(condition38) then !String to Gauge75 + j16=j16+1 + K79=1 + endif + + if(condition39) then !Dump to Gauge75 + j16=j16+1 + K78=1 + endif + +!================================================ +!write(*,*) '****j16=' , j16 +!===============PathsToGauge76=================== + if(condition40) then !Pump1 to Gauge76 + j17=j17+1 + L82=1 + endif + + if(condition41) then !Pump2 to Gauge76 + j17=j17+1 + L83=1 + endif + + if(condition42) then !Pump3 to Gauge76 + j17=j17+1 + L84=1 + endif + + if(condition43) then !String to Gauge76 + j17=j17+1 + L79=1 + endif + + if(condition44) then !Dump to Gauge76 + j17=j17+1 + L78=1 + endif + +!================================================ + +!====Pump1-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(condition46) then + j18=j18+1 + M71=1. + Pump1toCh= 1. + endif + + if(condition47) then + j18=j18+1 + M77=1. + Pump1toCh= 1. + endif + + if(condition48) then + j18=j18+1 + M78=1. + Pump1toCh= 1. + endif +!================================================================= + + +!====Pump2-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(condition49) then + j18=j18+1 + M71=1. + Pump2toCh= 1. + endif + + if(condition50) then + j18=j18+1 + M77=1. + Pump2toCh= 1. + endif + + if(condition51) then + j18=j18+1 + M78=1. + Pump2toCh= 1. + endif +!================================================================= + + +!====Pump3-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(condition52) then + j18=j18+1 + M71=1. + Pump3toCh= 1. + endif + + if(condition53) then + j18=j18+1 + M77=1. + Pump3toCh= 1. + endif + + if(condition54) then + j18=j18+1 + M78=1. + Pump3toCh= 1. + endif +!================================================================= + + +!===============PumpsToWell_KillLine============ + if(condition55) then + j19=j19+1 + N82=1 + endif + + if(condition56) then + j19=j19+1 + N83=1 + endif + + if(condition57) then + j19=j19+1 + N84=1 + endif +!================================================ + +!===============WellToChokeLineGauge============ + if(condition58) then + j20=j20+1 + endif + + if (j20>0) then + data%State%MudSystem%WellToChokeLineGauge= .true. + else + data%State%MudSystem%WellToChokeLineGauge= .false. + endif +!================================================ + + +!============ChokeLineGaugeToTanks=============== + if(condition59) then + j21=j21+1 + endif + + if(condition60) then + j21=j21+1 + endif + + if(condition61) then + j21=j21+1 + endif + + if (j21>0) then + data%State%MudSystem%ChokeLineGaugeToTanks= .true. + else + data%State%MudSystem%ChokeLineGaugeToTanks= .false. + endif +!================================================ + + + end subroutine + + subroutine main + Use GeoElements_FluidModule + use SimulationVariables + USE CHOKEVARIABLES +use SimulationVariables !@ + use CDataDisplayConsole + use SimulationVariables + use SimulationVariables !@ + USE CHOKEVARIABLES +use SimulationVariables !@ + use CChokeManifoldVariables + use SimulationVariables + use CTanks + use SimulationVariables + use KickVARIABLESModule + use CHoistingVariables + use SimulationVariables +! use CSimulationVariables + + implicit none + Integer I + + data%State%MudSystem%MudSys_timeCounter = data%State%MudSystem%MudSys_timeCounter + 1 + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + data%State%MudSystem%MudSys_timeCounter= 0 + endif + +!WRITE (*,*) 'MudSys_timeCounter', MudSys_timeCounter + if (data%Configuration%Pumps%MudPump1ReliefValveIsSet==.false.) data%Configuration%Pumps%MudPump1ReliefValvePressure=6000. + if (data%Configuration%Pumps%MudPump2ReliefValveIsSet==.false.) data%Configuration%Pumps%MudPump2ReliefValvePressure=6000. + if (data%Configuration%Pumps%CementPumpReliefValveIsSet==.false.) data%Configuration%Pumps%CementPumpReliefValvePressure=6000. +!=========================================================================================================================== +!=========================================================================================================================== +! >>> Should Be on Top of Other Codes <<< + + +!ActiveTankVolume= ActiveMudVolumeGal ! update from student input +!ActiveTankDensity= ActiveDensity ! update from student input +!ReserveTankVolume= ReserveMudVolumeGal ! update from student input +!ReserveTankDensity= ReserveDensity ! update from student input + if (j7 > 0) then !ActiveTankToDump + data%State%MudSystem%ActiveTankDensity= 0. + data%State%MudSystem%ActiveTankVolume= 0. + endif + + if (j8 > 0) then !TripTankToDump + data%State%MudSystem%TripTankDensityCalc= 0. + data%State%MudSystem%TripTankVolumeCalc= 0. + endif +!=========================================================================================================================== +!=========================================================================================================================== + if (j15 > 0) then !MudPumps1&2ToActiveTank_Through65&66 +!write(*,*) 'j15 is open' +! << if H82 or H83 or H4 are open, no flow goes to other parts of system >> + if (j2>0) Mp1Coef= 1.0 + if (j12>0) Mp2Coef= 1.0 + if (j2 /= 0 .or. j12/= 0) then + data%State%MudSystem%ActiveTankDensity = (data%State%MudSystem%ActiveTankDensity*data%State%MudSystem%ActiveTankVolume+ Mp1Coef*data%State%MudSystem%Mp1Density*(data%State%Pump(1)%Flow_Rate*data%State%MudSystem%DeltaT_Mudline/60.) + Mp2Coef*data%State%MudSystem%Mp2Density*(data%State%Pump(2)%Flow_Rate*data%State%MudSystem%DeltaT_Mudline/60.))/ & + (data%State%MudSystem%ActiveTankVolume+ Mp1Coef*(data%State%Pump(1)%Flow_Rate*data%State%MudSystem%DeltaT_Mudline/60.) + Mp2Coef*(data%State%Pump(2)%Flow_Rate*data%State%MudSystem%DeltaT_Mudline/60.)) + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ Mp1Coef*data%State%Pump(1)%Flow_Rate*data%State%MudSystem%DeltaT_Mudline/60. + Mp2Coef*data%State%Pump(2)%Flow_Rate*data%State%MudSystem%DeltaT_Mudline/60. +!write(*,*) 'active by j15' + endif + data%State%MudSystem%ActiveTankVolume=min(data%State%MudSystem%ActiveTankVolume , data%Configuration%Mud%ActiveTotalTankCapacityGal-data%Configuration%Mud%ActiveSettledContentsGal) +!if ActiveTankVolume is higher, excess amount is dumped + endif + if (H84 > 0.0) then !CementPumpToCementTank_Through67 + if (j13>0) CpCoef= 1.0 + data%State%MudSystem%CementTankDensityCalc= (data%State%MudSystem%CementTankDensityCalc*data%State%MudSystem%CementTankVolumeCalc+ CpCoef*data%State%MudSystem%Mp3Density*(data%State%Pump(3)%Flow_Rate*data%State%MudSystem%DeltaT_Mudline/60.) ) / & + (data%State%MudSystem%CementTankVolumeCalc+CpCoef*(data%State%Pump(3)%Flow_Rate*data%State%MudSystem%DeltaT_Mudline/60.)) + data%State%MudSystem%CementTankVolumeCalc= data%State%MudSystem%CementTankVolumeCalc+ CpCoef*(data%State%Pump(3)%Flow_Rate*data%State%MudSystem%DeltaT_Mudline/60.) + endif +!=========================================================================================================================== +!=========================================================================================================================== +! DUMP Path + data%State%MudSystem%PumpsDumpVolume= data%State%MudSystem%PumpsDumpVolume+ (jj2*(1-H82)*DumpPump1*data%State%Pump(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*data%State%Pump(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*data%State%Pump(3)%Flow_Rate) *data%State%MudSystem%DeltaT_Mudline/60. + data%State%MudSystem%PumpsDumpFlowRate= jj2*(1-H82)*DumpPump1*data%State%Pump(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*data%State%Pump(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*data%State%Pump(3)%Flow_Rate +!write(*,*) 'PumpsDumpFlowRate=' , PumpsDumpFlowRate + + if (data%Configuration%Hoisting%DriveType==1 .and. data%State%MudSystem%PumpsDumpFlowRate > 0.0 .and. (DumpFromKelly_Pump1 .or. DumpFromKelly_Pump2 .or. DumpFromKelly_Pump3)) then +!write(*,*) 'Set_FlowFromKelly(.TRUE.)' + call Activate_PumpWithKellyDisconnected() +!write(*,*) 'PumpsDumpFlowRate=' , PumpsDumpFlowRate + CALL Set_FlowFromKelly(min(data%State%MudSystem%PumpsDumpFlowRate/6.,100.)) ! .TRUE. before + elseif (data%Configuration%Hoisting%DriveType==1) then + call Deactivate_PumpWithKellyDisconnected() + CALL Set_FlowFromKelly(0.0) ! .FALSE. before +!write(*,*) 'Set_FlowFromKelly(.FALSE.)' + endif +!write(*,*) 'DumpFromFillupHead_Pump1=' , DumpFromFillupHead_Pump1 + if (data%Configuration%Hoisting%DriveType==0 .and. data%State%MudSystem%PumpsDumpFlowRate > 0.0 .and. (DumpFromTopDrive_Pump1 .or. DumpFromTopDrive_Pump2 .or. DumpFromTopDrive_Pump3)) then +!write(*,*) 'Set_FlowFromKelly(.TRUE.)' + call Activate_PumpWithTopdriveDisconnected() + CALL Set_FlowFromKelly(min(data%State%MudSystem%PumpsDumpFlowRate/6.,100.)) ! .TRUE. before + elseif (data%Configuration%Hoisting%DriveType==0) then + call Deactivate_PumpWithTopdriveDisconnected() + CALL Set_FlowFromKelly(0.0) ! .FALSE. before +!write(*,*) 'Set_FlowFromKelly(.FALSE.)' + endif + if (data%State%MudSystem%PumpsDumpFlowRate > 0.0 .and. (DumpFromFillupHead_Pump1 .or. DumpFromFillupHead_Pump2 .or. DumpFromFillupHead_Pump3)) then +!call Activate_PumpWithKellyDisconnected() + CALL Set_FlowFromFillupHead(min(data%State%MudSystem%PumpsDumpFlowRate/6.,100.)) ! .TRUE. before + else +!call Deactivate_PumpWithKellyDisconnected() + CALL Set_FlowFromFillupHead(0.0) ! .FALSE. before + endif +!####C_Program -----> DriveType = +! = 0 TopDrive_DriveType +! = 1 Kelly_DriveType +!=========================================================================================================================== +!=========================================================================================================================== +! ****** Calculating Maximum Working Pressure + if (data%Configuration%Pumps%MudPump1ReliefValveIsSet) then + MaxWorkingPressure1= data%Configuration%Pumps%MudPump1ReliefValvePressure + else + MaxWorkingPressure1= 6000. !psi + endif + if (data%Configuration%Pumps%MudPump2ReliefValveIsSet) then + MaxWorkingPressure2= data%Configuration%Pumps%MudPump2ReliefValvePressure + else + MaxWorkingPressure2= 6000. !psi + endif + if (data%Configuration%Pumps%CementPumpReliefValveIsSet) then + MaxWorkingPressure3= data%Configuration%Pumps%CementPumpReliefValveIsSet + else + MaxWorkingPressure3= 6000. !psi + endif + if (State1) then + MaxWorkingPressure= min(MaxWorkingPressure1 , MaxWorkingPressure2 , MaxWorkingPressure3) + MaxWorkingPressure1= MaxWorkingPressure + MaxWorkingPressure2= MaxWorkingPressure + MaxWorkingPressure3= MaxWorkingPressure + endif + if (State2) then + MaxWorkingPressure= min(MaxWorkingPressure1 , MaxWorkingPressure2) + MaxWorkingPressure1= MaxWorkingPressure + MaxWorkingPressure2= MaxWorkingPressure + endif + if (State3) then + MaxWorkingPressure= min(MaxWorkingPressure1 , MaxWorkingPressure3) + MaxWorkingPressure1= MaxWorkingPressure + MaxWorkingPressure3= MaxWorkingPressure + endif + if (State4) then + MaxWorkingPressure= min(MaxWorkingPressure2 , MaxWorkingPressure3) + MaxWorkingPressure2= MaxWorkingPressure + MaxWorkingPressure3= MaxWorkingPressure + endif +! Calculating Maximum Working Pressure ****** +!=========================================================================================================================== +!=========================================================================================================================== + + +! ****** Blown Conditions + +!G: PumpsToString Coefficient +!jJ2,Jj12,Jj13: TanksToMudPump Coefficient +!H: Pumps To Tank_Through65 or 67 Coefficient + +!write(*,*) 'j12=' , j12 +!write(*,*) 'H83=' , H83 +!write(*,*) 'DumpPump2=' , DumpPump2 +!write(*,*) 'G83=' , G83 + PumpPressure1= jj2*(1-H82)*(1-DumpPump1)*G82* data%State%PressureDisplay%PressureGauges(1) + PumpPressure2= jj12*(1-H83)*(1-DumpPump2)*G83* data%State%PressureDisplay%PressureGauges(1) + PumpPressure3= jj13*(1-H84)*(1-DumpCementPump)*G84* data%State%PressureDisplay%PressureGauges(1) +! +!write(*,*) 'jj2 , H82 , DumpPump1 , G82,PresCsureGauges(1)=' , jj2 , H82 , DumpPump1 , G82,PressureGauges(1) +!write(*,*) '1)PumpPressure1=' , PumpPressure1 +!write(*,*) 'PumpPressure2=' , PumpPressure2 + data%State%FricPressDrop%PumpToManifoldMudVol = 3.0 * 42.0 +!PumpToManifoldCompressedMudVol = PumpToManifoldCompressedMudVol + MP1_Q / ConvMinToSec * dt +!PumpToManifoldDeltaPDueToCompressibility = PumpToManifoldCompressedMudVol / (MudCompressibility * PumpToManifoldMudVol) + IF(Mp1_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_82 .and. MP1_Q > 0.0) then + data%State%FricPressDrop%PumpToManifoldCompressedMudVol = data%State%FricPressDrop%PumpToManifoldCompressedMudVol + MP1_Q / ConvMinToSec * dt + PumpPressure1= data%State%FricPressDrop%PumpToManifoldCompressedMudVol / (MudCompressibility * data%State%FricPressDrop%PumpToManifoldMudVol) + write(*,*) '21)PumpPressure1=' , PumpPressure1 + WRITE (*,*) ' valve 1 ', Manifold%Valve(1)%Status + WRITE (*,*) ' valve 4 ', Manifold%Valve(4)%Status + WRITE (*,*) ' valve 6 ', Manifold%Valve(6)%Status + WRITE (*,*) ' valve 7 ', Manifold%Valve(7)%Status + WRITE (*,*) ' valve 8 ', Manifold%Valve(8)%Status + WRITE (*,*) ' valve 9 ', Manifold%Valve(9)%Status + WRITE (*,*) ' valve 13 ', Manifold%Valve(13)%Status + WRITE (*,*) ' valve 68 ', Manifold%Valve(68)%Status + WRITE (*,*) ' valve 69 ', Manifold%Valve(69)%Status + WRITE (*,*) ' valve 48 ', Manifold%Valve(48)%Status +!call DisplayOpenPathsWrite() + ENDIF + + IF(Mp2_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_83 .and. MP2_Q > 0.0 ) then + data%State%FricPressDrop%PumpToManifoldCompressedMudVol = data%State%FricPressDrop%PumpToManifoldCompressedMudVol + MP2_Q / ConvMinToSec * dt + PumpPressure2= data%State%FricPressDrop%PumpToManifoldCompressedMudVol / (MudCompressibility * data%State%FricPressDrop%PumpToManifoldMudVol) + write(*,*) '22)PumpPressure1=' , PumpPressure2 + WRITE (*,*) ' -valve 1 ', Manifold%Valve(1)%Status + WRITE (*,*) ' -valve 4 ', Manifold%Valve(4)%Status + WRITE (*,*) ' -valve 6 ', Manifold%Valve(6)%Status + WRITE (*,*) ' -valve 7 ', Manifold%Valve(7)%Status + WRITE (*,*) ' -valve 8 ', Manifold%Valve(8)%Status + WRITE (*,*) ' -valve 9 ', Manifold%Valve(9)%Status + WRITE (*,*) ' -valve 13 ', Manifold%Valve(13)%Status + WRITE (*,*) ' -valve 68 ', Manifold%Valve(68)%Status + WRITE (*,*) ' -valve 69 ', Manifold%Valve(69)%Status + WRITE (*,*) ' -valve 48 ', Manifold%Valve(48)%Status +!call DisplayOpenPathsWrites() + ENDIF + + IF(Cp_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_84 .AND. MP3_Q > 0.0 ) then + data%State%FricPressDrop%PumpToManifoldCompressedMudVol = data%State%FricPressDrop%PumpToManifoldCompressedMudVol + MP3_Q / ConvMinToSec * dt + PumpPressure3= data%State%FricPressDrop%PumpToManifoldCompressedMudVol / (MudCompressibility * data%State%FricPressDrop%PumpToManifoldMudVol) + ENDIF +!***************************************************************************** +!if(((Mp1_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_82) .or. ( PumpPressure1 >= MaxWorkingPressure1 ) & +!.or.(J14> 0 .and. j4==0 .and. j9==0 .and. NOT(ALLOCATED(GasPocketWeight%Array)))) .and. MP1_Q > 0.0 ) then +!write(*,*) ' failurrrrre ' + + if (PumpPressure1 >= MaxWorkingPressure1 .and. MP1_Q > 0.0) then + write(*,*) 'mp1,if=' , PumpPressure1 , MaxWorkingPressure1 , MP1_Q + data%State%MudSystem%Pump1BlownCount = data%State%MudSystem%Pump1BlownCount + 1 +!if (Pump1BlownStarted == .FALSE.) then +! write(*,*) 'if (Pump1BlownStarted == .FALSE. ) then' +! Pump1BlownInTimeStep = SimulationTime + BlownThresholdInSecond +! Pump1BlownStarted = .TRUE. +!endif +!write(*,*) 'SimulationTime===', SimulationTime, Pump1BlownInTimeStep + if(data%Configuration%Pumps%MudPump1ReliefValveIsSet .and. data%State%MudSystem%Pump1BlownCount >= BlownThreshold) then + write(*,*) 'valve 65 open, BLOWN' + call ChangeValve(65, .TRUE.) + data%State%FricPressDrop%PumpToManifoldCompressedMudVol= 0.0 + data%State%MudSystem%Pump1BlownCount = 0 +!Pump1BlownStarted = .FALSE. +!else +! write(*,*) 'PumpPressure1= 6000 psi' +! PumpPressure1= 6000. !psi + endif +!else +!Pump1BlownInTimeStep = 0 +!Pump1BlownStarted = .FALSE. +!write(*,*) 'Pump1BlownStarted = .FALSE.' + endif + +!write(*,*) ' valve 65=' , Valve(65)%Status +!if(((Mp2_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_83) .or. PumpPressure2 >= MaxWorkingPressure2 & +!.or.(J14> 0 .and. j4==0 .and. j9==0 .and. NOT(ALLOCATED(GasPocketWeight%Array))) ) .and. MP2_Q > 0.0 ) then + + if(PumpPressure2 >= MaxWorkingPressure2 .and. MP2_Q > 0.0 ) then + write(*,*) 'mp2,if=' , PumpPressure2 , MaxWorkingPressure2 , MP2_Q + data%State%MudSystem%Pump2BlownCount = data%State%MudSystem%Pump2BlownCount + 1 +!if (Pump2BlownStarted == .FALSE. ) then +! Pump2BlownInTimeStep = SimulationTime + BlownThresholdInSecond +! Pump2BlownStarted = .TRUE. +!endif +!if (MudPump2ReliefValveIsSet .and. SimulationTime >= Pump2BlownInTimeStep .and. Pump2BlownStarted) then + if (data%Configuration%Pumps%MudPump2ReliefValveIsSet .and. data%State%MudSystem%Pump2BlownCount >= BlownThreshold) then + write(*,*) 'valve 66 open, BLOWN' + call ChangeValve(66, .TRUE.) + data%State%FricPressDrop%PumpToManifoldCompressedMudVol= 0.0 + data%State%MudSystem%Pump2BlownCount = 0 +!Pump2BlownInTimeStep = 0 +!Pump2BlownStarted = .FALSE. +!else +! PumpPressure2= 6000. !psi + endif +!else +!Pump2BlownInTimeStep = 0 +!Pump2BlownStarted = .FALSE. + endif +!if(((Cp_NoPath == 1 .and. ThereIsPathFrom_71_72_73_To_84) .or. PumpPressure3 >= MaxWorkingPressure3 & +!.or.(J14> 0 .and. j4==0 .and. j9==0 .and. NOT(ALLOCATED(GasPocketWeight%Array)))) .and. MP3_Q > 0.0 ) then + + if(PumpPressure3 >= MaxWorkingPressure3 .and. MP3_Q > 0.0 ) then + data%State%MudSystem%Pump3BlownCount = data%State%MudSystem%Pump3BlownCount + 1 + if (data%Configuration%Pumps%CementPumpReliefValveIsSet .and. data%State%MudSystem%Pump3BlownCount >= BlownThreshold) then +!write(*,*) 'valve 67 open, BLOWN' + call ChangeValve(67, .TRUE.) + data%State%FricPressDrop%PumpToManifoldCompressedMudVol= 0.0 + data%State%MudSystem%Pump3BlownCount = 0 +!else +! PumpPressure3= 6000. !psi + endif +!else +!Pump3BlownInTimeStep = 0 +!Pump3BlownStarted = .FALSE. + endif +!write(*,*) '3)PumpPressure1=' , PumpPressure1 + if (PumpPressure1>= 6000.) then + data%State%MudSystem%Pump1BlownCount = data%State%MudSystem%Pump1BlownCount + 1 + if(data%State%MudSystem%Pump1BlownCount >= BlownThreshold) then + call ChangeValve(65, .TRUE.) + data%State%FricPressDrop%PumpToManifoldCompressedMudVol= 0.0 + call Activate_Pump1Failure() + data%State%MudSystem%Pump1OffFailure= .true. + data%State%MudSystem%Pump1BlownCount = 0 + endif +!else +!Pump1BlownInTimeStep = 0 +!Pump1BlownStarted = .FALSE. + endif + + if (PumpPressure2>= 6000.) then + data%State%MudSystem%Pump2BlownCount = data%State%MudSystem%Pump2BlownCount + 1 + if(data%State%MudSystem%Pump2BlownCount >= BlownThreshold) then + call ChangeValve(66, .TRUE.) + data%State%FricPressDrop%PumpToManifoldCompressedMudVol= 0.0 + call Activate_Pump2Failure() + data%State%MudSystem%Pump2OffFailure= .true. + data%State%MudSystem%Pump2BlownCount = 0 + endif +!else +!Pump2BlownInTimeStep = 0 +!Pump2BlownStarted = .FALSE. + endif + + if (PumpPressure3>= 6000.) then + data%State%MudSystem%Pump3BlownCount = data%State%MudSystem%Pump3BlownCount + 1 + if(data%State%MudSystem%Pump3BlownCount >= BlownThreshold) then + call ChangeValve(67, .TRUE.) + data%State%FricPressDrop%PumpToManifoldCompressedMudVol= 0.0 + call Activate_Pump3Failure() + data%State%MudSystem%Pump3OffFailure= .true. + data%State%MudSystem%Pump3BlownCount = 0 + endif +!else +!Pump3BlownInTimeStep = 0 +!Pump3BlownStarted = .FALSE. + endif +! Blown Conditions ******** +!=========================================================================================================================== +!=========================================================================================================================== + if (j9 > 0 ) then !.and. WellisNOTFull== .false.) then !WellToBellNipple +!write(*,*) 'j9 is open' +!data%State%MUD(7)%Q= ( Ann_Saved_MudDischarged_Volume_Final+Ann_Kick_Saved_Volume_Final - ((Qlost/60.0d0)*DeltaT_Mudline) )*60.d0/DeltaT_Mudline + data%State%MUD(7)%Q= ( data%State%MudSystem%MudVolume_InjectedFromAnn + data%State%MudSystem%Ann_Kick_Saved_Volume )*60.d0/data%State%MudSystem%DeltaT_Mudline !Injected is referred only to Mud + if (j4 > 0) then + BellNipple_FlowCoef= 13.625/(13.625+data%Configuration%BopStack%ChokeLineId) ! 13.625= BellNipple ID (inch) + data%State%MUD(7)%Q= BellNipple_FlowCoef * data%State%MUD(7)%Q + endif + +!total_annFlow= total_annFlow+(AnnulusFlowRateFinal/600.d0) +!total_DeltaVPipe= total_DeltaVPipe + DeltaVolumePipe +!write(*,*) 'total_annFlow,total_DeltaVPipe' , total_annFlow,total_DeltaVPipe + if (data%State%MUD(7)%Q < 0.0 ) data%State%MUD(7)%Q= 0.0 !.or. WellisNOTFull== .true.) data%State%MUD(7)%Q= 0.0 +!!AnnulusFlowRateFinal: flow from string mud , DeltaVolumeOp: due to trip in + +!write(*,*) 'data%State%MUD(7)%Q=' , data%State%MUD(7)%Q +!write(*,*) 'data%State%MudSystem%MudVolume_InjectedFromAnn-WellToBellNipple=' , data%State%MudSystem%MudVolume_InjectedFromAnn +!write(*,*) 'Ann_Kick_Saved_Volume=' , Ann_Kick_Saved_Volume + sys_total_injected= sys_total_injected+ data%State%MudSystem%MudVolume_InjectedFromAnn + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + sys_total_injected= 0. + endif +!write(*,*) 'sys_total_injected=' , sys_total_injected +!WellOutletDensity= Ann_Density%Last() ! (ppg) <<< in CirculationCodeSelect Code + if ((data%State%MudSystem%BellNippleVolume+((data%State%MUD(7)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) /= 0.0) then + data%State%MudSystem%BellNippleDensity= ((data%State%MudSystem%BellNippleDensity*data%State%MudSystem%BellNippleVolume)+(data%State%MudSystem%WellOutletDensity*(data%State%MUD(7)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%BellNippleVolume+((data%State%MUD(7)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + else + data%State%MudSystem%BellNippleDensity= 0.0 + endif +!IF (WellisNOTFull== .false.) THEN ! well must be full to do this order + data%State%MudSystem%BellNippleVolume= data%State%MudSystem%BellNippleVolume+ ((data%State%MUD(7)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) +!ENDIF + VolumeToBellNipple= VolumeToBellNipple + data%State%MudSystem%BellNippleVolume +!write(*,*) 'VolumeToBellNipple*****=' , VolumeToBellNipple +!write(*,*) 'BellNippleVolume in j9=' , BellNippleVolume , data%State%MUD(7)%Q + endif + + if (j9 == 0 ) then !.or. WellisNOTFull== .true.) then +!write(*,*) 'WellisNOTFull=' , WellisNOTFull + data%State%MUD(7)%Q=0.0 ! for normal circulation input + endif + + if (j9 > 0) then + data%State%MudSystem%WellToPitsOpen= .true. + else + data%State%MudSystem%WellToPitsOpen= .false. + endif +!=========================================================================================================================== +!=========================================================================================================================== + if (j10 > 0) then !MudBucketToBellNipple +!write(*,*) 'j10 is open' +!MudBucketVolume= 0. +!MudBucketDensity= 0. +! MudBucketVolume gets value in DisconnectingPipe subroutine + data%State%MudSystem%BellNippleVolume= data%State%MudSystem%BellNippleVolume+ data%State%MudSystem%MudBucketVolume + data%State%MudSystem%BellNippleDensity= data%State%MudSystem%ActiveTankDensity + data%State%MudSystem%MudBucketVolume= 0. + endif +!=========================================================================================================================== +!=========================================================================================================================== + if (j6 > 0) then !TripTankToActiveTank And BellNipple +!write(*,*) 'j6 is open' +!write(*,*) 'active by j6' + data%State%MUD(6)%Q= 300. ! constant flow rate(gpm) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc - ((data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) +!write(*,*) 'ActiveTankVolume before=', ActiveTankVolume + if (j6 == 1 .and. D71==1) then +!write(*,*) 'add to active' + data%State%MudSystem%ActiveTankDensity= ((data%State%MudSystem%ActiveTankDensity*data%State%MudSystem%ActiveTankVolume)+(data%State%MudSystem%TripTankDensityCalc*(data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%ActiveTankVolume+((data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ ((data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) +!write(*,*) 'ActiveTankVolume after=', ActiveTankVolume + + endif + + if (j6 == 1 .and. D80==1) then + data%State%MudSystem%BellNippleDensity= ((data%State%MudSystem%BellNippleDensity*data%State%MudSystem%BellNippleVolume)+(data%State%MudSystem%TripTankDensityCalc*(data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%BellNippleVolume+((data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%BellNippleVolume= data%State%MudSystem%BellNippleVolume+ ((data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + endif + + if (j6 == 2) then + data%State%MudSystem%ActiveTankDensity= ((data%State%MudSystem%ActiveTankDensity*data%State%MudSystem%ActiveTankVolume)+(data%State%MudSystem%TripTankDensityCalc*(0.5*data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%ActiveTankVolume+((0.5*data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%BellNippleDensity= ((data%State%MudSystem%BellNippleDensity*data%State%MudSystem%BellNippleVolume)+(data%State%MudSystem%TripTankDensityCalc*(0.5*data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%BellNippleVolume+((0.5*data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ ((0.5*data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%BellNippleVolume= data%State%MudSystem%BellNippleVolume+ ((0.5*data%State%MUD(6)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + endif + data%State%MudSystem%ActiveTankVolume=min(data%State%MudSystem%ActiveTankVolume , data%Configuration%Mud%ActiveTotalTankCapacityGal-data%Configuration%Mud%ActiveSettledContentsGal) +!if ActiveTankVolume is higher, excess amount is dumped + endif + + if (j6 == 0) then + data%State%MUD(6)%Q=0.0 + endif +!=========================================================================================================================== +!=========================================================================================================================== + CALL Set_FlowFromReturnLine(.false.) + if (j3 > 0) then !BellNippleToPits-FullWell - must be after **WellToBellNipple(j9)** +!write(*,*) 'j3 is open' +!write(*,*) 'active by j3' +!BellNipple flow rate= sum flow rate (well+ mudbucket+ triptank) +!Well to BellNipple: BellNippleVolume +!MudBucket to BellNipple: BellNippleVolume +!TripTnak to BellNipple: BellNippleVolume + data%State%MUD(3)%Q = (data%State%MudSystem%BellNippleVolume/data%State%MudSystem%DeltaT_Mudline)*60.d0 ! (gpm) +!write(*,*) 'BellNippleVolume in j3 =' , BellNippleVolume +!write(*,*) 'data%State%MUD(3)%Q =' , data%State%MUD(3)%Q + call Set_FlowRate(real(100.*min(data%State%MUD(3)%Q,data%State%MudSystem%PedalMeter)/data%State%MudSystem%PedalMeter, 8)) ! for unity display + unityreturn = real(100.*min(data%State%MUD(3)%Q,data%State%MudSystem%PedalMeter)/data%State%MudSystem%PedalMeter, 8) +!write(*,*) 'unity return=' , real(100.*min(data%State%MUD(3)%Q,PedalMeter)/PedalMeter, 8) + if (data%State%MUD(3)%Q > data%State%MudSystem%PedalMeter .and. B78==0) then + data%State%MudSystem%BellNippleDumpVolume= data%State%MudSystem%BellNippleDumpVolume + ((data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline - (data%State%MudSystem%PedalMeter/60.)*data%State%MudSystem%DeltaT_Mudline) +!BellNippleDumpRate= data%State%MUD(3)%Q - PedalMeter + CALL Set_FlowFromReturnLine(.TRUE.) ! for unity display + endif +!VolumeToActive = VolumeToActive + BellNippleVolume +!write(*,*) 'VolumeToActive*******=' , VolumeToActive + active_before= data%State%MudSystem%ActiveTankVolume + data%State%MudSystem%BellNippleVolume= data%State%MudSystem%BellNippleVolume- ((data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) ! to be 0. + if ( data%State%MudSystem%BellNippleDensity > 1.0) then + if (j3 == 1 .and. B71==1) then !(volumes in galon) + data%State%MUD(3)%Q = min(data%State%MUD(3)%Q , data%State%MudSystem%PedalMeter) +!write(*,*) 'data%State%MUD(3)%Q=' , data%State%MUD(3)%Q + IF (data%Configuration%Mud%ActiveAutoDensity == .FALSE.) THEN + data%State%MudSystem%ActiveTankDensity= ((data%State%MudSystem%ActiveTankDensity*data%State%MudSystem%ActiveTankVolume)+(data%State%MudSystem%BellNippleDensity*(data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%ActiveTankVolume+((data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ ((data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) +!write(*,*) 'active increase bell 1=' , ((data%State%MUD(3)%Q/60.)*DeltaT_Mudline) + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. data%State%MudSystem%BellNippleDensity > data%State%MudSystem%ActiveTankDensity) THEN + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ ((20.8d0-data%State%MudSystem%BellNippleDensity)/(20.8d0-data%State%MudSystem%ActiveTankDensity))*((data%State%MUD(3)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) ! asumed cutting density = 20.8 ppg +!write(*,*) 'active increase bell 2=' , ((20.8d0-BellNippleDensity)/(20.8d0-ActiveTankDensity))*((data%State%MUD(3)%Q/60.d0)*DeltaT_Mudline) + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. data%State%MudSystem%BellNippleDensity < 5.0) THEN + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ ((2.d0-data%State%MudSystem%BellNippleDensity)/(2.d0-data%State%MudSystem%ActiveTankDensity))*((data%State%MUD(3)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg +!write(*,*) 'active increase bell 3=' , ((2.d0-BellNippleDensity)/(2.d0-ActiveTankDensity))*((data%State%MUD(3)%Q/60.d0)*DeltaT_Mudline) + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. 5.0 < data%State%MudSystem%BellNippleDensity .and. data%State%MudSystem%BellNippleDensity <= data%State%MudSystem%ActiveTankDensity) THEN +!write(*,*) ' Auto true 3' + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ ((data%State%MUD(3)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) +!write(*,*) 'active increase bell 4=' , ((data%State%MUD(3)%Q/60.d0)*DeltaT_Mudline) + ENDIF + endif + if (j3 == 1 .and. B77==1) then + data%State%MUD(3)%Q = min(data%State%MUD(3)%Q , data%State%MudSystem%PedalMeter) + IF (data%Configuration%Mud%ActiveAutoDensity == .FALSE.) THEN + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%BellNippleDensity*(data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%TripTankVolumeCalc+((data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ (data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. data%State%MudSystem%BellNippleDensity > data%State%MudSystem%ActiveTankDensity) THEN + AddedVolumeToTank= ((20.8d0-data%State%MudSystem%BellNippleDensity)/(20.8d0-data%State%MudSystem%ActiveTankDensity))*((data%State%MUD(3)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. data%State%MudSystem%BellNippleDensity < 5.0) THEN + AddedVolumeToTank= ((2.d0-data%State%MudSystem%BellNippleDensity)/(2.d0-data%State%MudSystem%ActiveTankDensity))*((data%State%MUD(3)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. 5.0 < data%State%MudSystem%BellNippleDensity .and. data%State%MudSystem%BellNippleDensity <= data%State%MudSystem%ActiveTankDensity) THEN + AddedVolumeToTank= ((data%State%MUD(3)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + ENDIF + endif + if (j3 == 1 .and. B78==1) then + data%State%MudSystem%BellNippleDumpVolume= data%State%MudSystem%BellNippleDumpVolume+ (data%State%MUD(3)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline +!BellNippleDumpRate= data%State%MUD(3)%Q + endif + if (j3 == 2) then !78 is not allowded in this position + + data%State%MUD(3)%Q = min(data%State%MUD(3)%Q , data%State%MudSystem%PedalMeter) + + IF (data%Configuration%Mud%ActiveAutoDensity == .FALSE.) THEN + + data%State%MudSystem%ActiveTankDensity= ((data%State%MudSystem%ActiveTankDensity*data%State%MudSystem%ActiveTankVolume)+(data%State%MudSystem%BellNippleDensity*(0.5*data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%ActiveTankVolume+((0.5*data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%BellNippleDensity*(0.5*data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%TripTankVolumeCalc+((0.5*data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ ((0.5*data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ ((0.5*data%State%MUD(3)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. data%State%MudSystem%BellNippleDensity > data%State%MudSystem%ActiveTankDensity) THEN + + + AddedVolumeToTank= ((20.8d0-data%State%MudSystem%BellNippleDensity)/(20.8d0-data%State%MudSystem%ActiveTankDensity))*((0.5d0*data%State%MUD(3)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ AddedVolumeToTank + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. 5.0 < data%State%MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= ((2.d0-data%State%MudSystem%BellNippleDensity)/(2.d0-data%State%MudSystem%ActiveTankDensity))*((0.5d0*data%State%MUD(3)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ AddedVolumeToTank + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. 5.0 < data%State%MudSystem%BellNippleDensity .and. data%State%MudSystem%BellNippleDensity <= data%State%MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= ((data%State%MUD(3)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ AddedVolumeToTank + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + + ENDIF + + + endif + + endif !( BellNippleDensity > 1.0) then + + active_after= data%State%MudSystem%ActiveTankVolume + + active_increase = active_after - active_before + + total_active_increase= total_active_increase + active_increase + + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + total_active_increase= 0. + endif + +!write(*,*) 'total_active_increase=' , total_active_increase + + + +!write(*,*) 'ReturnFlowRate=data%State%MUD(3)%Q= after' , data%State%MUD(3)%Q + + data%State%MudSystem%ReturnFlowRate = data%State%MUD(3)%Q + + data%State%MudSystem%TripTankVolumeCalc = min(data%State%MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal +!if TripTankVolumeCalc>50 BBl, excess value(TripTankVolumeCalc-50) is dumped + + data%State%MudSystem%ActiveTankVolume = min(data%State%MudSystem%ActiveTankVolume , data%Configuration%Mud%ActiveTotalTankCapacityGal - data%Configuration%Mud%ActiveSettledContentsGal) +!if ActiveTankVolume is higher, excess amount is dumped +!write(*,*) 'BellNippleDensity=' , BellNippleDensity + +!MudWeightOut2 = BellNippleDensity !for drillwatch display +!write(*,*) 'MudWeightOut2=' , MudWeightOut2 + +!write(*,*) + + + endif + + if (j3 == 0) then + data%State%MUD(3)%Q=0.0 ! for normal circulation input + call Set_FlowRate(0d0) + endif + + + +!=========================================================================================================================== +!=========================================================================================================================== + + + + if (j11 > 0 .and. data%State%MudSystem%MudChecked== .true.) then !BellNippleToWell-NonFullWell ( FillingWell_By_BellNipple subroutine is called for this state ) +!write(*,*) 'j11 is open' + data%State%MudSystem%MudChecked= .false. !to be sure that well is not full after arranging muds +!WellToPitsOpen = .TRUE. + +!BellNipple flow rate= sum flow rate (well+ mudbucket+ triptank) + +!Well to BellNipple: BellNippleVolume +!MudBucket to BellNipple: BellNippleVolume +!TripTnak to BellNipple: BellNippleVolume + + data%State%MUD(8)%Q = (data%State%MudSystem%BellNippleVolume/data%State%MudSystem%DeltaT_Mudline)*60. +!write(*,*) 'data%State%MUD(8)%Q=' , data%State%MUD(8)%Q + + + data%State%MudSystem%BellNippleVolume= data%State%MudSystem%BellNippleVolume- ((data%State%MUD(8)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) ! to be 0. +!write(*,*) 'BellNippleVolume-2nd Mode=' , BellNippleVolume + +!BellNippleDensity +! +! +!BellNippleDensity , data%State%MUD(8)%Q be code gel dade beshe +!shart: j11 > 0 , data%State%MUD(8)%Q > 0.0 + + + endif + + if (j11 == 0) then + data%State%MUD(8)%Q=0.0 ! for normal circulation input +!WellToPitsOpen= .false. + endif + + + +!=========================================================================================================================== +!=========================================================================================================================== + + + +!WRITE (*,*) 'choke condition', j4, ChokeLineNOTFull + if (j4 > 0 .and. data%State%MudSystem%ChokeLineNOTFull== .false.) then !WellToChokeManifold(Through 26) +!write(*,*) 'j4 is open' +!write(*,*) 'active by j4' + + + +!data%State%MUD(4)%Q= ( Ann_Saved_MudDischarged_Volume_Final+Ann_Kick_Saved_Volume_Final - ((Qlost/60.0d0)*DeltaT_Mudline) )*60.d0/DeltaT_Mudline + data%State%MUD(4)%Q= ( data%State%MudSystem%MudVolume_InjectedFromAnn + data%State%MudSystem%Ann_Kick_Saved_Volume )*60.d0/data%State%MudSystem%DeltaT_Mudline !Injected is referred only to Mud + + +!if ( WellisNOTFull== .true. ) data%State%MUD(4)%Q= 0.0 + + + if (j9 > 0) then + ChokeLine_FlowCoef= data%Configuration%BopStack%ChokeLineId/(13.625+data%Configuration%BopStack%ChokeLineId) ! 13.625= BellNipple ID (inch) + data%State%MUD(4)%Q= ChokeLine_FlowCoef * data%State%MUD(4)%Q + endif + + +!call Log_1('data%State%MUD(4)%Q=', data%State%MUD(4)%Q) + + data%State%MudSystem%ChokeOutletDensity= data%State%MudSystem%ChokeLine_Density%Last() ! <<< in CirculationCodeSelect Code + + +!MudWeightOut2= ChokeOutletDensity !for drillwatch display +! +!AnnulusFlowRateFinal: flow from string mud , DeltaVolumeOp: due to trip in + + + + + + RealJ4= real(j4) + +!C71: Active Tank C77: Trip Tank C78: ChokeManifoldDump + + if ( data%State%MudSystem%BellNippleDensity > 1.0) then +! IN ALL CONDITIONS EFFECT OF 78 IS COMPUTED BY RealJ4 + if (C71==1 .and. C77==0) then !(volumes in galon) RealJ4: 1 OR 2(IF 78 IS OPEN) + + IF (data%Configuration%Mud%ActiveAutoDensity == .FALSE.) THEN + + data%State%MudSystem%ActiveTankDensity= ((data%State%MudSystem%ActiveTankDensity*data%State%MudSystem%ActiveTankVolume)+(data%State%MudSystem%ChokeOutletDensity*((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%ActiveTankVolume+(((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ (((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) +!write(*,*) 'active increase choke1=' , (((1./RealJ4)*data%State%MUD(4)%Q/60.)*DeltaT_Mudline) + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. data%State%MudSystem%ChokeOutletDensity > data%State%MudSystem%ActiveTankDensity) THEN + + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ ((20.8d0-data%State%MudSystem%ChokeOutletDensity)/(20.8d0-data%State%MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) ! asumed cutting density = 20.8 ppg + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) +!write(*,*) 'active increase choke2=' , ((20.8d0-ChokeOutletDensity)/(20.8d0-ActiveTankDensity))*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*DeltaT_Mudline) + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. data%State%MudSystem%ChokeOutletDensity < 5.0) THEN + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ ((2.d0-data%State%MudSystem%ChokeOutletDensity)/(2.d0-data%State%MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) +!write(*,*) 'active increase choke3=' ,((2.d0-ChokeOutletDensity)/(2.d0-ActiveTankDensity))*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*DeltaT_Mudline) + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. 5.0 < data%State%MudSystem%ChokeOutletDensity .and. data%State%MudSystem%ChokeOutletDensity <= data%State%MudSystem%ActiveTankDensity) THEN +!write(*,*) ' Auto true 3' + + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ (((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + +!write(*,*) 'active increase choke4=' , (((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*DeltaT_Mudline) + + ENDIF + + + + endif + + if (C77==1 .and. C71==0) then !RealJ4: 1 OR 2(IF 78 IS OPEN) + + IF (data%Configuration%Mud%ActiveAutoDensity == .FALSE.) THEN + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ChokeOutletDensity*((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%TripTankVolumeCalc+(((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ (((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. data%State%MudSystem%ChokeOutletDensity > data%State%MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= ((20.8d0-data%State%MudSystem%ChokeOutletDensity)/(20.8d0-data%State%MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. data%State%MudSystem%ChokeOutletDensity < 5.0) THEN + + AddedVolumeToTank= ((2.d0-data%State%MudSystem%ChokeOutletDensity)/(2.d0-data%State%MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. 5.0 < data%State%MudSystem%ChokeOutletDensity .and. data%State%MudSystem%ChokeOutletDensity <= data%State%MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= (((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + + ENDIF + + + + endif + + if (C71==1 .and. C77==1) then !RealJ4: 2 OR 3(IF 78 IS OPEN) + + IF (data%Configuration%Mud%ActiveAutoDensity == .FALSE.) THEN + data%State%MudSystem%ActiveTankDensity= ((data%State%MudSystem%ActiveTankDensity*data%State%MudSystem%ActiveTankVolume)+(data%State%MudSystem%ChokeOutletDensity*((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%ActiveTankVolume+(((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ChokeOutletDensity*((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%TripTankVolumeCalc+(((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ (((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ (((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. data%State%MudSystem%ChokeOutletDensity > data%State%MudSystem%ActiveTankDensity) THEN + + + AddedVolumeToTank= ((20.8d0-data%State%MudSystem%ChokeOutletDensity)/(20.8d0-data%State%MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ AddedVolumeToTank + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. 5.0 < data%State%MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= ((2.d0-data%State%MudSystem%ChokeOutletDensity)/(2.d0-data%State%MudSystem%ActiveTankDensity))*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) ! asumed GAS density = 2.0 ppg + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ AddedVolumeToTank + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + + ELSEIF (data%Configuration%Mud%ActiveAutoDensity .and. 5.0 < data%State%MudSystem%ChokeOutletDensity .and. data%State%MudSystem%ChokeOutletDensity <= data%State%MudSystem%ActiveTankDensity) THEN + + AddedVolumeToTank= ((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*AddedVolumeToTank))/(data%State%MudSystem%TripTankVolumeCalc+AddedVolumeToTank) + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ AddedVolumeToTank + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ AddedVolumeToTank + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1.d0/RealJ4)*data%State%MUD(4)%Q/60.d0)*data%State%MudSystem%DeltaT_Mudline) + + + ENDIF + + + endif + + + if (C71==0 .and. C77==0 .and. C78==1) then !RealJ4: 1 +! autodensity niaz nadarad + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ (((1./RealJ4)*data%State%MUD(4)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + endif + + + + endif ! if ( BellNippleDensity > 1.0) then + + + data%State%MudSystem%TripTankVolumeCalc=min(data%State%MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal +!if TripTankVolumeCalc>50 BBl, excess value(TripTankVolumeCalc-50) is dumped + + data%State%MudSystem%ActiveTankVolume=min(data%State%MudSystem%ActiveTankVolume , data%Configuration%Mud%ActiveTotalTankCapacityGal-data%Configuration%Mud%ActiveSettledContentsGal) +!if ActiveTankVolume is higher, excess amount is dumped + + endif + + + + + + if (j4 == 0 .or. data%State%MudSystem%ChokeLineNOTFull== .true.) then +!Pressure_BeforeChokes=0.0 ! for normal circulation input + data%State%MUD(4)%Q=0.0 ! for CirculationCodeSelect input. + endif + + + if (j4 > 0) then + data%State%MudSystem%WellToChokeManifoldOpen= .true. + else + data%State%MudSystem%WellToChokeManifoldOpen= .false. + endif + +!=========================================================================================================================== +!=========================================================================================================================== + + if (j18 > 0) then !StandPipeManifoldToChokeManifold-Through ChokeLine +!write(*,*) 'j18 is open' +!write(*,*) 'active by j18' + +! STEP 1: REDUCTION FROM PUMPS STEP 1: REDUCTION FROM PUMPS STEP 1: REDUCTION FROM PUMPS (SAME TO PumpsToString LINE) +! (NOT NEEDED) + + + +! STEP 2: ADD TO TANKS STEP 2: ADD TO TANKS STEP 2: ADD TO TANKS STEP 2: ADD TO TANKS (SAME TO WellToChokeManifold LINE) + +!Pump1toCh: PumpsToChokeManifold Coefficient +!Jj2,Jj12,Jj13: TanksToMudPump Coefficient +!H: Pumps To Tank_Through65 or 67 Coefficient + + data%State%MUD(9)%Q= jj2*(1-H82)*(1-DumpPump1)*Pump1toCh*data%State%Pump(1)%Flow_Rate + jj12*(1-H83)*(1-DumpPump2)*Pump2toCh*data%State%Pump(2)%Flow_Rate + jj13*(1-H84)*(1-DumpCementPump)*Pump3toCh*data%State%Pump(3)%Flow_Rate + + + + Denominator_a= (jj2*(1.-H82)*(1.-DumpPump1)*Pump1toCh*data%State%Pump(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*Pump2toCh*data%State%Pump(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*Pump3toCh*data%State%Pump(3)%Flow_Rate) + + if (Denominator_a /= 0.) then + data%State%MudSystem%Density_Ch= (jj2*(1.-H82)*(1.-DumpPump1)*Pump1toCh*data%State%MudSystem%Mp1Density*data%State%Pump(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*Pump2toCh*data%State%MudSystem%Mp2Density*data%State%Pump(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*Pump3toCh*data%State%MudSystem%Mp3Density*data%State%Pump(3)%Flow_Rate)/ & + Denominator_a +!write(*,*) 'Density_Ch=' , Density_Ch +! +! else +!Density_Ch= 0.0 + endif + + + RealJ18= M71+M77+M78 + +!C71: Active Tank C77: Trip Tank C78: ChokeManifoldDump + + +! IN ALL CONDITIONS EFFECT OF 78 IS COMPUTED BY RealJ18 + if (M71==1 .and. M77==0) then !(volumes in galon) RealJ18: 1 OR 2(IF 78 IS OPEN) + +! autodensity niaz nadarad + data%State%MudSystem%ActiveTankDensity= ((data%State%MudSystem%ActiveTankDensity*data%State%MudSystem%ActiveTankVolume)+(data%State%MudSystem%Density_Ch*((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%ActiveTankVolume+(((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ (((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + endif + + if (M77==1 .and. M71==0) then !RealJ18: 1 OR 2(IF 78 IS OPEN) + +! autodensity niaz nadarad + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%Density_Ch*((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%TripTankVolumeCalc+(((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ (((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + endif + + if (M71==1 .and. M77==1) then !RealJ18: 2 OR 3(IF 78 IS OPEN) + +! autodensity niaz nadarad + data%State%MudSystem%ActiveTankDensity= ((data%State%MudSystem%ActiveTankDensity*data%State%MudSystem%ActiveTankVolume)+(data%State%MudSystem%Density_Ch*((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%ActiveTankVolume+(((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%Density_Ch*((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%TripTankVolumeCalc+(((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume+ (((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc+ (((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ C78*(((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + endif + + + if (M71==0 .and. M77==0 .and. M78==1) then !RealJ18: 1 +! autodensity niaz nadarad + data%State%MudSystem%ChokeManifoldDumpVolume= data%State%MudSystem%ChokeManifoldDumpVolume+ (((1./RealJ18)*data%State%MUD(9)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + endif + + + + + + + + + data%State%MudSystem%TripTankVolumeCalc=min(data%State%MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal +!if TripTankVolumeCalc>50 BBl, excess value(TripTankVolumeCalc-50) is dumped + + data%State%MudSystem%ActiveTankVolume=min(data%State%MudSystem%ActiveTankVolume , data%Configuration%Mud%ActiveTotalTankCapacityGal-data%Configuration%Mud%ActiveSettledContentsGal) +!if ActiveTankVolume is higher, excess amount is dumped + + endif + + + if (j18 == 0) then + data%State%MUD(9)%Q=0.0 + endif + + +!=========================================================================================================================== +!=========================================================================================================================== + + if (j5 > 0 .and. (data%State%MudSystem%ActiveTankVolume/data%State%MudSystem%ActiveTankFloorArea) > (data%State%MudSystem%TripTankVolumeCalc/data%State%MudSystem%TripTankFloorArea)) then !ActiveTankToTripTank +! second condition is for Utube flow +!write(*,*) 'j5 is open' + +! ActiveTankVolume/ActiveTankFloorArea... means tank height + data%State%MUD(5)%Q= 300. ! constant flow rate(gpm) + + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume - ((data%State%MUD(5)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%TripTankVolumeCalc= data%State%MudSystem%TripTankVolumeCalc + ((data%State%MUD(5)%Q/60.)*data%State%MudSystem%DeltaT_Mudline) + + data%State%MudSystem%TripTankDensityCalc= ((data%State%MudSystem%TripTankDensityCalc*data%State%MudSystem%TripTankVolumeCalc)+(data%State%MudSystem%ActiveTankDensity*(data%State%MUD(5)%Q/60.)*data%State%MudSystem%DeltaT_Mudline))/(data%State%MudSystem%TripTankVolumeCalc+((data%State%MUD(5)%Q/60.)*data%State%MudSystem%DeltaT_Mudline)) + + + + data%State%MudSystem%TripTankVolumeCalc=min(data%State%MudSystem%TripTankVolumeCalc,50.*42.) !50. BBL *42. gal/BBL = gal +!if TripTankVolumeCalc>50, excess value(TripTankVolumeCalc-50) is dumped + + endif + + if (j5 == 0) then + data%State%MUD(5)%Q=0.0 + endif + +!=========================================================================================================================== +!=========================================================================================================================== + + if (j16 > 0) then !PathsToGauge75 + + if (K79 == 1) then + + data%State%MudSystem%PressureGauge75= data%State%PressureDisplay%PressureGauges(1) !String to Gauge75 + + elseif (K82 == 1 .and. k83 == 0 .and. k84 == 0 .and. k78 == 0) then + data%State%MudSystem%PressureGauge75= PumpPressure1 + elseif (K82 == 0 .and. k83 == 1 .and. k84 == 0 .and. k78 == 0) then + data%State%MudSystem%PressureGauge75= PumpPressure2 + elseif (K82 == 0 .and. k83 == 0 .and. k84 == 1 .and. k78 == 0) then + data%State%MudSystem%PressureGauge75= PumpPressure3 + elseif (K82 == 0 .and. k83 == 0 .and. k84 == 0 .and. k78 == 1) then + data%State%MudSystem%PressureGauge75= 0. + endif + +!if (K82 == 1) PressureGauge75= PumpPressure1 !Pump1 to Gauge75' +!if (K83 == 1) PressureGauge75= PumpPressure2 !Pump2 to Gauge75 +!if (K84 == 1) PressureGauge75= PumpPressure3 !Pump3 to Gauge75 +!if (K78 == 1) PressureGauge75= 0. !Dump to Gauge75 + + endif + + + data%Equipments%StandPipeManifold%StandPipeGauge1= (1 - data%State%MudSystem%StandPipeGauge1Malf) * data%State%MudSystem%PressureGauge75 ! for STManifold Display +!write(*,*) 'PressureGauge75=' , PressureGauge75 +!P1toSt= jj2*(1-H82)*(1-DumpPump1)*G82 +!P2toSt= jj12*(1-H83)*(1-DumpPump2)*G83 +!CptoSt= jj13*(1-H84)*(1-DumpCementPump)*G84 +!=========================================================================================================================== +!=========================================================================================================================== + + if (j17 > 0) then !PumpsToGauge76 + + if (L79 == 1) then + + data%State%MudSystem%PressureGauge76= data%State%PressureDisplay%PressureGauges(1) !String to Gauge76 + + elseif (L82 == 1 .and. L83 == 0 .and. L84 == 0 .and. L78 == 0) then + data%State%MudSystem%PressureGauge76= PumpPressure1 + elseif (L82 == 0 .and. L83 == 1 .and. L84 == 0 .and. L78 == 0) then + data%State%MudSystem%PressureGauge76= PumpPressure2 + elseif (L82 == 0 .and. L83 == 0 .and. L84 == 1 .and. L78 == 0) then + data%State%MudSystem%PressureGauge76= PumpPressure3 + elseif (L82 == 0 .and. L83 == 0 .and. L84 == 0 .and. L78 == 1) then + data%State%MudSystem%PressureGauge76= 0. + endif + + +!if (L79 == 1) PressureGauge76= PressureGauges(1) !String to Gauge76 +!if (L82 == 1) PressureGauge76= PumpPressure1 !Pump1 to Gauge76 +!if (L83 == 1) PressureGauge76= PumpPressure2 !Pump2 to Gauge76 +!if (L84 == 1) PressureGauge76= PumpPressure3 !Pump3 to Gauge76 +!if (L78 == 1) PressureGauge76= 0. !Dump to Gauge76 + + endif + data%Equipments%StandPipeManifold%StandPipeGauge2= (1 - data%State%MudSystem%StandPipeGauge2Malf) * data%State%MudSystem%PressureGauge76 ! for STManifold Display +!=========================================================================================================================== +!=========================================================================================================================== +! +!if (PressureGauge75 == PressureGauges(1)) then ! means: 75 goes to string +! PumpPressureDW= PressureGauges(1) !for DrillWatch Display +! CALL Set_StandPipePressure(real(PressureGauges(1) , 8)) !for Data Display Console +!endif +! +! +!if (PressureGauge76 == PressureGauges(1)) then ! means: 76 goes to string +! PumpPressureDW= PressureGauges(1) !for DrillWatch Display +! CALL Set_StandPipePressure(real(PressureGauges(1) , 8)) !for Data Display Console +!endif +! +!if (PressureGauge75 /= PressureGauges(1) .and. PressureGauge76 /= PressureGauges(1)) then ! means: non of gauges go to string +! PumpPressureDW= max(PressureGauge75,PressureGauge76) !for DrillWatch Display +! !StandPipePressureGauge= max(PressureGauge75,PressureGauge76) !for Data Display Console +! CALL Set_StandPipePressure(real(max(PressureGauge75,PressureGauge76) , 8)) !for Data Display Console +!endif +!write(*,*) 'TapSelector=' , TapSelector + + + if (data%State%StudentStation%TapSelector == .false.) then + + data%Equipments%DrillingWatch%PumpPressure= data%State%MudSystem%PressureGauge75 !for DrillWatch Display + CALL Set_StandPipePressure(real((1-data%State%MudSystem%DrillPipePressureMalf)*data%State%MudSystem%PressureGauge75 , 8)) !for Data Display Console + else + data%Equipments%DrillingWatch%PumpPressure= data%State%MudSystem%PressureGauge76 !for DrillWatch Display + CALL Set_StandPipePressure(real((1-data%State%MudSystem%DrillPipePressureMalf)*data%State%MudSystem%PressureGauge76 , 8)) !for Data Display Console + endif + +!=========================================================================================================================== +!=========================================================================================================================== +! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem + + if (j2 > 0) then !TanksToMudPump1 + + +!Relief= 0: deactive 1: active data%State%Pump(1)%Flow_Rate , data%State%Pump(2)%Flow_Rate + + + RealJ2= real(j2) + + if (A71==1 .and. (data%State%MudSystem%ActiveTankVolume-(((1./RealJ2)*data%State%Pump(1)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline)) < 0.0) then + A71= 0 + RealJ2= RealJ2-1 + write(*,*) 'ActiveTank Level Warning' + call Activate_ActiveTankUnderVolume() + endif + + if (A72==1 .and. (data%State%MudSystem%ReserveTankVolume-(((1./RealJ2)*data%State%Pump(1)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline)) < 0.0) then + A72= 0 + RealJ2= RealJ2-1 + write(*,*) 'ReserveTank Level Warning' + endif + + if (A71==3 .and. (data%State%MudSystem%CementTankVolumeCalc-(((1./RealJ2)*data%State%Pump(1)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline)) < 0.0) then + A73= 0 + RealJ2= RealJ2-1 + write(*,*) 'CementTank Level Warning' + endif + + + if(RealJ2> 0.0) then + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume- A71*(((1./RealJ2)*data%State%Pump(1)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%ReserveTankVolume= data%State%MudSystem%ReserveTankVolume- A72*(((1./RealJ2)*data%State%Pump(1)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%CementTankVolumeCalc= data%State%MudSystem%CementTankVolumeCalc- A73*(((1./RealJ2)*data%State%Pump(1)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) +!write(*,*) 'Active-decline=' , A71*(((1./RealJ2)*data%State%Pump(1)%Flow_Rate/60.)*DeltaT_Mudline) + total_decrease= total_decrease+ A71*(((1./RealJ2)*data%State%Pump(1)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) + + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + total_decrease= 0. + endif +!write(*,*) 'total_decrease=' , total_decrease + + + data%State%MudSystem%Mp1Density= (A71*data%State%MudSystem%ActiveTankDensity+A72*data%State%MudSystem%ReserveTankDensity+A73*data%State%MudSystem%CementTankDensityCalc)/RealJ2 + else + write(*,*) 'stop' + endif + + + + endif + + +!=========================================================================================================================== +!=========================================================================================================================== +! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem + + if (j12 > 0) then !TanksToMudPump2 + + +!Relief= 0: deactive 1: active data%State%Pump(1)%Flow_Rate , data%State%Pump(2)%Flow_Rate + + RealJ12= real(J12) + + if (E71==1 .and. (data%State%MudSystem%ActiveTankVolume-(((1/RealJ12)*data%State%Pump(2)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline)) < 0.0) then + E71= 0 + RealJ12= RealJ12-1 + write(*,*) 'ActiveTank Level Warning' + endif + + if (E72==1 .and. (data%State%MudSystem%ReserveTankVolume-(((1/RealJ12)*data%State%Pump(2)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline)) < 0.0) then + E72= 0 + RealJ12= RealJ12-1 + write(*,*) 'ReserveTank Level Warning' + endif + + if (E71==3 .and. (data%State%MudSystem%CementTankVolumeCalc-(((1/RealJ12)*data%State%Pump(2)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline)) < 0.0) then + E73= 0 + RealJ12= RealJ12-1 + write(*,*) 'CementTank Level Warning' + endif + + + if(RealJ12> 0.0) then + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume- E71*(((1/RealJ12)*data%State%Pump(2)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%ReserveTankVolume= data%State%MudSystem%ReserveTankVolume- E72*(((1/RealJ12)*data%State%Pump(2)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%CementTankVolumeCalc= data%State%MudSystem%CementTankVolumeCalc- E73*(((1/RealJ12)*data%State%Pump(2)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) + + + + data%State%MudSystem%Mp2Density= (E71*data%State%MudSystem%ActiveTankDensity+E72*data%State%MudSystem%ReserveTankDensity+E73*data%State%MudSystem%CementTankDensityCalc)/RealJ12 + else + write(*,*) 'stop' + endif + + + endif + + +!=========================================================================================================================== +!=========================================================================================================================== +! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem + + if (j13 > 0) then !TanksToCementPump + + +!Relief= 0: deactive 1: active data%State%Pump(1)%Flow_Rate , data%State%Pump(2)%Flow_Rate + + + RealJ13= real(J13) + + if (F71==1 .and. (data%State%MudSystem%ActiveTankVolume-(((1/RealJ13)*data%State%Pump(3)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline)) < 0.0) then + F71= 0 + RealJ13= RealJ13-1 + write(*,*) 'ActiveTank Level Warning' + endif + + if (F72==1 .and. (data%State%MudSystem%ReserveTankVolume-(((1/RealJ13)*data%State%Pump(3)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline)) < 0.0) then + F72= 0 + RealJ13= RealJ13-1 + write(*,*) 'ReserveTank Level Warning' + endif + + if (F71==3 .and. (data%State%MudSystem%CementTankVolumeCalc-(((1/RealJ13)*data%State%Pump(3)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline)) < 0.0) then + F73= 0 + RealJ13= RealJ13-1 + write(*,*) 'CementTank Level Warning' + endif + + + if(RealJ13> 0.0) then + + data%State%MudSystem%ActiveTankVolume= data%State%MudSystem%ActiveTankVolume- F71*(((1/RealJ13)*data%State%Pump(3)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%ReserveTankVolume= data%State%MudSystem%ReserveTankVolume- F72*(((1/RealJ13)*data%State%Pump(3)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%CementTankVolumeCalc= data%State%MudSystem%CementTankVolumeCalc- F73*(((1/RealJ13)*data%State%Pump(3)%Flow_Rate/60.)*data%State%MudSystem%DeltaT_Mudline) + + + data%State%MudSystem%Mp3Density= (F71*data%State%MudSystem%ActiveTankDensity+F72*data%State%MudSystem%ReserveTankDensity+F73*data%State%MudSystem%CementTankDensityCalc)/RealJ13 + else + write(*,*) 'stop' + endif + + + endif + + + +!=========================================================================================================================== +!=========================================================================================================================== +! SHOULD BE AT LAST TO HAVE THE CORRECT DENSITIES FOR Suction_Density_MudSystem + + if (j14 > 0) then !PumpsToString Suction_Density_MudSystem is used for Mud Circulation Code +!write(*,*) 'j14 is open' +!call Log_1('j14 is open') + +! << if H82 or H83 or H4 are open, no flow goes to other parts of system >> + +! pump flow rate1 be sharti be samte string miravad ke masire j2 bar gharar bashad +! pump flow rate2 be sharti be samte string miravad ke masire j12 bar gharar bashad +! pump flow rate3 be sharti be samte string miravad ke masire j13 bar gharar bashad + +!G: PumpsToString Coefficient +!Jj2,Jj12,Jj13: TanksToMudPump Coefficient +!H: Pumps To Tank_Through65 or 67 Coefficient +! +!write(*,*) 'jj2=' , jj2 +!write(*,*) 'jj12=' , jj12 +!write(*,*) 'jj13=' , jj13 +!write(*,*) 'H82=' , H82 +!write(*,*) 'H83=' , H83 +!write(*,*) 'H84=' , H84 +!write(*,*) 'DumpPump1=' , DumpPump1 +!write(*,*) 'DumpPump2=' , DumpPump2 +!write(*,*) 'DumpCementPump=' , DumpCementPump +!write(*,*) 'G82=' , G82 +!write(*,*) 'G83=' , G83 +!write(*,*) 'G84=' , G84 +!write(*,*) 'Mp1Density=' , Mp1Density +!write(*,*) 'Mp2Density=' , Mp2Density +!write(*,*) 'Mp3Density=' , Mp3Density +! +! + + + +!PumpsDumpVolume= PumpsDumpVolume+ jj2*(1-H82)*DumpPump1*data%State%Pump(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*data%State%Pump(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*data%State%Pump(3)%Flow_Rate + + Denominator= (jj2*(1.-H82)*(1.-DumpPump1)*G82*data%State%Pump(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*G83*data%State%Pump(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*G84*data%State%Pump(3)%Flow_Rate) + + if (Denominator /= 0.) then + data%State%MudSystem%Suction_Density_MudSystem= (jj2*(1.-H82)*(1.-DumpPump1)*G82*data%State%MudSystem%Mp1Density*data%State%Pump(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*G83*data%State%MudSystem%Mp2Density*data%State%Pump(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*G84*data%State%MudSystem%Mp3Density*data%State%Pump(3)%Flow_Rate)/ & + Denominator + endif + + data%State%MudSystem%CompressedMudDensity= data%State%MudSystem%Suction_Density_MudSystem + + data%Equipments%DrillingWatch%MudWeightIn= data%State%MudSystem%Suction_Density_MudSystem !for drillwatch display + + + data%State%MUD(2)%Q= jj2*(1-H82)*(1-DumpPump1)*G82*data%State%Pump(1)%Flow_Rate + jj12*(1-H83)*(1-DumpPump2)*G83*data%State%Pump(2)%Flow_Rate + jj13*(1-H84)*(1-DumpCementPump)*G84*data%State%Pump(3)%Flow_Rate + +!write(*,*) 'data%State%MUD(2)%Q=' , data%State%MUD(2)%Q + + + +!jj2*(1-H82)*(1-DumpPump1)*G82 :if ==1, Pump1 to String is open +!jj12*(1-H83)*(1-DumpPump2)*G83 :if ==1, Pump2 to String is open +!jj13*(1-H84)*(1-DumpCementPump)*G84 :if ==1, Cement to String is open + + + + endif + + if (j14 == 0) then ! for normal circulation input + data%State%MUD(2)%Q=0.0 +!PumpPressure1= 0.0 +!PumpPressure2= 0.0 +!PumpPressure3= 0.0 + endif + + + +!=========================================================================================================================== +!=========================================================================================================================== + + if (j19 > 0 .and. data%State%MudSystem%MudChecked== .true.) then !PumpsToWell_KillLine Suction_Density_PumpsToWell is used for Mud Circulation Code +!write(*,*) 'j19 is open' + data%State%MudSystem%MudChecked= .false. !to be sure that well is not full after arranging muds + +! << if H82 or H83 or H4 are open, no flow goes to other parts of system >> + +! pump flow rate1 be sharti be samte well miravad ke masire j2 bar gharar bashad +! pump flow rate2 be sharti be samte well miravad ke masire j12 bar gharar bashad +! pump flow rate3 be sharti be samte well miravad ke masire j13 bar gharar bashad + +!G: PumpsToString Coefficient +!Jj2,Jj12,Jj13: TanksToMudPump Coefficient +!H: Pumps To Tank_Through65 or 67 Coefficient +! +!write(*,*) 'jj2=' , jj2 +!write(*,*) 'jj12=' , jj12 +!write(*,*) 'jj13=' , jj13 +!write(*,*) 'H82=' , H82 +!write(*,*) 'H83=' , H83 +!write(*,*) 'H84=' , H84 +!write(*,*) 'DumpPump1=' , DumpPump1 +!write(*,*) 'DumpPump2=' , DumpPump2 +!write(*,*) 'DumpCementPump=' , DumpCementPump +!write(*,*) 'G82=' , G82 +!write(*,*) 'G83=' , G83 +!write(*,*) 'G84=' , G84 +!write(*,*) 'Mp1Density=' , Mp1Density +!write(*,*) 'Mp2Density=' , Mp2Density +!write(*,*) 'Mp3Density=' , Mp3Density +! +! + + + +!PumpsDumpVolume= PumpsDumpVolume+ jj2*(1-H82)*DumpPump1*data%State%Pump(1)%Flow_Rate + jj12*(1-H83)*DumpPump2*data%State%Pump(2)%Flow_Rate + jj13*(1-H84)*DumpCementPump*data%State%Pump(3)%Flow_Rate + + Denominator= (jj2*(1.-H82)*(1.-DumpPump1)*N82*data%State%Pump(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*N83*data%State%Pump(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*N84*data%State%Pump(3)%Flow_Rate) + + if (Denominator /= 0.) then + data%State%MudSystem%Suction_Density_PumpsToWell= (jj2*(1.-H82)*(1.-DumpPump1)*N82*data%State%MudSystem%Mp1Density*data%State%Pump(1)%Flow_Rate + jj12*(1.-H83)*(1.-DumpPump2)*N83*data%State%MudSystem%Mp2Density*data%State%Pump(2)%Flow_Rate + jj13*(1.-H84)*(1.-DumpCementPump)*N84*data%State%MudSystem%Mp3Density*data%State%Pump(3)%Flow_Rate)/ & + Denominator + endif + + + + + + data%State%MUD(10)%Q= jj2*(1-H82)*(1-DumpPump1)*N82*data%State%Pump(1)%Flow_Rate + jj12*(1-H83)*(1-DumpPump2)*N83*data%State%Pump(2)%Flow_Rate + jj13*(1-H84)*(1-DumpCementPump)*N84*data%State%Pump(3)%Flow_Rate + + + + + + + endif + + if (j19 == 0) then ! for normal circulation input + data%State%MUD(10)%Q=0.0 +!PumpPressure1= 0.0 +!PumpPressure2= 0.0 +!PumpPressure3= 0.0 + endif +!=========================================================================================================================== +!=========================================================================================================================== + + + +!AnnulusFlowRateFinal = 0.d0 ! this is a reset for calculated flow rate in UTUBES,TRIPIN,TRIPOUT codes + + + + + + + + + + + + + +!!====================================================================== +!! Well Head Condition Determination +!!====================================================================== + + + if ( data%State%MudSystem%WellToChokeManifoldOpen .or. data%State%MudSystem%WellToPitsOpen) then + data%State%MudSystem%WellHeadIsOpen= .true. + else + data%State%MudSystem%WellHeadIsOpen= .false. + endif + + + + + + + +!!====================================================================== +!! WARNINGS +!!====================================================================== + + + IF (Manifold%Valve(65)%Status == .TRUE.) call Activate_Pump1PopOffValveBlown() !Pump1PopOffValveBlown= .TRUE. + IF (Manifold%Valve(66)%Status == .TRUE.) call Activate_Pump2PopOffValveBlown() ! Pump2PopOffValveBlown= .TRUE. + IF (Manifold%Valve(67)%Status == .TRUE.) call Activate_Pump3PopOffValveBlown() !Pump2PopOffValveBlown= .TRUE. + + + IF (data%State%MudSystem%ActiveTankVolume >= (data%Configuration%Mud%ActiveTotalTankCapacityGal-data%Configuration%Mud%ActiveSettledContentsGal)) THEN + data%State%MudSystem%ActiveTankVolume = (data%Configuration%Mud%ActiveTotalTankCapacityGal-data%Configuration%Mud%ActiveSettledContentsGal) + call Activate_ActiveTankOverflow() + ELSE + call Deactivate_ActiveTankOverflow() + ENDIF + + + +!!====================================================================== +!! UPDATING TANKS DENSITIES & Volumes FOR MUD CIRCULATION +!!====================================================================== + +!write(*,*) 'ReserveTankVolume=' , real(ReserveTankVolume) + + call Set_ActiveMudVolume_StudentStation(real(data%State%MudSystem%ActiveTankVolume/42.,8)) ! 42: gal to bbl + call Set_ActiveDensity_StudentStation(real(data%State%MudSystem%ActiveTankDensity,8)) + call Set_ReserveMudVolume_StudentStation(real(data%State%MudSystem%ReserveTankVolume/42.,8)) ! 42: gal to bbl + call Set_ReserveDensity_StudentStation(real(data%State%MudSystem%ReserveTankDensity,8)) + data%Equipments%DrillingWatch%KillMudVolume= data%State%MudSystem%ReserveTankVolume/42. ! for DrillWatch +!PitGainLose= + + +!!====================================================================== +!! DRILLING DATA DISPLAY +!!====================================================================== + + + IF (data%Equipments%DataDisplayConsole%TotalStrokeCounterResetSwitch == 1) then !for drilling data display + data%State%MudSystem%TotalStrokesPump1=0. + data%State%MudSystem%TotalStrokesPump2=0. + ENDIF + + data%State%MudSystem%TotalStrokesPump1=data%State%MudSystem%TotalStrokesPump1+((data%Equipments%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline !for drilling data display + data%State%MudSystem%TotalStrokesPump2=data%State%MudSystem%TotalStrokesPump2+((data%Equipments%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline !for drilling data display + data%State%MudSystem%GraphTotalStrokes=data%State%MudSystem%GraphTotalStrokes+((data%Equipments%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline+((data%Equipments%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + + + data%State%MPumps%Total_Stroke_Counter_For_Plot = data%State%MPumps%Total_Stroke_Counter_For_Plot + ((data%Equipments%DataDisplayConsole%MP1SPMGauge + data%Equipments%DataDisplayConsole%MP2SPMGauge) / 60.0) * data%State%MudSystem%DeltaT_Mudline + +! CALL SetTotalStrokes(INT(data%State%MPumps%Total_Stroke_Counter_For_Plot)) + + data%Equipments%DataDisplayConsole%TotalStrokeCounter= real(nint(data%State%MudSystem%TotalStrokesPump1+data%State%MudSystem%TotalStrokesPump2)) !for drilling data display + +!=========================================================================== +! MUD PUMP STROKES +! & TOTAL STROKE- CHOKE CONTROL PANEL +!=========================================================================== +!write(*,*) 'a)))' , ChokePanelStrokeResetSwitch + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + IF (data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 1) THEN +!write(*,*) '1 reset' + data%State%Choke%TotalStrokes1 =0. + elseif (data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 2) THEN +!write(*,*) '2 reset' + data%State%Choke%TotalStrokes2 =0. + else +!write(*,*) 'both reset' + + data%State%Choke%TotalStrokes1 =0. + data%State%Choke%TotalStrokes2 =0. + endif + endif + +!write(*,*) 'b)))' , ChokePanelStrokeResetSwitch + + + data%State%Choke%TotalStrokes1= data%State%Choke%TotalStrokes1+((data%Equipments%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + data%State%Choke%TotalStrokes2= data%State%Choke%TotalStrokes2+((data%Equipments%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + + + + IF (data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 1) THEN + data%Equipments%ChokeControlPanel%ChokePanelSPMCounter = real(nint(data%Equipments%DataDisplayConsole%MP1SPMGauge)) + data%Equipments%ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(data%State%Choke%TotalStrokes1)) + ELSEIF (data%Equipments%ChokeControlPanel%ChokePanelPumpSelectorSwitch == 2) THEN + data%Equipments%ChokeControlPanel%ChokePanelSPMCounter = real(nint(data%Equipments%DataDisplayConsole%MP2SPMGauge)) + data%Equipments%ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(data%State%Choke%TotalStrokes2)) + ELSE + data%Equipments%ChokeControlPanel%ChokePanelSPMCounter= real(nint(data%Equipments%DataDisplayConsole%MP1SPMGauge+data%Equipments%DataDisplayConsole%MP2SPMGauge)) + data%Equipments%ChokeControlPanel%ChokePanelTotalStrokeCounter = real(nint(data%State%Choke%TotalStrokes1+data%State%Choke%TotalStrokes2)) + ENDIF + +! ChokePanelStrokeResetSwitch = 0 +!====================================================================== + +!!====================================================================== +!! MUD VOLUME TOTALIZER DISPLAY VALUES +!!====================================================================== + + + data%Equipments%DrillingWatch%PitVolume= data%State%MudSystem%ActiveTankVolume/42.d0 !(bbl) For DrillWatch Display + +!write(*,*) 'PitVolume,ActiveTankVolume=' ,PitVolume,ActiveTankVolume + + + data%State%MudSystem%MudTank1_vol= data%State%MudSystem%ActiveTankVolume/3. ! (gal) + data%State%MudSystem%MudTank2_vol= data%State%MudSystem%ActiveTankVolume/3. ! (gal) + data%State%MudSystem%MudTank3_vol= data%State%MudSystem%ActiveTankVolume/3. ! (gal) + data%State%MudSystem%MudTank4_vol= data%State%MudSystem%TripTankVolumeCalc + + + + + + IF (data%Equipments%DataDisplayConsole%MVTPowerSwitch==1) THEN + data%Equipments%DataDisplayConsole%MudTanksVolumeGauge= (1 - data%State%MudSystem%MudTanksVolumeGaugeMalf) *((data%State%MudSystem%MudTank1_vol*data%Equipments%DataDisplayConsole%MudTank1Switch)+(data%State%MudSystem%MudTank2_vol*data%Equipments%DataDisplayConsole%MudTank2Switch)+ & + (data%State%MudSystem%MudTank3_vol*data%Equipments%DataDisplayConsole%MudTank3Switch)+(data%State%MudSystem%MudTank4_vol*data%Equipments%DataDisplayConsole%MudTank4Switch)+data%State%MudSystem%ActiveTankSettled) !(gal) + ELSEIF (data%Equipments%DataDisplayConsole%MVTPowerSwitch==0) THEN + data%Equipments%DataDisplayConsole%MudTanksVolumeGauge= (1 - data%State%MudSystem%MudTanksVolumeGaugeMalf) *0. + ENDIF + +!!====================================================================== +!! MUD VOLUME TOTALIZER +!!====================================================================== + + + + +! IF (data%Equipments%DataDisplayConsole%MVTPowerSwitch==1 .and. IsPortable==.false.) THEN + + + +! IF (data%Equipments%DataDisplayConsole%MVTSetAlarmSwitch==0) THEN + +! data%Equipments%DataDisplayConsole%PitGainLossGauge= ( ((ActiveTankVolume/42.) - RefrencePitVolume)) - PitGainLossGaugeMalf*(( ((ActiveTankVolume/42.) - RefrencePitVolume))+50) !(bbl) + +! ELSEIF (data%Equipments%DataDisplayConsole%MVTSetAlarmSwitch==-1) THEN + + +! MVT_MinVol_Allowded= PitGainLossZero+ MIN(0.,(data%Equipments%DataDisplayConsole%MVTSetAlarmLowKnob-50))-0.1 +! data%Equipments%DataDisplayConsole%PitGainLossGauge= MVT_MinVol_Allowded - PitGainLossGaugeMalf*(MVT_MinVol_Allowded+50) +! ! - PitGainLossGaugeMalf*(MVT_MinVol_Allowded+50) : Malf effect +! !PitGainLose=(MVT_MinVol_Allowded) ! DrillWatch (incorrect) +! !RefrencePitVolume= ActiveTankVolume/42. !(bbl) + +! ELSE !(MVTSetAlarmSwitch==1) + +! MVT_MaxVol_Allowded= PitGainLossZero+ MAX(0., (data%Equipments%DataDisplayConsole%MVTSetAlarmHighKnob-50.))+0.1 +! data%Equipments%DataDisplayConsole%PitGainLossGauge= MVT_MaxVol_Allowded - PitGainLossGaugeMalf*(MVT_MaxVol_Allowded+50) +! ! - PitGainLossGaugeMalf*(MVT_MaxVol_Allowded+50) : Malf effect +! !PitGainLose=(MVT_MaxVol_Allowded) ! DrillWatch (incorrect) +! !RefrencePitVolume= ActiveTankVolume/42. !(bbl) +! ENDIF + +! !PitGainLossZero_Old= PitGainLossZero +! !MVTCoarseKnob_Old= MVTCoarseKnob +! !MVTFineKnob_Old= MVTFineKnob +! !FirstSet_Time= .false. + + + +! IF ( ActiveTankVolume/42. < (RefrencePitVolume-ABS(MVT_MinVol_Allowded)) .OR. ActiveTankVolume/42. > (RefrencePitVolume+ABS(MVT_MaxVol_Allowded)) ) THEN + +! data%Equipments%DataDisplayConsole%MVTAlarmLED = 1 !(blinking) +! IF (data%Equipments%DataDisplayConsole%MVTHornSwitch) THEN +! data%Equipments%DataDisplayConsole%Buzzer2= .TRUE. +! ELSE +! data%Equipments%DataDisplayConsole%Buzzer2= .FALSE. +! ENDIF + +! ELSE +! data%Equipments%DataDisplayConsole%MVTAlarmLED = 0 !(OFF) +! data%Equipments%DataDisplayConsole%Buzzer2= .false. +! ENDIF + + + +! ELSEIF (data%Equipments%DataDisplayConsole%MVTPowerSwitch==0) THEN +! !MudTanksVolumeGauge= 0. +! data%Equipments%DataDisplayConsole%PitGainLossGauge= -50 +! data%Equipments%DataDisplayConsole%MVTAlarmLED= 0 +! data%Equipments%DataDisplayConsole%Buzzer2= .false. + + +! ENDIF + +!!====================================================================== +!! RETURN CALCULATIONS +!!====================================================================== + + + + + data%Equipments%DrillingWatch%PercentFlow= (data%State%MudSystem%ReturnFlowRate/data%State%MudSystem%PedalMeter) *100. !(percent) ! for DrillWatch display + if (abs(data%Equipments%DrillingWatch%PercentFlow - unityreturn) > 1.0) then + + write(*,*) 'PercentFlow,ReturnFlowRate,PedalMeter=' , data%Equipments%DrillingWatch%PercentFlow,data%State%MudSystem%ReturnFlowRate,data%State%MudSystem%PedalMeter + write(*,*) 'unityreturn=' , unityreturn + endif + + +! ReturnFlowRate=800. set in startup as initial value + data%State%MudSystem%ReturnFlowPercent= (data%State%MudSystem%ReturnFlowRate/data%State%MudSystem%PedalMeter) *100. !(percent) +!write(*,*) 'ReturnFlowPercent,ReturnFlowRate=' , ReturnFlowPercent,ReturnFlowRate +! if ReturnFlowRate>PedalMeter, excess value(ReturnFlowRate-PedalMeter) is dumped in the code before + + +!!====================================================================== +!! DRILL WATCH +!!====================================================================== + + data%Equipments%DrillingWatch%PitGainLose= ((data%State%MudSystem%ActiveTankVolume/42.) - data%State%MudSystem%RefrencePitVolume_DrillWatch) ! DrillWatch +!write(*,*) 'PitGainLose galon' , PitGainLose*42. + + +! if (IsPortable) then + +! MVT_MinVol_Allowded= data%Equipments%DataDisplayConsole%PitAlarmLow +! MVT_MaxVol_Allowded= data%Equipments%DataDisplayConsole%PitAlarmHigh + +! IF ( ActiveTankVolume/42. < (RefrencePitVolume-ABS(MVT_MinVol_Allowded)) .OR. ActiveTankVolume/42. > (RefrencePitVolume+ABS(MVT_MaxVol_Allowded)) ) THEN + +! data%Equipments%DataDisplayConsole%MVTAlarmLED = 1 !(blinking) +! IF (data%Equipments%DataDisplayConsole%MVTHornSwitch) THEN +! data%Equipments%DataDisplayConsole%Buzzer2= .TRUE. +! ELSE +! data%Equipments%DataDisplayConsole%Buzzer2= .FALSE. +! ENDIF + +! ELSE +! data%Equipments%DataDisplayConsole%MVTAlarmLED = 0 !(OFF) +! data%Equipments%DataDisplayConsole%Buzzer2= .false. +! ENDIF + +! endif + + + if (data%State%StudentStation%PitGainLossZero) then + + data%Equipments%DrillingWatch%PitGainLose= 0.d0 !DrillWatch + data%State%MudSystem%RefrencePitVolume_DrillWatch= data%State%MudSystem%ActiveTankVolume/42. !(bbl) !DrillWatch +!********************************************* + + data%Equipments%DataDisplayConsole%PitGainLossGauge= 0. !MFF Indicator + data%State%MudSystem%RefrencePitVolume= data%State%MudSystem%ActiveTankVolume/42. !(bbl) !MFF Indicator + + endif + + + + + + + +!!====================================================================== +!! MUD FLOW-FILL INDICATOR +!!====================================================================== + + IF (data%Equipments%DataDisplayConsole%MFFIPowerSwitch==1 ) THEN !.and. IsPortable==.false. + + +!====================TotalStrokes Reset and Calculate====================== + if (data%Equipments%DataDisplayConsole%MFFIResetTotalStrokes == 1) then + IF (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN + data%State%MudSystem%TotalStrokes1MFFI =0. + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) THEN + data%State%MudSystem%TotalStrokes2MFFI =0. + else + data%State%MudSystem%TotalStrokes1MFFI =0. + data%State%MudSystem%TotalStrokes2MFFI =0. + endif + endif + data%State%MudSystem%TotalStrokes1MFFI= data%State%MudSystem%TotalStrokes1MFFI+((data%Equipments%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + data%State%MudSystem%TotalStrokes2MFFI= data%State%MudSystem%TotalStrokes2MFFI+((data%Equipments%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + +!==================FillStrokes Reset and Calculate========================= + if (data%Equipments%DataDisplayConsole%MFFIResetFillCounter == 1) then + IF (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) THEN + data%State%MudSystem%TotalFillStrokes1MFFI =0. + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) THEN + data%State%MudSystem%TotalFillStrokes2MFFI =0. + else + data%State%MudSystem%TotalFillStrokes1MFFI =0. + data%State%MudSystem%TotalFillStrokes2MFFI =0. + endif + endif + + + data%State%MudSystem%TotalFillStrokes1MFFI= data%State%MudSystem%TotalFillStrokes1MFFI+((data%Equipments%DataDisplayConsole%MP1SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline + data%State%MudSystem%TotalFillStrokes2MFFI= data%State%MudSystem%TotalFillStrokes2MFFI+((data%Equipments%DataDisplayConsole%MP2SPMGauge)/60.)*data%State%MudSystem%DeltaT_Mudline +!=================================================================== + + + if (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter = real(nint(data%State%MudSystem%TotalStrokes1MFFI)) !TotalStroke LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter = real(nint(data%State%MudSystem%TotalStrokes2MFFI)) !TotalStroke LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter = real(nint(data%State%MudSystem%TotalStrokes1MFFI+data%State%MudSystem%TotalStrokes2MFFI)) !TotalStroke LED + endif + + + IF (data%Equipments%DataDisplayConsole%MFFIFillSPMSelectorSwitch== .false.) THEN !(spm mode) + if (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = real(nint(data%Equipments%DataDisplayConsole%MP1SPMGauge)) !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = real(nint(data%Equipments%DataDisplayConsole%MP2SPMGauge)) !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + data%Equipments%DataDisplayConsole%FillStrokeCounter= real(nint(data%Equipments%DataDisplayConsole%MP1SPMGauge+data%Equipments%DataDisplayConsole%MP2SPMGauge)) !Fill or SPM LED + endif + + ELSE ! (MFFIFillSPMSelectorSwitch== .true.) then !(fill mode) + if (data%State%MudSystem%ReturnFlowRate== 0) then + if (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = real(nint(data%State%MudSystem%TotalFillStrokes1MFFI)) !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = real(nint(data%State%MudSystem%TotalFillStrokes2MFFI)) !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + data%Equipments%DataDisplayConsole%FillStrokeCounter= real(nint(data%State%MudSystem%TotalFillStrokes1MFFI+data%State%MudSystem%TotalFillStrokes2MFFI)) !Fill or SPM LED + endif + + + data%State%MudSystem%TotalFilledStrokesBy1MFFI = real(nint(data%State%MudSystem%TotalFillStrokes1MFFI))! for values=fix on LED after the well filled + data%State%MudSystem%TotalFilledStrokesBy2MFFI = real(nint(data%State%MudSystem%TotalFillStrokes2MFFI))! for values=fix on LED after the well filled + data%State%MudSystem%TotalFilledStrokesBy1and2MFFI= real(nint(data%State%MudSystem%TotalFillStrokes1MFFI+data%State%MudSystem%TotalFillStrokes2MFFI))! for values=fix on LED after the well filled + + + + else !(ReturnFlowRate>0) + +! these values=fix on LED after the well filled + if (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 1) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = data%State%MudSystem%TotalFilledStrokesBy1MFFI !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 2) then + data%Equipments%DataDisplayConsole%FillStrokeCounter = data%State%MudSystem%TotalFilledStrokesBy2MFFI !Fill or SPM LED + elseif (data%Equipments%DataDisplayConsole%MFFIPumpSelectorSwitch == 3) then + data%Equipments%DataDisplayConsole%FillStrokeCounter= data%State%MudSystem%TotalFilledStrokesBy1and2MFFI !Fill or SPM LED + endif + endif + + + ENDIF + + + +!=================================================================================== + + + + + if (data%State%MudSystem%ReturnFlowRate>0) then + data%Equipments%DataDisplayConsole%MFFIPumpLED=1 !(Returns Lamp) + else + data%Equipments%DataDisplayConsole%MFFIPumpLED=0 !(Returns Lamp) + endif + + + + IF (data%Equipments%DataDisplayConsole%MFFISetAlarmSwitch==0) THEN + + data%Equipments%DataDisplayConsole%ReturnMudFlowGauge= (1 - data%State%MudSystem%ReturnMudFlowGaugeMalf)*data%State%MudSystem%ReturnFlowPercent !(percent) + + ELSEIF (data%Equipments%DataDisplayConsole%MFFISetAlarmSwitch==-1) THEN + data%State%MudSystem%MFFI_MinPercent_Allowded=data%Equipments%DataDisplayConsole%MFFISetAlarmLowKnob + data%Equipments%DataDisplayConsole%ReturnMudFlowGauge= (1 - data%State%MudSystem%ReturnMudFlowGaugeMalf)*data%State%MudSystem%MFFI_MinPercent_Allowded + + ELSE !(MFFISetAlarmSwitch==1) + + data%State%MudSystem%MFFI_MaxPercent_Allowded=data%Equipments%DataDisplayConsole%MFFISetAlarmHighKnob + data%Equipments%DataDisplayConsole%ReturnMudFlowGauge= (1 - data%State%MudSystem%ReturnMudFlowGaugeMalf)*data%State%MudSystem%MFFI_MaxPercent_Allowded + ENDIF + + + IF (data%State%MudSystem%ReturnFlowPercentdata%State%MudSystem%MFFI_MaxPercent_Allowded) THEN +!write(*,*) 'alarm return:' , ReturnFlowRate + data%Equipments%DataDisplayConsole%MFFIAlarmLED = 2 !(blinking) + IF (data%Equipments%DataDisplayConsole%MFFIHornSwitch) THEN + data%Equipments%DataDisplayConsole%Buzzer3= .true. + ELSE + data%Equipments%DataDisplayConsole%Buzzer3= .FALSE. + ENDIF + ELSE + data%Equipments%DataDisplayConsole%MFFIAlarmLED = 0 !(OFF) + data%Equipments%DataDisplayConsole%Buzzer3= .false. + ENDIF +!=================================================================================== + + + ELSEIF (data%Equipments%DataDisplayConsole%MFFIPowerSwitch==0) THEN + data%Equipments%DataDisplayConsole%ReturnMudFlowGauge= 0. + data%Equipments%DataDisplayConsole%FillStrokeCounter= 0 + data%Equipments%DataDisplayConsole%MFFITotalStrokeCounter= 0 + data%Equipments%DataDisplayConsole%MFFIAlarmLED= 0 + data%Equipments%DataDisplayConsole%Buzzer3= .false. + ENDIF + + +! if ( IsPortable ) then + +! MFFI_MinPercent_Allowded=data%Equipments%DataDisplayConsole%RetFlowAlarmLow +! MFFI_MaxPercent_Allowded=data%Equipments%DataDisplayConsole%RetFlowAlarmHigh + + +! IF (ReturnFlowPercentMFFI_MaxPercent_Allowded) THEN + +! data%Equipments%DataDisplayConsole%MFFIAlarmLED = 1 !(blinking) +! IF (data%Equipments%DataDisplayConsole%MFFIHornSwitch) THEN +! data%Equipments%DataDisplayConsole%Buzzer3= .true. +! ELSE +! data%Equipments%DataDisplayConsole%Buzzer3= .FALSE. +! ENDIF +! ELSE +! data%Equipments%DataDisplayConsole%MFFIAlarmLED = 0 !(OFF) +! data%Equipments%DataDisplayConsole%Buzzer3= .false. +! ENDIF + +! endif + + +!!====================================================================== +!! TRIP TANK PANEL DISPLAY VALUES +!!====================================================================== + + data%Equipments%Tank%TripTankVolume = data%State%MudSystem%TripTankVolumeCalc/42. !(Drill Watch display) + data%Equipments%Tank%TripTankDensity= data%State%MudSystem%TripTankDensityCalc !(display) + + + IF (data%Equipments%DataDisplayConsole%TripTankPowerSwitch==1 ) THEN !.and. IsPortable==.false. + + IF (data%Equipments%DataDisplayConsole%TripTankSetAlarmSwitch==0) THEN + + data%Equipments%DataDisplayConsole%TripTankGauge= (1 - data%State%MudSystem%TripTankPressure_DataDisplayMalf) * data%State%MudSystem%TripTankVolumeCalc ! (gal) + ELSEIF (data%Equipments%DataDisplayConsole%TripTankSetAlarmSwitch==-1) THEN + + data%State%MudSystem%TripTank_MinVol_Allowded= data%Equipments%DataDisplayConsole%TripTankSetAlarmLow/2. ! 2: because knob input is 0-100 but gauge is 0-50 + data%Equipments%DataDisplayConsole%TripTankGauge= (1 - data%State%MudSystem%TripTankPressure_DataDisplayMalf) * data%State%MudSystem%TripTank_MinVol_Allowded + + ELSE !(TripTankSetAlarmSwitch==1) + data%State%MudSystem%TripTank_MaxVol_Allowded= data%Equipments%DataDisplayConsole%TripTankSetAlarmHigh/2. ! 2: because knob input is 0-100 but gauge is 0-50 + data%Equipments%DataDisplayConsole%TripTankGauge= (1 - data%State%MudSystem%TripTankPressure_DataDisplayMalf) * data%State%MudSystem%TripTank_MaxVol_Allowded + ENDIF + + + + IF ((data%State%MudSystem%TripTankVolumeCalc < data%State%MudSystem%TripTank_MinVol_Allowded) .OR. (data%State%MudSystem%TripTankVolumeCalc > data%State%MudSystem%TripTank_MaxVol_Allowded)) THEN + data%Equipments%DataDisplayConsole%TripTankAlarmLED = 2 !(blinking) + IF (data%Equipments%DataDisplayConsole%TripTankHornSwitch) THEN + data%Equipments%DataDisplayConsole%Buzzer1= .true. + ELSE + data%Equipments%DataDisplayConsole%Buzzer1= .false. + ENDIF + ELSE + data%Equipments%DataDisplayConsole%TripTankAlarmLED = 0 !(OFF) + data%Equipments%DataDisplayConsole%Buzzer1= .false. + ENDIF + + data%Equipments%DataDisplayConsole%TripTankPumpLED= data%Equipments%DataDisplayConsole%TripTankPumpSwitch + + + ELSEIF (data%Equipments%DataDisplayConsole%TripTankPowerSwitch==0) THEN + data%Equipments%DataDisplayConsole%TripTankGauge= 0. !(gal) + data%Equipments%DataDisplayConsole%TripTankAlarmLED= 0 + data%Equipments%DataDisplayConsole%TripTankPumpLED= 0 + data%Equipments%DataDisplayConsole%Buzzer1= .false. + ENDIF + + +! if ( IsPortable ) then + +! TripTank_MinVol_Allowded= data%Equipments%DataDisplayConsole%TripAlarmLow +! TripTank_MaxVol_Allowded= data%Equipments%DataDisplayConsole%TripAlarmHigh + + +! IF ((TripTankVolumeCalc < TripTank_MinVol_Allowded) .OR. (TripTankVolumeCalc > TripTank_MaxVol_Allowded)) THEN +! data%Equipments%DataDisplayConsole%TripTankAlarmLED = 1 !(blinking) +! IF (data%Equipments%DataDisplayConsole%TripTankHornSwitch) THEN +! data%Equipments%DataDisplayConsole%Buzzer1= .true. +! ELSE +! data%Equipments%DataDisplayConsole%Buzzer1= .false. +! ENDIF +! ELSE +! data%Equipments%DataDisplayConsole%TripTankAlarmLED = 0 !(OFF) +! data%Equipments%DataDisplayConsole%Buzzer1= .false. +! ENDIF + +! endif + + + + +!write(*,*) '=====================================================================' + + + +! if (IsStopped) return + + end subroutine main + + + + +!=================================================================================================================== +!=================================================================================================================== +!=================================================================================================================== + + subroutine ActiveMudVolumeChanged(v) +!use CLog4 + implicit none + real(8), intent (in) :: v +!call Log_4('ActiveMudVolumeChanged=', v) + data%State%MudSystem%ActiveTankVolume= data%Configuration%Mud%ActiveMudVolumeGal ! update from student input + end subroutine + + subroutine ActiveDensityChanged(v) +!use CLog4 + implicit none + real(8), intent (in) :: v +!call Log_4('ActiveDensityChanged=', v) + data%State%MudSystem%ActiveTankDensity= data%Configuration%Mud%ActiveDensity ! update from student input + end subroutine + + subroutine ReserveMudVolumeChanged(v) +!use CLog4 + implicit none + real(8), intent (in) :: v +!call Log_4('ReserveMudVolumeChanged=', v) + data%State%MudSystem%ReserveTankVolume= data%Configuration%Mud%ReserveMudVolumeGal ! update from student input + end subroutine + + subroutine ReserveDensityChanged(v) +!use CLog4 + implicit none + real(8), intent (in) :: v +!call Log_4('ReserveDensityChanged=', v) + data%State%MudSystem%ReserveTankDensity= data%Configuration%Mud%ReserveDensity ! update from student input + end subroutine + +! subroutine SetupMudSystem() +! use CPathChangeEvents +! use CMudPropertiesVariables +! implicit none + +! call BeforeTraverse%Add(InitialVarsBeforePathsChanges) +! call AfterTraverse%Add(AfterPathsChanges) +! call OnPathOpen%Add(WhenPathOpen) + + +! call OnActiveMudVolumeChange%Add(ActiveMudVolumeChanged) +! call OnActiveDensityChange%Add(ActiveDensityChanged) +! call OnReserveMudVolumeChange%Add(ReserveMudVolumeChanged) +! call OnReserveDensityChange%Add(ReserveDensityChanged) + +! end subroutine + + subroutine AfterPathsChanges() + implicit none + integer i + + if(Pump1_Lasts%Length() <= 0) return + do i = 1, Pump1_Lasts%Length() + if(Pump2_Lasts%Length() <= 0) cycle + if(any(Pump2_Lasts%Array == Pump1_Lasts%Array(i))) then + State2 = .true. ! Pumps 1 & 2 have same destination +!print*, 'State2 = .true.' + endif + if(Pump3_Lasts%Length() <= 0) cycle + if(any(Pump3_Lasts%Array == Pump1_Lasts%Array(i))) then + State3 = .true. ! Pumps 1 & 3 have same destination +!print*, 'State3 = .true.' + endif + enddo + + if(Pump2_Lasts%Length() <= 0) return + do i = 1, Pump2_Lasts%Length() + if(Pump3_Lasts%Length() <= 0) cycle + if(any(Pump3_Lasts%Array == Pump2_Lasts%Array(i))) then + State4 = .true. ! Pumps 2 & 3 have same destination +!print*, 'State4 = .true.' + endif + enddo + + State1 = State2 .and. State3 ! Pumps 1 & 2 & 3 have same destination +!if(State1) print*, 'State1 = .true.' + + end subroutine + + subroutine InitialVarsBeforePathsChanges() + implicit none + + condition1 = .false. + condition2 = .false. + condition3 = .false. + condition4 = .false. + condition5 = .false. + condition6 = .false. + condition7 = .false. + condition8 = .false. + condition9 = .false. + condition10 = .false. + condition11 = .false. + condition12 = .false. + condition13 = .false. + condition14 = .false. + condition15 = .false. + condition16 = .false. + condition17 = .false. + condition18 = .false. + condition19 = .false. + condition20 = .false. + condition21 = .false. + condition22 = .false. + condition23 = .false. + condition24 = .false. + condition25 = .false. + condition26 = .false. + condition27 = .false. + condition28 = .false. + condition29 = .false. + condition30 = .false. + condition31 = .false. + condition32 = .true. + condition33 = .true. + condition34 = .true. + condition35 = .false. + condition36 = .false. + condition37 = .false. + condition38 = .false. + condition39 = .false. + condition40 = .false. + condition41 = .false. + condition42 = .false. + condition43 = .false. + condition44 = .false. + condition45 = .false. + condition46 = .false. + condition47 = .false. + condition48 = .false. + condition49 = .false. + condition50 = .false. + condition51 = .false. + condition52 = .false. + condition53 = .false. + condition54 = .false. + condition55 = .false. + condition56 = .false. + condition57 = .false. + condition58 = .false. + condition59= .false. + condition60= .false. + condition61= .false. + + + + + + + +!ThereIsPathFrom82 = .false. +!!print*, "ThereIsPathFrom82=",ThereIsPathFrom82 +!ThereIsPathFrom83 = .false. +!!print*, "ThereIsPathFrom82=",ThereIsPathFrom82 +!ThereIsPathFrom84 = .false. +!!print*, "ThereIsPathFrom82=",ThereIsPathFrom82 + + ThereIsPathFrom_71_72_73_To_82 = .false. +!print*, "ThereIsPathFrom_71_72_73_To_82=",ThereIsPathFrom_71_72_73_To_82 + ThereIsPathFrom_71_72_73_To_83 = .false. +!print*, "ThereIsPathFrom_71_72_73_To_83=",ThereIsPathFrom_71_72_73_To_83 + ThereIsPathFrom_71_72_73_To_84 = .false. +!print*, "ThereIsPathFrom_71_72_73_To_84=",ThereIsPathFrom_71_72_73_To_84 + + DumpFromKelly_Pump1 = .false. + DumpFromFillupHead_Pump1 = .false. + DumpFromTopDrive_Pump1 = .false. + + + DumpFromKelly_Pump2 = .false. + DumpFromFillupHead_Pump2 = .false. + DumpFromTopDrive_Pump2 = .false. + + + DumpFromKelly_Pump3 = .false. + DumpFromFillupHead_Pump3 = .false. + DumpFromTopDrive_Pump3 = .false. + + + + State1 = .false. + State2 = .false. + State3 = .false. + State4 = .false. + + call Pump1_Lasts%Empty() + call Pump2_Lasts%Empty() + call Pump3_Lasts%Empty() + + + + + + ac32 = .false. + ac33 = .false. + ac34 = .false. + ac35 = .false. + ac29 = .false. + + end subroutine + + subroutine WhenPathOpen(valves) + use SimulationVariables + implicit none + integer, allocatable, intent (in) :: valves(:) + integer :: first, last + if (.not.allocated(valves)) return + if(size(valves) <= 0) return + + if ( any(valves == 32)) ac32 = .true. + if ( any(valves == 33)) ac33 = .true. + if ( any(valves == 34)) ac34 = .true. + if ( any(valves == 35)) ac35 = .true. + if ( any(valves == 29)) ac29 = .true. + + + first = 1 + last = size(valves) + + MP1_Q = data%State%Pump(1)%Flow_Rate + MP2_Q = data%State%Pump(2)%Flow_Rate + MP3_Q = data%State%Pump(3)%Flow_Rate + + + + if(valves(first) == 82) call Pump1_Lasts%Add(valves(last)) + if(valves(first) == 83) call Pump2_Lasts%Add(valves(last)) + if(valves(first) == 84) call Pump3_Lasts%Add(valves(last)) + +!print*, '==============================================' +!do i = 1, Pump1_Lasts%Length() +! print*, 'mp1=', Pump1_Lasts%Array(i) +!enddo +! +!print*, '-------------------------------' +! +!do i = 1, Pump2_Lasts%Length() +! print*, 'mp2=', Pump2_Lasts%Array(i) +!enddo +! +!print*, '-------------------------------' +! +! +!do i = 1, Pump3_Lasts%Length() +! print*, 'mp3=', Pump3_Lasts%Array(i) +!enddo +! +!print*, '==============================================' + + +!if(valves(first)==82 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71)) then +! ThereIsPathFrom82 = .true. +! !print*, "ThereIsPathFrom82=",ThereIsPathFrom82 +!endif +! +!if(valves(first)==83 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71)) then +! ThereIsPathFrom83 = .true. +! !print*, "ThereIsPathFrom83=",ThereIsPathFrom83 +!endif +! +!if(valves(first)==84 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71)) then +! ThereIsPathFrom84 = .true. +! !print*, "ThereIsPathFrom84=",ThereIsPathFrom84 +!endif + + if(valves(last)==82 .and. (valves(first)==71 .or. valves(first)==72 .or. valves(first)==73)) then + ThereIsPathFrom_71_72_73_To_82 = .true. +!print*, "ThereIsPathFrom_71_72_73_To_82=",ThereIsPathFrom_71_72_73_To_82 + endif + + if(valves(last)==83 .and. (valves(first)==71 .or. valves(first)==72 .or. valves(first)==73)) then + ThereIsPathFrom_71_72_73_To_83 = .true. +!print*, "ThereIsPathFrom_71_72_73_To_83=",ThereIsPathFrom_71_72_73_To_83 + endif + + if(valves(last)==84 .and. (valves(first)==71 .or. valves(first)==72 .or. valves(first)==73)) then + ThereIsPathFrom_71_72_73_To_84 = .true. +!print*, "ThereIsPathFrom_71_72_73_To_84=",ThereIsPathFrom_71_72_73_To_84 + endif + +!if (.not.allocated(OpenPaths)) exit +!===============TanksToMudPump1=================== + if(valves(last)==82) then + if(valves(first)==71) then +!j2=j2+1 +!A71=1 + condition1 = .true. + endif + + if(valves(first)==72) then +!j2=j2+1 +!A72=1 + condition2 = .true. + endif + + if(valves(first)==73) then +!j2=j2+1 +!A73=1 + condition3 = .true. + endif + + endif +!================================================ + + +!============BellNippleToPits-FullWell(MLnumber=3)============== + + if ( Manifold%Valve(41)%Status == .false. .and. Manifold%Valve(42)%Status == .false. ) then + call ChangeValve(60, .TRUE.) + else + call ChangeValve(60, .FALSE.) + endif + + if(valves(first)==80 .and. valves(last)==71 .and. any(valves == 42)) condition4 = .true. + if(valves(first)==80 .and. valves(last)==77 .and. any(valves == 41)) condition5 = .true. + if(valves(first)==80 .and. valves(last)==78) condition6 = .true. + +!================================================ + + +!============WellToChokeManifold(Through 26)============== + if(valves(first)==79 .and. any(valves == 26)) then + if(valves(last)==71) then +!j4=j4+1 +!C71=1. + condition7 = .true. + endif + + if(valves(last)==77) then +!j4=j4+1 +!C77=1. + condition8 = .true. + endif + + if(valves(last)==78) then +!j4=j4+1 +!C78=1. + condition45 = .true. + endif + + endif + +!================================================ + + +!============ActiveTankToTripTank============== + if(valves(first)==71 .and. valves(last)==77) then +!j5=j5+1 + condition9 = .true. + endif +!================================================ + + + +!============TripTankToActiveTank And BellNipple============== + if(valves(first)==77) then + if(valves(last)==71) then +!j6=j6+1 +!D71=1 + condition10 = .true. + endif + + if(valves(last)==80) then +!j6=j6+1 +!D80=1 + condition11 = .true. + endif + + endif +!================================================ + + +!============ActiveTankToDump============== + if(valves(first)==71 .and. valves(last)==78) then +!j7=j7+1 + condition12 = .true. + endif +!================================================ + + +!============TripTankToDump============== + if(valves(first)==77 .and. valves(last)==78) then +!j8=j8+1 + condition13 = .true. + endif +!================================================ + + +!============WellToBellNipple============== + if(valves(first)==79 .and. valves(last)==80) then +!j9=j9+1 + condition14 = .true. + endif +!================================================ + +!============MudBucketToBellNipple============== + if(valves(first)==81 .and. valves(last)==80) then +!j10=j10+1 + condition15 = .true. + endif +!================================================ + + +!============BellNippleToWell-NonFullWell============== + if(valves(first)==80 .and. valves(last)==79) then ! Well is NOT Full +!j11=j11+1 + condition16 = .true. + endif +!================================================ + +!===============TanksToMudPump2=================== + if(valves(last)==83) then + if(valves(first)==71) then +!j12=j12+1 +!E71=1 + condition17 = .true. + endif + + if(valves(first)==72) then +!j12=j12+1 +!E72=1 + condition18 = .true. + endif + + if(valves(first)==73) then +!j12=j12+1 +!E73=1 + condition19 = .true. + endif + + endif +!================================================ + + +!===============TanksToCementPump=================== + if(valves(last)==84) then + if(valves(first)==71) then +!j13=j13+1 +!F71=1 + condition20 = .true. + endif + + if(valves(first)==72) then +!j13=j13+1 +!F72=1 + condition21 = .true. + endif + + if(valves(first)==73) then +!j13=j13+1 +!F73=1 + condition22 = .true. + endif + + endif +!================================================ + +!===============PumpsToString=================== + if(valves(last)==79) then + if(valves(first)==82) then +!j14=j14+1 +!G82=1 + condition23 = .true. + endif + + if(valves(first)==83) then +!j14=j14+1 +!G83=1 + condition24 = .true. + endif + + if(valves(first)==84) then +!j14=j14+1 +!G84=1 + condition25 = .true. + endif + + endif +!================================================ + + + + + +!============MudPump1HasPath=================== + if(ThereIsPathFrom_71_72_73_To_82 .and. (valves(first)==82 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71))) then +!Mp1_NoPath= 0 + condition32 = .false. + endif + data%State%MudSystem%condition32Final = condition32 +!================================================ + + +!============MudPump2HasPath=================== + if(ThereIsPathFrom_71_72_73_To_83 .and. (valves(first)==83 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71))) then +!write(*,*) 'condition33 ******' +!Mp2_NoPath= 0 + condition33 = .false. + endif + data%State%MudSystem%condition33Final= condition33 +!================================================ + + +!============CementPumpHasNoPath=================== + if(ThereIsPathFrom_71_72_73_To_84 .and. (valves(first)==84 .and. (valves(last)==79 .or. valves(last)==78 .or. valves(last)==77 .or. valves(last)==71))) then +!Cp_NoPath= 1 + condition34 = .false. + endif + data%State%MudSystem%condition34Final = condition34 +!================================================ + + + + +!===============PumpsToDump=================== +!DumpFromKelly = 0.0 +!DumpFromFillupHead= 0.0 + + if(valves(last)==78) then + if(valves(first)==82) then +!DumpPump1=1 + condition26 = .true. + IF(any(valves == 56)) DumpFromKelly_Pump1 = .true. + IF(any(valves == 14)) DumpFromFillupHead_Pump1 = .true. + IF(any(valves == 70)) DumpFromTopDrive_Pump1 = .true. + + + endif + + + if(valves(first)==83) then +!DumpPump2=1 + print*, "THERE IS DUMP" + condition27 = .true. + IF(any(valves == 56)) DumpFromKelly_Pump2 = .true. + IF(any(valves == 14)) DumpFromFillupHead_Pump2 = .true. + IF(any(valves == 70)) DumpFromTopDrive_Pump2 = .true. + + endif + + + if(valves(first)==84) then +!DumpCementPump=1 + condition28 = .true. + IF(any(valves == 56)) DumpFromKelly_Pump3 = .true. + IF(any(valves == 14)) DumpFromFillupHead_Pump3 = .true. + IF(any(valves == 70)) DumpFromTopDrive_Pump3 = .true. + + endif + +! DumpFromKelly +!if (DumpFromKelly_Pump1 .or. DumpFromKelly_Pump2 .or. DumpFromKelly_Pump3) then +! DumpFromKelly = 1.0 +!else +! DumpFromKelly = 0.0 +!endif + + +! DumpFromFillupHead + if (DumpFromFillupHead_Pump1 .or. DumpFromFillupHead_Pump2 .or. DumpFromFillupHead_Pump3) then + DumpFromFillupHead = 1.0 + else + DumpFromFillupHead = 0.0 + endif + + endif + + + +!================================================ + + +!=======MudPumps1&2ToActiveTank_Through65&66========== + +! << if H82 or H83 or H4 are open, no flow goes to other parts of system >> + + + if(valves(last)==71) then + if(valves(first)==82 .and. any(valves == 65)) then +!j15=j15+1 +!H82=1.0 + condition29 = .true. + endif + + if(valves(first)==83 .and. any(valves == 66)) then +!j15=j15+1 +!H83=1.0 + condition30 = .true. + endif + + endif +!================================================ + +!=======CementPumpToCementTank_Through67========== + +! << if H82 or H83 or H4 are open, no flow goes to other parts of system >> + + + if(valves(last)==73 .and. valves(first)==84 .and. any(valves == 67)) then + +!H84=1.0 + condition31 = .true. + + endif +!================================================ + + + +!===============PathsToGauge75=================== + if(valves(last)==75) then + if(valves(first)==82) then !Pump1 to Gauge75 +!j16=j16+1 +!K82=1 + condition35 = .true. + endif + + if(valves(first)==83) then !Pump2 to Gauge75 +!j16=j16+1 +!K83=1 + condition36 = .true. + endif + + if(valves(first)==84) then !Pump3 to Gauge75 +!j16=j16+1 +!K84=1 + condition37 = .true. + endif + + if(valves(first)==79) then !String to Gauge75 +!j16=j16+1 +!K79=1 + condition38 = .true. + endif + + if(valves(first)==78) then !Dump to Gauge75 +!j16=j16+1 +!K78=1 + condition39 = .true. + endif + + endif +!================================================ + +!===============PathsToGauge76=================== + if(valves(last)==76) then + if(valves(first)==82) then !Pump1 to Gauge76 +!j17=j17+1 +!L82=1 + condition40 = .true. + endif + + if(valves(first)==83) then !Pump2 to Gauge76 +!j17=j17+1 +!L83=1 + condition41 = .true. + endif + + if(valves(first)==84) then !Pump3 to Gauge76 +!j17=j17+1 +!L84=1 + condition42 = .true. + endif + + if(valves(first)==79) then !String to Gauge76 +!j17=j17+1 +!L79=1 + condition43 = .true. + endif + + if(valves(first)==78) then !Dump to Gauge76 +!j17=j17+1 +!L78=1 + condition44 = .true. + endif + + endif +!================================================ + + +!====Pump1-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(valves(first)==82 .and. any(valves == 2)) then + if(valves(last)==71) then +!j18=j18+1 +!M71=1. +!Pump1toCh= 1. + condition46 = .true. + endif + + if(valves(last)==77) then +!j18=j18+1 +!M77=1. +!Pump1toCh= 1. + condition47 = .true. + endif + + if(valves(last)==78) then +!j18=j18+1 +!M78=1. +!Pump1toCh= 1. + condition48 = .true. + endif + + endif +!================================================================= + + +!====Pump2-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(valves(first)==83 .and. any(valves == 2)) then + if(valves(last)==71) then +!j18=j18+1 +!M71=1. +!Pump2toCh= 1. + condition49 = .true. + endif + + if(valves(last)==77) then +!j18=j18+1 +!M77=1. +!Pump2toCh= 1. + condition50 = .true. + endif + + if(valves(last)==78) then +!j18=j18+1 +!M78=1. +!Pump2toCh= 1. + condition51 = .true. + endif + + endif +!================================================================= + + +!====Pump3-StandPipeManifoldToChokeManifold-Through ChokeLine==== + if(valves(first)==84 .and. any(valves == 2)) then + if(valves(last)==71) then +!j18=j18+1 +!M71=1. +!Pump3toCh= 1. + condition52 = .true. + endif + + if(valves(last)==77) then +!j18=j18+1 +!M77=1. +!Pump3toCh= 1. + condition53 = .true. + endif + + if(valves(last)==78) then +!j18=j18+1 +!M78=1. +!Pump3toCh= 1. + condition54 = .true. + endif + + endif +!================================================================= + + + + +!===============PumpsToWell_KillLine============ + if(valves(last)==79) then + if(valves(first)==82) then +!j19=j19+1 +!N82=1 + condition55 = .true. + endif + + if(valves(first)==83) then +!j19=j19+1 +!N83=1 + condition56 = .true. + endif + + if(valves(first)==84) then +!j19=j19+1 +!N84=1 + condition57 = .true. + endif + + endif +!================================================ + +!===============WellToChokeLineGauge============ + if(valves(first)==79 .and. valves(last)==85) then +!j20=j20+1 + condition58 = .true. + endif +!================================================ + + +!============ChokeLineGaugeToTanks=============== + if(valves(first)==85) then + if(valves(last)==71) then +!j21=j21+1 + condition59 = .true. + endif + + if(valves(last)==77) then +!j21=j21+1 + condition60 = .true. + endif + + if(valves(last)==78) then +!j21=j21+1 + condition61 = .true. + endif + + endif +!================================================ + + end subroutine + +end module MudSystemModule diff --git a/Equipments/MudSystem/MudSystemStartup.f90 b/Equipments/MudSystem/MudSystemStartup.f90 index 21e48e4..71d61dd 100644 --- a/Equipments/MudSystem/MudSystemStartup.f90 +++ b/Equipments/MudSystem/MudSystemStartup.f90 @@ -48,7 +48,7 @@ data%State%MudSystem%FluidFlowCounter = 0 ! MUD CIRCULATION STARTUP !======================================================================== - data%State%MudSystem%FormationLostPressure= Shoe%LeakOff * Shoe%ShoeDepth + data%State%MudSystem%FormationLostPressure= data%Configuration%Shoe%LeakOff * data%Configuration%Shoe%ShoeDepth data%State%MudSystem%ShoeFractured= .false. data%State%MudSystem%UGBOSuccessionCounter = 0 ! also in starup @@ -183,7 +183,7 @@ data%State%MudSystem%TripTankFloorArea= (50.*42.) / (7.48051948*100./12.) ! data%State%MudSystem%TripTank_Vol= data%Configuration%Mud%InitialTripTankMudVolumeGal !(gal) data%State%MudSystem%TripTank_Dens= 1. -data%EquipmentControl%DataDisplayConsole%TripTankGauge=0. +data%Equipments%DataDisplayConsole%TripTankGauge=0. @@ -211,8 +211,8 @@ data%State%MudSystem%ReserveTankDensity= data%Configuration%Mud%ReserveDensity -data%State%MudSystem%CementTankVolumeCalc= data%EquipmentControl%Tank%CementTankVolume !movaghat--- initial volume (gal) -data%State%MudSystem%CementTankDensityCalc= data%EquipmentControl%Tank%CementTankDensity !movaghat--- initial +data%State%MudSystem%CementTankVolumeCalc= data%Equipments%Tank%CementTankVolume !movaghat--- initial volume (gal) +data%State%MudSystem%CementTankDensityCalc= data%Equipments%Tank%CementTankDensity !movaghat--- initial data%State%MudSystem%PumpsDumpVolume=0.0 data%State%MudSystem%PumpsDumpFlowRate= 0.0 @@ -234,14 +234,14 @@ data%State%MudSystem%MudTank4_vol= data%Configuration%Mud%InitialTripTankMudVolu data%State%MudSystem%TripTankVolumeCalc= data%Configuration%Mud%InitialTripTankMudVolumeGal ! initial volume (gal) data%State%MudSystem%ActiveTankDensity= data%Configuration%Mud%ActiveDensity ! initial(ppg) -data%State%MudSystem%TripTankDensityCalc= data%EquipmentControl%Tank%TripTankDensity ! initial(ppg) +data%State%MudSystem%TripTankDensityCalc= data%Equipments%Tank%TripTankDensity ! initial(ppg) data%State%MudSystem%ChokeManifoldDumpVolume= 0.0 data%State%MudSystem%PitGainLossZero= 0. data%State%MudSystem%PitGainLossZero_Old= data%State%MudSystem%PitGainLossZero -data%State%MudSystem%MVTCoarseKnob_Old= data%EquipmentControl%DataDisplayConsole%MVTCoarseKnob -data%State%MudSystem%MVTFineKnob_Old= data%EquipmentControl%DataDisplayConsole%MVTFineKnob +data%State%MudSystem%MVTCoarseKnob_Old= data%Equipments%DataDisplayConsole%MVTCoarseKnob +data%State%MudSystem%MVTFineKnob_Old= data%Equipments%DataDisplayConsole%MVTFineKnob data%State%MudSystem%FirstSet_Time= .true. diff --git a/Equipments/MudSystem/MudSystemStartup.i90 b/Equipments/MudSystem/MudSystemStartup.i90 new file mode 100644 index 0000000..5e70b8d --- /dev/null +++ b/Equipments/MudSystem/MudSystemStartup.i90 @@ -0,0 +1,514 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/MudSystemStartup.f90" + SUBROUTINE NormalCirculation_StartUp() ! is called in module FluidFlowMain + + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use CTanks + use SimulationVariables + USE CMudPropertiesVariables + Use GeoElements_FluidModule + use KickVARIABLESModule + Use CUnityOutputs + Use CShoeVariables + use SimulationVariables + + implicit none + +! temporary varibales for solving pressure jerks -- 1399-11-09 +!Pump1BlownInTimeStep = 0 +!Pump2BlownInTimeStep = 0 +!Pump3BlownInTimeStep = 0 + +!Pump1BlownStarted = .FALSE. +!Pump2BlownStarted = .FALSE. +!Pump3BlownStarted = .FALSE. + + data%State%MudSystem%Pump1BlownCount = 0 + data%State%MudSystem%Pump2BlownCount = 0 + data%State%MudSystem%Pump3BlownCount = 0 + + +data%State%MudSystem%DeltaWellCap=0. +data%State%MudSystem%WellCapOld = 0. +data%State%MudSystem%AnnCapOld=0. +data%State%MudSystem%DeltaAnnCap=0. + + +data%State%MPumps%Total_Stroke_Counter_For_Plot = 0.0 + + data%State%MudSystem%DeltaT_Mudline=0.1 !second + + Call Set_FlowKellyDisconnect(.false.) + Call Set_FlowPipeDisconnect(.false.) + +!HZ_ADD= 0.d0 +data%State%MudSystem%Flow_timeCounter= 0 +data%State%MudSystem%MudSys_timeCounter= 0 +data%State%MudSystem%FluidFlowCounter = 0 +!======================================================================== +! MUD CIRCULATION STARTUP +!======================================================================== + + data%State%MudSystem%FormationLostPressure= data%Configuration%Shoe%LeakOff * data%Configuration%Shoe%ShoeDepth + data%State%MudSystem%ShoeFractured= .false. + + data%State%MudSystem%UGBOSuccessionCounter = 0 ! also in starup + data%State%MudSystem%UGBOSuccessionCounterOld = 0 ! also in starup + + + + data%State%MudSystem%ChokeLineFlowRate= 0.0 + data%State%MudSystem%StringFlowRate= 0.0 + data%State%MudSystem%AnnulusFlowRate= 0.0 + + data%State%MudSystem%MudVolume_InjectedFromAnn= 0.D0 + data%State%MudSystem%MudVolume_InjectedToBH= 0.D0 + + data%State%MudSystem%DensityMixTol= 0.1 !(ppg) + data%State%MudSystem%CuttingDensityMixTol= 0.5 + data%State%MudSystem%NewPipeFilling= 1 + data%State%MudSystem%UtubeFilling= 1 + data%State%MudSystem%UtubeEmptyVolume= 0.0 + + data%State%MudSystem%UtubeMode1Activated= .false. + data%State%MudSystem%UtubeMode2Activated= .false. + data%State%MudSystem%UtubePossibility= .false. + + +!KickMigration_2SideBit = .FALSE. + + data%State%MudSystem%KickDx= (Reservoir%AutoMigrationRate/3600.)*data%State%MudSystem%DeltaT_Mudline !AutoMigrationRate (ft/h)= ft per DeltaT_Mudline + + + data%State%MudSystem%NewInfluxElementCreated= 0 + data%State%MudSystem%NewInfluxNumber= 0 + +!KickVolumeinAnnulus= 0.0 + data%State%MudSystem%KickDeltaVinAnnulus= 0.0 + KickVARIABLES%GasKickPumpFlowRate= 0.0 + + data%State%MudSystem%FirstMudSet= 0 + data%State%MudSystem%FirstSetUtube1=0 + data%State%MudSystem%FirstSetUtube2=0 + data%State%MudSystem%SuctionMud=1 + data%State%MudSystem%ImudCount= 1 + imud=1 + data%State%MudSystem%iLoc= 1 ! for Kick + + data%State%MudSystem%Suction_Density_MudSystem= data%Configuration%Mud%ActiveDensity + data%State%MudSystem%SuctionDensity_Old= data%Configuration%Mud%ActiveDensity ! initial(ppg) + data%State%MudSystem%StringDensity_Old= data%Configuration%Mud%ActiveDensity ! initial(ppg) + data%State%MudSystem%AnnulusSuctionDensity_Old= data%Configuration%Mud%ActiveDensity ! initial(ppg) + data%State%MudSystem%ChokeLineDensity_Old= data%Configuration%Mud%ActiveDensity ! initial(ppg) + + data%State%MudSystem%TotalAddedVolume= 0. + + + data%State%MudSystem%xx=0. + + + + END SUBROUTINE NormalCirculation_StartUp + + + + + + + + SUBROUTINE MudSystem_StartUp() + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use CDataDisplayConsole + use SimulationVariables + USE CHOKEVARIABLES +use SimulationVariables !@ + use SimulationVariables + USE CBopStackVariables + use CPumpsVariables + use CPumps + use CTanks + use SimulationVariables + use KickVARIABLESModule + implicit none + + + + + + CALL MUDLINE_LOSS_INPUTS() + +!data%State%MPumps%Total_Pump_GPM=10. ! Initial Value + + data%State%MUD%Q=0. ! Commented by mahmood + + data%State%MudSystem%Q_flow32=0. + data%State%MudSystem%Q_flow33=0. + data%State%MudSystem%Q_flow34=0. + data%State%MudSystem%Q_flow35=0. + + data%State%MudSystem%DeltaT_Mudline=0.1 !second + + KickVARIABLES%GasKickPumpFlowRate= 0. + data%State%MudSystem%BellNippleVolume= 0. + data%State%MudSystem%BellNippleDensity= 0. + data%State%MudSystem%MudBucketVolume= 0. + data%State%MudSystem%MudBucketDensity= 0. + data%State%MudSystem%BellNippleDumpVolume= 0. +!BellNippleDumpRate= 0. +!BellNippleToPitsRate= 0.0 + data%State%MudSystem%MudChecked= .true. + + data%State%MudSystem%condition32Final= .TRUE. + data%State%MudSystem%condition33Final= .TRUE. + data%State%MudSystem%condition34Final= .TRUE. + + +data%State%MudSystem%PressureGauge75= 0.0 +data%State%MudSystem%PressureGauge76 = 0.0 + + +!!====================================================================== +!! TRIP TANK +!!====================================================================== + + data%State%MudSystem%TripTank_MinVol_Allowded= 50.*42. !(bbl to gal, initial value) + data%State%MudSystem%TripTank_MaxVol_Allowded= 50. *42. !(bbl to gal, initial value) + + +data%State%MudSystem%ActiveTankFloorArea= (data%Configuration%Mud%ActiveTotalTankCapacityGal) / (7.48051948*100./12.) ! (ft^2) - Tank Height= 100 inch , 12=inch to ft 7.48051948=gal to ft^3 +data%State%MudSystem%TripTankFloorArea= (50.*42.) / (7.48051948*100./12.) ! (ft^2) - 50.*42.=Trip Tank Capacity in BBl*42= Gal , Tank Height= 100 inch , 12=inch to ft 7.48051948=gal to ft^3 + + + +data%State%MudSystem%TripTank_Vol= data%Configuration%Mud%InitialTripTankMudVolumeGal !(gal) +data%State%MudSystem%TripTank_Dens= 1. +data%Equipments%DataDisplayConsole%TripTankGauge=0. + + + +data%State%MudSystem%ReturnToTrip_Q= 1. +data%State%MudSystem%ActiveToTrip_Q= 1. + + +data%State%MudSystem%TripTankPump_Q= .8 + + +data%State%MudSystem%ReturnToTrip_Dens=1.0 ! ppg(lbm/gal) +data%State%MudSystem%ActiveToTrip_Dens=1.0 + +!!====================================================================== +!! MUD VOLUME TOTALIZER +!!====================================================================== + +data%State%MudSystem%Mp1Density= 0.0 !(VALVE82) +data%State%MudSystem%Mp2Density= 0.0 !(VALVE83) +data%State%MudSystem%Mp3Density= 0.0 !(VALVE84) + + +data%State%MudSystem%ReserveTankVolume= data%Configuration%Mud%ReserveMudVolumeGal ! initial volume (gal) +data%State%MudSystem%ReserveTankDensity= data%Configuration%Mud%ReserveDensity ! initial + + + +data%State%MudSystem%CementTankVolumeCalc= data%Equipments%Tank%CementTankVolume !movaghat--- initial volume (gal) +data%State%MudSystem%CementTankDensityCalc= data%Equipments%Tank%CementTankDensity !movaghat--- initial + +data%State%MudSystem%PumpsDumpVolume=0.0 +data%State%MudSystem%PumpsDumpFlowRate= 0.0 + + + +data%State%MudSystem%ActiveTankVolume= data%Configuration%Mud%ActiveMudVolumeGal ! initial volume (gal) +data%State%MudSystem%RefrencePitVolume= data%State%MudSystem%ActiveTankVolume/42. !(bbl) +data%State%MudSystem%RefrencePitVolume_DrillWatch= data%State%MudSystem%ActiveTankVolume/42. !(bbl) + +data%State%MudSystem%MVT_MinVol_Allowded= 0. +data%State%MudSystem%MVT_MaxVol_Allowded= 0. + +data%State%MudSystem%MudTank1_vol= data%Configuration%Mud%ActiveMudVolumeGal/3. ! (gal) +data%State%MudSystem%MudTank2_vol= data%Configuration%Mud%ActiveMudVolumeGal/3. ! (gal) +data%State%MudSystem%MudTank3_vol= data%Configuration%Mud%ActiveMudVolumeGal/3. ! (gal) +data%State%MudSystem%ActiveTankSettled= data%Configuration%Mud%ActiveSettledContentsGal ! (gal) +data%State%MudSystem%MudTank4_vol= data%Configuration%Mud%InitialTripTankMudVolumeGal ! (gal) + +data%State%MudSystem%TripTankVolumeCalc= data%Configuration%Mud%InitialTripTankMudVolumeGal ! initial volume (gal) +data%State%MudSystem%ActiveTankDensity= data%Configuration%Mud%ActiveDensity ! initial(ppg) +data%State%MudSystem%TripTankDensityCalc= data%Equipments%Tank%TripTankDensity ! initial(ppg) + +data%State%MudSystem%ChokeManifoldDumpVolume= 0.0 + +data%State%MudSystem%PitGainLossZero= 0. +data%State%MudSystem%PitGainLossZero_Old= data%State%MudSystem%PitGainLossZero +data%State%MudSystem%MVTCoarseKnob_Old= data%Equipments%DataDisplayConsole%MVTCoarseKnob +data%State%MudSystem%MVTFineKnob_Old= data%Equipments%DataDisplayConsole%MVTFineKnob +data%State%MudSystem%FirstSet_Time= .true. + + + +data%State%MudSystem%PedalMeter= data%Configuration%Mud%PedalFlowMeter !1600. !(gpm) +data%State%MudSystem%ReturnFlowRate=0. + + + + data%State%MudSystem%TotalStrokes1MFFI =0. + data%State%MudSystem%TotalStrokes2MFFI =0. + + data%State%MudSystem%TotalStrokesPump1=0. + data%State%MudSystem%TotalStrokesPump2=0. + data%State%MudSystem%GraphTotalStrokes=0. + + + data%State%Choke%TotalStrokes1 =0. + data%State%Choke%TotalStrokes2 =0. + + + + + + + end + + + + + + + + + + + +SUBROUTINE MUDLINE_LOSS_INPUTS() +USE MudSystemVARIABLES +use SimulationVariables !@@@ +USE CBopStackVariables +use CPumpsVariables + use CPumps +implicit none +INTEGER I + + + +!=========================================================================== +! MUDLINE MINOR LOSSES INPUT +!=========================================================================== + +data%State%MudSystem%NO_MudMinors=4 + +ALLOCATE (data%State%MudSystem%MudMinors(data%State%MudSystem%NO_MudMinors,4)) + +! ID(INCH) LF CV NOTE(BAR) DESCRIPTION +data%State%MudSystem%MudMinors(1,1)= data%Configuration%Pumps%MudPump1Output +data%State%MudSystem%MudMinors(1,2:4)= (/1.5*8., 0., 0./) !elbow (MLnumber=1,,PumpsToString) +data%State%MudSystem%MudMinors(2,1)= data%Configuration%Pumps%MudPump1Output +data%State%MudSystem%MudMinors(2,2:4)= (/1.5*6., 0., 0./) !elbow (MLnumber=2,,STGaugeToString) +data%State%MudSystem%MudMinors(3,1:4)= (/0., 0., 0., 0./) !elbow (MLnumber=3,,WellToPits) +data%State%MudSystem%MudMinors(4,1)= data%Configuration%BopStack%ChokeLineId +data%State%MudSystem%MudMinors(4,2:4)= (/1.5*7., 0., 0./) !elbow (MLnumber=4,,WellToChokeManifold) + + + +ALLOCATE (data%State%MudSystem%MINORDIAMETER_MUDLINE(data%State%MudSystem%NO_MudMinors),data%State%MudSystem%AREAMINOR_MUDLINE(data%State%MudSystem%NO_MudMinors),data%State%MudSystem%LF_MUDLINE(data%State%MudSystem%NO_MudMinors),data%State%MudSystem%CV_MUDLINE(data%State%MudSystem%NO_MudMinors) & + ,data%State%MudSystem%NOTE_MUDLINE(data%State%MudSystem%NO_MudMinors)) + + + +DO I=1,data%State%MudSystem%NO_MudMinors + data%State%MudSystem%MINORDIAMETER_MUDLINE(I)=data%State%MudSystem%MudMinors(I,1) + data%State%MudSystem%LF_MUDLINE(I)=data%State%MudSystem%MudMinors(I,2) + data%State%MudSystem%CV_MUDLINE(I)=data%State%MudSystem%MudMinors(I,3) + data%State%MudSystem%NOTE_MUDLINE(I)=data%State%MudSystem%MudMinors(I,4) + + + data%State%MudSystem%AREAMINOR_MUDLINE(I)=PII*(data%State%MudSystem%MINORDIAMETER_MUDLINE(I)*0.0254)**2/4. !D(in), AREA(m^2) +ENDDO + +!=========================================================================== +! MUDLINE PIPNING LOSSES INPUT +!=========================================================================== +data%State%MudSystem%NO_PIPINGSMUDLINE=4 + +ALLOCATE (data%State%MudSystem%PIPINGS_MUDLINE(data%State%MudSystem%NO_PIPINGSMUDLINE,3)) + +! ID(INCH) L(FEET) ROUGHNESS(MM)=e DESCRIPTION +data%State%MudSystem%PIPINGS_MUDLINE(1,1)= data%Configuration%Pumps%MudPump1Output +data%State%MudSystem%PIPINGS_MUDLINE(1,2:3)= (/265., 0.03/) !(MLnumber=1,,PumpsToString) +data%State%MudSystem%PIPINGS_MUDLINE(2,1)= data%Configuration%Pumps%MudPump1Output +data%State%MudSystem%PIPINGS_MUDLINE(2,2:3)= (/100., 0.03/) !(MLnumber=2,,STGaugeToString) +data%State%MudSystem%PIPINGS_MUDLINE(3,1:3)= (/0., 0., 0./) !(MLnumber=3,,WellToPits) +data%State%MudSystem%PIPINGS_MUDLINE(4,1)= data%Configuration%BopStack%ChokeLineId +data%State%MudSystem%PIPINGS_MUDLINE(4,2)= data%Configuration%BopStack%ChokeLineLength +data%State%MudSystem%PIPINGS_MUDLINE(4,3)= 0.03 !(MLnumber=4,,WellToChokeManifold) + +data%State%MudSystem%Area_ChokeLineFt= PII*((data%Configuration%BopStack%ChokeLineId/12.)**2)/4. !D(in), AREA(ft^2) +data%State%MudSystem%ChokeLine_VolumeCapacity= data%State%MudSystem%Area_ChokeLineFt* data%Configuration%BopStack%ChokeLineLength* 7.48051948 ! (gal) + + ALLOCATE (data%State%MudSystem%DIAM_MUDLINE_INCH(data%State%MudSystem%NO_PIPINGSMUDLINE), & + data%State%MudSystem%AREA_MUDLINE(data%State%MudSystem%NO_PIPINGSMUDLINE),data%State%MudSystem%LENGT_MUDLINE(data%State%MudSystem%NO_PIPINGSMUDLINE),data%State%MudSystem%ROUGHNESS_MUDLINE(data%State%MudSystem%NO_PIPINGSMUDLINE),data%State%MudSystem%RELROUGH_MUDLINE(data%State%MudSystem%NO_PIPINGSMUDLINE)) + + +DO I=1,data%State%MudSystem%NO_PIPINGSMUDLINE + data%State%MudSystem%DIAM_MUDLINE_INCH(I)=data%State%MudSystem%PIPINGS_MUDLINE(I,1) + data%State%MudSystem%LENGT_MUDLINE(I)=data%State%MudSystem%PIPINGS_MUDLINE(I,2) + data%State%MudSystem%ROUGHNESS_MUDLINE(I)=data%State%MudSystem%PIPINGS_MUDLINE(I,3) + + + + data%State%MudSystem%AREA_MUDLINE(I)=PII*(data%State%MudSystem%DIAM_MUDLINE_INCH(I)*0.0254)**2/4 !D(in), AREA(m^2) + data%State%MudSystem%RELROUGH_MUDLINE(I)=data%State%MudSystem%ROUGHNESS_MUDLINE(I)/(data%State%MudSystem%DIAM_MUDLINE_INCH(I)*25.4) !e/D +!DIAM_MUDLINE_MM(I)=DIAM_MUDLINE_MM(I)*.001 ! (m) + data%State%MudSystem%LENGT_MUDLINE(I)=data%State%MudSystem%LENGT_MUDLINE(I)*.3048 ! (m) +ENDDO + + +!=========================================================================== +! MUDLINE STATIC LOSSES INPUT +!=========================================================================== + +! Height are in (meter) +data%State%MudSystem%Pumps_Height= 0. +data%State%MudSystem%STpipeGauge_Height= 2. !(m) +data%State%MudSystem%Pits_Height= 1. !(m) +data%State%MudSystem%ChokeManifold_Height= 1.*0.3048 !(ft to meter) +data%State%MudSystem%WellChokeExit_Height= data%Configuration%BopStack%GroundLevel-data%Configuration%BopStack%KillHeight + + + + + + + + + + + + + + END + + + + + SUBROUTINE MUDLINE_LOSSES(MLnumber) + + USE MudSystemVARIABLES +use SimulationVariables !@@@ + implicit none + integer I + INTEGER MLnumber + + +!===============================PIPE LOSS=================================== + data%State%MUD(MLnumber)%Re_MUDline=data%State%MUD(MLnumber)%Q*6.30902e-5*data%State%MudSystem%DIAM_MUDLINE_INCH(MLnumber)*0.0254/(data%State%MudSystem%AREA_MUDLINE(MLnumber)*data%State%MUD(MLnumber)%nu) !<<<<<< nu: DOROST SHAVAD.ALAN DAR STARTUP SET SHODE +!write(*,*) 'data%State%MUD(MLnumber)%Re_MUDline=' , data%State%MUD(MLnumber)%Re_MUDline +! Q*6.30902e-5 for (gpm) to (m^3/sec) + if ( data%State%MUD(MLnumber)%Re_MUDline data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables use KickVARIABLESModule @@ -37,7 +37,7 @@ use SimulationVariables !@@@ - if (data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then write(*,*) 'well cap=' , sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) data%State%MudSystem%DeltaWellCap= sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) - data%State%MudSystem%WellCapOld data%State%MudSystem%WellCapOld= sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) diff --git a/Equipments/MudSystem/Plot_Final_Mud_Elements.i90 b/Equipments/MudSystem/Plot_Final_Mud_Elements.i90 new file mode 100644 index 0000000..1866b0c --- /dev/null +++ b/Equipments/MudSystem/Plot_Final_Mud_Elements.i90 @@ -0,0 +1,418 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/Plot_Final_Mud_Elements.f90" +subroutine PlotFinalMudElements ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + Use TD_StringConnectionData + USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!use CDataDisplayConsole +!@ use ConfigurationVariables , StandPipePressureDataDisplay=>StandPipePressure +!use CManifolds + use SimulationVariables !@ + USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!use CChokeManifoldVariables + use SimulationVariables +!use CTanks +!@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + use OperationScenariosModule + use UTUBEVARSModule + use DownHoleModule + use CLog1 + Use CError + Use , intrinsic :: IEEE_Arithmetic + + implicit none + + integer jelement, jmud, jsection,ielement,i + integer jopelement,jopmud,jopsection + character(len=120) :: temp1, temp2 + + + + + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + write(*,*) 'well cap=' , sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) + data%State%MudSystem%DeltaWellCap= sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) - data%State%MudSystem%WellCapOld + data%State%MudSystem%WellCapOld= sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) + write(*,*) 'cap_reset,DeltaWellCap=' , data%State%MudSystem%DeltaWellCap + endif + + + + +!========================ANNULUS END================= +if ((data%State%MudSystem%Ann_Mud_Forehead_X%Last() - data%Configuration%BopStack%AboveAnnularHeight) > 0.8 .or. data%State%MudSystem%Ann_Density%Last()==0.0) then ! for Line (BellNippleToWell-NonFullWell) + data%State%MudSystem%WellisNOTFull= .true. +else + data%State%MudSystem%WellisNOTFull= .false. +endif + +!WRITE(*,*) 'Ann_Mud_Forehead_X%Last() , KillHeight', Ann_Mud_Forehead_X%Last() , KillHeight +if ((data%State%MudSystem%Ann_Mud_Forehead_X%Last() - data%Configuration%BopStack%KillHeight)>0.8 .or. data%State%MudSystem%Ann_Density%Last()==0.0) then ! for Line j4 , WellToChokeManifold(Through 26) + data%State%MudSystem%ChokeLineNOTFull= .true. +else + data%State%MudSystem%ChokeLineNOTFull= .false. +endif + +!========================================================= + + jmud= 1 + jsection= 1 + jelement= 0 ! number of final mud elements + + + + call data%State%MudSystem%Xend_MudElement%Empty() + call data%State%MudSystem%TVDend_MudElement%Empty() + call data%State%MudSystem%Density_MudElement%Empty() + call data%State%MudSystem%MudGeoType%Empty() + call data%State%MudSystem%PipeID_MudElement%Empty() + call data%State%MudSystem%PipeOD_MudElement%Empty() +!call Angle_MudElement%Empty() + call data%State%MudSystem%MudType_MudElement%Empty() + + + + DO WHILE(jmud <= data%State%MudSystem%Hz_Mud_Forehead_X%Length() .and. jsection<=1) + + jelement= jelement+1 + data%State%MudSystem%TrueMinValue= min(data%State%MudSystem%Hz_Mud_Forehead_X%Array(jmud), data%State%MudSystem%Xend_PipeSection(jsection)) + + call data%State%MudSystem%Xend_MudElement%Add(data%State%MudSystem%TrueMinValue) + call TVD_Calculator(data%State%MudSystem%TrueMinValue,data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%TVDend_MudElement%Add(data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%Density_MudElement%Add(data%State%MudSystem%Hz_Density%Array(jmud)) + call data%State%MudSystem%PipeID_MudElement%Add(data%State%MudSystem%ID_PipeSectionInch(jsection)) + call data%State%MudSystem%PipeOD_MudElement%Add(data%State%MudSystem%OD_PipeSectionInch(jsection)) +!call Angle_MudElement%Add(Angle_PipeSection(jsection)) + call data%State%MudSystem%MudType_MudElement%Add(data%State%MudSystem%Hz_MudOrKick%Array(jmud)) + + + if (data%State%MudSystem%Xend_MudElement%Array(jelement)== data%State%MudSystem%Hz_Mud_Forehead_X%Array(jmud)) then + jmud= jmud+1 + else + jsection= jsection+1 + endif + + ENDDO + + data%State%MudSystem%NoHorizontalMudElements= jelement + + + + + jmud= 1 + jsection= 2 + + DO WHILE(jmud <= data%State%MudSystem%St_Mud_Forehead_X%Length() .and. jsection<=data%State%F_Counts%StringIntervalCounts) + + jelement= jelement+1 + data%State%MudSystem%TrueMinValue= min(data%State%MudSystem%St_Mud_Forehead_X%Array(jmud), data%State%MudSystem%Xend_PipeSection(jsection)) + + call data%State%MudSystem%Xend_MudElement%Add(data%State%MudSystem%TrueMinValue) + call TVD_Calculator(data%State%MudSystem%TrueMinValue,data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%TVDend_MudElement%Add(data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%Density_MudElement%Add(data%State%MudSystem%St_Density%Array(jmud)) + call data%State%MudSystem%PipeID_MudElement%Add(data%State%MudSystem%ID_PipeSectionInch(jsection)) + call data%State%MudSystem%PipeOD_MudElement%Add(data%State%MudSystem%OD_PipeSectionInch(jsection)) +!call Angle_MudElement%Add(Angle_PipeSection(jsection)) + call data%State%MudSystem%MudType_MudElement%Add(data%State%MudSystem%St_MudOrKick%Array(jmud)) + + + if (data%State%MudSystem%Xend_MudElement%Array(jelement)== data%State%MudSystem%St_Mud_Forehead_X%Array(jmud)) then + jmud= jmud+1 + else + jsection= jsection+1 + endif + + ENDDO + + data%State%MudSystem%NoStringMudElements= jelement- data%State%MudSystem%NoHorizontalMudElements + + + + + + jmud= 1 + jsection= data%State%F_Counts%StringIntervalCounts+1 + DO WHILE(jmud<= data%State%MudSystem%Ann_Mud_Forehead_X%Length() .and. jsection<=data%State%MudSystem%NoPipeSections) + + jelement= jelement+1 + data%State%MudSystem%TrueMinValue= max(data%State%MudSystem%Ann_Mud_Forehead_X%Array(jmud), data%State%MudSystem%Xend_PipeSection(jsection)) + + call data%State%MudSystem%Xend_MudElement%Add(data%State%MudSystem%TrueMinValue) + call TVD_Calculator(data%State%MudSystem%TrueMinValue,data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%TVDend_MudElement%Add(data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%Density_MudElement%Add(data%State%MudSystem%Ann_Density%Array(jmud)) + call data%State%MudSystem%PipeID_MudElement%Add(data%State%MudSystem%ID_PipeSectionInch(jsection)) + call data%State%MudSystem%PipeOD_MudElement%Add(data%State%MudSystem%OD_PipeSectionInch(jsection)) +!call Angle_MudElement%Add(Angle_PipeSection(jsection)) + call data%State%MudSystem%MudType_MudElement%Add(data%State%MudSystem%Ann_MudOrKick%Array(jmud)) + + + if (data%State%MudSystem%Xend_MudElement%Array(jelement)== data%State%MudSystem%Ann_Mud_Forehead_X%Array(jmud)) then + jmud= jmud+1 + else + jsection= jsection+1 + endif + + ENDDO + + do i= 2, data%State%MudSystem%Xend_MudElement%Length() + if ( i== data%State%MudSystem%NoHorizontalMudElements+data%State%MudSystem%NoStringMudElements+1) then + call data%State%MudSystem%Xstart_MudElement%Add (data%State%MudSystem%Ann_Mud_Backhead_X%Array(1)) ! start of annulus + call TVD_Calculator(data%State%MudSystem%Ann_Mud_Backhead_X%Array(1),data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%TVDstart_MudElement%Add(data%State%MudSystem%MudCircVerticalDepth) + elseif ( i== data%State%MudSystem%NoHorizontalMudElements+1 ) then + call data%State%MudSystem%Xstart_MudElement%Add (data%State%MudSystem%St_Mud_Backhead_X%Array(1)) ! start of stirng + call TVD_Calculator(data%State%MudSystem%St_Mud_Backhead_X%Array(1),data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%TVDstart_MudElement%Add(data%State%MudSystem%MudCircVerticalDepth) + else + call data%State%MudSystem%Xstart_MudElement%Add(data%State%MudSystem%Xend_MudElement%Array(i-1)) ! normal calculation + call data%State%MudSystem%TVDstart_MudElement%Add(data%State%MudSystem%TVDend_MudElement%Array(i-1)) ! normal calculation + endif + + enddo + + data%State%MudSystem%NoCasingMudElements = jelement- data%State%MudSystem%NoStringMudElements- data%State%MudSystem%NoHorizontalMudElements + + +!=========================For Torque and Drag======================== + if (allocated(data%State%MudSystem%TDXstart_MudElementArray)) deallocate(data%State%MudSystem%TDXstart_MudElementArray) + allocate(data%State%MudSystem%TDXstart_MudElementArray(data%State%MudSystem%NoHorizontalMudElements+data%State%MudSystem%NoStringMudElements+data%State%MudSystem%NoCasingMudElements)) + if (allocated(data%State%MudSystem%TDXend_MudElementArray)) deallocate(data%State%MudSystem%TDXend_MudElementArray) + allocate(data%State%MudSystem%TDXend_MudElementArray(data%State%MudSystem%NoHorizontalMudElements+data%State%MudSystem%NoStringMudElements+data%State%MudSystem%NoCasingMudElements)) + if (allocated(data%State%MudSystem%TDDensity_MudElementArray)) deallocate(data%State%MudSystem%TDDensity_MudElementArray) + allocate(data%State%MudSystem%TDDensity_MudElementArray(data%State%MudSystem%NoHorizontalMudElements+data%State%MudSystem%NoStringMudElements+data%State%MudSystem%NoCasingMudElements)) + + data%State%MudSystem%TDNoHorizontalMudElements= data%State%MudSystem%NoHorizontalMudElements + data%State%MudSystem%TDNoStringMudElements= data%State%MudSystem%NoStringMudElements + data%State%MudSystem%TDNoCasingMudElements= data%State%MudSystem%NoCasingMudElements + + + data%State%MudSystem%TDXstart_MudElementArray(:) = data%State%MudSystem%Xstart_MudElement%Array(:) + data%State%MudSystem%TDXend_MudElementArray(:) = data%State%MudSystem%Xend_MudElement%Array(:) + data%State%MudSystem%TDDensity_MudElementArray(:) = data%State%MudSystem%Density_MudElement%Array(:) +!===================================================================== + + +!do i=NoHorizontalMudElements+1, NoHorizontalMudElements+NoStringMudElements ! 2-string elements +! write(*,333) 'STRING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'Density=' , Density_MudElement%Array(i), 'MudType=' , MudType_MudElement%Array(i) +!enddo + + + +!================================================================ + +! Open Hole Mud Elements + jopmud= 1 + jopsection= 1 + jopelement= 0 ! number of final mud elements + + + call data%State%MudSystem%Xend_OpMudElement%Empty() + call data%State%MudSystem%TVDend_OpMudElement%Empty() + call data%State%MudSystem%Density_OpMudElement%Empty() + call data%State%MudSystem%PipeID_OpMudElement%Empty() + call data%State%MudSystem%PipeOD_OpMudElement%Empty() +!call Angle_OpMudElement%Empty() + call data%State%MudSystem%MudTypeOp_MudElement%Empty() + + + + DO WHILE(jopmud<= data%State%MudSystem%Op_Mud_Forehead_X%Length() .and. jopsection<=data%State%F_Counts%BottomHoleIntervalCounts) + + jopelement= jopelement+1 + data%State%MudSystem%TrueMinValue= max(data%State%MudSystem%Op_Mud_Forehead_X%Array(jopmud), data%State%MudSystem%Xend_OpSection(jopsection)) + call data%State%MudSystem%Xend_OpMudElement%Add(data%State%MudSystem%TrueMinValue) + call TVD_Calculator(data%State%MudSystem%TrueMinValue,data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%TVDend_OpMudElement%Add(data%State%MudSystem%MudCircVerticalDepth) + call data%State%MudSystem%Density_OpMudElement%Add(data%State%MudSystem%Op_Density%Array(jopmud)) + call data%State%MudSystem%PipeID_OpMudElement%Add(data%State%MudSystem%ID_OpSectionInch(jopsection)) + call data%State%MudSystem%PipeOD_OpMudElement%Add(data%State%MudSystem%OD_OpSectionInch(jopsection)) +!call Angle_MudElement%Add(Angle_PipeSection(jopsection)) + call data%State%MudSystem%MudTypeOp_MudElement%Add(data%State%MudSystem%Op_MudOrKick%Array(jopmud)) + + + if (data%State%MudSystem%Xend_OpMudElement%Array(jopelement)== data%State%MudSystem%Op_Mud_Forehead_X%Array(jopmud)) then + jopmud= jopmud+1 + else + jopsection= jopsection+1 + endif + + ENDDO + + do i= 2, data%State%MudSystem%Xend_OpMudElement%Length() + call data%State%MudSystem%Xstart_OpMudElement%Add(data%State%MudSystem%Xend_OpMudElement%Array(i-1)) + call data%State%MudSystem%TVDstart_OpMudElement%Add(data%State%MudSystem%TVDend_OpMudElement%Array(i-1)) + enddo + + data%State%MudSystem%NoBottomHoleMudElements = jopelement + + +!================================================================ + + + + if(allocated(data%State%MudSystem%StringMudElement)) deallocate(data%State%MudSystem%StringMudElement) + allocate(data%State%MudSystem%StringMudElement(data%State%MudSystem%NoStringMudElements)) + + if(allocated(data%State%MudSystem%CasingMudElement)) deallocate(data%State%MudSystem%CasingMudElement) + allocate(data%State%MudSystem%CasingMudElement(data%State%MudSystem%NoCasingMudElements+data%State%MudSystem%NoBottomHoleMudElements)) + + data%State%MudSystem%istring=0 + data%State%MudSystem%icasing=0 + + data%State%MudSystem%BitMudDensity= data%State%MudSystem%Density_MudElement%Array(data%State%MudSystem%NoHorizontalMudElements+data%State%MudSystem%NoStringMudElements) ! (for ROP module) +!================================================================ + +!============================ UTUBE ============================= + +!IF (UtubePossibility== .true. .and. Get_KellyConnection() /= KELLY_CONNECTION_STRING .and. WellHeadIsOpen) THEN + IF (data%State%MudSystem%UtubePossibility== .true. .and. data%State%TD_StConn%FluidStringConnectionMode==0 .and. data%State%MudSystem%WellHeadIsOpen .AND. KickVARIABLES%NoGasPocket == 0) THEN + CALL WellPressureDataTransfer +!WRITE (*,*) ' U-Tube Done 1' + CALL Utube +!WRITE (*,*) ' U-Tube Done 2' + if (UTUBEVARS%QUtubeInput> 0.0) call Utube1_and_TripIn + if (UTUBEVARS%QUtubeOutput> 0.0) call Utube2_and_TripIn + END IF + +!========================== UTUBE- end ========================= + +! do imud=1, st_MudDischarged_Volume%Length() +! write(*,*) 'st-plot:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud) +!enddo +!==================== Display ======================== +!do i=1, St_MudOrKick%Length() +! write(*,555) i,'St_Volume(i), type=' ,St_MudDischarged_Volume%Array(i),St_MudOrKick%Array(i) +! +! IF (IEEE_Is_NaN(St_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in St Volume-Plot') +! IF (St_MudDischarged_Volume%Array(i)<0.) call ErrorStop('St Volume <0' , St_MudDischarged_Volume%Array(i)) +!enddo + + + IF (ANY(IEEE_Is_NaN(data%State%MudSystem%Op_MudDischarged_Volume%Array(:))) .OR. ANY(data%State%MudSystem%Op_MudDischarged_Volume%Array(:) <= 0.0)) THEN + do i = 1 , data%State%MudSystem%Op_MudOrKick%Length() + write(*,555) i,'Op_Volume(i), type=' ,data%State%MudSystem%Op_MudDischarged_Volume%Array(i) , data%State%MudSystem%Op_MudOrKick%Array(i) , data%State%MudSystem%Op_Density%Array(i) + end do + call ErrorStop('NaN in Op Volume-Plot or Op Volume <=0') + END IF + + + IF (ANY(IEEE_Is_NaN(data%State%MudSystem%Ann_MudDischarged_Volume%Array(:))) .OR. ANY(data%State%MudSystem%Ann_MudDischarged_Volume%Array(:) <= 0.0)) THEN + do i = 1 , data%State%MudSystem%Ann_MudOrKick%Length() + write(*,555) i,'Ann_Volume(i), type=' ,data%State%MudSystem%Ann_MudDischarged_Volume%Array(i) , data%State%MudSystem%Ann_MudOrKick%Array(i) , data%State%MudSystem%Ann_Density%Array(i) + end do + call ErrorStop('NaN in Ann Volume-Plot or Ann Volume <=0') + END IF + +!do i=1, Ann_MudOrKick%Length() +! !write(*,555) i,'Ann_Volume(i), type=' ,Ann_MudDischarged_Volume%Array(i),Ann_MudOrKick%Array(i),Ann_Density%Array(i) +! +! IF (IEEE_Is_NaN(Ann_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in Ann Volume-Plot') +! IF (Ann_MudDischarged_Volume%Array(i)<=0.) call ErrorStop('Ann Volume <=0' , Ann_MudDischarged_Volume%Array(i)) +!enddo + +555 FORMAT(I3,5X,A42,(f12.5),5X,I3,5X,(f12.5)) + + data%State%MudSystem%NoStringMudElementsForPlot= data%State%MudSystem%NoStringMudElements + +! 1-Horizontal Mud Elements are not shown +!write(*,333) 'Horiz:', 1,'Xstart\=', Xstart_MudElement%Array(1), 'Xend=' , Xend_MudElement%Array(1), 'Density=' , Density_MudElement%Array(1), 'MudType=' , MudType_MudElement%Array(1) + + do i=data%State%MudSystem%NoHorizontalMudElements+1, data%State%MudSystem%NoHorizontalMudElements+data%State%MudSystem%NoStringMudElements ! 2-string elements + if (data%State%MudSystem%Xend_MudElement%Array(i) <= 0.0) then + data%State%MudSystem%NoStringMudElementsForPlot= data%State%MudSystem%NoStringMudElementsForPlot-1 + cycle + endif + data%State%MudSystem%istring= data%State%MudSystem%istring+1 + data%State%MudSystem%StringMudElement(data%State%MudSystem%istring)%StartMd = data%State%MudSystem%Xstart_MudElement%Array(i) + data%State%MudSystem%StringMudElement(data%State%MudSystem%istring)%EndMd = data%State%MudSystem%Xend_MudElement%Array(i) +!StringMudElement(istring)%Id = PipeID_MudElement%Array(i) +!StringMudElement(istring)%Od = PipeOD_MudElement%Array(i) + data%State%MudSystem%StringMudElement(data%State%MudSystem%istring)%Density = data%State%MudSystem%Density_MudElement%Array(i) + + if (data%State%MudSystem%MudType_MudElement%Array(i) == 104) then + data%State%MudSystem%MudType_MudElement%Array(i)= 4 ! air + elseif (data%State%MudSystem%MudType_MudElement%Array(i) > 0 .and. data%State%MudSystem%MudType_MudElement%Array(i) < 100) then ! all kicks + data%State%MudSystem%MudType_MudElement%Array(i)= 1 ! gas kick + endif + + data%State%MudSystem%StringMudElement(data%State%MudSystem%istring)%MudType = data%State%MudSystem%MudType_MudElement%Array(i) +!write(*,333) 'STRING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'Density=' , Density_MudElement%Array(i), 'MudType=' , MudType_MudElement%Array(i) + enddo + + + + do i=data%State%MudSystem%Xend_MudElement%Length(), data%State%MudSystem%NoHorizontalMudElements+data%State%MudSystem%NoStringMudElements+1 , -1 ! 3-casing elements + data%State%MudSystem%icasing= data%State%MudSystem%icasing+1 + data%State%MudSystem%CasingMudElement(data%State%MudSystem%icasing)%StartMd = data%State%MudSystem%Xend_MudElement%Array(i) + data%State%MudSystem%CasingMudElement(data%State%MudSystem%icasing)%EndMd = data%State%MudSystem%Xstart_MudElement%Array(i) +!CasingMudElement(icasing)%Id = PipeID_MudElement%Array(i) +!CasingMudElement(icasing)%Od = PipeOD_MudElement%Array(i) +!write(*,333) 'CASING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'Density=' , Density_MudElement%Array(i), 'MudType=' , MudType_MudElement%Array(i) +!call Log_1(temp1) +!write(*,444) 'CASING:', i,'Xstart\=', Xstart_MudElement%Array(i), 'Xend=' , Xend_MudElement%Array(i), 'PipeID_MudElement%Array(i)=' , PipeID_MudElement%Array(i), 'PipeOD_MudElement%Array(i)=' , PipeOD_MudElement%Array(i) + data%State%MudSystem%CasingMudElement(data%State%MudSystem%icasing)%Density = data%State%MudSystem%Density_MudElement%Array(i) + + if (data%State%MudSystem%MudType_MudElement%Array(i) == 104) then + data%State%MudSystem%MudType_MudElement%Array(i)= 4 ! air + elseif (data%State%MudSystem%MudType_MudElement%Array(i) > 0 .and. data%State%MudSystem%MudType_MudElement%Array(i) < 100) then + data%State%MudSystem%MudType_MudElement%Array(i)= 1 ! gas kick + endif + + data%State%MudSystem%CasingMudElement(data%State%MudSystem%icasing)%MudType = data%State%MudSystem%MudType_MudElement%Array(i) + + enddo + + do i= data%State%MudSystem%NoBottomHoleMudElements, 1 , -1 ! 4-open hole elements + data%State%MudSystem%icasing= data%State%MudSystem%icasing+1 + data%State%MudSystem%CasingMudElement(data%State%MudSystem%icasing)%StartMd = data%State%MudSystem%Xend_OpMudElement%Array(i) + data%State%MudSystem%CasingMudElement(data%State%MudSystem%icasing)%EndMd = data%State%MudSystem%Xstart_OpMudElement%Array(i) +!CasingMudElement(icasing)%Id = PipeID_OpMudElement%Array(i) +!CasingMudElement(icasing)%Od = PipeOD_OpMudElement%Array(i) +!write(*,333) 'OpenHole:',i,'Xstart\=', Xstart_OpMudElement%Array(i), 'Xend=' , Xend_OpMudElement%Array(i), 'Density=' , Density_OpMudElement%Array(i), 'MudType=' , MudTypeOp_MudElement%Array(i) +!call Log_1(temp2) +!write(*,444) 'OpenHole:',i,'Xstart\=', Xstart_OpMudElement%Array(i), 'Xend=' , Xend_OpMudElement%Array(i), 'PipeID_MudElement%Array(i)=' , PipeID_MudElement%Array(i), 'PipeOD_MudElement%Array(i)=' , PipeOD_MudElement%Array(i) + data%State%MudSystem%CasingMudElement(data%State%MudSystem%icasing)%Density = data%State%MudSystem%Density_OpMudElement%Array(i) + + if (data%State%MudSystem%MudTypeOp_MudElement%Array(i) == 104) then + data%State%MudSystem%MudTypeOp_MudElement%Array(i)= 4 ! air + elseif (data%State%MudSystem%MudTypeOp_MudElement%Array(i) > 0 .and. data%State%MudSystem%MudTypeOp_MudElement%Array(i) < 100) then + data%State%MudSystem%MudTypeOp_MudElement%Array(i)= 1 ! gas kick + endif + + data%State%MudSystem%CasingMudElement(data%State%MudSystem%icasing)%MudType = data%State%MudSystem%MudTypeOp_MudElement%Array(i) + enddo + + + +333 FORMAT(A10,I3,5X,A8,(f12.5),5X,A8,(f12.5),5X,A8,(f12.5),5X,A8,I3) +444 FORMAT(A10,I2,5X,A8,(f12.3),5X,A8,(f12.3),5X,A8,(f12.3),5X,A8,(f12.3)) + + + +! shomare gozari be tartib HZ mud, ST mud, Casing +! shomare gzari OpenHole jodagane ast az 1 + + call SetStringFluids(data%State%MudSystem%NoStringMudElementsForPlot, data%State%MudSystem%StringMudElement) !for data display in string + call SetAnnalusFluids(data%State%MudSystem%NoCasingMudElements+data%State%MudSystem%NoBottomHoleMudElements, data%State%MudSystem%CasingMudElement) !for data display in casing + + +!=========================================================================================================================== +!=========================================================================================================================== + + + end subroutine PlotFinalMudElements + + + diff --git a/Equipments/MudSystem/Pump_and_Trip_In.f90 b/Equipments/MudSystem/Pump_and_Trip_In.f90 index 04f8afc..85052de 100644 --- a/Equipments/MudSystem/Pump_and_Trip_In.f90 +++ b/Equipments/MudSystem/Pump_and_Trip_In.f90 @@ -16,7 +16,7 @@ use SimulationVariables !@@@ !use CChokeManifoldVariables use SimulationVariables !use CTanks - !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables use KickVARIABLESModule @@ -60,7 +60,7 @@ integer i,ii,AddLocation data%State%MudSystem%total_add = data%State%MudSystem%total_add + ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) - if (data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then data%State%MudSystem%total_add= 0. endif @@ -902,7 +902,7 @@ IF (data%State%MudSystem%WellHeadIsOpen) data%State%MudSystem%MudVolume_In data%State%MudSystem%total_injected = data%State%MudSystem%total_injected + data%State%MudSystem%MudVolume_InjectedFromAnn - if (data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then data%State%MudSystem%total_injected= 0. endif @@ -930,7 +930,7 @@ imud= 0 ! <<< Fracture Shoe Lost - IF ( data%State%MudSystem%ShoeLost .and. Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then + IF ( data%State%MudSystem%ShoeLost .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then @@ -1192,7 +1192,7 @@ use SimulationVariables !@@@ !use CChokeManifoldVariables use SimulationVariables !use CTanks - !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables use KickVARIABLESModule diff --git a/Equipments/MudSystem/Pump_and_Trip_In.i90 b/Equipments/MudSystem/Pump_and_Trip_In.i90 new file mode 100644 index 0000000..05dd885 --- /dev/null +++ b/Equipments/MudSystem/Pump_and_Trip_In.i90 @@ -0,0 +1,1646 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/Pump_and_Trip_In.f90" +subroutine Pump_and_TripIn ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!use CDataDisplayConsole +!@ use ConfigurationVariables , StandPipePressureDataDisplay=>StandPipePressure +!use CManifolds + use SimulationVariables !@ + USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!use CChokeManifoldVariables + use SimulationVariables +!use CTanks +!@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + Use CShoeVariables + use CError + + + implicit none + +integer i,ii,AddLocation +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + + data%State%MudSystem%StringFlowRate= data%State%MUD(2)%Q + data%State%MudSystem%AnnulusFlowRate= data%State%MUD(2)%Q + + +!write(*,*) 'Trip In' + + +!========================Horizontal PIPE ENTRANCE================= + + if (ABS(data%State%MudSystem%SuctionDensity_Old - data%State%MudSystem%Suction_Density_MudSystem) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped + + call data%State%MudSystem%Hz_Density%AddToFirst (data%State%MudSystem%Suction_Density_MudSystem) + call data%State%MudSystem%Hz_MudDischarged_Volume%AddToFirst (0.0d0) + call data%State%MudSystem%Hz_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(1)) + call data%State%MudSystem%Hz_Mud_Forehead_section%AddToFirst (1) + call data%State%MudSystem%Hz_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(1)) + call data%State%MudSystem%Hz_Mud_Backhead_section%AddToFirst (1) + call data%State%MudSystem%Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Hz_MudOrKick%AddToFirst (0) + + data%State%MudSystem%SuctionDensity_Old= data%State%MudSystem%Suction_Density_MudSystem + endif + +!========================Horizontal PIPE STRING================= + + data%State%MudSystem%Hz_MudDischarged_Volume%Array(1)= data%State%MudSystem%Hz_MudDischarged_Volume%Array(1)+ ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + + data%State%MudSystem%total_add = data%State%MudSystem%total_add + ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) + + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + data%State%MudSystem%total_add= 0. + endif + + +!write(*,*) ' total decrease(add to HZ)=' , total_add +!write(*,*) ' add to HZ=' , ((data%State%MudSystem%StringFlowRate/60.0d0)*DeltaT_Mudline) + +imud=0 + do while (imud < data%State%MudSystem%Hz_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%Hz_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud-1) + endif + + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Hz_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud) + data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Hz_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)) + + else + + + data%State%MudSystem%isection= data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > 1) then ! (horizontal pipe exit) + data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(1) + data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud)= 1 + + if (data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveHzMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + endif + + enddo + + endif + + enddo +!========================Horizontal PIPE END================= + + +!========================Utube1 Air Element Removing================= + +!if (UtubeMode1Activated== .true.) then ! StringUpdate == .true. +! +! +! !StringDensity_Old=data%State%MudSystem%St_Density%Array(2) +! +! write(*,*) 'StringDensity_Old=' , StringDensity_Old +! +! UtubeMode1Activated= .false. +!endif + +!========================Utube1 Air Element Removing End================= + +!!========================Utube2 Removing from Annulus================= not needed 97.04.26 +! +! if (UtubeMode2Activated== .true.) then ! StringUpdate == .true. +! +! if (Ann_MudOrKick%Last() == 104) then !movaghati. albate age merge anjam shode bashe moshkeli nist +! call RemoveAnnulusMudArrays(Ann_MudOrKick%Length()) +! endif +! +! UtubeMode2Activated= .false. +! endif +! +! +!!========================Utube2 Removing from Annulus End================= + +!========================New Pipe Filling================= + +!if (F_StringIntervalCounts > F_StringIntervalCountsOld) then ! StringUpdate == .true. + if (data%State%MudSystem%AddedElementsToString > 0) then ! StringUpdate == .true. + +!NoPipeAdded= data%State%F_Counts%StringIntervalCounts - F_StringIntervalCountsOld + + + data%State%MudSystem%NewPipeFilling=0 + + IF (data%State%MudSystem%St_MudOrKick%First() == 104) then + data%State%MudSystem%St_MudDischarged_Volume%Array(1) = data%State%MudSystem%St_MudDischarged_Volume%Array(1) + sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:1+data%State%MudSystem%AddedElementsToString)) ! new pipe is filled by air + else + call data%State%MudSystem%St_Density%AddToFirst (0.d0) + call data%State%MudSystem%St_MudDischarged_Volume%AddToFirst (sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:1+data%State%MudSystem%AddedElementsToString))) + call data%State%MudSystem%St_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Forehead_section%AddToFirst (2) + call data%State%MudSystem%St_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Backhead_section%AddToFirst (2) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.d0) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.d0) + call data%State%MudSystem%St_MudOrKick%AddToFirst (104) + endif + + endif + +!F_StringIntervalCountsOld= F_StringIntervalCounts + + + + if (data%State%MudSystem%NewPipeFilling == 0) then ! 2= is the first element of string (1= is for Hz pipe) + + + data%State%MudSystem%LackageMudVolume= data%State%MudSystem%St_MudDischarged_Volume%Array(1) ! = Air element + + + write(*,*) 'LackageMudVolume=' , data%State%MudSystem%LackageMudVolume + + + + if (ABS(data%State%MudSystem%St_Density%Array(2) - data%State%MudSystem%Hz_Density%Last()) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped + call data%State%MudSystem%St_Density%AddTo (2,data%State%MudSystem%Hz_Density%Last()) + call data%State%MudSystem%St_MudDischarged_Volume%AddTo (2, 0.d0) + call data%State%MudSystem%St_Mud_Forehead_X%AddTo (2,data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Forehead_section%AddTo (2 , 2) + call data%State%MudSystem%St_Mud_Backhead_X%AddTo (2,data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Backhead_section%AddTo (2 ,2) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddTo (2,0.d0) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddTo (2,0.d0) + call data%State%MudSystem%St_MudOrKick%AddTo (2,0) + +!StringDensity_Old= Hz_Density%Last() + endif + + + data%State%MudSystem%St_MudDischarged_Volume%Array(2)= data%State%MudSystem%St_MudDischarged_Volume%Array(2)+ min( ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline), data%State%MudSystem%LackageMudVolume) !(gal) + + data%State%MudSystem%St_MudDischarged_Volume%Array(1)= data%State%MudSystem%St_MudDischarged_Volume%Array(1)- min( ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline), data%State%MudSystem%LackageMudVolume) ! air(gal) + +!LackageMudVolumeAfterFilling= sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts)) - sum(St_MudDischarged_Volume%Array(:)) + + data%State%MudSystem%LackageMudVolumeAfterFilling= data%State%MudSystem%St_MudDischarged_Volume%Array(1) ! last time it should be zero + + + + if (data%State%MudSystem%LackageMudVolumeAfterFilling == 0.) then + data%State%MudSystem%NewPipeFilling= 1 + call RemoveStringMudArrays(1) + data%State%MudSystem%St_Mud_Backhead_X%Array(1) = data%State%MudSystem%Xstart_PipeSection(2) + data%State%MudSystem%St_Mud_Backhead_section%Array(1) = 2 + endif + + endif + +!========================New Pipe Filling End================= + + + + + if (data%State%MudSystem%NewPipeFilling == 0) then + data%State%MudSystem%StringFlowRate= 0. + data%State%MudSystem%AnnulusFlowRate= 0. + endif + + data%State%MudSystem%StringFlowRateFinal= data%State%MudSystem%StringFlowRate + data%State%MudSystem%AnnulusFlowRateFinal= data%State%MudSystem%AnnulusFlowRate + + + + +!========================STRING ENTRANCE================= + + if (data%State%MudSystem%StringFlowRateFinal > 0.0 .and. ABS(data%State%MudSystem%St_Density%First() - data%State%MudSystem%Hz_Density%Last()) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped + call data%State%MudSystem%St_Density%AddToFirst (data%State%MudSystem%Hz_Density%Last()) + call data%State%MudSystem%St_MudDischarged_Volume%AddToFirst (0.0d0) + call data%State%MudSystem%St_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Forehead_section%AddToFirst (2) + call data%State%MudSystem%St_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Backhead_section%AddToFirst (2) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%St_MudOrKick%AddToFirst (0) + +!StringDensity_Old= Hz_Density%Last() + endif + + + data%State%MudSystem%St_MudDischarged_Volume%Array(1)= data%State%MudSystem%St_MudDischarged_Volume%Array(1)+ ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + +!=============== save String Mud data=========== + + + + + data%State%MudSystem%StMudVolumeSum= 0.d0 +!St_MudSaved_Density= 0.d0 + data%State%MudSystem%St_Saved_MudDischarged_Volume= 0.d0 +!Saved_St_MudOrKick= 0 +!Ann_to_Choke_2mud= .false. + + do imud=1, data%State%MudSystem%St_MudDischarged_Volume%Length() + + data%State%MudSystem%StMudVolumeSum = data%State%MudSystem%StMudVolumeSum + data%State%MudSystem%St_MudDischarged_Volume%Array(imud) + + if ( data%State%MudSystem%StMudVolumeSum > sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:data%State%F_Counts%StringIntervalCounts)) ) then + +!IF (St_MudOrKick%Array(imud) == 0) THEN + data%State%MudSystem%St_MudSaved_Density =data%State%MudSystem%St_Density%Array(imud) + data%State%MudSystem%St_Saved_MudDischarged_Volume = data%State%MudSystem%StMudVolumeSum - sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:data%State%F_Counts%StringIntervalCounts)) +!ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR +! St_Kick_Saved_Volume = StMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +! Saved_St_MudOrKick= St_MudOrKick%Array (imud) +! St_KickSaved_Density=data%State%MudSystem%St_Density%Array(imud) +!END IF + + do ii= imud + 1, data%State%MudSystem%St_MudDischarged_Volume%Length() +!IF (St_MudOrKick%Array(ii) == 0) THEN + data%State%MudSystem%St_MudSaved_Density = ((data%State%MudSystem%St_MudSaved_Density * data%State%MudSystem%St_Saved_MudDischarged_Volume) + (data%State%MudSystem%St_Density%Array(ii) * data%State%MudSystem%St_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%St_Saved_MudDischarged_Volume + data%State%MudSystem%St_MudDischarged_Volume%Array(ii)) + data%State%MudSystem%St_Saved_MudDischarged_Volume = data%State%MudSystem%St_Saved_MudDischarged_Volume + data%State%MudSystem%St_MudDischarged_Volume%Array(ii) + +!ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR +! St_Kick_Saved_Volume = St_Kick_Saved_Volume + St_MudDischarged_Volume%Array(ii) +! Saved_St_MudOrKick= St_MudOrKick%Array (ii) +! St_KickSaved_Density=data%State%MudSystem%St_Density%Array(ii) +!END IF + enddo + + +!WRITE (*,*) 'St_Saved_Mud_Volume, St_Kick_Saved_Volume', St_Saved_MudDischarged_Volume, St_Kick_Saved_Volume + exit ! exits do + + endif + + enddo +data%State%MudSystem%St_Saved_MudDischarged_Volume_Final = data%State%MudSystem%St_Saved_MudDischarged_Volume + +IF (data%State%MudSystem%WellHeadIsOpen) data%State%MudSystem%MudVolume_InjectedToBH = data%State%MudSystem%St_Saved_MudDischarged_Volume_Final +!====================================================================== + +!========================STRING================= + +imud=0 + do while (imud < data%State%MudSystem%St_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%St_Mud_Backhead_X%Array(imud)= data%State%MudSystem%St_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%St_Mud_Backhead_section%Array(imud)= data%State%MudSystem%St_Mud_Forehead_section%Array(imud-1) + endif + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))- data%State%MudSystem%St_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%St_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + +!write(*,*) 'St_Mud_Backhead_section%Array(1)=' , St_Mud_Backhead_section%Array(1) +!write(*,*) 'Xend_PipeSection(St_Mud_Backhead_section%Array(1))=' , Xend_PipeSection(St_Mud_Backhead_section%Array(1)) +! +!write(*,*) 'St_EmptyVolume_inBackheadLocation%Array(1)=' , St_EmptyVolume_inBackheadLocation%Array(1) +!write(*,*) 'St_Mud_Backhead_X%Array(1)=' , St_Mud_Backhead_X%Array(1) + + + if ( data%State%MudSystem%St_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%MudSystem%St_Mud_Backhead_section%Array(imud) + data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= data%State%MudSystem%St_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%St_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%St_Mud_Backhead_section%Array(imud)) +! 7.48 is for gal to ft^3 + + else + + data%State%MudSystem%isection= data%State%MudSystem%St_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > data%State%F_Counts%StringIntervalCounts) then ! last pipe section(string exit) data%State%F_Counts%StringIntervalCounts includes Horizontal line + data%State%MudSystem%St_MudDischarged_Volume%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts) + data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%F_Counts%StringIntervalCounts + + if (data%State%MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveStringMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + + endif + + enddo + + endif + + enddo + + +!write(*,*) ' a before==' +! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +! +! do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! enddo +! +!write(*,*) '==== a before' + + + + +!write(*,*) ' iloc (a): ' , iloc + +!========================STRING END================= + + IF (data%State%MudSystem%Op_MudOrKick%Last() /= 0 .and. data%State%MudSystem%Op_MudOrKick%Last()==data%State%MudSystem%Ann_MudOrKick%First()) data%State%MudSystem%iLoc=2 ! it may be 1,2,3 or more, all of them are kick +!write(*,*) ' iloc (b): ' , iloc + +!=============================Add PumpFlowRate to Bottom Hole ============================== +!if ( data%State%MudSystem%AnnulusFlowRate>0.0 ) then + if ( data%State%MudSystem%MudVolume_InjectedToBH > 0.0 ) then + + + if (KickVARIABLES%KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the + AddLocation= data%State%MudSystem%Op_Density%Length()-data%State%MudSystem%iLoc+1+1 ! well, thus pumped mud should be placed above the kick + else + AddLocation= data%State%MudSystem%Op_Density%Length()+1 + endif +!write(*,*) 'AddLocation====' , AddLocation + if ( AddLocation== 0) CALL ErrorStop ('AddLocation=0') + + + if ( ABS(data%State%MudSystem%St_Density%Last() - data%State%MudSystem%Op_Density%Array(AddLocation-1)) >= data%State%MudSystem%DensityMixTol ) then +!write(*,*) 'new pocket**' +!write(*,*) data%State%MudSystem%St_Density%Last()=' ,data%State%MudSystem%St_Density%Last() +!write(*,*) 'Op_Density%Array(AddLocation-1)=' , Op_Density%Array(AddLocation-1) + + + call data%State%MudSystem%Op_Density% AddTo (AddLocation,data%State%MudSystem%St_Density%Last()) +!call Op_MudDischarged_Volume%AddTo (AddLocation,((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)) + call data%State%MudSystem%Op_MudDischarged_Volume%AddTo (AddLocation,data%State%MudSystem%MudVolume_InjectedToBH) + call data%State%MudSystem%Op_Mud_Forehead_X%AddTo (AddLocation,data%State%MudSystem%Xstart_OpSection(1)) + call data%State%MudSystem%Op_Mud_Forehead_section%AddTo (AddLocation,1) + call data%State%MudSystem%Op_Mud_Backhead_X%AddTo (AddLocation,data%State%MudSystem%Xstart_OpSection(1)) + call data%State%MudSystem%Op_Mud_Backhead_section%AddTo (AddLocation,1) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddTo (AddLocation,0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (AddLocation,0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddTo (AddLocation,0) + else +!write(*,*) 'merge**' +!write(*,*) 'density before=' , Op_Density%Array(AddLocation-1) +!write(*,*) data%State%MudSystem%St_Density%Last() for mix=' ,data%State%MudSystem%St_Density%Last() + +!Op_Density%Array(AddLocation-1)= (Op_Density%Array(AddLocation-1)*Op_MudDischarged_Volume%Array(AddLocation-1)data%State%MudSystem%St_Density%Last()*((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline))/(Op_MudDischarged_Volume%Array(AddLocation-1)+((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)) +!Op_MudDischarged_Volume%Array(AddLocation-1)= Op_MudDischarged_Volume%Array(AddLocation-1) + ((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) + + data%State%MudSystem%Op_Density%Array(AddLocation-1)= (data%State%MudSystem%Op_Density%Array(AddLocation-1)*data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)+data%State%MudSystem%St_Density%Last()*data%State%MudSystem%MudVolume_InjectedToBH)/(data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)+data%State%MudSystem%MudVolume_InjectedToBH) + data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1) + data%State%MudSystem%MudVolume_InjectedToBH +!write(*,*) 'density after=' , Op_Density%Array(AddLocation-1) + + endif + + endif +!=======================Add PumpFlowRate to Bottom Hole- End ============================== + + + + +!=============== save OP Mud data to transfer to the annulus enterance due to tripin or kick + data%State%MudSystem%OpMudVolumeSum= 0.d0 +!Op_MudSaved_Density= 0.d0 +!Op_KickSaved_Density= 0.d0 + data%State%MudSystem%Op_Saved_MudDischarged_Volume= 0.d0 + data%State%MudSystem%Op_Kick_Saved_Volume= 0.d0 + data%State%MudSystem%Saved_Op_MudOrKick= 0 + + + +!write(*,*) 'Op_Capacity===' , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) +!write(*,*) 'Op_MudDischarged_Volume%Length()===' , Op_MudDischarged_Volume%Length() +! + + do imud=1, data%State%MudSystem%Op_MudDischarged_Volume%Length() +!write(*,*) 'imud, Op_MudDischarged_Volume%Array(imud)=' , imud,Op_MudDischarged_Volume%Array(imud) + + data%State%MudSystem%OpMudVolumeSum= data%State%MudSystem%OpMudVolumeSum + data%State%MudSystem%Op_MudDischarged_Volume%Array(imud) + + if ( data%State%MudSystem%OpMudVolumeSum > sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) ) then + + IF (data%State%MudSystem%Op_MudOrKick%Array(imud) == 0) THEN + data%State%MudSystem%Op_MudSaved_Density = data%State%MudSystem%Op_Density%Array(imud) + data%State%MudSystem%Op_Saved_MudDischarged_Volume = data%State%MudSystem%OpMudVolumeSum - sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) + ELSE + data%State%MudSystem%Op_Kick_Saved_Volume = data%State%MudSystem%OpMudVolumeSum - sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) +!write(*,*) 'cond 1- Op_MudOrKick%Array (imud),Op_Density%Array(imud):' ,Op_MudOrKick%Array (imud),Op_Density%Array(imud) + data%State%MudSystem%Saved_Op_MudOrKick= data%State%MudSystem%Op_MudOrKick%Array (imud) + data%State%MudSystem%Op_KickSaved_Density= data%State%MudSystem%Op_Density%Array(imud) + data%State%MudSystem%iLoc= 2 + END IF + + do ii= imud + 1, data%State%MudSystem%Op_MudDischarged_Volume%Length() + IF (data%State%MudSystem%Op_MudOrKick%Array(ii) == 0) THEN + data%State%MudSystem%Op_MudSaved_Density = ((data%State%MudSystem%Op_MudSaved_Density * data%State%MudSystem%Op_Saved_MudDischarged_Volume) + (data%State%MudSystem%Op_Density%Array(ii) * data%State%MudSystem%Op_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%Op_Saved_MudDischarged_Volume + data%State%MudSystem%Op_MudDischarged_Volume%Array(ii)) + data%State%MudSystem%Op_Saved_MudDischarged_Volume = data%State%MudSystem%Op_Saved_MudDischarged_Volume + data%State%MudSystem%Op_MudDischarged_Volume%Array(ii) + ELSE + data%State%MudSystem%Op_Kick_Saved_Volume = data%State%MudSystem%Op_Kick_Saved_Volume + data%State%MudSystem%Op_MudDischarged_Volume%Array(ii) +!write(*,*) 'cond 2- Op_MudOrKick%Array (ii),Op_Density%Array(ii):' ,Op_MudOrKick%Array (ii),Op_Density%Array(ii) + data%State%MudSystem%Saved_Op_MudOrKick= data%State%MudSystem%Op_MudOrKick%Array (ii) + data%State%MudSystem%Op_KickSaved_Density= data%State%MudSystem%Op_Density%Array(ii) + data%State%MudSystem%iLoc= 2 + END IF + enddo + + exit ! exits do + + endif + + enddo +!WRITE (*,*) 'Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume',Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume +!write(*,*) ' iloc (c): ' , iloc + +!====================================================================== + +!====================================================================== + + + + + +!if (iLoc == 1) then + data%State%MudSystem%MudSection= data%State%F_Counts%StringIntervalCounts+1 + data%State%MudSystem%BackheadX= data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1) +!elseif (iLoc == 2) then +! MudSection= Kick_Forehead_section +! BackheadX= Kick_Forehead_X +!endif + +!========================ANNULUS ENTRANCE==================== +!if (KickMigration_2SideBit == .FALSE.) then ! because its effect is applied in Migration Code +! !write(*,*) 'iloc=====' , iLoc bejaye data%State%ROP_Bit%RateOfPenetration ==0. in bude: DeltaVolumeOp == 0.0 +! if (ABS(AnnulusSuctionDensity_OldMudSystem%St_Density%Last()) >= DensityMixTol .OR. (DeltaVolumeOp == 0.0 .and. ABS(Ann_Density%Array(iLoc)data%State%MudSystem%St_Density%Last())>=DensityMixTol .and. data%State%MudSystem%AnnulusFlowRate/=0.0d0) ) then ! new mud is pumped +! call Ann_Density%AddTo (iLocMudSystem%St_Density%Last()) +! call Ann_MudDischarged_Volume%AddTo (iLoc,0.0d0) +! call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX) +! call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection) +! call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX) +! call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection) +! call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0) +! call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0) +! call Ann_MudOrKick%AddTo (iLoc,0) +! call Ann_CuttingMud%AddTo (iLoc,0) +! !write(*,*) 'c) annLength=' , Ann_Density%Length() +! +! AnnulusSuctionDensity_Old=data%State%MudSystem%St_Density%Last() +! +! MudIsChanged= .true. +! endif +! +! Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+ ((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) !(gal) +! +!endif + + + + + + + data%State%MudSystem%Ann_Mud_Backhead_section%Array(1)= data%State%MudSystem%MudSection !it is needed to be updated for a condition that one pipe is removed from Annulus due to trip out + data%State%MudSystem%Ann_Mud_Backhead_X%Array(1)= data%State%MudSystem%BackheadX + + + +! write(*,*) 'zero)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:)) +! +! +!write(*,*) 'pump added-before add to ann==' +! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +! +! do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! enddo +! +!write(*,*) '====pump added-before add to ann' + + + +!========================Tripping In==================== + +!write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp + if (data%State%ROP_Bit%RateOfPenetration==0.) then ! .and. Op_MudOrKick%Last() == 0) then ! trip in mode(loole paeen) Mud + +!write(*,*) 'Tripping In' +!write(*,*) 'before' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + +!if ( MudIsChanged== .true. ) then +! call RemoveAnnulusMudArrays(iLoc) +!endif + + + if (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .and. data%State%MudSystem%Ann_MudOrKick%First() == 0) then + write(*,*) 'Kick influx enters Annulus' + call data%State%MudSystem%Ann_Density%AddToFirst (data%State%MudSystem%Op_KickSaved_Density) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddToFirst (data%State%MudSystem%Op_Kick_Saved_Volume) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddToFirst (data%State%MudSystem%Saved_Op_MudOrKick) !<<<<<<<< + call data%State%MudSystem%Ann_CuttingMud%AddToFirst (0) + elseif (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .and. data%State%MudSystem%Ann_MudOrKick%First() /= 0) then + data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) + data%State%MudSystem%Op_Kick_Saved_Volume + endif + + + if (data%State%MudSystem%Op_Saved_MudDischarged_Volume> 0.0) then + data%State%MudSystem%NewDensity= data%State%MudSystem%Op_MudSaved_Density + data%State%MudSystem%NewVolume= data%State%MudSystem%Op_Saved_MudDischarged_Volume +!write(*,*) 'NewVolume=' , NewVolume +!write(*,*) 'iloc=' , iloc,'Ann_MudDischarged_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + + + if ((data%State%ROP_Bit%RateOfPenetration==0 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%DensityMixTol) & + .or. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==1 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%CuttingDensityMixTol) & + .or. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==0 .and. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged + + data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)= (data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume + data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_Mud_Backhead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Backhead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(data%State%MudSystem%iLoc)= (0.0d0) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%iLoc)= (0.0d0) +!write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + else ! 2-Merging conditions are not meeted, so new pocket + call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%iLoc,0) + call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%iLoc,0) +!write(*,*) 'd) annLength=' , Ann_Density%Length() +!write(*,*) 'new' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + endif + endif + + endif + +!========================Tripping In - End==================== + +!========================Drilling Mode======================== + + if (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%DeltaVolumeOp>0.0) then ! trip in mode(loole paeen) DrillingMode== .true. +!write(*,*) 'Drilling Mode' + +!if ( MudIsChanged== .true. ) then +! call RemoveAnnulusMudArrays(iLoc) +!endif +!write(*,*) 'before' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + +!data%State%MudSystem%NewDensity= data%State%MudSystem%St_Density%Last() * data%State%MudSystem%AnnulusFlowRate + 141.4296E-4*data%State%ROP_Bit%RateOfPenetration*data%State%ROP_Spec%DiameterOfBit**2)/(data%State%MudSystem%AnnulusFlowRate+6.7995E-4*data%State%ROP_Bit%RateOfPenetration*Diameter_of_Bit**2) + + data%State%MudSystem%NewDensity=data%State%MudSystem%St_Density%Last() + + +!NewVolume= ((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline)+DeltaVolumeOp +!!! Density in ppg, flow rate in gpm, ROP in ft/s, bit diameter in inch + + + do imud=1, data%State%MudSystem%Op_MudDischarged_Volume%Length() + if ( data%State%MudSystem%Op_MudOrKick%Array(imud) == 0 ) then + data%State%MudSystem%Op_Density%Array(imud)= data%State%MudSystem%NewDensity + + endif + enddo + + + + if (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .and. data%State%MudSystem%Ann_MudOrKick%First() == 0) then + write(*,*) 'Kick influx enters Annulus first time' +!write(*,*) 'Saved_Op_MudOrKick=',Saved_Op_MudOrKick + call data%State%MudSystem%Ann_Density%AddToFirst (data%State%MudSystem%Op_KickSaved_Density) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddToFirst (data%State%MudSystem%Op_Kick_Saved_Volume) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddToFirst (data%State%MudSystem%Saved_Op_MudOrKick) !<<<<<<<< + call data%State%MudSystem%Ann_CuttingMud%AddToFirst (0) + elseif (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .and. data%State%MudSystem%Ann_MudOrKick%First() /= 0) then + data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) + data%State%MudSystem%Op_Kick_Saved_Volume + endif + + + if (data%State%MudSystem%Op_Saved_MudDischarged_Volume> 0.0) then +!write(*,*) 'Op_Saved_Mud added' + data%State%MudSystem%NewDensity= data%State%MudSystem%NewDensity !(drilling density) + data%State%MudSystem%NewVolume= data%State%MudSystem%Op_Saved_MudDischarged_Volume + data%State%MudSystem%DeltaVolumeOp ! (DeltaVolumeOp: for Cuttings Volume) +!write(*,*) 'NewVolume=' , NewVolume +!write(*,*) 'iloc=' , iloc,'Ann_MudDischarged_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + if ( (data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==1 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%CuttingDensityMixTol ) & + .or. (data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==0 .and. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged + + data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)= (data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume + data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_Mud_Backhead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Backhead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(data%State%MudSystem%iLoc)= (0.0d0) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%iLoc)= (0.0d0) + data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)= 1 +!write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + else ! 2-Merging conditions are not meeted, so new pocket +!write(*,*) 'before e) ', iloc, Ann_Density%Array(iLoc),data%State%MudSystem%NewDensity +!write(*,*) 'before e) Ann_MudDischarged_Volume%Array(iLoc)=' , Ann_MudDischarged_Volume%Array(iLoc) + + + call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%iLoc,0) + call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%iLoc,1) ! 1= cutting 0= mud +!write(*,*) 'new' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + +!write(*,*) 'e) annLength=' , Ann_Density%Length() + + + endif + + + endif + + endif +!=================================================================== + +!write(*,*) 'after add to ann==' +! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +! +! do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! enddo +! +!write(*,*) '==after add to ann' + + data%State%MudSystem%NewVolume= ((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) - data%State%MudSystem%Op_Saved_MudDischarged_Volume + + if (data%State%MudSystem%iLoc==2 .and. data%State%MudSystem%Op_MudOrKick%Last()==0 .and. data%State%MudSystem%NewVolume > 0.d0 ) then ! for avoid kick separation +!write(*,*) 'avoid kick separation' + + + data%State%MudSystem%NewDensity= data%State%MudSystem%Op_MudSaved_Density + + call RemoveOpMudArrays(data%State%MudSystem%Op_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann + if ( data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) > ((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline)- data%State%MudSystem%Op_Saved_MudDischarged_Volume) then! 1st in Ann = kick +!write(*,*) 'mode1' + data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) - (((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) -data%State%MudSystem%Op_Saved_MudDischarged_Volume) + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())+ (((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) - data%State%MudSystem%Op_Saved_MudDischarged_Volume) !kick + else + call RemoveAnnulusMudArrays(1) !kick is removed + data%State%MudSystem%iLoc= 1 + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())+ (((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) - data%State%MudSystem%Op_Saved_MudDischarged_Volume) +!write(*,*) 'mode2' + +! including a little expand + endif + + + if ((data%State%ROP_Bit%RateOfPenetration==0 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%DensityMixTol) & + .or. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==1 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%CuttingDensityMixTol) & + .or. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==0 .and. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged + + data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)= (data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume + data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_Mud_Backhead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Backhead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(data%State%MudSystem%iLoc)= (0.0d0) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%iLoc)= (0.0d0) + else ! 2-Merging conditions are not meeted, so new pocket + call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%iLoc,0) + call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%iLoc,0) +!write(*,*) 'd) annLength=' , Ann_Density%Length() + + endif + + + endif +!=================================================================== + if( data%State%MudSystem%Op_MudOrKick%Last() == 1 .and. data%State%MudSystem%Ann_MudOrKick%First() == 0 ) then + + write(*,*) '***error2****==' + + write(*,*) 'Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume=' , data%State%MudSystem%Op_Kick_Saved_Volume,data%State%MudSystem%Op_Saved_MudDischarged_Volume + + + write(*,*) 'after add to ann==' + + do imud=1, data%State%MudSystem%Op_MudDischarged_Volume%Length() + write(*,*) 'Op:', imud, data%State%MudSystem%Op_MudDischarged_Volume%Array(imud), data%State%MudSystem%Op_Density%Array(imud) ,data%State%MudSystem%Op_MudOrKick%Array(imud) + enddo + + do imud=1, data%State%MudSystem%Ann_MudDischarged_Volume%Length() + write(*,*) 'Ann:', imud, data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud), data%State%MudSystem%Ann_Density%Array(imud) ,data%State%MudSystem%Ann_MudOrKick%Array(imud) + enddo + + write(*,*) '==after add to ann' + + write(*,*) 'NewVolume,Op_MudOrKick%Last=' , data%State%MudSystem%NewVolume,data%State%MudSystem%Op_MudOrKick%Last() + write(*,*) '==***error2****' + + endif + + + + + +!=============== save Ann Mud data to transfer to the ChokeLine enterance + data%State%MudSystem%AnnMudVolumeSum= 0.d0 +!Ann_MudSaved_Density= 0.d0 +!Ann_KickSaved_Density= 0.d0 + data%State%MudSystem%Ann_Saved_MudDischarged_Volume= 0.d0 + data%State%MudSystem%Ann_Kick_Saved_Volume= 0.d0 + data%State%MudSystem%Saved_Ann_MudOrKick= 0 + data%State%MudSystem%Ann_to_Choke_2mud= .false. + + + + + do imud=1, data%State%MudSystem%Ann_MudDischarged_Volume%Length() + + data%State%MudSystem%AnnMudVolumeSum= data%State%MudSystem%AnnMudVolumeSum + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) + + if ( data%State%MudSystem%AnnMudVolumeSum > sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) ) then + + IF (data%State%MudSystem%Ann_MudOrKick%Array(imud) == 0) THEN + data%State%MudSystem%Ann_MudSaved_Density = data%State%MudSystem%Ann_Density%Array(imud) + data%State%MudSystem%Ann_Saved_MudDischarged_Volume = data%State%MudSystem%AnnMudVolumeSum - sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + ELSEIF (data%State%MudSystem%Ann_MudOrKick%Array(imud) > 0 .AND. data%State%MudSystem%Ann_MudOrKick%Array(imud) <100) THEN ! 104= AIR + data%State%MudSystem%Ann_Kick_Saved_Volume = data%State%MudSystem%AnnMudVolumeSum - sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + data%State%MudSystem%Saved_Ann_MudOrKick= data%State%MudSystem%Ann_MudOrKick%Array (imud) + data%State%MudSystem%Ann_KickSaved_Density= data%State%MudSystem%Ann_Density%Array(imud) + END IF + + do ii= imud + 1, data%State%MudSystem%Ann_MudDischarged_Volume%Length() + IF (data%State%MudSystem%Ann_MudOrKick%Array(ii) == 0) THEN + data%State%MudSystem%Ann_MudSaved_Density = ((data%State%MudSystem%Ann_MudSaved_Density * data%State%MudSystem%Ann_Saved_MudDischarged_Volume) + (data%State%MudSystem%Ann_Density%Array(ii) * data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%Ann_Saved_MudDischarged_Volume + data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii)) + data%State%MudSystem%Ann_Saved_MudDischarged_Volume = data%State%MudSystem%Ann_Saved_MudDischarged_Volume + data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii) + data%State%MudSystem%Ann_to_Choke_2mud= .true. + ELSEIF (data%State%MudSystem%Ann_MudOrKick%Array(ii) > 0 .AND. data%State%MudSystem%Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR + data%State%MudSystem%Ann_Kick_Saved_Volume = data%State%MudSystem%Ann_Kick_Saved_Volume + data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii) + data%State%MudSystem%Saved_Ann_MudOrKick= data%State%MudSystem%Ann_MudOrKick%Array (ii) + data%State%MudSystem%Ann_KickSaved_Density= data%State%MudSystem%Ann_Density%Array(ii) + END IF + enddo + + +!WRITE (*,*) 'Ann_Saved_Mud_Volume, Ann_Kick_Saved_Volume', Ann_Saved_MudDischarged_Volume, Ann_Kick_Saved_Volume + exit + + endif + + enddo +data%State%MudSystem%Ann_Saved_MudDischarged_Volume_Final= data%State%MudSystem%Ann_Saved_MudDischarged_Volume !+ Ann_Kick_Saved_Volume +data%State%MudSystem%Ann_Kick_Saved_Volume_Final= data%State%MudSystem%Ann_Kick_Saved_Volume +IF (data%State%MudSystem%WellHeadIsOpen) data%State%MudSystem%MudVolume_InjectedFromAnn = data%State%MudSystem%Ann_Saved_MudDischarged_Volume_Final -((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) +!WRITE (*,*) 'data%State%MudSystem%MudVolume_InjectedFromAnn=', data%State%MudSystem%MudVolume_InjectedFromAnn +!====================================================================== + +!write(*,*) 'c)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:)) +!write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +!write(*,*) 'Ann_Saved_Mud=' , Ann_Saved_MudDischarged_Volume + + data%State%MudSystem%total_injected = data%State%MudSystem%total_injected + data%State%MudSystem%MudVolume_InjectedFromAnn + + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + data%State%MudSystem%total_injected= 0. + endif + +!write(*,*) ' total injected-tripin =' , total_injected +!write(*,*) 'injected-tripin =' , data%State%MudSystem%MudVolume_InjectedFromAnn + + + + + +!======================== Annulus ==================== + +!MudIsChanged= .false. + +imud= 0 + + do while (imud < data%State%MudSystem%Ann_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud-1) + endif + + + +! <<< Fracture Shoe Lost + IF ( data%State%MudSystem%ShoeLost .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then +!write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then +!write(*,*) 'mud is removed by shoe lost, imud=' , imud + call RemoveAnnulusMudArrays(imud) + imud= imud-1 + cycle + endif + + ENDIF +! Fracture Shoe Lost >>> + + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud) + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)) +! 7.48 is for gal to ft^3 + + else + + data%State%MudSystem%isection= data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > data%State%MudSystem%NoPipeSections) then ! last pipe section(well exit) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections) + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%NoPipeSections + + if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well +!write(*,*) 'remove******' + call RemoveAnnulusMudArrays(imud) + endif + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + endif + + enddo + + endif +! write(*,*) 'imud=' , imud +!write(*,*) 'Pinter4 **Ann_Length()=' , Ann_Mud_Forehead_X%Length() +! write(*,*) 'Ann_Density%Array (imud)=' , Ann_Density%Array (imud) +! +! +!write(*,*) imud,'Ann_Mud_Forehead_X%Array(imud)=' , Ann_Mud_Forehead_X%Array(imud) + +!if (Ann_Mud_Forehead_X%Array(imud) < Xend_PipeSection(NoPipeSections)) then +! Ann_Mud_Forehead_X%Array(imud) = Xend_PipeSection(NoPipeSections) ! for error preventing +!endif + +!write(*,*) imud, 'Ann_MudDischarged_Volume%Array(imud)=' , Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) + + + enddo + + if (data%State%MudSystem%Ann_Mud_Forehead_X%Last() < data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections)) then + data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%Ann_Mud_Forehead_X%Length()) = data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections) ! for error preventing + endif + +!========================ANNULUS END================= +!write(*,*) 'sum(Ann_MudDischarged_Volume%Array())=' , sum(Ann_MudDischarged_Volume%Array(:)) + +!========================================================= + + +!write(*,*) 'before======2' +! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +!write(*,*) '2======before' + + +!========================Bottom Hole================= +imud=0 + do while (imud < data%State%MudSystem%Op_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%Op_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Op_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Op_Mud_Forehead_section%Array(imud-1) + endif +!write(*,*) 'imud**=' , imud + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Op_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal +!write(*,*) ' Op_EmptyVolume_inBackheadLocation%Array(1) =' , Op_EmptyVolume_inBackheadLocation%Array(1) + if ( data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(1) < 0.0) CALL ErrorStop1 ('Negative Empty volume') + + if ( data%State%MudSystem%Op_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Op_Mud_Backhead_section%Array(imud) + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Op_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)) +! 7.48 is for gal to ft^3 + + else + + + data%State%MudSystem%isection= data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > data%State%F_Counts%BottomHoleIntervalCounts) then ! last pipe section(well exit) +!if( imud==1) KickDeltaVinAnnulus= Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space + data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts) + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%F_Counts%BottomHoleIntervalCounts + + if (data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveOpMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%OpSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%OpSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + endif + + enddo + + endif +! for OP remove: + + if (data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)== data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts)) then + data%State%MudSystem%totalLength = data%State%MudSystem%Op_MudDischarged_Volume%Length() + do while(imud < data%State%MudSystem%totalLength) + +!imud = imud + 1 + call RemoveOpMudArrays(data%State%MudSystem%totalLength) + data%State%MudSystem%totalLength = data%State%MudSystem%totalLength - 1 + + + enddo + + exit ! + + endif + + + + +!if (Op_Mud_Forehead_X%Array(imud)== Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts)) then +! totalLength = Op_MudDischarged_Volume%Length() +! do while(imud <= totalLength) +! +! imud = imud + 1 +! call RemoveOpMudArrays(imud) +! totalLength = totalLength - 1 +! +! +! enddo +! +! exit ! +! +!endif + + enddo + +!write(*,*) 'OpSection_VolumeCapacity sum=' , sum(OpSection_VolumeCapacity(:)) + + + +!========================Bottom Hole END================= + + +!write(*,*) 'after sorting==' +! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +! +! do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! enddo +! +! ! +! !do imud=1, st_MudDischarged_Volume%Length() +! ! write(*,*) 'st:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud) +! !enddo +! +!write(*,*) '==after sorting' + + +! write(*,*) 'after sorting st==' +! +! do imud=1, st_MudDischarged_Volume%Length() +! write(*,*) 'st-plot:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud)data%State%MudSystem%St_Density%Array(imud) +! enddo +! +!write(*,*) '==after sorting st' + + + + +!write(*,*) '**Ann_Kick_Saved_Final,Mud_InjectedFromAnn' , Ann_Kick_Saved_Volume_Final,data%State%MudSystem%MudVolume_InjectedFromAnn + + end subroutine Pump_and_TripIn + + + + + + + + + + + + subroutine ChokeLineMud ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!use CDataDisplayConsole +!@ use ConfigurationVariables , StandPipePressureDataDisplay=>StandPipePressure +!use CManifolds + use SimulationVariables !@ + USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!use CChokeManifoldVariables + use SimulationVariables +!use CTanks +!@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + use PressureDisplayVARIABLESModule + Use CError + Use , intrinsic :: IEEE_Arithmetic + + + implicit none + + integer i,ii,error_occured + + error_occured = 0 + + + + +!write(*,*) 'begining chokeline==' +!write(*,*) 'Ann last:', Ann_MudDischarged_Volume%Last(), Ann_Density%Last() ,Ann_MudOrKick%Last() +! +!do imud=1, ChokeLine_MudDischarged_Volume%Length() +! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud) +!enddo + + + +!write(*,*) 'Ann_Kick_Saved_Volume_Final,data%State%MudSystem%MudVolume_InjectedFromAnn' , Ann_Kick_Saved_Volume_Final,data%State%MudSystem%MudVolume_InjectedFromAnn + +!write(*,*) 'begining chokeline==' + + + + + + + + data%State%MudSystem%ChokeLineFlowRate = data%State%MUD(4)%Q +!WRITE (*,*) 'data%State%MUD(4)%Q', data%State%MUD(4)%Q + + + if (data%State%MudSystem%NewPipeFilling == 0) then ! .or. UtubeFilling==0) then + data%State%MudSystem%ChokeLineFlowRate= 0. + endif + + + do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()-2 + if ( data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then + write(*,*) 'error_location is 1' + error_occured = 1 + endif + enddo + + + +! +!do imud=1, st_MudDischarged_Volume%Length() +! write(*,*) 'st:', imud, St_MudDischarged_Volume%Array(imud), St_Mud_Backhead_X%Array(imud) ,St_Mud_Forehead_X%Array(imud) +!enddo + + +!========================CHOKE LINE ENTRANCE================= + +!if ( Ann_Kick_Saved_Volume > 0.0 .and. ( Ann_Saved_MudDischarged_Volume-((Qlost/60.0d0)*DeltaT_Mudline) ) == 0.0 ) then + if ( data%State%MudSystem%Ann_Kick_Saved_Volume > 1.0e-5 .and. ( data%State%MudSystem%MudVolume_InjectedFromAnn ) <= 1.0e-5 ) then + +!WRITE (*,*) 'only kick enters to chokeline, Casing pressure = ', PressureGauges(2) + + if (data%State%MudSystem%ChokeLine_MudOrKick%First() == 0) then + call data%State%MudSystem%ChokeLine_Density%AddToFirst (data%State%MudSystem%Ann_KickSaved_Density) + call data%State%MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (0.d0) + call data%State%MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1) + call data%State%MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1) + call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_MudOrKick%AddToFirst (data%State%MudSystem%Saved_Ann_MudOrKick) + + data%State%MudSystem%ChokeLineDensity_Old= data%State%MudSystem%Ann_KickSaved_Density + + endif + + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ data%State%MudSystem%Ann_Kick_Saved_Volume !(gal) + + endif + + + do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()-2 + if ( data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then + write(*,*) 'error_location is 2' + + error_occured = 1 + + endif + enddo + + + +!if ( Ann_Kick_Saved_Volume == 0.0 .and. ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 ) then + if ( data%State%MudSystem%Ann_Kick_Saved_Volume <= 1.0e-5 .and. data%State%MudSystem%MudVolume_InjectedFromAnn > 1.0e-5 ) then + +!WRITE (*,*) 'only mud enters to chokeline' + + + if ((data%State%MudSystem%Ann_to_Choke_2mud == .false. .and. ABS(data%State%MudSystem%ChokeLineDensity_Old - data%State%MudSystem%Ann_MudSaved_Density) >= data%State%MudSystem%DensityMixTol) .or. data%State%MudSystem%ChokeLine_MudOrKick%First() /= 0) then ! new mud is pumped + call data%State%MudSystem%ChokeLine_Density%AddToFirst (data%State%MudSystem%Ann_MudSaved_Density) + call data%State%MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1) + call data%State%MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1) + call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_MudOrKick%AddToFirst (0) + + data%State%MudSystem%ChokeLineDensity_Old= data%State%MudSystem%Ann_MudSaved_Density + endif + +!ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) !(gal) + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ (data%State%MudSystem%MudVolume_InjectedFromAnn) !(gal) + + + + endif + + + + do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()-2 + if ( data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then + write(*,*) 'error_location is 3' + error_occured = 1 + + endif + enddo + + +!if ( Ann_Kick_Saved_Volume > 0.0 .and. (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 .and. ChokeLine_MudOrKick%First() /= 0 ) then + if ( data%State%MudSystem%Ann_Kick_Saved_Volume > 1.0e-5 .and. (data%State%MudSystem%MudVolume_InjectedFromAnn) > 1.0e-5 .and. data%State%MudSystem%ChokeLine_MudOrKick%First() /= 0 ) then + + WRITE (*,*) 'Kick Enters Choke line Last Time' + + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ data%State%MudSystem%Ann_Kick_Saved_Volume !(gal) + + + + call data%State%MudSystem%ChokeLine_Density%AddToFirst (data%State%MudSystem%Ann_MudSaved_Density) +!call ChokeLine_MudDischarged_Volume%AddToFirst (Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) + call data%State%MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (data%State%MudSystem%MudVolume_InjectedFromAnn) + call data%State%MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1) + call data%State%MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1) + call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_MudOrKick%AddToFirst (0) + + data%State%MudSystem%ChokeLineDensity_Old= data%State%MudSystem%Ann_MudSaved_Density + + + + + +!ELSE if ( Ann_Kick_Saved_Volume > 0.0 .and. ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) > 0.0 .and. ChokeLine_MudOrKick%First() == 0 ) then + ELSE if ( data%State%MudSystem%Ann_Kick_Saved_Volume > 1.0e-5 .and. ( data%State%MudSystem%MudVolume_InjectedFromAnn ) > 1.0e-5 .and. data%State%MudSystem%ChokeLine_MudOrKick%First() == 0 ) then + WRITE (*,*) 'Kick Enters Choke line First Time' + + + +!ChokeLine_MudDischarged_Volume%Array(1)= ChokeLine_MudDischarged_Volume%Array(1)+ ( Ann_Saved_MudDischarged_Volume - ((Qlost/60.0d0)*DeltaT_Mudline) ) !(gal) + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(1)+ ( data%State%MudSystem%MudVolume_InjectedFromAnn ) !(gal) + + + + + call data%State%MudSystem%ChokeLine_Density%AddToFirst (data%State%MudSystem%Ann_KickSaved_Density) + call data%State%MudSystem%ChokeLine_MudDischarged_Volume%AddToFirst (data%State%MudSystem%Ann_Kick_Saved_Volume) + call data%State%MudSystem%ChokeLine_Mud_Forehead_X%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_Mud_Forehead_section%AddToFirst (1) + call data%State%MudSystem%ChokeLine_Mud_Backhead_X%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_Mud_Backhead_section%AddToFirst (1) + call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%ChokeLine_MudOrKick%AddToFirst (data%State%MudSystem%Saved_Ann_MudOrKick) + + data%State%MudSystem%ChokeLineDensity_Old= data%State%MudSystem%Ann_KickSaved_Density + + + endif + + do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length()-2 + if ( data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) ==1 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+1) ==0 .and. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud+2) ==1 ) then + write(*,*) 'error_location is 4' + error_occured = 1 + + endif + enddo + + if (error_occured == 1) then + + do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length() + write(*,*) 'ChokeLine:', imud, data%State%MudSystem%ChokeLine_Density%Array(imud) ,data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) + enddo + + endif + + +!========================================================== + +! +!write(*,*) 'after add chokeline==' +! +! do imud=1, ChokeLine_MudDischarged_Volume%Length() +! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud) +! enddo +! +!write(*,*) 'after add chokeline==' +! +! + + +!=============== save Choke Mud data========================== + data%State%MudSystem%ChokeMudVolumeSum= 0.d0 +!Ann_MudSaved_Density= 0.d0 +!Ann_KickSaved_Density= 0.d0 + data%State%MudSystem%Choke_Saved_MudDischarged_Volume= 0.d0 + data%State%MudSystem%Choke_Kick_Saved_Volume= 0.d0 + data%State%MudSystem%Saved_Choke_MudOrKick= 0 + + + + + do imud=1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length() + + data%State%MudSystem%ChokeMudVolumeSum= data%State%MudSystem%ChokeMudVolumeSum + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud) + + if ( data%State%MudSystem%ChokeMudVolumeSum > data%State%MudSystem%ChokeLine_VolumeCapacity ) then + + IF (data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) == 0) THEN + data%State%MudSystem%Choke_MudSaved_Density = data%State%MudSystem%ChokeLine_Density%Array(imud) + data%State%MudSystem%Choke_Saved_MudDischarged_Volume = data%State%MudSystem%ChokeMudVolumeSum - data%State%MudSystem%ChokeLine_VolumeCapacity + ELSEIF (data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) > 0 .AND. data%State%MudSystem%ChokeLine_MudOrKick%Array(imud) <100) THEN ! 104= AIR + data%State%MudSystem%Choke_Kick_Saved_Volume = data%State%MudSystem%ChokeMudVolumeSum - data%State%MudSystem%ChokeLine_VolumeCapacity + data%State%MudSystem%Saved_Choke_MudOrKick= data%State%MudSystem%ChokeLine_MudOrKick%Array (imud) + data%State%MudSystem%Choke_KickSaved_Density= data%State%MudSystem%ChokeLine_Density%Array(imud) + END IF + + do ii= imud + 1, data%State%MudSystem%ChokeLine_MudDischarged_Volume%Length() + + IF (data%State%MudSystem%ChokeLine_MudOrKick%Array(ii) == 0) THEN + data%State%MudSystem%Choke_MudSaved_Density = ((data%State%MudSystem%Choke_MudSaved_Density * data%State%MudSystem%Choke_Saved_MudDischarged_Volume) + (data%State%MudSystem%ChokeLine_Density%Array(ii) * data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%Choke_Saved_MudDischarged_Volume + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(ii)) + data%State%MudSystem%Choke_Saved_MudDischarged_Volume = data%State%MudSystem%Choke_Saved_MudDischarged_Volume + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(ii) + ELSEIF (data%State%MudSystem%ChokeLine_MudOrKick%Array(ii) > 0 .AND. data%State%MudSystem%ChokeLine_MudOrKick%Array(ii) <100) THEN ! 104= AIR + data%State%MudSystem%Choke_Kick_Saved_Volume = data%State%MudSystem%Choke_Kick_Saved_Volume + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(ii) + data%State%MudSystem%Saved_Choke_MudOrKick= data%State%MudSystem%ChokeLine_MudOrKick%Array (ii) + data%State%MudSystem%Choke_KickSaved_Density= data%State%MudSystem%ChokeLine_Density%Array(ii) + END IF + enddo + + +!WRITE (*,*) 'Choke_Saved_Mud_Volume, Choke_Kick_Saved_Volume', Choke_Saved_MudDischarged_Volume, Choke_Kick_Saved_Volume + exit ! exits do + + endif + + enddo +data%State%MudSystem%Choke_Saved_MudDischarged_Volume_Final= data%State%MudSystem%Choke_Saved_MudDischarged_Volume !+ Choke_Kick_Saved_Volume +data%State%MudSystem%Choke_Kick_Saved_Volume_Final= data%State%MudSystem%Choke_Kick_Saved_Volume +!====================================================================== + + +! +!do imud=1, ChokeLine_MudDischarged_Volume%Length() +! write(*,*) 'a)ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud) ,ChokeLine_MudOrKick%Array(imud) +!enddo + + +!write(*,*) 'choke_Mud sum=' , sum(ChokeLine_MudDischarged_Volume%Array(:)) +!write(*,*) 'choke_cap=' , ChokeLine_VolumeCapacity +!write(*,*) 'Choke_Saved_Mud=' , Choke_Saved_MudDischarged_Volume_Final +!write(*,*) 'Choke_Saved_Kick=' , Choke_Kick_Saved_Volume_Final + + + +!========================Choke Line================= + +imud=0 + do while (imud < data%State%MudSystem%ChokeLine_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%ChokeLine_Mud_Backhead_X%Array(imud)= data%State%MudSystem%ChokeLine_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%ChokeLine_Mud_Backhead_section%Array(imud)= data%State%MudSystem%ChokeLine_Mud_Forehead_section%Array(imud-1) + endif + + +!DirectionCoef= (Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud))) & +! / ABS(Xend_PipeSection(St_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(St_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)= (data%Configuration%BopStack%ChokeLineLength- data%State%MudSystem%ChokeLine_Mud_Backhead_X%Array(imud))* data%State%MudSystem%Area_ChokeLineFt !(ft^3) + + data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + if ( data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%ChokeLine_Mud_Forehead_section%Array(imud)= data%State%MudSystem%ChokeLine_Mud_Backhead_section%Array(imud) + data%State%MudSystem%ChokeLine_Mud_Forehead_X%Array(imud)= data%State%MudSystem%ChokeLine_Mud_Backhead_X%Array(imud)+ (data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_ChokeLineFt +! 7.48 is for gal to ft^3 + + else + + data%State%MudSystem%isection= data%State%MudSystem%ChokeLine_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)- data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > 1) then ! last pipe section(Chokeline exit) + data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)= data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)- data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%ChokeLine_Mud_Forehead_X%Array(imud)= data%Configuration%BopStack%ChokeLineLength + data%State%MudSystem%ChokeLine_Mud_Forehead_section%Array(imud)= 1 + if (data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call data%State%MudSystem%ChokeLine_MudDischarged_Volume%Remove (imud) + call data%State%MudSystem%ChokeLine_Mud_Backhead_X%Remove (imud) + call data%State%MudSystem%ChokeLine_Mud_Backhead_section%Remove (imud) + call data%State%MudSystem%ChokeLine_Mud_Forehead_X%Remove (imud) + call data%State%MudSystem%ChokeLine_Mud_Forehead_section%Remove (imud) + call data%State%MudSystem%ChokeLine_Density%Remove (imud) + call data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Remove (imud) + call data%State%MudSystem%ChokeLine_EmptyVolume_inBackheadLocation%Remove (imud) + call data%State%MudSystem%ChokeLine_MudOrKick%Remove (imud) + + endif + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%ChokeLine_VolumeCapacity !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%ChokeLine_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%ChokeLine_Mud_Forehead_X%Array(imud)= data%State%MudSystem%xx * data%Configuration%BopStack%ChokeLineLength + exit + else + data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%ChokeLine_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%ChokeLine_VolumeCapacity + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + + endif + + enddo + + endif + + enddo +!========================Choke Line END================= + +!do imud=1, ChokeLine_MudDischarged_Volume%Length() +! write(*,*) 'b)ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud) ,ChokeLine_MudOrKick%Array(imud) +!enddo + + data%State%MudSystem%ChokeOutletDensity= data%State%MudSystem%ChokeLine_Density%Last() ! used in MudSystem + + + + + + do i=1, data%State%MudSystem%ChokeLine_MudOrKick%Length() +!write(*,555) i,'Choke_Volume(i), type=' ,ChokeLine_MudDischarged_Volume%Array(i),ChokeLine_MudOrKick%Array(i) + + IF (IEEE_Is_NaN(data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(i))) call ErrorStop('NaN in Choke Volume-Plot') + IF (data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(i)<=0.) call ErrorStop('Choke Volume= <=0' , data%State%MudSystem%ChokeLine_MudDischarged_Volume%Array(i)) + enddo + +555 FORMAT(I3,5X,A42,(f12.5),5X,I3) + + +!write(*,*) 'after sorting chokeline==' +!IF (ANY(ChokeLine_MudOrKick%Array(:) > 0)) THEN +! do imud=1, ChokeLine_MudDischarged_Volume%Length() +! write(*,*) 'ChokeLine:', imud, ChokeLine_MudDischarged_Volume%Array(imud), ChokeLine_Density%Array(imud) ,ChokeLine_MudOrKick%Array(imud) +! enddo +!END IF + + +!do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +!enddo +! +!write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + + +!write(*,*) '==after sorting chokeline' + + + end subroutine ChokeLineMud + + + + + +subroutine Choke_GasSound ! is called in subroutine CirculationCodeSelect + + +use CSounds +!Use GeoElements_FluidModule +!USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ +!use ConfigurationVariables +!USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!!use CDataDisplayConsole +!@ use ConfigurationVariables , StandPipePressureDataDisplay=>StandPipePressure +!!use CManifolds +!use ConfigurationVariables !@ +!USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!!use CChokeManifoldVariables + use SimulationVariables +!use CTanks +!@use ConfigurationVariables, TripTankVolume2 => TripTankVolume, TripTankDensity2 => TripTankDensity +!USE sROP_Other_Variables +!USE sROP_Variables +!use KickVARIABLESModule +!use PressureDisplayVARIABLESModule +!Use CError +!Use , intrinsic :: IEEE_Arithmetic + + + + + + if ( data%State%MudSystem%ChokeLine_MudOrKick%Last() > 0 .AND. data%State%MudSystem%WellToChokeManifoldOpen == .true.) then +!WellToChokeManifoldWasOpen + + data%State%MudSystem%SoundGasThroughChoke = 100 !100:chon dar adadhaye kamtar az 100 seda ghaat mishavad. eslah shavad.5.8.98 !int (min(ChokeLineFlowRate/2. , 100.)) + print* , 'SoundGasThroughChoke1=', data%State%MudSystem%SoundGasThroughChoke +!WRITE (*,*) 'WellToChokeManifoldWasOpen-Sound', WellToChokeManifoldWasOpen + WRITE (*,*) 'WellToChokeManifoldOpen', data%State%MudSystem%WellToChokeManifoldOpen + else + data%State%MudSystem%SoundGasThroughChoke = 0 + print* , 'SoundGasThroughChoke2=', data%State%MudSystem%SoundGasThroughChoke + endif +!print* , 'SoundGasThroughChoke3=', SoundGasThroughChoke + + + + call SetSoundGasThroughChoke(data%State%MudSystem%SoundGasThroughChoke) + + + end subroutine Choke_GasSound diff --git a/Equipments/MudSystem/Trip_Out_andPump.f90 b/Equipments/MudSystem/Trip_Out_andPump.f90 index b42b3cc..55480db 100644 --- a/Equipments/MudSystem/Trip_Out_andPump.f90 +++ b/Equipments/MudSystem/Trip_Out_andPump.f90 @@ -16,7 +16,7 @@ use SimulationVariables !@@@ !use CChokeManifoldVariables use SimulationVariables !use CTanks - !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity USE sROP_Other_Variables USE sROP_Variables use KickVARIABLESModule @@ -77,7 +77,7 @@ Real(8) ExcessMudVolume_Remained,SavedDensityForOp data%State%MudSystem%total_add = data%State%MudSystem%total_add + ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) - if (data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then data%State%MudSystem%total_add= 0. endif @@ -1138,7 +1138,7 @@ imud= data%State%MudSystem%Ann_Mud_Forehead_X%Length() + 1 ! <<< Fracture Shoe Lost - IF ( data%State%MudSystem%ShoeLost .and. Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then + IF ( data%State%MudSystem%ShoeLost .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then @@ -1350,7 +1350,7 @@ imud=0 data%State%MudSystem%total_injected = data%State%MudSystem%total_injected + data%State%MudSystem%MudVolume_InjectedFromAnn - if (data%EquipmentControl%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then data%State%MudSystem%total_injected= 0. endif !write(*,*) ' data%State%MudSystem%MudVolume_InjectedFromAnn =' , data%State%MudSystem%MudVolume_InjectedFromAnn diff --git a/Equipments/MudSystem/Trip_Out_andPump.i90 b/Equipments/MudSystem/Trip_Out_andPump.i90 new file mode 100644 index 0000000..cdd51e4 --- /dev/null +++ b/Equipments/MudSystem/Trip_Out_andPump.i90 @@ -0,0 +1,1371 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/Trip_Out_andPump.f90" +subroutine TripOut_and_Pump ! is called in subroutine CirculationCodeSelect + + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!use CDataDisplayConsole +!!@ use ConfigurationVariables , StandPipePressureDataDisplay=>StandPipePressure +!use CManifolds + use SimulationVariables !@ + USE CHOKEVARIABLES +!use ConfigurationVariables !@ +!use CChokeManifoldVariables + use SimulationVariables +!use CTanks +!@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + USE sROP_Other_Variables + USE sROP_Variables + use KickVARIABLESModule + Use CShoeVariables + use CError + + implicit none + +integer i,ii,AddLocation, iloc_edited, iloc_changedTo2 +Real(8) ExcessMudVolume_Remained,SavedDensityForOp + +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + + data%State%MudSystem%StringFlowRate= data%State%MUD(2)%Q + data%State%MudSystem%AnnulusFlowRate= data%State%MUD(2)%Q +!write(*,*) 'data%State%MUD(2)%Q=====' , data%State%MUD(2)%Q + + + write(*,*) 'Trip Out' + +! write(*,*) 'check point 1==' +! +! +! +! do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! enddo +! +! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) +! +! +!write(*,*) '==check point 1' + +!========================Horizontal PIPE ENTRANCE================= + + if (ABS(data%State%MudSystem%SuctionDensity_Old - data%State%MudSystem%Suction_Density_MudSystem) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped + + call data%State%MudSystem%Hz_Density%AddToFirst (data%State%MudSystem%Suction_Density_MudSystem) + call data%State%MudSystem%Hz_MudDischarged_Volume%AddToFirst (0.0d0) + call data%State%MudSystem%Hz_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(1)) + call data%State%MudSystem%Hz_Mud_Forehead_section%AddToFirst (1) + call data%State%MudSystem%Hz_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(1)) + call data%State%MudSystem%Hz_Mud_Backhead_section%AddToFirst (1) + call data%State%MudSystem%Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Hz_MudOrKick%AddToFirst (0) + + data%State%MudSystem%SuctionDensity_Old= data%State%MudSystem%Suction_Density_MudSystem + endif + +!========================Horizontal PIPE STRING================= + + data%State%MudSystem%Hz_MudDischarged_Volume%Array(1)= data%State%MudSystem%Hz_MudDischarged_Volume%Array(1)+ ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + + + data%State%MudSystem%total_add = data%State%MudSystem%total_add + ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) + + + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + data%State%MudSystem%total_add= 0. + endif + +!write(*,*) ' total decrease(add to HZ)=' , total_add +!write(*,*) ' add to HZ=' , ((data%State%MudSystem%StringFlowRate/60.0d0)*DeltaT_Mudline) + + + +imud=0 + do while (imud < data%State%MudSystem%Hz_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%Hz_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud-1) + endif + + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Hz_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud) + data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Hz_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)) + + else + + + data%State%MudSystem%isection= data%State%MudSystem%Hz_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Hz_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > 1) then ! (horizontal pipe exit) + data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(1) + data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud)= 1 + + if (data%State%MudSystem%Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveHzMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Hz_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Hz_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Hz_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + endif + + enddo + + endif + + enddo +!========================Horizontal PIPE END================= + + + +!========================Utube1 Air Element Removing================= + +!if (UtubeMode1Activated== .true.) then ! StringUpdate == .true. +! +! StringDensity_Old= data%State%MudSystem%St_Density%Array(2) +! +! UtubeMode1Activated= .false. +!endif + +!========================Utube1 Air Element Removing================= + + +!========================Utube2 Removing from Annulus================= + + if (data%State%MudSystem%UtubeMode2Activated== .true.) then ! StringUpdate == .true. + data%State%MudSystem%TotalAddedVolume=0. + + if (data%State%MudSystem%Ann_MudOrKick%Last() == 104) then !movaghati. albate age merge anjam shode bashe moshkeli nist + call RemoveAnnulusMudArrays(data%State%MudSystem%Ann_MudOrKick%Length()) + endif + + data%State%MudSystem%UtubeMode2Activated= .false. + endif + + +!========================Utube2 Removing from Annulus End================= + +!========================New Pipe Filling================= + + if (data%State%MudSystem%AddedElementsToString > 0) then ! StringUpdate == .true. + +!NoPipeAdded= F_StringIntervalCounts - F_StringIntervalCountsOld + + + data%State%MudSystem%NewPipeFilling=0 + + IF (data%State%MudSystem%St_MudOrKick%First() == 104) then + data%State%MudSystem%St_MudDischarged_Volume%Array(1) = data%State%MudSystem%St_MudDischarged_Volume%Array(1) + sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:1+data%State%MudSystem%AddedElementsToString)) ! new pipe is filled by air + else + call data%State%MudSystem%St_Density%AddToFirst (0.d0) + call data%State%MudSystem%St_MudDischarged_Volume%AddToFirst (sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:1+data%State%MudSystem%AddedElementsToString))) + call data%State%MudSystem%St_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Forehead_section%AddToFirst (2) + call data%State%MudSystem%St_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Backhead_section%AddToFirst (2) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.d0) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.d0) + call data%State%MudSystem%St_MudOrKick%AddToFirst (104) + endif + + endif + +!F_StringIntervalCountsOld= F_StringIntervalCounts + + + + if (data%State%MudSystem%NewPipeFilling == 0) then ! 2= is the first element of string (1= is for Hz pipe) + + + data%State%MudSystem%LackageMudVolume= data%State%MudSystem%St_MudDischarged_Volume%Array(1) ! = Air element + + +!write(*,*) 'LackageMudVolume=' , LackageMudVolume + + + + if (ABS(data%State%MudSystem%St_Density%Array(2) - data%State%MudSystem%Hz_Density%Last()) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped + call data%State%MudSystem%St_Density%AddTo (2,data%State%MudSystem%Hz_Density%Last()) + call data%State%MudSystem%St_MudDischarged_Volume%AddTo (2,0.d0) + call data%State%MudSystem%St_Mud_Forehead_X%AddTo (2,data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Forehead_section%AddTo (2 , 2) + call data%State%MudSystem%St_Mud_Backhead_X%AddTo (2,data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Backhead_section%AddTo (2 ,2) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddTo (2,0.d0) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddTo (2,0.d0) + call data%State%MudSystem%St_MudOrKick%AddTo (2,0) + +!StringDensity_Old= Hz_Density%Last() + endif + + + data%State%MudSystem%St_MudDischarged_Volume%Array(2)= data%State%MudSystem%St_MudDischarged_Volume%Array(2)+ min( ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline), data%State%MudSystem%LackageMudVolume) !(gal) + + data%State%MudSystem%St_MudDischarged_Volume%Array(1)= data%State%MudSystem%St_MudDischarged_Volume%Array(1)- min( ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline), data%State%MudSystem%LackageMudVolume) ! air(gal) + +!LackageMudVolumeAfterFilling= sum(PipeSection_VolumeCapacity(2:F_StringIntervalCounts)) - sum(St_MudDischarged_Volume%Array(:)) + + data%State%MudSystem%LackageMudVolumeAfterFilling= data%State%MudSystem%St_MudDischarged_Volume%Array(1) ! last time it should be zero + + + + if (data%State%MudSystem%LackageMudVolumeAfterFilling == 0.) then + data%State%MudSystem%NewPipeFilling= 1 + call RemoveStringMudArrays(1) + data%State%MudSystem%St_Mud_Backhead_X%Array(1) = data%State%MudSystem%Xstart_PipeSection(2) + data%State%MudSystem%St_Mud_Backhead_section%Array(1) = 2 + endif + + endif + +!========================New Pipe Filling End================= + + + if (data%State%MudSystem%NewPipeFilling == 0) then + data%State%MudSystem%StringFlowRate= 0. + data%State%MudSystem%AnnulusFlowRate= 0. + endif + + data%State%MudSystem%StringFlowRateFinal= data%State%MudSystem%StringFlowRate + data%State%MudSystem%AnnulusFlowRateFinal= data%State%MudSystem%AnnulusFlowRate + + +!========================STRING ENTRANCE================= + if (data%State%MudSystem%StringFlowRateFinal > 0.0 .and. ABS(data%State%MudSystem%St_Density%First() - data%State%MudSystem%Hz_Density%Last()) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped +!if (ABS(StringDensity_Old - Hz_Density%Last()) >= DensityMixTol) then ! new mud is pumped + call data%State%MudSystem%St_Density%AddToFirst (data%State%MudSystem%Hz_Density%Last()) + call data%State%MudSystem%St_MudDischarged_Volume%AddToFirst (0.0d0) + call data%State%MudSystem%St_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Forehead_section%AddToFirst (2) + call data%State%MudSystem%St_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Backhead_section%AddToFirst (2) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%St_MudOrKick%AddToFirst (0) + +!StringDensity_Old= Hz_Density%Last() + endif + data%State%MudSystem%St_MudDischarged_Volume%Array(1)= data%State%MudSystem%St_MudDischarged_Volume%Array(1)+ ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + +!=============== save String Mud data=========== + data%State%MudSystem%StMudVolumeSum= 0.d0 +!St_MudSaved_Density= 0.d0 + data%State%MudSystem%St_Saved_MudDischarged_Volume= 0.d0 +!Saved_St_MudOrKick= 0 +!Ann_to_Choke_2mud= .false. + + do imud=1, data%State%MudSystem%St_MudDischarged_Volume%Length() + data%State%MudSystem%StMudVolumeSum= data%State%MudSystem%StMudVolumeSum + data%State%MudSystem%St_MudDischarged_Volume%Array(imud) + if ( data%State%MudSystem%StMudVolumeSum > sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:data%State%F_Counts%StringIntervalCounts)) ) then +!IF (St_MudOrKick%Array(imud) == 0) THEN + data%State%MudSystem%St_MudSaved_Density = data%State%MudSystem%St_Density%Array(imud) + data%State%MudSystem%St_Saved_MudDischarged_Volume = data%State%MudSystem%StMudVolumeSum - sum(data%State%MudSystem%PipeSection_VolumeCapacity(2:data%State%F_Counts%StringIntervalCounts)) +!ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR +! St_Kick_Saved_Volume = StMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +! Saved_St_MudOrKick= St_MudOrKick%Array (imud) +! St_KickSaved_Density= data%State%MudSystem%St_Density%Array(imud) +!END IF + + do ii= imud + 1, data%State%MudSystem%St_MudDischarged_Volume%Length() +!IF (St_MudOrKick%Array(ii) == 0) THEN + data%State%MudSystem%St_MudSaved_Density = ((data%State%MudSystem%St_MudSaved_Density * data%State%MudSystem%St_Saved_MudDischarged_Volume) + (data%State%MudSystem%St_Density%Array(ii) * data%State%MudSystem%St_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%St_Saved_MudDischarged_Volume + data%State%MudSystem%St_MudDischarged_Volume%Array(ii)) + data%State%MudSystem%St_Saved_MudDischarged_Volume = data%State%MudSystem%St_Saved_MudDischarged_Volume + data%State%MudSystem%St_MudDischarged_Volume%Array(ii) + +!ELSEIF (St_MudOrKick%Array(imud) > 0 .AND. St_MudOrKick%Array(imud) <100) THEN ! 104= AIR +! St_Kick_Saved_Volume = St_Kick_Saved_Volume + St_MudDischarged_Volume%Array(ii) +! Saved_St_MudOrKick= St_MudOrKick%Array (ii) +! St_KickSaved_Density= data%State%MudSystem%St_Density%Array(ii) +!END IF + enddo + + +!WRITE (*,*) 'St_Saved_Mud_Volume, St_Kick_Saved_Volume', St_Saved_MudDischarged_Volume, St_Kick_Saved_Volume + exit ! exits do + + endif + + enddo +data%State%MudSystem%St_Saved_MudDischarged_Volume_Final= data%State%MudSystem%St_Saved_MudDischarged_Volume + +IF (data%State%MudSystem%WellHeadIsOpen) data%State%MudSystem%MudVolume_InjectedToBH = data%State%MudSystem%St_Saved_MudDischarged_Volume_Final + +!====================================================================== + + +!========================STRING================= + +imud=0 + do while (imud < data%State%MudSystem%St_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%St_Mud_Backhead_X%Array(imud)= data%State%MudSystem%St_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%St_Mud_Backhead_section%Array(imud)= data%State%MudSystem%St_Mud_Forehead_section%Array(imud-1) + endif + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))- data%State%MudSystem%St_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%St_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + if ( data%State%MudSystem%St_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%MudSystem%St_Mud_Backhead_section%Array(imud) + data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= data%State%MudSystem%St_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%St_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%St_Mud_Backhead_section%Array(imud)) +! 7.48 is for gal to ft^3 + + else + + data%State%MudSystem%isection= data%State%MudSystem%St_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > data%State%F_Counts%StringIntervalCounts) then ! last pipe section(string exit) + data%State%MudSystem%St_MudDischarged_Volume%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts) + data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%F_Counts%StringIntervalCounts + + if (data%State%MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveStringMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + + endif + + enddo + + endif + + enddo +!========================STRING END================= + +!write(*,*) ' a before==' +! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +! +! do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! enddo +! +! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) +! +! +!write(*,*) '==== a before' + + iloc_changedTo2 = 0 + + IF (data%State%MudSystem%Op_MudOrKick%Last() /= 0 .and. data%State%MudSystem%Op_MudOrKick%Last()==data%State%MudSystem%Ann_MudOrKick%First()) then + data%State%MudSystem%iLoc=2 ! it may be 1,2,3 or more, all of them are kick + iloc_changedTo2= 1 + endif + + + + iloc_edited= 0 +!write(*,*) sum(Op_MudDischarged_Volume%Array(:)) , ((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) , Ann_MudDischarged_Volume%First() , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) + if (data%State%MudSystem%iLoc==2 .and. sum(data%State%MudSystem%Op_MudDischarged_Volume%Array(:))+((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline)+data%State%MudSystem%Ann_MudDischarged_Volume%First() < sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) ) then + data%State%MudSystem%iLoc = 1 + iloc_edited = 1 +!write(*,*) 'hellooooooo' + endif + + +!write(*,*) 'ann-cap:' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1 :F_StringIntervalCounts+F_AnnulusIntervalCounts) ) + + +!write(*,*) 'iloc====' , iloc +!MudVolume_InjectedToBH + + +!=============================Add PumpFlowRate to Bottom Hole ============================== +!if ( data%State%MudSystem%AnnulusFlowRate>0.0 ) then + if ( data%State%MudSystem%MudVolume_InjectedToBH > 0.0 ) then + + + if (KickVARIABLES%KickOffBottom) then ! (kickOffBottom = F) means kick is next to the bottom hole and usually kick is entering the + AddLocation= data%State%MudSystem%Op_Density%Length()-data%State%MudSystem%iLoc+1+1 ! well, thus pumped mud should be placed above the kick + else + AddLocation= data%State%MudSystem%Op_Density%Length()+1 + endif +!write(*,*) 'AddLocation====' , AddLocation + if ( AddLocation== 0) CALL ErrorStop ('AddLocation=0') + + + if ( ABS(data%State%MudSystem%St_Density%Last() - data%State%MudSystem%Op_Density%Array(AddLocation-1)) >= data%State%MudSystem%DensityMixTol ) then +!write(*,*) 'new pocket**' +!write(*,*) 'data%State%MudSystem%St_Density%Last()=' , data%State%MudSystem%St_Density%Last() +!write(*,*) 'Op_Density%Array(AddLocation-1)=' , Op_Density%Array(AddLocation-1) + + + call data%State%MudSystem%Op_Density% AddTo (AddLocation,data%State%MudSystem%St_Density%Last()) +!call Op_MudDischarged_Volume%AddTo (AddLocation,((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)) + call data%State%MudSystem%Op_MudDischarged_Volume%AddTo (AddLocation,data%State%MudSystem%MudVolume_InjectedToBH) + call data%State%MudSystem%Op_Mud_Forehead_X%AddTo (AddLocation,data%State%MudSystem%Xstart_OpSection(1)) + call data%State%MudSystem%Op_Mud_Forehead_section%AddTo (AddLocation,1) + call data%State%MudSystem%Op_Mud_Backhead_X%AddTo (AddLocation,data%State%MudSystem%Xstart_OpSection(1)) + call data%State%MudSystem%Op_Mud_Backhead_section%AddTo (AddLocation,1) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%AddTo (AddLocation,0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%AddTo (AddLocation,0.0d0) + call data%State%MudSystem%Op_MudOrKick%AddTo (AddLocation,0) + else +!write(*,*) 'merge**' +!write(*,*) 'density before=' , Op_Density%Array(AddLocation-1) +!write(*,*) 'data%State%MudSystem%St_Density%Last() for mix=' , data%State%MudSystem%St_Density%Last() + +!Op_Density%Array(AddLocation-1)= (Op_Density%Array(AddLocation-1)*Op_MudDischarged_Volume%Array(AddLocation-1)+data%State%MudSystem%St_Density%Last()*((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline))/(Op_MudDischarged_Volume%Array(AddLocation-1)+((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)) +!Op_MudDischarged_Volume%Array(AddLocation-1)= Op_MudDischarged_Volume%Array(AddLocation-1) + ((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) + + data%State%MudSystem%Op_Density%Array(AddLocation-1)= (data%State%MudSystem%Op_Density%Array(AddLocation-1)*data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)+data%State%MudSystem%St_Density%Last()*data%State%MudSystem%MudVolume_InjectedToBH)/(data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)+data%State%MudSystem%MudVolume_InjectedToBH) + data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1)= data%State%MudSystem%Op_MudDischarged_Volume%Array(AddLocation-1) + data%State%MudSystem%MudVolume_InjectedToBH +!write(*,*) 'density after=' , Op_Density%Array(AddLocation-1) + + endif + + endif +!=======================Add PumpFlowRate to Bottom Hole- End ============================== + +!write(*,*) 'pump added-before add to ann==' +! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +! +! do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! enddo +! +! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) +! +! +! +!write(*,*) 'pump added====before add to ann' + + +!=============== save OP Mud data to transfer to the annulus enterance due to tripin or kick + data%State%MudSystem%OpMudVolumeSum= 0.d0 +!Op_MudSaved_Density= 0.d0 +!Op_KickSaved_Density= 0.d0 + data%State%MudSystem%Op_Saved_MudDischarged_Volume= 0.d0 + data%State%MudSystem%Op_Kick_Saved_Volume= 0.d0 + data%State%MudSystem%Saved_Op_MudOrKick= 0 + data%State%MudSystem%Op_NeededVolume_ToFill= 0.d0 + + + + + do imud=1, data%State%MudSystem%Op_MudDischarged_Volume%Length() + + data%State%MudSystem%OpMudVolumeSum= data%State%MudSystem%OpMudVolumeSum + data%State%MudSystem%Op_MudDischarged_Volume%Array(imud) + + if ( data%State%MudSystem%OpMudVolumeSum > sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) ) then !1st mode + + IF (data%State%MudSystem%Op_MudOrKick%Array(imud) == 0) THEN + data%State%MudSystem%Op_MudSaved_Density = data%State%MudSystem%Op_Density%Array(imud) + data%State%MudSystem%Op_Saved_MudDischarged_Volume = data%State%MudSystem%OpMudVolumeSum - sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) + ELSE + + data%State%MudSystem%Op_Kick_Saved_Volume = data%State%MudSystem%OpMudVolumeSum - sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) + data%State%MudSystem%Saved_Op_MudOrKick= data%State%MudSystem%Op_MudOrKick%Array (imud) + data%State%MudSystem%Op_KickSaved_Density= data%State%MudSystem%Op_Density%Array(imud) + data%State%MudSystem%iLoc= 2 + iloc_changedTo2= 2 + END IF + + do ii= imud + 1, data%State%MudSystem%Op_MudDischarged_Volume%Length() + IF (data%State%MudSystem%Op_MudOrKick%Array(ii) == 0) THEN + data%State%MudSystem%Op_MudSaved_Density = ((data%State%MudSystem%Op_MudSaved_Density * data%State%MudSystem%Op_Saved_MudDischarged_Volume) + (data%State%MudSystem%Op_Density%Array(ii) * data%State%MudSystem%Op_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%Op_Saved_MudDischarged_Volume + data%State%MudSystem%Op_MudDischarged_Volume%Array(ii)) + data%State%MudSystem%Op_Saved_MudDischarged_Volume = data%State%MudSystem%Op_Saved_MudDischarged_Volume + data%State%MudSystem%Op_MudDischarged_Volume%Array(ii) + ELSE + data%State%MudSystem%Op_Kick_Saved_Volume = data%State%MudSystem%Op_Kick_Saved_Volume + data%State%MudSystem%Op_MudDischarged_Volume%Array(ii) + data%State%MudSystem%Saved_Op_MudOrKick= data%State%MudSystem%Op_MudOrKick%Array (ii) + data%State%MudSystem%Op_KickSaved_Density= data%State%MudSystem%Op_Density%Array(ii) + data%State%MudSystem%iLoc= 2 + iloc_changedTo2= 3 + END IF + enddo + + exit ! exits do + + endif + + enddo + + if ( sum(data%State%MudSystem%Op_MudDischarged_Volume%Array(:)) < sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) ) then !2nd & 3rd mode + + data%State%MudSystem%Op_NeededVolume_ToFill= sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) - sum(data%State%MudSystem%Op_MudDischarged_Volume%Array(:)) + endif + + +! +!write(*,*) 'Op_NeededVolume_ToFill=' , Op_NeededVolume_ToFill +!write(*,*) 'Op_Saved_MudDischarged_Volume=' , Op_Saved_MudDischarged_Volume +!write(*,*) 'Op_Kick_Saved_Volume=' , Op_Kick_Saved_Volume +! +!write(*,*) 'op cap=' , sum(OpSection_VolumeCapacity(1:F_BottomHoleIntervalCounts)) +!write(*,*) ' op sum mud=' , sum(Op_MudDischarged_Volume%Array(:)) + + + + + +!====================================================================== + + + + +!========================Tripping Out- 1st & 3rd Mode==================== + + + + if ( (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .or. data%State%MudSystem%Op_Saved_MudDischarged_Volume> 0.0) .or. & ! 1st Mode-Pump flow is more than trip out so fluid Level in Annulus Increases + (data%State%MudSystem%Op_NeededVolume_ToFill < ABS(data%State%MudSystem%DeltaVolumeAnnulusCapacity)) ) then !3rd Mode-fluid Level in Annulus Increases + + +!if ( Op_Kick_Saved_Volume > 0.0 .or. Op_Saved_MudDischarged_Volume> 0.0 ) write(*,*) 'trip out 1st mode' + + if ( data%State%MudSystem%Op_NeededVolume_ToFill > 0.0 .and. data%State%MudSystem%Op_NeededVolume_ToFill < ABS(data%State%MudSystem%DeltaVolumeAnnulusCapacity) ) then +! write(*,*) 'trip out 3rd mode' + + data%State%MudSystem%NewVolume= 0.d0 ! for condition iloc=1 + + SavedDensityForOp= data%State%MudSystem%Ann_Density%Array(1) + + ExcessMudVolume_Remained= data%State%MudSystem%Op_NeededVolume_ToFill + + + imud=1 + + Do + + if(data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) < ExcessMudVolume_Remained) then + ExcessMudVolume_Remained= ExcessMudVolume_Remained- data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) + call data%State%MudSystem%Ann_MudDischarged_Volume%Remove (imud) + call data%State%MudSystem%Ann_Mud_Backhead_X%Remove (imud) + call data%State%MudSystem%Ann_Mud_Backhead_section%Remove (imud) + call data%State%MudSystem%Ann_Mud_Forehead_X%Remove (imud) + call data%State%MudSystem%Ann_Mud_Forehead_section%Remove (imud) + call data%State%MudSystem%Ann_Density%Remove (imud) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Remove (imud) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (imud) + call data%State%MudSystem%Ann_MudOrKick%Remove (imud) + + elseif(data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) > ExcessMudVolume_Remained) then + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- ExcessMudVolume_Remained + exit + + else !(Ann_MudDischarged_Volume%Array(imud) == ExcessMudVolume_Remained) + call data%State%MudSystem%Ann_MudDischarged_Volume%Remove (imud) + call data%State%MudSystem%Ann_Mud_Backhead_X%Remove (imud) + call data%State%MudSystem%Ann_Mud_Backhead_section%Remove (imud) + call data%State%MudSystem%Ann_Mud_Forehead_X%Remove (imud) + call data%State%MudSystem%Ann_Mud_Forehead_section%Remove (imud) + call data%State%MudSystem%Ann_Density%Remove (imud) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Remove (imud) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Remove (imud) + call data%State%MudSystem%Ann_MudOrKick%Remove (imud) + exit + + endif + + enddo + + +!write(*,*) 'Op_NeededVolume_ToFill=' ,Op_NeededVolume_ToFill +!write(*,*) 'ABS(DeltaVolumeAnnulusCapacity)=' ,ABS(DeltaVolumeAnnulusCapacity) +!write(*,*) 'Op_MudOrKick%Last()=' ,Op_MudOrKick%Last() +!write(*,*) 'iloc=' ,iloc +!write(*,*) 'iloc_edited=' ,iloc_edited + + + endif + + +! (data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) - DeltaVolumeOp will be added to annulus + +!if (iLoc == 1) then + data%State%MudSystem%MudSection= data%State%F_Counts%StringIntervalCounts+1 + data%State%MudSystem%BackheadX= data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1) +!elseif (iLoc == 2) then +! MudSection= Kick_Forehead_section +! BackheadX= Kick_Forehead_X +!endif + +!========================ANNULUS ENTRANCE==================== +!if (KickMigration_2SideBit == .FALSE.) then +! if ( ABS(AnnulusSuctionDensity_Old - data%State%MudSystem%St_Density%Last()) >= DensityMixTol ) then ! new mud is pumped +! call Ann_Density%AddTo (iLoc,data%State%MudSystem%St_Density%Last()) +! call Ann_MudDischarged_Volume%AddTo (iLoc,0.0d0) +! call Ann_Mud_Forehead_X%AddTo (iLoc,BackheadX) +! call Ann_Mud_Forehead_section%AddTo (iLoc,MudSection) +! call Ann_Mud_Backhead_X%AddTo (iLoc,BackheadX) +! call Ann_Mud_Backhead_section%AddTo (iLoc,MudSection) +! call Ann_RemainedVolume_in_LastSection%AddTo (iLoc,0.0d0) +! call Ann_EmptyVolume_inBackheadLocation%AddTo (iLoc,0.0d0) +! call Ann_MudOrKick%AddTo (iLoc,0) +! call Ann_CuttingMud%AddTo (iLoc,0) +! +! AnnulusSuctionDensity_Old= data%State%MudSystem%St_Density%Last() +! +! MudIsChanged= .true. +! endif +! +! Ann_MudDischarged_Volume%Array(iLoc)= Ann_MudDischarged_Volume%Array(iLoc)+ ((data%State%MudSystem%AnnulusFlowRate/60.0d0)*DeltaT_Mudline) - ((2-iloc)*ABS(DeltaVolumePipe)) !(gal) +! +!endif + + + + + data%State%MudSystem%Ann_Mud_Backhead_section%Array(1)= data%State%MudSystem%MudSection !it is needed to be updated for (a condition that one pipe is removed from Annulus due to trip out)- (and add pipe) + data%State%MudSystem%Ann_Mud_Backhead_X%Array(1)= data%State%MudSystem%BackheadX + + + +!iloc=1 : (2-iloc)=1 normal +!iloc=2 : (2-iloc)=0 kick influx or migration is in annulus + +!========================Same to Tripping In==================== + +!write(*,*) 'Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume=' , Op_Kick_Saved_Volume,Op_Saved_MudDischarged_Volume + + + if (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .and. data%State%MudSystem%Ann_MudOrKick%First() == 0) then !1st Mode + write(*,*) 'Kick influx enters Annulus' + call data%State%MudSystem%Ann_Density%AddToFirst (data%State%MudSystem%Op_KickSaved_Density) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddToFirst (data%State%MudSystem%Op_Kick_Saved_Volume) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1)) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddToFirst (data%State%F_Counts%StringIntervalCounts+1) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddToFirst (data%State%MudSystem%Saved_Op_MudOrKick) !<<<<<<<< + call data%State%MudSystem%Ann_CuttingMud%AddToFirst (0) + elseif (data%State%MudSystem%Op_Kick_Saved_Volume > 0.0 .and. data%State%MudSystem%Ann_MudOrKick%First() /= 0) then + data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) + data%State%MudSystem%Op_Kick_Saved_Volume + endif + + + + if ( data%State%MudSystem%Op_NeededVolume_ToFill > 0.0 .and. (data%State%MudSystem%Op_NeededVolume_ToFill < ABS(data%State%MudSystem%DeltaVolumeAnnulusCapacity)) .and. data%State%MudSystem%Op_MudOrKick%Last() == 0 .and. (data%State%MudSystem%iLoc==2 .or. iloc_edited==1)) then !3rd Mode +!write(*,*) 'checkpoint 0' +!! for avoid kick separation -Op_MudOrKick%Last() == 0: because of pump + data%State%MudSystem%NewVolume= ((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) ! =volume that should be added to iloc=2 in Ann + call RemoveOpMudArrays(data%State%MudSystem%Op_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann in %%1 section + if ( data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) > ((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) ) then! 1st in Ann = kick ,, we expect: ((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline)= OpMudVolLast + data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) - ((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())+ ((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) ! kick + else + call RemoveAnnulusMudArrays(1) !kick is removed + data%State%MudSystem%iLoc= 1 + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())+ ((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) + write(*,*) 'little expand' +! including a little expand + endif + endif + + if (data%State%MudSystem%Op_Saved_MudDischarged_Volume> 0.0) then !1st Mode + data%State%MudSystem%NewDensity= data%State%MudSystem%Op_MudSaved_Density +!write(*,*) 'iloc,...' , iloc,((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline),Op_Saved_MudDischarged_Volume + if (data%State%MudSystem%iLoc==1) then +!write(*,*) 'checkpoint 1' + data%State%MudSystem%NewVolume= data%State%MudSystem%Op_Saved_MudDischarged_Volume + elseif (real(((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline)) - real(data%State%MudSystem%Op_Saved_MudDischarged_Volume) > 0.d0 ) then ! for avoid kick separation +!write(*,*) 'checkpoint 2' + data%State%MudSystem%NewVolume= ((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) !- Op_Saved_MudDischarged_Volume + call RemoveOpMudArrays(data%State%MudSystem%Op_Density%Length()) ! mud here is removed and then will be added to iloc=2 in Ann + if ( data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) > (((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) - data%State%MudSystem%Op_Saved_MudDischarged_Volume) ) then! 1st in Ann = kick + data%State%MudSystem%Ann_MudDischarged_Volume%Array(1)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(1) - (((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) - data%State%MudSystem%Op_Saved_MudDischarged_Volume) + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())+ (((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) - data%State%MudSystem%Op_Saved_MudDischarged_Volume) !kick + else + call RemoveAnnulusMudArrays(1) !kick is removed + data%State%MudSystem%iLoc =1 + data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array(data%State%MudSystem%Op_Density%Length())+ (((data%State%MudSystem%AnnulusFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) - data%State%MudSystem%Op_Saved_MudDischarged_Volume) + write(*,*) 'little expand' + +! including a little expand + endif + + + else ! iloc==2 , ((data%State%MudSystem%AnnulusFlowRate/60.d0)*DeltaT_Mudline) == Op_Saved_MudDischarged_Volume +!write(*,*) 'checkpoint 3' + data%State%MudSystem%NewVolume= data%State%MudSystem%Op_Saved_MudDischarged_Volume ! it is normal mode + endif + + + endif + +!write(*,*) 'NewVolume=' ,NewVolume + + + if( data%State%MudSystem%Ann_Density%Length() == 1 .and. data%State%MudSystem%iLoc ==2 ) then + + write(*,*) '***errorb****==' + + write(*,*) 'iloc_edited=' , iloc_edited + write(*,*) 'iloc_changedTo2=' , iloc_changedTo2 + + write(*,*) 'Op_Capacity===' , sum(data%State%MudSystem%OpSection_VolumeCapacity(1:data%State%F_Counts%BottomHoleIntervalCounts)) + + WRITE (*,*) 'Op_Saved_MudDischarged_Volume, Op_Kick_Saved_Volume',data%State%MudSystem%Op_Saved_MudDischarged_Volume, data%State%MudSystem%Op_Kick_Saved_Volume + + do imud=1, data%State%MudSystem%Op_MudDischarged_Volume%Length() + write(*,*) 'Op:', imud, data%State%MudSystem%Op_MudDischarged_Volume%Array(imud), data%State%MudSystem%Op_Density%Array(imud) ,data%State%MudSystem%Op_MudOrKick%Array(imud) + enddo + + do imud=1, data%State%MudSystem%Ann_MudDischarged_Volume%Length() + write(*,*) 'Ann:', imud, data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud), data%State%MudSystem%Ann_Density%Array(imud) ,data%State%MudSystem%Ann_MudOrKick%Array(imud) + enddo + + + + write(*,*) '==***errorb****' + endif + + + + + + if ((data%State%ROP_Bit%RateOfPenetration==0 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%DensityMixTol) & !%%1 section + .or. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==1 .and. abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%CuttingDensityMixTol) & + .or. (data%State%ROP_Bit%RateOfPenetration>0. .and. data%State%MudSystem%Ann_CuttingMud%Array(data%State%MudSystem%iLoc)==0 .and. data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc) < 42.) ) then ! 1-Pockets are Merged +!write(*,*) '%%1 section a)' + data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)= (data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume + data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_Mud_Backhead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Backhead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(data%State%MudSystem%iLoc)= (0.0d0) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%iLoc)= (0.0d0) + else ! 2-Merging conditions are not meeted, so new pocket +!write(*,*) '%%1 section b)' + + call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%iLoc,0) + call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%iLoc,0) +!write(*,*) 'd) annLength=' , Ann_Density%Length() + + endif + + + + +!========================Same to Tripping In - End==================== + +!write(*,*) 'b)Ann_Mud sum=' , sum(Ann_MudDischarged_Volume%Array(:)) + +!write(*,*) 'no======2' +! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +! +! do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! enddo +! +! +! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) +! +! +!write(*,*) '2======no' + +!=============== save Ann Mud data to transfer to the ChokeLine enterance + data%State%MudSystem%AnnMudVolumeSum= 0.d0 +!Ann_MudSaved_Density= 0.d0 +!Ann_KickSaved_Density= 0.d0 + data%State%MudSystem%Ann_Saved_MudDischarged_Volume= 0.d0 + data%State%MudSystem%Ann_Kick_Saved_Volume= 0.d0 + data%State%MudSystem%Saved_Ann_MudOrKick= 0 + data%State%MudSystem%Ann_to_Choke_2mud= .false. + + + + + do imud=1, data%State%MudSystem%Ann_MudDischarged_Volume%Length() + + data%State%MudSystem%AnnMudVolumeSum= data%State%MudSystem%AnnMudVolumeSum + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) + + if ( data%State%MudSystem%AnnMudVolumeSum > sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) ) then + + IF (data%State%MudSystem%Ann_MudOrKick%Array(imud) == 0) THEN + data%State%MudSystem%Ann_MudSaved_Density = data%State%MudSystem%Ann_Density%Array(imud) + data%State%MudSystem%Ann_Saved_MudDischarged_Volume = data%State%MudSystem%AnnMudVolumeSum - sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + ELSEIF (data%State%MudSystem%Ann_MudOrKick%Array(imud) > 0 .AND. data%State%MudSystem%Ann_MudOrKick%Array(imud) <100) THEN ! 104= AIR + data%State%MudSystem%Ann_Kick_Saved_Volume = data%State%MudSystem%AnnMudVolumeSum - sum(data%State%MudSystem%PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:data%State%MudSystem%NoPipeSections)) + data%State%MudSystem%Saved_Ann_MudOrKick= data%State%MudSystem%Ann_MudOrKick%Array (imud) + data%State%MudSystem%Ann_KickSaved_Density= data%State%MudSystem%Ann_Density%Array(imud) + END IF + + do ii= imud + 1, data%State%MudSystem%Ann_MudDischarged_Volume%Length() + IF (data%State%MudSystem%Ann_MudOrKick%Array(ii) == 0) THEN + data%State%MudSystem%Ann_MudSaved_Density = ((data%State%MudSystem%Ann_MudSaved_Density * data%State%MudSystem%Ann_Saved_MudDischarged_Volume) + (data%State%MudSystem%Ann_Density%Array(ii) * data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii))) / (data%State%MudSystem%Ann_Saved_MudDischarged_Volume + data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii)) + data%State%MudSystem%Ann_Saved_MudDischarged_Volume = data%State%MudSystem%Ann_Saved_MudDischarged_Volume + data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii) + data%State%MudSystem%Ann_to_Choke_2mud= .true. + ELSEIF (data%State%MudSystem%Ann_MudOrKick%Array(ii) > 0 .AND. data%State%MudSystem%Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR + data%State%MudSystem%Ann_Kick_Saved_Volume = data%State%MudSystem%Ann_Kick_Saved_Volume + data%State%MudSystem%Ann_MudDischarged_Volume%Array(ii) + data%State%MudSystem%Saved_Ann_MudOrKick= data%State%MudSystem%Ann_MudOrKick%Array (ii) + data%State%MudSystem%Ann_KickSaved_Density= data%State%MudSystem%Ann_Density%Array(ii) + END IF + enddo + + exit ! exits do + + endif + + enddo + +data%State%MudSystem%Ann_Saved_MudDischarged_Volume_Final= data%State%MudSystem%Ann_Saved_MudDischarged_Volume +data%State%MudSystem%Ann_Kick_Saved_Volume_Final= data%State%MudSystem%Ann_Kick_Saved_Volume +!write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(data%State%F_Counts%StringIntervalCounts+1:NoPipeSections)) +!write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + +IF (data%State%MudSystem%WellHeadIsOpen) data%State%MudSystem%MudVolume_InjectedFromAnn = data%State%MudSystem%Ann_Saved_MudDischarged_Volume_Final-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) +!NoGasPocket +!write(*,*) 'Ann_Saved_Mud_Vol,Ann_Kick_Saved_Vol=' , Ann_Saved_MudDischarged_Volume,Ann_Kick_Saved_Volume + +!====================================================================== + + +!write(*,*) 'Ann_Saved_Mud=' , Ann_Saved_MudDischarged_Volume +!======================== Annulus ==================== + +!MudIsChanged= .false. + +imud= 0 + + do while (imud < data%State%MudSystem%Ann_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud-1) + endif + +! write(*,*) 'imud==' , imud +!write(*,*) '***)Ann_Mud_Backhead_section(imud)= ' , Ann_Mud_Backhead_section%Array(imud), Ann_density%Array(imud) + + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud) + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)) +! 7.48 is for gal to ft^3 + + else + + data%State%MudSystem%isection= data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > data%State%MudSystem%NoPipeSections) then ! last pipe section(well exit) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections) + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%NoPipeSections + + if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveAnnulusMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + endif + + enddo + + endif + + enddo + + if (data%State%MudSystem%Ann_Mud_Forehead_X%Last() < data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections)) then + data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%Ann_Mud_Forehead_X%Length()) = data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections) ! for error preventing + endif + +!========================ANNULUS END================= + + + +!************************************************************************************************************************* + +!========================Tripping Out- 2nd Mode==================== + + + elseif ( data%State%MudSystem%Op_NeededVolume_ToFill > ABS(data%State%MudSystem%DeltaVolumeAnnulusCapacity) ) then !pump is off or Pump flow is less than trip out so fluid Level in Annulus decreases +!write(*,*) 'trip out 2nd mode' + + + SavedDensityForOp= data%State%MudSystem%Ann_Density%Array(1) +!========================ANNULUS ENTRANCE==================== + +! <<< SIMILAR TO UTUBE 2 >>> + if ( data%State%MudSystem%Ann_Density%Last() /= 0.0 ) then ! new mud is pumped + call data%State%MudSystem%Ann_Density%Add (0.0d0) + call data%State%MudSystem%Ann_MudDischarged_Volume%Add (0.0d0) + call data%State%MudSystem%Ann_Mud_Forehead_X%Add (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections)) + call data%State%MudSystem%Ann_Mud_Forehead_section%Add (data%State%MudSystem%NoPipeSections) + call data%State%MudSystem%Ann_Mud_Backhead_X%Add (data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%NoPipeSections)) + call data%State%MudSystem%Ann_Mud_Backhead_section%Add (data%State%MudSystem%NoPipeSections) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Add (0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Add (0.0d0) + call data%State%MudSystem%Ann_MudOrKick%Add (104) + call data%State%MudSystem%Ann_CuttingMud%Add (0) + +!AnnulusSuctionDensity_Old= Hz_Density%Last() + endif + + data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%Ann_Mud_Forehead_section%Length())= data%State%MudSystem%NoPipeSections !it is needed to be updated for (a condition that one pipe is removed from Annulus due to trip out)- (and add pipe) + data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%Ann_Mud_Forehead_X%Length())= data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections) + + + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_MudDischarged_Volume%Length())= data%State%MudSystem%Ann_MudDischarged_Volume%Last()+ (data%State%MudSystem%Op_NeededVolume_ToFill - ABS(data%State%MudSystem%DeltaVolumeAnnulusCapacity)) ! Op_NeededVolume_ToFill !ABS(DeltaVolumePipe) - ((data%State%MudSystem%AnnulusFlowRate/60.)*DeltaT_Mudline) !(gal) + +!=================================================================== + + + + if ( (data%State%MudSystem%iLoc==2 .or. iloc_edited==1) .and. data%State%MudSystem%Op_MudOrKick%Last()==0 ) then ! for avoid kick separation +!write(*,*) 'here mud should be removed from Op last' + + if (abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%Op_Density%Last())< data%State%MudSystem%DensityMixTol) then + + data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)= (data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%Op_Density%Last()*data%State%MudSystem%Op_MudDischarged_Volume%Last())/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%Op_MudDischarged_Volume%Last()) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%Op_MudDischarged_Volume%Last() ! OP_Last is data%State%MUD(effect of pump added mud) + data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_Mud_Backhead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Backhead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(data%State%MudSystem%iLoc)= (0.0d0) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%iLoc)= (0.0d0) +!write(*,*) 'merge' ,'Ann_Volume%Array(1)=' , Ann_MudDischarged_Volume%Array(1) + + else ! 2-Merging conditions are not meeted, so new pocket + call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%Op_Density%Last()) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%Op_MudDischarged_Volume%Last()) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%iLoc,0) + call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%iLoc,0) + endif + + data%State%MudSystem%Op_NeededVolume_ToFill= data%State%MudSystem%Op_NeededVolume_ToFill + data%State%MudSystem%Op_MudDischarged_Volume%Last() ! OP_Last is data%State%MUD(effect of pump added mud) + + call RemoveOpMudArrays(data%State%MudSystem%Op_MudOrKick%Length()) + + + endif +!=================================================================== + + +!=============== save Ann Mud data to transfer to the ChokeLine enterance +!AnnMudVolumeSum= 0.d0 +!!Ann_MudSaved_Density= 0.d0 +!!Ann_KickSaved_Density= 0.d0 + data%State%MudSystem%Ann_Saved_MudDischarged_Volume= 0.d0 + data%State%MudSystem%Ann_Kick_Saved_Volume= 0.d0 +!Saved_Ann_MudOrKick= 0 +!Ann_to_Choke_2mud= .false. + + + + +!do imud=1, Ann_MudDischarged_Volume%Length() +! +! AnnMudVolumeSum= AnnMudVolumeSum + Ann_MudDischarged_Volume%Array(imud) +! +! if ( AnnMudVolumeSum > sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) ) then +! +! IF (Ann_MudOrKick%Array(imud) == 0) THEN +! Ann_MudSaved_Density = Ann_Density%Array(imud) +! Ann_Saved_MudDischarged_Volume = AnnMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +! ELSEIF (Ann_MudOrKick%Array(imud) > 0 .AND. Ann_MudOrKick%Array(imud) <100) THEN ! 104= AIR +! Ann_Kick_Saved_Volume = AnnMudVolumeSum - sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +! Saved_Ann_MudOrKick= Ann_MudOrKick%Array (imud) +! Ann_KickSaved_Density= Ann_Density%Array(imud) +! END IF +! +! do ii= imud + 1, Ann_MudDischarged_Volume%Length() +! IF (Ann_MudOrKick%Array(ii) == 0) THEN +! Ann_MudSaved_Density = ((Ann_MudSaved_Density * Ann_Saved_MudDischarged_Volume) + (Ann_Density%Array(ii) * Ann_MudDischarged_Volume%Array(ii))) / (Ann_Saved_MudDischarged_Volume + Ann_MudDischarged_Volume%Array(ii)) +! Ann_Saved_MudDischarged_Volume = Ann_Saved_MudDischarged_Volume + Ann_MudDischarged_Volume%Array(ii) +! Ann_to_Choke_2mud= .true. +! ELSEIF (Ann_MudOrKick%Array(ii) > 0 .AND. Ann_MudOrKick%Array(ii) <100) THEN ! 104= AIR +! Ann_Kick_Saved_Volume = Ann_Kick_Saved_Volume + Ann_MudDischarged_Volume%Array(ii) +! Saved_Ann_MudOrKick= Ann_MudOrKick%Array (ii) +! Ann_KickSaved_Density= Ann_Density%Array(ii) +! END IF +! enddo +! +! exit ! exits do +! +! endif +! +!enddo + + +! write(*,*) 'check point 2==' +! +! +! +! do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! enddo +! +! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) +! +! +!write(*,*) '==check point 2' + + + + + +data%State%MudSystem%Ann_Saved_MudDischarged_Volume_Final= data%State%MudSystem%Ann_Saved_MudDischarged_Volume +data%State%MudSystem%Ann_Kick_Saved_Volume_Final= data%State%MudSystem%Ann_Kick_Saved_Volume +!write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +!write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) + +!write(*,*) 'Ann_Saved_MudDischarged_Volume_Final=' , Ann_Saved_MudDischarged_Volume_Final + + + +IF (data%State%MudSystem%WellHeadIsOpen) data%State%MudSystem%MudVolume_InjectedFromAnn = data%State%MudSystem%Ann_Saved_MudDischarged_Volume_Final-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) +!! NoGasPocket > 0 .AND. + +!write(*,*) 'Ann_Saved_Mud_Vol,Ann_Kick_Saved_Vol=' , Ann_Saved_MudDischarged_Volume,Ann_Kick_Saved_Volume + + +!====================================================================== + +!========================ANNULUS==================== +! <<< SIMILAR TO UTUBE 2 >>> + +!write(*,*) Ann_MudOrKick%Last(), 'DeltaVolumePipe , after volume=' ,ABS(DeltaVolumePipe), Ann_MudDischarged_Volume%Last() +imud= data%State%MudSystem%Ann_Mud_Forehead_X%Length() + 1 + + do while (imud > 1) + imud = imud - 1 + + if (imud< data%State%MudSystem%Ann_Mud_Forehead_X%Length()) then + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud+1) + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud+1) + endif + + +! <<< Fracture Shoe Lost + IF ( data%State%MudSystem%ShoeLost .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then +!write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then +!write(*,*) 'mud is removed by shoe lost, imud=' , imud + call RemoveAnnulusMudArrays(imud) + imud= imud-1 + cycle + endif + data%State%MudSystem%LostInTripOutIsDone= .true. + ENDIF +! Fracture Shoe Lost >>> + + + + + + + + +!write(*,*) 'a)imud,Ann_Mud_Forehead_section=',imud,Ann_Mud_Forehead_section%Array(imud) + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud))) +! +1 for string , -1 for annulus + +!write(*,*) 'b)imud,Forehead_X,Xstart_PipeSection=',imud,Ann_Mud_Forehead_X%Array(imud),Xstart_PipeSection(Ann_Mud_Forehead_section%Array(imud)) + + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + if ( data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud) + data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)- data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)) +! 7.48051948 is for gal to ft^3 + else + data%State%MudSystem%isection= data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)-1 + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection < data%State%F_Counts%StringIntervalCounts+1) then ! last pipe section(well exit) data%State%F_Counts%StringIntervalCounts+1 is the first section in Annulus + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1) + data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)= data%State%F_Counts%StringIntervalCounts+1 + + if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveAnnulusMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection- 1 + + + endif + + enddo + + endif + + enddo +!========================ANNULUS END================= + + endif ! end of 1st &3rd & 2nd Mode + + +!************************************************************************************************************************* + + + + + + +!======================== Bottom Hole Entrance ========================== +!if (iloc == 1) then + if ( data%State%MudSystem%Op_NeededVolume_ToFill > 0.0 ) then ! it is needed for 2nd & 3rd mode +!write(*,*) 'op add for 2nd & 3rd mode done' + + + + if ( ABS(data%State%MudSystem%Op_Density%Last() - SavedDensityForOp ) >= data%State%MudSystem%DensityMixTol) then ! .OR. (Op_MudDischarged_Volume%Last()>42.) ) then ! 1-Merging conditions are not meeted, so new pocket + + call data%State%MudSystem%Op_Density%Add (SavedDensityForOp) + call data%State%MudSystem%Op_MudDischarged_Volume%Add (data%State%MudSystem%Op_NeededVolume_ToFill) + call data%State%MudSystem%Op_Mud_Forehead_X%Add (0.0d0) + call data%State%MudSystem%Op_Mud_Forehead_section%Add (1) + call data%State%MudSystem%Op_Mud_Backhead_X%Add (0.0d0) + call data%State%MudSystem%Op_Mud_Backhead_section%Add (1) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%Add (0.0d0) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Add (0.0d0) + call data%State%MudSystem%Op_MudOrKick%Add (data%State%MudSystem%Ann_MudOrKick%Array(1)) + else ! 2-Pockets are Merged + + data%State%MudSystem%Op_Density%Array (data%State%MudSystem%Op_Density%Length())= (SavedDensityForOp*data%State%MudSystem%Op_NeededVolume_ToFill+data%State%MudSystem%Op_Density%Last()*data%State%MudSystem%Op_MudDischarged_Volume%Last())/(data%State%MudSystem%Op_MudDischarged_Volume%Last()+data%State%MudSystem%Op_NeededVolume_ToFill) + data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_Density%Length())= data%State%MudSystem%Op_MudDischarged_Volume%Array (data%State%MudSystem%Op_Density%Length()) + data%State%MudSystem%Op_NeededVolume_ToFill + data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array (data%State%MudSystem%Op_Density%Length())= 0.0 + data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array (data%State%MudSystem%Op_Density%Length())= 0.0 + + endif + + endif + + + + +!============================= Bottom Hole ============================== + +imud=0 + do while (imud < data%State%MudSystem%Op_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%Op_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Op_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Op_Mud_Forehead_section%Array(imud-1) + endif + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + + data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Op_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( data%State%MudSystem%Op_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Op_Mud_Backhead_section%Array(imud) + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Op_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)) +! 7.48051948 is for gal to ft^3 + + else + + data%State%MudSystem%isection= data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > data%State%F_Counts%BottomHoleIntervalCounts) then ! last pipe section(well exit) +!if( imud==1) KickDeltaVinAnnulus= Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space + data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts) + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%F_Counts%BottomHoleIntervalCounts + + if (data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call data%State%MudSystem%Op_MudDischarged_Volume%Remove (imud) + call data%State%MudSystem%Op_Mud_Backhead_X%Remove (imud) + call data%State%MudSystem%Op_Mud_Backhead_section%Remove (imud) + call data%State%MudSystem%Op_Mud_Forehead_X%Remove (imud) + call data%State%MudSystem%Op_Mud_Forehead_section%Remove (imud) + call data%State%MudSystem%Op_Density%Remove (imud) + call data%State%MudSystem%Op_RemainedVolume_in_LastSection%Remove (imud) + call data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Remove (imud) + call data%State%MudSystem%Op_MudOrKick%Remove (imud) + + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%OpSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%OpSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + endif + + enddo + + endif + + enddo + + + +!========================Bottom Hole END================= +! write(*,*) 'after sorting==' +!!! +! do imud=1, Op_MudDischarged_Volume%Length() +! write(*,*) 'Op:', imud, Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) ,Op_MudOrKick%Array(imud) +! enddo +! +! do imud=1, Ann_MudDischarged_Volume%Length() +! write(*,*) 'Ann:', imud, Ann_MudDischarged_Volume%Array(imud), Ann_Density%Array(imud) ,Ann_MudOrKick%Array(imud) +! enddo +!!! +!! write(*,*) 'Ann cap=' , sum(PipeSection_VolumeCapacity(F_StringIntervalCounts+1:NoPipeSections)) +!! write(*,*) 'Ann mud sum vol=' , sum(Ann_MudDischarged_Volume%Array(:)) +!!! +!!! +!write(*,*) '==after sorting' + +!========================================================= + + + data%State%MudSystem%total_injected = data%State%MudSystem%total_injected + data%State%MudSystem%MudVolume_InjectedFromAnn + + if (data%Equipments%ChokeControlPanel%ChokePanelStrokeResetSwitch == 1) then + data%State%MudSystem%total_injected= 0. + endif +!write(*,*) ' data%State%MudSystem%MudVolume_InjectedFromAnn =' , data%State%MudSystem%MudVolume_InjectedFromAnn + +!write(*,*) ' total injected-tripout =' , total_injected +!write(*,*) ' injected-tripout =' , data%State%MudSystem%MudVolume_InjectedFromAnn + + + + + + + + end subroutine TripOut_and_Pump + + + diff --git a/Equipments/MudSystem/Utube1_and_Trip_In.f90 b/Equipments/MudSystem/Utube1_and_Trip_In.f90 index 582f3f9..7ef5b64 100644 --- a/Equipments/MudSystem/Utube1_and_Trip_In.f90 +++ b/Equipments/MudSystem/Utube1_and_Trip_In.f90 @@ -9,7 +9,7 @@ use SimulationVariables !@@@ USE sROP_Variables use SimulationVariables !@ !use CTanks - !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity Use CShoeVariables Use CUnityOutputs @@ -451,7 +451,7 @@ imud= 0 ! <<< Fracture Shoe Lost - IF ( data%State%MudSystem%ShoeLost .and. data%State%MudSystem%LostInTripOutIsDone== .false. .and. Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then + IF ( data%State%MudSystem%ShoeLost .and. data%State%MudSystem%LostInTripOutIsDone== .false. .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then diff --git a/Equipments/MudSystem/Utube1_and_Trip_In.i90 b/Equipments/MudSystem/Utube1_and_Trip_In.i90 new file mode 100644 index 0000000..5a0540e --- /dev/null +++ b/Equipments/MudSystem/Utube1_and_Trip_In.i90 @@ -0,0 +1,535 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/Utube1_and_Trip_In.f90" +SUBROUTINE Utube1_and_TripIn ! is called in subroutine CirculationCodeSelect string to annulus + + use UTUBEVARSModule + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + USE sROP_Variables + use SimulationVariables !@ +!use CTanks +!@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + Use CShoeVariables + Use CUnityOutputs + + implicit none + + write(*,*) 'Utube1 code' +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + data%State%MudSystem%UtubeMode1Activated= .true. +!write(*,*) 'QUTubeInput=' , QUTubeInput +!Qinput=5000. + data%State%MudSystem%StringFlowRate= UTUBEVARS%QUTubeInput ! (gpm) + data%State%MudSystem%AnnulusFlowRate= UTUBEVARS%QUTubeInput + data%State%MudSystem%StringFlowRateFinal= data%State%MudSystem%StringFlowRate + data%State%MudSystem%AnnulusFlowRateFinal= data%State%MudSystem%AnnulusFlowRate +!=========================================== + + if (data%State%MudSystem%FirstSetUtube1==0) then +! call St_MudDischarged_Volume%AddToFirst (REAL(sum(data%State%F_Interval(1:F_StringIntervalCounts)%Volume))) !startup initial +! call St_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1)) +! call St_Mud_Backhead_section%AddToFirst (1) +! call St_Mud_Forehead_X%AddToFirst (Xend_PipeSection(F_StringIntervalCounts)) +! call St_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts) +! call data%State%MudSystem%St_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg) +! call St_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! +! call Ann_MudDischarged_Volume%AddToFirst (REAL(sum(data%State%F_Interval((F_StringIntervalCounts+F_BottomHoleIntervalCounts+1):F_IntervalsTotalCounts)%Volume))) !startup initial +! call Ann_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1)) +! call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1) +! call Ann_Mud_Forehead_X%AddToFirst (Xend_PipeSection(NoPipeSections)) +! call Ann_Mud_Forehead_section%AddToFirst (NoPipeSections) +! call Ann_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg) +! call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +!Hz_Density%Array(:)= 0.0 !commented +!Hz_MudOrKick%Array(:)= 104 !commented + + data%State%MudSystem%Hz_Density_Utube= 0.0 + data%State%MudSystem%Hz_MudOrKick_Utube= 104 + + data%State%MudSystem%FirstSetUtube1= 1 + endif + + + + +!========================Horizontal PIPE ENTRANCE================= + +!if (SuctionDensity_Old >= (ActiveDensity+0.05) .or. SuctionDensity_Old <= (ActiveDensity-0.05)) then ! new mud is pumped +! !ImudCount= ImudCount+1 +! !SuctionMud= ImudCount +! call Hz_Density%AddToFirst (REAL(ActiveDensity)) !ActiveDensity : badan in moteghayer bayad avaz beshe +! call Hz_MudDischarged_Volume%AddToFirst (0.0d0) +! call Hz_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(1)) +! call Hz_Mud_Forehead_section%AddToFirst (1) +! call Hz_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1)) +! call Hz_Mud_Backhead_section%AddToFirst (1) +! call Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call Hz_MudOrKick%AddToFirst (0) +! +! SuctionDensity_Old= ActiveDensity +!endif + +!========================Horizontal PIPE STRING================= + +!commented + +! Hz_MudDischarged_Volume%Array(1)= Hz_MudDischarged_Volume%Array(1)+ ((data%State%MudSystem%StringFlowRate/60.)*DeltaT_Mudline) !(gal) +! +!imud=0 +! do while (imud < Hz_Mud_Forehead_X%Length()) +! imud = imud + 1 +! +! if (imud> 1) then +! Hz_Mud_Backhead_X%Array(imud)= Hz_Mud_Forehead_X%Array(imud-1) +! Hz_Mud_Backhead_section%Array(imud)= Hz_Mud_Forehead_section%Array(imud-1) +! endif +! +! +! DirectionCoef= (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud))) & +! / ABS(Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud))) +! ! +1 for string , -1 for annulus +! +! +! Hz_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))- Hz_Mud_Backhead_X%Array(imud))* & +! Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud)) !(ft^3) +! Hz_EmptyVolume_inBackheadLocation%Array(imud)= Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948 ! ft^3 to gal +! +! +! if ( Hz_MudDischarged_Volume%Array(imud) <= Hz_EmptyVolume_inBackheadLocation%Array(imud)) then +! Hz_Mud_Forehead_section%Array(imud)= Hz_Mud_Backhead_section%Array(imud) +! Hz_Mud_Forehead_X%Array(imud)= Hz_Mud_Backhead_X%Array(imud)+ DirectionCoef*(Hz_MudDischarged_Volume%Array(imud)/7.48051948)/Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud)) +! ! 7.48 is for gal to ft^3 +! else +! +! isection= Hz_Mud_Backhead_section%Array(imud)+1 +! Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_EmptyVolume_inBackheadLocation%Array(imud) +! +! do +! if (isection > 1) then ! (horizontal pipe exit) +! Hz_MudDischarged_Volume%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_RemainedVolume_in_LastSection%Array(imud) +! Hz_Mud_Forehead_X%Array(imud)= Xend_PipeSection(1) +! Hz_Mud_Forehead_section%Array(imud)= 1 +! if (Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string +! call Hz_MudDischarged_Volume%Remove (imud) +! call Hz_Mud_Backhead_X%Remove (imud) +! call Hz_Mud_Backhead_section%Remove (imud) +! call Hz_Mud_Forehead_X%Remove (imud) +! call Hz_Mud_Forehead_section%Remove (imud) +! call Hz_Density%Remove (imud) +! call Hz_RemainedVolume_in_LastSection%Remove (imud) +! call Hz_EmptyVolume_inBackheadLocation%Remove (imud) +! call Hz_MudOrKick%Remove (imud) +! +! endif +! exit +! endif +! +! xx= Hz_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal) +! +! if (xx<= 1.0) then +! Hz_Mud_Forehead_section%Array(imud)= isection +! Hz_Mud_Forehead_X%Array(imud)= (xx * (Xend_PipeSection(isection)- Xstart_PipeSection(isection)))+ Xstart_PipeSection(isection) +! exit +! else +! Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection) +! isection= isection+ 1 +! +! +! endif +! +! enddo +! +! endif +! +! enddo + +!commented + +!========================Horizontal PIPE END================= + +!========================STRING ENTRANCE================= +!write(*,*) 'a) data%State%MudSystem%St_Density%Length()=' , data%State%MudSystem%St_Density%Length() + + if (ABS(data%State%MudSystem%St_Density%First() - data%State%MudSystem%Hz_Density_Utube) >= data%State%MudSystem%DensityMixTol) then ! new mud is pumped + call data%State%MudSystem%St_Density%AddToFirst (data%State%MudSystem%Hz_Density_Utube) + call data%State%MudSystem%St_MudDischarged_Volume%AddToFirst (0.0d0) + call data%State%MudSystem%St_Mud_Forehead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Forehead_section%AddToFirst (2) + call data%State%MudSystem%St_Mud_Backhead_X%AddToFirst (data%State%MudSystem%Xstart_PipeSection(2)) + call data%State%MudSystem%St_Mud_Backhead_section%AddToFirst (2) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%AddToFirst (0.0d0) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) + call data%State%MudSystem%St_MudOrKick%AddToFirst (data%State%MudSystem%Hz_MudOrKick_Utube) ! Hz_MudOrKick%Last() = 104 + +!StringDensity_Old= Hz_Density_Utube + endif +!write(*,*) 'b) data%State%MudSystem%St_Density%Length()=' , data%State%MudSystem%St_Density%Length() +!write(*,*) 'b) data%State%MudSystem%St_Density%Array(1)=' , data%State%MudSystem%St_Density%Array(1) +!write(*,*) 'b) St_MudOrKick%Array(1)=' , St_MudOrKick%Array(1) + + +!========================STRING================= +!WRITE (*,*) 'Utube1 data%State%MudSystem%StringFlowRate', data%State%MudSystem%StringFlowRate + data%State%MudSystem%St_MudDischarged_Volume%Array(1)= data%State%MudSystem%St_MudDischarged_Volume%Array(1)+ ((data%State%MudSystem%StringFlowRate/60.d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + +imud=0 + do while (imud < data%State%MudSystem%St_Mud_Forehead_X%Length()) + imud = imud + 1 + + + if (imud> 1) then + data%State%MudSystem%St_Mud_Backhead_X%Array(imud)= data%State%MudSystem%St_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%St_Mud_Backhead_section%Array(imud)= data%State%MudSystem%St_Mud_Forehead_section%Array(imud-1) + endif + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Backhead_section%Array(imud))- data%State%MudSystem%St_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%St_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + if ( data%State%MudSystem%St_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%MudSystem%St_Mud_Backhead_section%Array(imud) + data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= data%State%MudSystem%St_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%St_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%St_Mud_Backhead_section%Array(imud)) +! 7.48 is for gal to ft^3 + else + + data%State%MudSystem%isection= data%State%MudSystem%St_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > data%State%F_Counts%StringIntervalCounts) then ! last pipe section(string exit) data%State%F_Counts%StringIntervalCounts includes Horizontal line + data%State%MudSystem%St_MudDischarged_Volume%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts) + data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%F_Counts%StringIntervalCounts + + if (data%State%MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveStringMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + + endif + + enddo + + endif + + enddo +!========================STRING END================= + +!========================== tripping in for OP remove =============================== + +!if (DeltaVolumeOp>0. .and. DeltaVolumeOp< Op_MudDischarged_Volume%Last()) then +! Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length())= Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()) - DeltaVolumeOp +!else +! Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()-1)= Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()-1) - (DeltaVolumeOp-Op_MudDischarged_Volume%Last()) +! +! call Op_MudDischarged_Volume%Remove (Op_MudDischarged_Volume%Length()) +! call Op_Mud_Backhead_X%Remove (Op_MudDischarged_Volume%Length()) +! call Op_Mud_Backhead_section%Remove (Op_MudDischarged_Volume%Length()) +! call Op_Mud_Forehead_X%Remove (Op_MudDischarged_Volume%Length()) +! call Op_Mud_Forehead_section%Remove (Op_MudDischarged_Volume%Length()) +! call Op_Density%Remove (Op_MudDischarged_Volume%Length()) +! call Op_RemainedVolume_in_LastSection%Remove (Op_MudDischarged_Volume%Length()) +! call Op_EmptyVolume_inBackheadLocation%Remove (Op_MudDischarged_Volume%Length()) +! call Op_MudOrKick%Remove (Op_MudDischarged_Volume%Length()) +!endif +! + +!============================= Bottom Hole ============================== + +!Op_MudDischarged_Volume%Array(1)= Op_MudDischarged_Volume%Array(1)+ ((KickVARIABLES%GasKickPumpFlowRate/60.)*DeltaT_Mudline) !(gal) due to KickFlux +imud=0 + do while (imud < data%State%MudSystem%Op_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%Op_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Op_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Op_Mud_Forehead_section%Array(imud-1) + endif + + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + + data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Op_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( data%State%MudSystem%Op_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Op_Mud_Backhead_section%Array(imud) + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Op_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)) +! 7.48 is for gal to ft^3 + + else + + data%State%MudSystem%isection= data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > data%State%F_Counts%BottomHoleIntervalCounts) then ! last pipe section(well exit) + if( imud==1) data%State%MudSystem%KickDeltaVinAnnulus= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space + data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts) + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%F_Counts%BottomHoleIntervalCounts + + if (data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveOpMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%OpSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%OpSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + endif + + enddo + + endif + + + if (data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)== data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts)) then + data%State%MudSystem%totalLength = data%State%MudSystem%Op_MudDischarged_Volume%Length() + do while(imud < data%State%MudSystem%totalLength) + +!imud = imud + 1 + call RemoveOpMudArrays(data%State%MudSystem%totalLength) + data%State%MudSystem%totalLength = data%State%MudSystem%totalLength - 1 + + + enddo + + exit ! + + endif + +!WRITE(*,*) imud,'Op_MudDischarged_Volume%Array(imud)' , Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) + + + + enddo + + +!write(*,*) 'Op_Mud_Forehead_X%Length()' , Op_Mud_Forehead_X%Length() +! +! WRITE(*,*) 'Xend_PipeSection(F_StringIntervalCounts)' , Xend_PipeSection(F_StringIntervalCounts) +! WRITE(*,*) 'Op_Mud_Backhead_X%Array(1)' , Op_Mud_Backhead_X%Array(1) +! WRITE(*,*) 'Op_Mud_Forehead_X%Array(1)' , Op_Mud_Forehead_X%Array(1) +! WRITE(*,*) 'Op_Mud_Backhead_X%Array(2)' , Op_Mud_Backhead_X%Array(2) +! WRITE(*,*) 'Op_Mud_Forehead_X%Array(2)' , Op_Mud_Forehead_X%Array(2) +!========================Bottom Hole END================= + + if (data%State%MudSystem%iLoc == 1) then + data%State%MudSystem%MudSection= data%State%F_Counts%StringIntervalCounts+1 + data%State%MudSystem%BackheadX= data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1) + elseif (data%State%MudSystem%iLoc == 2) then + data%State%MudSystem%MudSection= data%State%MudSystem%Kick_Forehead_section + data%State%MudSystem%BackheadX= data%State%MudSystem%Kick_Forehead_X + endif + +!========================ANNULUS ENTRANCE==================== + +!write(*,*) 'iloc=====' , iLoc + if ((ABS(data%State%MudSystem%AnnulusSuctionDensity_Old - data%State%MudSystem%St_Density%Last()) >= data%State%MudSystem%DensityMixTol) .OR. (data%State%MudSystem%DeltaVolumeOp == 0.0 .and. ABS(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%St_Density%Last())>=data%State%MudSystem%DensityMixTol .and. data%State%MudSystem%AnnulusFlowRate/=0.0d0) ) then ! new mud is pumped + call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%St_Density%Last()) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%iLoc,0) + call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%iLoc,0) + + data%State%MudSystem%AnnulusSuctionDensity_Old= data%State%MudSystem%St_Density%Last() + + data%State%MudSystem%MudIsChanged= .true. + endif + + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+ ((data%State%MudSystem%AnnulusFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + +!========================Tripping In==================== + +!write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp + if (data%State%MudSystem%DeltaVolumeOp > 0.0 .and. data%State%MudSystem%MudIsChanged== .false.) then !.and. DrillingMode== .false.) then ! trip in mode(loole paeen) + +!write(*,*) 'Tripping In' + + data%State%MudSystem%NewDensity= (data%State%MudSystem%St_Density%Last()*((data%State%MudSystem%AnnulusFlowRate/60.)*data%State%MudSystem%DeltaT_Mudline)+data%State%MudSystem%Op_Density%Last()*data%State%MudSystem%DeltaVolumeOp)/(((data%State%MudSystem%AnnulusFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline)+data%State%MudSystem%DeltaVolumeOp) + data%State%MudSystem%NewVolume= ((data%State%MudSystem%AnnulusFlowRate/60.)*data%State%MudSystem%DeltaT_Mudline)+data%State%MudSystem%DeltaVolumeOp + +!write(*,*) 'Ann_MudDischarged_Volume%Array(1)=', Ann_MudDischarged_Volume%Array(1), 'NewVolume=', NewVolume + + if (abs(data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)-data%State%MudSystem%NewDensity)< data%State%MudSystem%DensityMixTol) then ! 1-Pockets are Merged - (ROP is 0) + data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)= (data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)*data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%NewVolume) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)+data%State%MudSystem%DeltaVolumeOp + data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_Mud_Backhead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Backhead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(data%State%MudSystem%iLoc)= (0.0d0) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%iLoc)= (0.0d0) + else ! 2-Merging conditions are not meeted, so new pocket + call data%State%MudSystem%Ann_Density%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewDensity) + call data%State%MudSystem%Ann_MudDischarged_Volume%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%NewVolume) + call data%State%MudSystem%Ann_Mud_Forehead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Forehead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_Mud_Backhead_X%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%BackheadX) + call data%State%MudSystem%Ann_Mud_Backhead_section%AddTo (data%State%MudSystem%iLoc,data%State%MudSystem%MudSection) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%AddTo (data%State%MudSystem%iLoc,0.0d0) + call data%State%MudSystem%Ann_MudOrKick%AddTo (data%State%MudSystem%iLoc,0) + call data%State%MudSystem%Ann_CuttingMud%AddTo (data%State%MudSystem%iLoc,0) + + endif + + + elseif (data%State%MudSystem%DeltaVolumeOp > 0.0 .and. data%State%MudSystem%MudIsChanged== .true. .and. data%State%ROP_Bit%RateOfPenetration==0.) then + data%State%MudSystem%Ann_Density%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%NewDensity + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%NewVolume + data%State%MudSystem%Ann_Mud_Forehead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Forehead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_Mud_Backhead_X%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%BackheadX + data%State%MudSystem%Ann_Mud_Backhead_section%Array(data%State%MudSystem%iLoc)= data%State%MudSystem%MudSection + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(data%State%MudSystem%iLoc)= (0.0d0) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%iLoc)= (0.0d0) + endif + + +!========================Tripping In - End==================== + + +!======================== ANNULUS ==================== + + data%State%MudSystem%MudIsChanged= .false. + +imud= 0 + + do while (imud < data%State%MudSystem%Ann_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud-1) + endif + + +! <<< Fracture Shoe Lost + IF ( data%State%MudSystem%ShoeLost .and. data%State%MudSystem%LostInTripOutIsDone== .false. .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then +!write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then +!write(*,*) 'mud is removed by shoe lost, imud=' , imud + call RemoveAnnulusMudArrays(imud) + imud= imud-1 + cycle + endif + ENDIF +! Fracture Shoe Lost >>> + + + + + + + + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud) + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)) +! 7.48 is for gal to ft^3 + + else + + data%State%MudSystem%isection= data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > data%State%MudSystem%NoPipeSections) then ! last pipe section(well exit) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections) + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%NoPipeSections + + if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveAnnulusMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + endif + + enddo + + endif + + enddo +!========================ANNULUS END================= + +!if ( WellisNOTFull == .false. ) then +! write(*,*) 'data%State%MudSystem%AnnulusFlowRate==' , data%State%MudSystem%AnnulusFlowRate +! call Set_FlowRate(real(100.*min(data%State%MudSystem%AnnulusFlowRate,PedalMeter)/(PedalMeter/10.), 8)) +! +! +!endif + + + +end subroutine Utube1_and_TripIn diff --git a/Equipments/MudSystem/Utube2_and_Trip_In.f90 b/Equipments/MudSystem/Utube2_and_Trip_In.f90 index 531251e..8bcbc2d 100644 --- a/Equipments/MudSystem/Utube2_and_Trip_In.f90 +++ b/Equipments/MudSystem/Utube2_and_Trip_In.f90 @@ -8,7 +8,7 @@ use SimulationVariables !@@@ use SimulationVariables use SimulationVariables !@ !use CTanks - !@use ConfigurationVariables, TripTankVolume2 => data%EquipmentControl%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + !@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity Use CShoeVariables implicit none @@ -186,7 +186,7 @@ imud= data%State%MudSystem%Ann_Mud_Forehead_X%Length() + 1 endif ! <<< Fracture Shoe Lost - IF ( data%State%MudSystem%ShoeLost .and. data%State%MudSystem%LostInTripOutIsDone== .false. .and. Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then + IF ( data%State%MudSystem%ShoeLost .and. data%State%MudSystem%LostInTripOutIsDone== .false. .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then !write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then diff --git a/Equipments/MudSystem/Utube2_and_Trip_In.i90 b/Equipments/MudSystem/Utube2_and_Trip_In.i90 new file mode 100644 index 0000000..18a17ad --- /dev/null +++ b/Equipments/MudSystem/Utube2_and_Trip_In.i90 @@ -0,0 +1,520 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/MudSystem/Utube2_and_Trip_In.f90" +SUBROUTINE Utube2_and_TripIn ! is called in subroutine CirculationCodeSelect annulus to string + + use UTUBEVARSModule + Use GeoElements_FluidModule + USE CMudPropertiesVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + use SimulationVariables !@ +!use CTanks +!@use ConfigurationVariables, TripTankVolume2 => data%Equipments%DrillingWatch%TripTankVolume, TripTankDensity2 => TripTankDensity + Use CShoeVariables + + implicit none + + write(*,*) 'Utube2 code' + +!===========================================================WELL============================================================ +!===========================================================WELL============================================================ + + data%State%MudSystem%UtubeMode2Activated= .true. + write(*,*) 'QUtubeOutput=' , UTUBEVARS%QUtubeOutput +!QUTubeInput=5000. + data%State%MudSystem%StringFlowRate= UTUBEVARS%QUtubeOutput ! (gpm) + data%State%MudSystem%AnnulusFlowRate= UTUBEVARS%QUtubeOutput + data%State%MudSystem%StringFlowRateFinal= data%State%MudSystem%StringFlowRate + data%State%MudSystem%AnnulusFlowRateFinal= data%State%MudSystem%AnnulusFlowRate +!=========================================== + + if (data%State%MudSystem%FirstSetUtube2==0) then +! call St_MudDischarged_Volume%AddToFirst (REAL(sum(data%State%F_Interval(1:F_StringIntervalCounts)%Volume))) !startup initial +! call St_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1)) +! call St_Mud_Backhead_section%AddToFirst (1) +! call St_Mud_Forehead_X%AddToFirst (Xend_PipeSection(F_StringIntervalCounts)) +! call St_Mud_Forehead_section%AddToFirst (F_StringIntervalCounts) +! call data%State%MudSystem%St_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg) +! call St_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call St_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! +! call Ann_MudDischarged_Volume%AddToFirst (REAL(sum(data%State%F_Interval((F_StringIntervalCounts+F_BottomHoleIntervalCounts+1):F_IntervalsTotalCounts)%Volume))) !startup initial +! call Ann_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(F_StringIntervalCounts+1)) +! call Ann_Mud_Backhead_section%AddToFirst (F_StringIntervalCounts+1) +! call Ann_Mud_Forehead_X%AddToFirst (Xend_PipeSection(NoPipeSections)) +! call Ann_Mud_Forehead_section%AddToFirst (NoPipeSections) +! call Ann_Density%AddToFirst (REAL(ActiveDensity)) ! initial(ppg) +! call Ann_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Ann_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +!Hz_Density%Array(:)= 0.0 +!Hz_MudOrKick%Array(:)= 104 + + data%State%MudSystem%Hz_Density_Utube= 0.0 + data%State%MudSystem%Hz_MudOrKick_Utube= 104 + + data%State%MudSystem%FirstSetUtube2= 1 + endif + + + + +!========================Horizontal PIPE ENTRANCE================= + +!if (SuctionDensity_Old >= (ActiveDensity+0.05) .or. SuctionDensity_Old <= (ActiveDensity-0.05)) then ! new mud is pumped +! !ImudCount= ImudCount+1 +! !SuctionMud= ImudCount +! call Hz_Density%AddToFirst (REAL(ActiveDensity)) !ActiveDensity : badan in moteghayer bayad avaz beshe +! call Hz_MudDischarged_Volume%AddToFirst (0.0d0) +! call Hz_Mud_Forehead_X%AddToFirst (Xstart_PipeSection(1)) +! call Hz_Mud_Forehead_section%AddToFirst (1) +! call Hz_Mud_Backhead_X%AddToFirst (Xstart_PipeSection(1)) +! call Hz_Mud_Backhead_section%AddToFirst (1) +! call Hz_RemainedVolume_in_LastSection%AddToFirst (0.0d0) +! call Hz_EmptyVolume_inBackheadLocation%AddToFirst (0.0d0) +! call Hz_MudOrKick%AddToFirst (0) + +! deltaV= 0. +! +! SuctionDensity_Old= ActiveDensity +!endif + +!========================Horizontal PIPE STRING================= + +!commented + +! Hz_MudDischarged_Volume%Array(1)= Hz_MudDischarged_Volume%Array(1)+ ((data%State%MudSystem%StringFlowRate/60.)*DeltaT_Mudline) !(gal) +! +!imud=0 +! do while (imud < Hz_Mud_Forehead_X%Length()) +! imud = imud + 1 +! +! if (imud> 1) then +! Hz_Mud_Backhead_X%Array(imud)= Hz_Mud_Forehead_X%Array(imud-1) +! Hz_Mud_Backhead_section%Array(imud)= Hz_Mud_Forehead_section%Array(imud-1) +! endif +! +! +! DirectionCoef= (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud))) & +! / ABS(Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))-Xstart_PipeSection(Hz_Mud_Backhead_section%Array(imud))) +! ! +1 for string , -1 for annulus +! +! +! Hz_EmptyVolume_inBackheadLocation%Array(imud)= DirectionCoef* (Xend_PipeSection(Hz_Mud_Backhead_section%Array(imud))- Hz_Mud_Backhead_X%Array(imud))* & +! Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud)) !(ft^3) +! Hz_EmptyVolume_inBackheadLocation%Array(imud)= Hz_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948 ! ft^3 to gal +! +! +! if ( Hz_MudDischarged_Volume%Array(imud) <= Hz_EmptyVolume_inBackheadLocation%Array(imud)) then +! Hz_Mud_Forehead_section%Array(imud)= Hz_Mud_Backhead_section%Array(imud) +! Hz_Mud_Forehead_X%Array(imud)= Hz_Mud_Backhead_X%Array(imud)+ DirectionCoef*(Hz_MudDischarged_Volume%Array(imud)/7.48051948)/Area_PipeSectionFt(Hz_Mud_Backhead_section%Array(imud)) +! ! 7.48051948 is for gal to ft^3 +! else +! +! isection= Hz_Mud_Backhead_section%Array(imud)+1 +! Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_EmptyVolume_inBackheadLocation%Array(imud) +! +! do +! if (isection > 1) then ! (horizontal pipe exit) +! Hz_MudDischarged_Volume%Array(imud)= Hz_MudDischarged_Volume%Array(imud)- Hz_RemainedVolume_in_LastSection%Array(imud) +! Hz_Mud_Forehead_X%Array(imud)= Xend_PipeSection(1) +! Hz_Mud_Forehead_section%Array(imud)= 1 +! if (Hz_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string +! call Hz_MudDischarged_Volume%Remove (imud) +! call Hz_Mud_Backhead_X%Remove (imud) +! call Hz_Mud_Backhead_section%Remove (imud) +! call Hz_Mud_Forehead_X%Remove (imud) +! call Hz_Mud_Forehead_section%Remove (imud) +! call Hz_Density%Remove (imud) +! call Hz_RemainedVolume_in_LastSection%Remove (imud) +! call Hz_EmptyVolume_inBackheadLocation%Remove (imud) +! call Hz_MudOrKick%Remove (imud) +! endif +! exit +! endif +! +! xx= Hz_RemainedVolume_in_LastSection%Array(imud)/ PipeSection_VolumeCapacity(isection) !(gal) +! +! if (xx<= 1.0) then +! Hz_Mud_Forehead_section%Array(imud)= isection +! Hz_Mud_Forehead_X%Array(imud)= (xx * (Xend_PipeSection(isection)- Xstart_PipeSection(isection)))+ Xstart_PipeSection(isection) +! exit +! else +! Hz_RemainedVolume_in_LastSection%Array(imud)= Hz_RemainedVolume_in_LastSection%Array(imud)- PipeSection_VolumeCapacity(isection) +! isection= isection+ 1 +! +! +! endif +! +! enddo +! +! endif +! +! enddo + +!commented + +!========================Horizontal PIPE END================= + +!========================ANNULUS ENTRANCE==================== + + if (ABS(data%State%MudSystem%AnnulusSuctionDensity_Old - data%State%MudSystem%Hz_Density_Utube) >= data%State%MudSystem%DensityMixTol ) then ! new mud is pumped + call data%State%MudSystem%Ann_Density%Add (data%State%MudSystem%Hz_Density_Utube) + call data%State%MudSystem%Ann_MudDischarged_Volume%Add (0.0d0) + call data%State%MudSystem%Ann_Mud_Forehead_X%Add (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%NoPipeSections)) + call data%State%MudSystem%Ann_Mud_Forehead_section%Add (data%State%MudSystem%NoPipeSections) + call data%State%MudSystem%Ann_Mud_Backhead_X%Add (data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%NoPipeSections)) + call data%State%MudSystem%Ann_Mud_Backhead_section%Add (data%State%MudSystem%NoPipeSections) + call data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Add (0.0d0) + call data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Add (0.0d0) + call data%State%MudSystem%Ann_MudOrKick%Add (data%State%MudSystem%Hz_MudOrKick_Utube) ! Hz_MudOrKick%Last() = 104 + call data%State%MudSystem%Ann_CuttingMud%Add (0) + + data%State%MudSystem%AnnulusSuctionDensity_Old= data%State%MudSystem%Hz_Density_Utube + endif + +!========================ANNULUS==================== + + data%State%MudSystem%Ann_MudDischarged_Volume%Array(data%State%MudSystem%Ann_MudDischarged_Volume%Length())= data%State%MudSystem%Ann_MudDischarged_Volume%Last()+ ((data%State%MudSystem%AnnulusFlowRate/60.)*data%State%MudSystem%DeltaT_Mudline) !(gal) + +imud= data%State%MudSystem%Ann_Mud_Forehead_X%Length() + 1 + + do while (imud > 1) + imud = imud - 1 + + if (imud< data%State%MudSystem%Ann_Mud_Forehead_X%Length()) then + data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud+1) + data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud+1) + endif + +! <<< Fracture Shoe Lost + IF ( data%State%MudSystem%ShoeLost .and. data%State%MudSystem%LostInTripOutIsDone== .false. .and. data%Configuration%Shoe%ShoeDepth < data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud) .and. data%Configuration%Shoe%ShoeDepth >= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud) ) then +!write(*,*) 'ShoeLost imud,AnnVolume(imud), VolumeLost:' , imud,Ann_MudDischarged_Volume%Array(imud), (( Qlost/60.0d0)*DeltaT_Mudline) + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)-((data%State%MudSystem%Qlost/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) < 0.0) then +!write(*,*) 'mud is removed by shoe lost, imud=' , imud + call RemoveAnnulusMudArrays(imud) + imud= imud-1 + cycle + endif + ENDIF +! Fracture Shoe Lost >>> + + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud) + data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Ann_Mud_Forehead_X%Array(imud)- data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)) +! 7.48051948 is for gal to ft^3 + else + + data%State%MudSystem%isection= data%State%MudSystem%Ann_Mud_Forehead_section%Array(imud)-1 + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection < data%State%F_Counts%StringIntervalCounts+1) then ! last pipe section(well exit) data%State%F_Counts%StringIntervalCounts+1 is the first section in Annulus + data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts+1) + data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)= data%State%F_Counts%StringIntervalCounts+1 + + if (data%State%MudSystem%Ann_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveAnnulusMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Ann_Mud_Backhead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Ann_Mud_Backhead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Ann_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection- 1 + + + endif + + enddo + + endif + + enddo +!========================ANNULUS END================= + +!========================== tripping in for OP remove =============================== + +!if (DeltaVolumeOp>0. .and. DeltaVolumeOp< Op_MudDischarged_Volume%Last()) then +! Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length())= Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()) - DeltaVolumeOp +!else +! Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()-1)= Op_MudDischarged_Volume%Array(Op_MudDischarged_Volume%Length()-1) - (DeltaVolumeOp-Op_MudDischarged_Volume%Last()) +! +! call Op_MudDischarged_Volume%Remove (Op_MudDischarged_Volume%Length()) +! call Op_Mud_Backhead_X%Remove (Op_MudDischarged_Volume%Length()) +! call Op_Mud_Backhead_section%Remove (Op_MudDischarged_Volume%Length()) +! call Op_Mud_Forehead_X%Remove (Op_MudDischarged_Volume%Length()) +! call Op_Mud_Forehead_section%Remove (Op_MudDischarged_Volume%Length()) +! call Op_Density%Remove (Op_MudDischarged_Volume%Length()) +! call Op_RemainedVolume_in_LastSection%Remove (Op_MudDischarged_Volume%Length()) +! call Op_EmptyVolume_inBackheadLocation%Remove (Op_MudDischarged_Volume%Length()) +! call Op_MudOrKick%Remove (Op_MudDischarged_Volume%Length()) +!endif +! + +!============================= Bottom Hole ============================== + +!Op_MudDischarged_Volume%Array(1)= Op_MudDischarged_Volume%Array(1)+ ((KickVARIABLES%GasKickPumpFlowRate/60.)*DeltaT_Mudline) !(gal) due to KickFlux +imud=0 + do while (imud < data%State%MudSystem%Op_Mud_Forehead_X%Length()) + imud = imud + 1 + + if (imud> 1) then + data%State%MudSystem%Op_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Op_Mud_Forehead_X%Array(imud-1) + data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)= data%State%MudSystem%Op_Mud_Forehead_section%Array(imud-1) + endif + + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))-data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))) +! +1 for string , -1 for annulus + + + + data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud))- data%State%MudSystem%Op_Mud_Backhead_X%Array(imud))* & + data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( data%State%MudSystem%Op_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%MudSystem%Op_Mud_Backhead_section%Array(imud) + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Op_Mud_Backhead_X%Array(imud)+ data%State%MudSystem%DirectionCoef*(data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_OpSectionFt(data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)) +! 7.48051948 is for gal to ft^3 + + else + + data%State%MudSystem%isection= data%State%MudSystem%Op_Mud_Backhead_section%Array(imud)+1 + data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Op_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection > data%State%F_Counts%BottomHoleIntervalCounts) then ! last pipe section(well exit) + if( imud==1) data%State%MudSystem%KickDeltaVinAnnulus= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud) ! Kick enters Annulus space + data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)= data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)- data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts) + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%F_Counts%BottomHoleIntervalCounts + + if (data%State%MudSystem%Op_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the well + call RemoveOpMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%OpSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%Op_Mud_Forehead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xend_OpSection(data%State%MudSystem%isection)- data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xstart_OpSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%Op_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%OpSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection+ 1 + + endif + + enddo + + endif + + if (data%State%MudSystem%Op_Mud_Forehead_X%Array(imud)== data%State%MudSystem%Xend_OpSection(data%State%F_Counts%BottomHoleIntervalCounts)) then + data%State%MudSystem%totalLength = data%State%MudSystem%Op_MudDischarged_Volume%Length() + do while(imud < data%State%MudSystem%totalLength) + +!imud = imud + 1 + call RemoveOpMudArrays(data%State%MudSystem%totalLength) + data%State%MudSystem%totalLength = data%State%MudSystem%totalLength - 1 + + + enddo + + exit ! + + endif + +!WRITE(*,*) imud,'Op_MudDischarged_Volume%Array(imud)' , Op_MudDischarged_Volume%Array(imud), Op_Density%Array(imud) + + + + + + + enddo + + +!write(*,*) 'Op_Mud_Forehead_X%Length()' , Op_Mud_Forehead_X%Length() +! +! WRITE(*,*) 'Xend_PipeSection(F_StringIntervalCounts)' , Xend_PipeSection(F_StringIntervalCounts) +! WRITE(*,*) 'Op_Mud_Backhead_X%Array(1)' , Op_Mud_Backhead_X%Array(1) +! WRITE(*,*) 'Op_Mud_Forehead_X%Array(1)' , Op_Mud_Forehead_X%Array(1) +! WRITE(*,*) 'Op_Mud_Backhead_X%Array(2)' , Op_Mud_Backhead_X%Array(2) +! WRITE(*,*) 'Op_Mud_Forehead_X%Array(2)' , Op_Mud_Forehead_X%Array(2) +!========================Bottom Hole END================= + + + + +! NO KICK + + + +!========================STRING ENTRANCE================= + + if ((ABS(data%State%MudSystem%St_Density%Last() - data%State%MudSystem%Ann_Density%First()) >= data%State%MudSystem%DensityMixTol) .OR. (data%State%MudSystem%DeltaVolumeOp == 0.0 .and. data%State%MudSystem%St_Density%Last() /= data%State%MudSystem%Ann_Density%Array(1) .and. data%State%MudSystem%StringFlowRate/=0.0d0)) then ! new mud is pumped + +!if ((ABS(StringDensity_Old - Ann_Density%First()) >= DensityMixTol) .OR. (DeltaVolumeOp == 0.0 .and. data%State%MudSystem%St_Density%Last() /= Ann_Density%Array(1) .and. data%State%MudSystem%StringFlowRate/=0.0d0)) then ! new mud is pumped + call data%State%MudSystem%St_Density%Add (data%State%MudSystem%Ann_Density%First()) + call data%State%MudSystem%St_MudDischarged_Volume%Add (0.0d0) + call data%State%MudSystem%St_Mud_Forehead_X%Add (data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts)) + call data%State%MudSystem%St_Mud_Forehead_section%Add (data%State%F_Counts%StringIntervalCounts) + call data%State%MudSystem%St_Mud_Backhead_X%Add (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts)) + call data%State%MudSystem%St_Mud_Backhead_section%Add (data%State%F_Counts%StringIntervalCounts) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%Add (0.0d0) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Add (0.0d0) + call data%State%MudSystem%St_MudOrKick%Add (0) + +!StringDensity_Old= Ann_Density%First() + + data%State%MudSystem%MudIsChanged= .true. + endif + + data%State%MudSystem%St_MudDischarged_Volume%Array(data%State%MudSystem%St_MudDischarged_Volume%Length())= data%State%MudSystem%St_MudDischarged_Volume%Last()+ ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline) !(gal) + +!========================Tripping In==================== + +!write(*,*) 'DeltaVolumeOp=' , DeltaVolumeOp +write(*,*) 'DeltaVolumeOp=' , data%State%MudSystem%DeltaVolumeOp + if (data%State%MudSystem%DeltaVolumeOp > 0.0 .and. data%State%MudSystem%MudIsChanged== .false.) then !.and. DrillingMode== .false.) then ! trip in mode(loole paeen) + +!write(*,*) 'Tripping In' + + data%State%MudSystem%NewDensity= (data%State%MudSystem%Ann_Density%First()*((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline)+data%State%MudSystem%Op_Density%Last()*data%State%MudSystem%DeltaVolumeOp)/(((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline)+data%State%MudSystem%DeltaVolumeOp) + data%State%MudSystem%NewVolume= ((data%State%MudSystem%StringFlowRate/60.0d0)*data%State%MudSystem%DeltaT_Mudline)+data%State%MudSystem%DeltaVolumeOp + +!write(*,*) 'St_MudDischarged_Volume%Last()=', St_MudDischarged_Volume%Last(), 'NewVolume=', NewVolume + + if (abs(data%State%MudSystem%St_Density%Last()-data%State%MudSystem%NewDensity)< data%State%MudSystem%DensityMixTol) then ! .OR. (St_MudDischarged_Volume%Last()< 42.) ) then !+ NewVolume)< 42.) then ! 1-Pockets are Merged + data%State%MudSystem%St_Density%Array(data%State%MudSystem%St_Density%Length())= (data%State%MudSystem%St_Density%Last()*data%State%MudSystem%St_MudDischarged_Volume%Last()+data%State%MudSystem%NewDensity*data%State%MudSystem%NewVolume)/(data%State%MudSystem%St_MudDischarged_Volume%Last()+data%State%MudSystem%NewVolume) + data%State%MudSystem%St_MudDischarged_Volume%Array(data%State%MudSystem%St_Density%Length())= data%State%MudSystem%St_MudDischarged_Volume%Last()+data%State%MudSystem%DeltaVolumeOp + data%State%MudSystem%St_Mud_Forehead_X%Array(data%State%MudSystem%St_Density%Length())= (data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts)) + data%State%MudSystem%St_Mud_Forehead_section%Array(data%State%MudSystem%St_Density%Length())= (data%State%F_Counts%StringIntervalCounts) + data%State%MudSystem%St_Mud_Backhead_X%Array(data%State%MudSystem%St_Density%Length())= (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts)) + data%State%MudSystem%St_Mud_Backhead_section%Array(data%State%MudSystem%St_Density%Length())= (data%State%F_Counts%StringIntervalCounts) + data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(data%State%MudSystem%St_Density%Length())= (0.0d0) + data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%St_Density%Length())= (0.0d0) + else ! 2-Merging conditions are not meeted, so new pocket + call data%State%MudSystem%St_Density%Add (data%State%MudSystem%NewDensity) + call data%State%MudSystem%St_MudDischarged_Volume%Add (data%State%MudSystem%NewVolume) + call data%State%MudSystem%St_Mud_Forehead_X%Add (data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts)) + call data%State%MudSystem%St_Mud_Forehead_section%Add (data%State%F_Counts%StringIntervalCounts) + call data%State%MudSystem%St_Mud_Backhead_X%Add (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts)) + call data%State%MudSystem%St_Mud_Backhead_section%Add (data%State%F_Counts%StringIntervalCounts) + call data%State%MudSystem%St_RemainedVolume_in_LastSection%Add (0.0d0) + call data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Add (0.0d0) + call data%State%MudSystem%St_MudOrKick%Add (0) + endif + + + elseif (data%State%MudSystem%DeltaVolumeOp > 0.0 .and. data%State%MudSystem%MudIsChanged== .true.) then + data%State%MudSystem%St_Density%Array(data%State%MudSystem%St_Density%Length())= data%State%MudSystem%NewDensity + data%State%MudSystem%St_MudDischarged_Volume%Array(data%State%MudSystem%St_Density%Length())= data%State%MudSystem%NewVolume + data%State%MudSystem%St_Mud_Forehead_X%Array(data%State%MudSystem%St_Density%Length())= (data%State%MudSystem%Xend_PipeSection(data%State%F_Counts%StringIntervalCounts)) + data%State%MudSystem%St_Mud_Forehead_section%Array(data%State%MudSystem%St_Density%Length())= (data%State%F_Counts%StringIntervalCounts) + data%State%MudSystem%St_Mud_Backhead_X%Array(data%State%MudSystem%St_Density%Length())= (data%State%MudSystem%Xstart_PipeSection(data%State%F_Counts%StringIntervalCounts)) + data%State%MudSystem%St_Mud_Backhead_section%Array(data%State%MudSystem%St_Density%Length())= (data%State%F_Counts%StringIntervalCounts) + data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(data%State%MudSystem%St_Density%Length())= (0.0d0) + data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(data%State%MudSystem%St_Density%Length())= (0.0d0) + endif + + +!========================Tripping In - End==================== + + +!======================== STRING ==================== + + data%State%MudSystem%MudIsChanged= .false. + + imud= data%State%MudSystem%St_Mud_Forehead_X%Length() + 1 + + do while (imud > 1) + imud = imud - 1 + + if (imud< data%State%MudSystem%St_Mud_Forehead_X%Length()) then + data%State%MudSystem%St_Mud_Forehead_X%Array(imud)= data%State%MudSystem%St_Mud_Backhead_X%Array(imud+1) + data%State%MudSystem%St_Mud_Forehead_section%Array(imud)= data%State%MudSystem%St_Mud_Backhead_section%Array(imud+1) + endif + + + data%State%MudSystem%DirectionCoef= (data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Forehead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Forehead_section%Array(imud))) & + / ABS(data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%St_Mud_Forehead_section%Array(imud))-data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Forehead_section%Array(imud))) +! +1 for string , -1 for annulus + + + data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%DirectionCoef* (data%State%MudSystem%St_Mud_Forehead_X%Array(imud)- data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%St_Mud_Forehead_section%Array(imud)))* & + data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%St_Mud_Backhead_section%Array(imud)) !(ft^3) + data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)= data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)* 7.48051948d0 ! ft^3 to gal + + + if ( data%State%MudSystem%St_MudDischarged_Volume%Array(imud) <= data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud)) then + data%State%MudSystem%St_Mud_Backhead_section%Array(imud)= data%State%MudSystem%St_Mud_Forehead_section%Array(imud) + data%State%MudSystem%St_Mud_Backhead_X%Array(imud)= data%State%MudSystem%St_Mud_Forehead_X%Array(imud)- data%State%MudSystem%DirectionCoef*(data%State%MudSystem%St_MudDischarged_Volume%Array(imud)/7.48051948d0)/data%State%MudSystem%Area_PipeSectionFt(data%State%MudSystem%St_Mud_Forehead_section%Array(imud)) +! 7.48051948 is for gal to ft^3 + else + + data%State%MudSystem%isection= data%State%MudSystem%St_Mud_Backhead_section%Array(imud)-1 + data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- data%State%MudSystem%St_EmptyVolume_inBackheadLocation%Array(imud) + + do + if (data%State%MudSystem%isection < 1) then ! last pipe section(string exit) + data%State%MudSystem%St_MudDischarged_Volume%Array(imud)= data%State%MudSystem%St_MudDischarged_Volume%Array(imud)- data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud) + data%State%MudSystem%St_Mud_Backhead_X%Array(imud)= data%State%MudSystem%Xstart_PipeSection(2) + data%State%MudSystem%St_Mud_Backhead_section%Array(imud)= 2 + + if (data%State%MudSystem%St_MudDischarged_Volume%Array(imud)<= 0.0d0) then ! imud is completely exited form the string + call RemoveStringMudArrays(imud) + endif + + exit + endif + + data%State%MudSystem%xx= data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)/ data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) !(gal) + + if (data%State%MudSystem%xx<= 1.0) then + data%State%MudSystem%St_Mud_Backhead_section%Array(imud)= data%State%MudSystem%isection + data%State%MudSystem%St_Mud_Backhead_X%Array(imud)= (data%State%MudSystem%xx * (data%State%MudSystem%Xstart_PipeSection(data%State%MudSystem%isection)- data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection)))+ data%State%MudSystem%Xend_PipeSection(data%State%MudSystem%isection) + exit + else + data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)= data%State%MudSystem%St_RemainedVolume_in_LastSection%Array(imud)- data%State%MudSystem%PipeSection_VolumeCapacity(data%State%MudSystem%isection) + data%State%MudSystem%isection= data%State%MudSystem%isection- 1 + + endif + + enddo + + endif + + enddo +!========================STRING END================= + + + + +end subroutine Utube2_and_TripIn diff --git a/Equipments/Pumps/Pumps_Inputs.f90 b/Equipments/Pumps/Pumps_Inputs.f90 index 6536581..566f42f 100644 --- a/Equipments/Pumps/Pumps_Inputs.f90 +++ b/Equipments/Pumps/Pumps_Inputs.f90 @@ -23,11 +23,11 @@ subroutine Pumps_Inputs end if end if - data%State%Pump(1)%AssignmentSwitchh = data%EquipmentControl%DrillingConsole%AssignmentSwitch + data%State%Pump(1)%AssignmentSwitchh = data%Equipments%DrillingConsole%AssignmentSwitch - data%State%Pump(1)%Switch = data%EquipmentControl%DrillingConsole%MP1CPSwitch + data%State%Pump(1)%Switch = data%Equipments%DrillingConsole%MP1CPSwitch - data%State%Pump(1)%Throttle = data%EquipmentControl%DrillingConsole%MP1Throttle ![RPM] + data%State%Pump(1)%Throttle = data%Equipments%DrillingConsole%MP1Throttle ![RPM] !data%State%Pump(1)%PowerFailMalf = 0 !??????? motaghayere voroudi (Pump1 Malfunction ----> Power Failure) !dar CPumpProblemsVariables meghdardehi mishavad @@ -54,11 +54,11 @@ subroutine Pumps_Inputs end if end if - data%State%Pump(2)%AssignmentSwitchh = data%EquipmentControl%DrillingConsole%AssignmentSwitch + data%State%Pump(2)%AssignmentSwitchh = data%Equipments%DrillingConsole%AssignmentSwitch - data%State%Pump(2)%Switch = data%EquipmentControl%DrillingConsole%MP2Switch + data%State%Pump(2)%Switch = data%Equipments%DrillingConsole%MP2Switch - data%State%Pump(2)%Throttle = data%EquipmentControl%DrillingConsole%MP2Throttle ![RPM] + data%State%Pump(2)%Throttle = data%Equipments%DrillingConsole%MP2Throttle ![RPM] !data%State%Pump(2)%PowerFailMalf = 0 !??????? motaghayere voroudi (Pump2 Malfunction ----> Power Failure) !dar CPumpProblemsVariables meghdardehi mishavad @@ -85,9 +85,9 @@ subroutine Pumps_Inputs end if end if - data%State%Pump(3)%Switch = data%EquipmentControl%DrillingConsole%MP1CPSwitch + data%State%Pump(3)%Switch = data%Equipments%DrillingConsole%MP1CPSwitch - data%State%Pump(3)%Throttle = data%EquipmentControl%DrillingConsole%MP1Throttle ![RPM] + data%State%Pump(3)%Throttle = data%Equipments%DrillingConsole%MP1Throttle ![RPM] !data%State%Pump(3)%PowerFailMalf = 0 !??????? motaghayere voroudi (Pump3 Malfunction ----> Power Failure) !dar CPumpProblemsVariables meghdardehi mishavad diff --git a/Equipments/Pumps/Pumps_Inputs.i90 b/Equipments/Pumps/Pumps_Inputs.i90 new file mode 100644 index 0000000..879e75c --- /dev/null +++ b/Equipments/Pumps/Pumps_Inputs.i90 @@ -0,0 +1,113 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/Pumps/Pumps_Inputs.f90" +subroutine Pumps_Inputs + + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables + use SimulationVariables + Use MudSystemModule + + IMPLICIT NONE + + + +!>>>>>>>>>>>>>>>>>>>>>>> PUMP 1 <<<<<<<<<<<<<<<<<<<<<<<<<<< + +!data%State%Pump(1)%BlowPopOffMalf = 0 !??????? motaghayere voroudi + + if ( data%State%Pump(1)%BlowPopOffMalf==1 ) then ! Pump1 Malfunction ----> Blow Pop-offs (Relief Valves) + data%State%Pump(1)%StandPipe_Pressure = 0.d0 + else + data%State%Pump(1)%StandPipe_Pressure = PumpPressure1 ![psi] + if ( data%State%Pump(1)%StandPipe_Pressure<=14.d0 ) then + data%State%Pump(1)%StandPipe_Pressure = 14.d0 + end if + end if + + data%State%Pump(1)%AssignmentSwitchh = data%Equipments%DrillingConsole%AssignmentSwitch + + data%State%Pump(1)%Switch = data%Equipments%DrillingConsole%MP1CPSwitch + + data%State%Pump(1)%Throttle = data%Equipments%DrillingConsole%MP1Throttle ![RPM] + +!data%State%Pump(1)%PowerFailMalf = 0 !??????? motaghayere voroudi (Pump1 Malfunction ----> Power Failure) !dar CPumpProblemsVariables meghdardehi mishavad + + data%State%Pump(1)%Failure = data%Warnings%Pump1Failure !(Pump1 Warning ----> Failure) + + data%State%Pump(1)%N_new = data%State%Pump(1)%Throttle + + + + + + + +!>>>>>>>>>>>>>>>>>>>>>>> PUMP 2 <<<<<<<<<<<<<<<<<<<<<<<<<<< + +!data%State%Pump(2)%BlowPopOffMalf = 0 !??????? motaghayere voroudi + + if ( data%State%Pump(2)%BlowPopOffMalf==1 ) then ! Pump2 Malfunction ----> Blow Pop-offs (Relief Valves) + data%State%Pump(2)%StandPipe_Pressure = 0.d0 + else + data%State%Pump(2)%StandPipe_Pressure = PumpPressure2 ![psi] + if ( data%State%Pump(2)%StandPipe_Pressure<=14.d0 ) then + data%State%Pump(2)%StandPipe_Pressure = 14.d0 + end if + end if + + data%State%Pump(2)%AssignmentSwitchh = data%Equipments%DrillingConsole%AssignmentSwitch + + data%State%Pump(2)%Switch = data%Equipments%DrillingConsole%MP2Switch + + data%State%Pump(2)%Throttle = data%Equipments%DrillingConsole%MP2Throttle ![RPM] + +!data%State%Pump(2)%PowerFailMalf = 0 !??????? motaghayere voroudi (Pump2 Malfunction ----> Power Failure) !dar CPumpProblemsVariables meghdardehi mishavad + + data%State%Pump(2)%Failure = data%Warnings%Pump2Failure !(Pump2 Warning ----> Failure) + + data%State%Pump(2)%N_new = data%State%Pump(2)%Throttle + + + + + + + +!!>>>>>>>>>>>>>>>>>>>>>>> PUMP 3 <<<<<<<<<<<<<<<<<<<<<<<<<<< + +!data%State%Pump(3)%BlowPopOffMalf = 0 !??????? motaghayere voroudi + + if ( data%State%Pump(3)%BlowPopOffMalf==1 ) then ! Pump3 Malfunction ----> Blow Pop-offs (Relief Valves) + data%State%Pump(3)%StandPipe_Pressure = 0.d0 + else + data%State%Pump(3)%StandPipe_Pressure = PumpPressure3 ![psi] + if ( data%State%Pump(3)%StandPipe_Pressure<=14.d0 ) then + data%State%Pump(3)%StandPipe_Pressure = 14.d0 + end if + end if + + data%State%Pump(3)%Switch = data%Equipments%DrillingConsole%MP1CPSwitch + + data%State%Pump(3)%Throttle = data%Equipments%DrillingConsole%MP1Throttle ![RPM] + +!data%State%Pump(3)%PowerFailMalf = 0 !??????? motaghayere voroudi (Pump3 Malfunction ----> Power Failure) !dar CPumpProblemsVariables meghdardehi mishavad + + data%State%Pump(3)%Failure = data%Warnings%Pump3Failure !(Pump1 Warning ----> Failure) + + data%State%Pump(3)%N_new = data%State%Pump(3)%Throttle + + + + + + +!>>>>>>>>>>>>>>>>>>>>>>> Total Pumps <<<<<<<<<<<<<<<<<<<<<<<<<<< + + + + + + + + +end subroutine Pumps_Inputs diff --git a/Equipments/Pumps/Pumps_Outputs.f90 b/Equipments/Pumps/Pumps_Outputs.f90 index d423585..0b555ef 100644 --- a/Equipments/Pumps/Pumps_Outputs.f90 +++ b/Equipments/Pumps/Pumps_Outputs.f90 @@ -20,14 +20,14 @@ subroutine Pumps_Outputs Call ClosePump1() End if - data%EquipmentControl%DrillingConsole%MP1BLWR = data%State%Pump(1)%BLWR + data%Equipments%DrillingConsole%MP1BLWR = data%State%Pump(1)%BLWR Call SetSoundBlowerMP1( data%State%Pump(1)%SoundBlower ) !.true. or .false. Call SetSoundMP1( data%State%Pump(1)%SoundSPM ) ![spm] , integer if ((data%State%Pump(1)%Switch==-1) .or. (data%State%Pump(1)%Switch==0)) then Call Set_MP1SPMGauge( sngl(1-data%State%Pump(1)%SPMGaugeMalf)*real((data%State%Pump(1)%Speed/data%State%Pump(1)%Trans_Ratio),8) ) ![spm] , real - data%EquipmentControl%DrillingWatch%SPM1 = data%EquipmentControl%DataDisplayConsole%MP1SPMGauge + data%Equipments%DrillingWatch%SPM1 = data%Equipments%DataDisplayConsole%MP1SPMGauge end if !data%State%Pump(1)%Flow_Rate !to other modules , [gpm] @@ -46,13 +46,13 @@ subroutine Pumps_Outputs Call ClosePump2() End if - data%EquipmentControl%DrillingConsole%MP2BLWR = data%State%Pump(2)%BLWR + data%Equipments%DrillingConsole%MP2BLWR = data%State%Pump(2)%BLWR Call SetSoundBlowerMP2( data%State%Pump(2)%SoundBlower ) Call SetSoundMP2( data%State%Pump(2)%SoundSPM ) Call Set_MP2SPMGauge( sngl(1-data%State%Pump(2)%SPMGaugeMalf)*real((data%State%Pump(2)%Speed/data%State%Pump(2)%Trans_Ratio),8) ) - data%EquipmentControl%DrillingWatch%SPM2 = data%EquipmentControl%DataDisplayConsole%MP2SPMGauge + data%Equipments%DrillingWatch%SPM2 = data%Equipments%DataDisplayConsole%MP2SPMGauge !data%State%Pump(2)%Flow_Rate !to other modules @@ -73,7 +73,7 @@ subroutine Pumps_Outputs if (data%State%Pump(3)%Switch==1) then Call Set_MP1SPMGauge( real((data%State%Pump(3)%Speed/data%State%Pump(3)%Trans_Ratio),8) ) - data%EquipmentControl%DrillingWatch%SPM1 = data%EquipmentControl%DataDisplayConsole%MP1SPMGauge + data%Equipments%DrillingWatch%SPM1 = data%Equipments%DataDisplayConsole%MP1SPMGauge end if !data%State%Pump(3)%Flow_Rate !to other modules diff --git a/Equipments/Pumps/Pumps_Outputs.i90 b/Equipments/Pumps/Pumps_Outputs.i90 new file mode 100644 index 0000000..3cc54b5 --- /dev/null +++ b/Equipments/Pumps/Pumps_Outputs.i90 @@ -0,0 +1,97 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/Pumps/Pumps_Outputs.f90" +subroutine Pumps_Outputs + + use CDataDisplayConsole + use SimulationVariables +! Use CSimulationVariables + use SimulationVariables + Use MudSystemModule + use SimulationVariables !@ + Use CSounds + + IMPLICIT NONE + + + +!>>>>>>>>>>>>>>>>>>>>>>> PUMP 1 <<<<<<<<<<<<<<<<<<<<<<<<<<< + + If (data%State%Pump(1)%Open_Close==1) then + Call OpenPump1() + Else if (data%State%Pump(1)%Open_Close==0) then + Call ClosePump1() + End if + + data%Equipments%DrillingConsole%MP1BLWR = data%State%Pump(1)%BLWR + + Call SetSoundBlowerMP1( data%State%Pump(1)%SoundBlower ) !.true. or .false. + Call SetSoundMP1( data%State%Pump(1)%SoundSPM ) ![spm] , integer + + if ((data%State%Pump(1)%Switch==-1) .or. (data%State%Pump(1)%Switch==0)) then + Call Set_MP1SPMGauge( sngl(1-data%State%Pump(1)%SPMGaugeMalf)*real((data%State%Pump(1)%Speed/data%State%Pump(1)%Trans_Ratio),8) ) ![spm] , real + data%Equipments%DrillingWatch%SPM1 = data%Equipments%DataDisplayConsole%MP1SPMGauge + end if + +!data%State%Pump(1)%Flow_Rate !to other modules , [gpm] + + + + + + + +!>>>>>>>>>>>>>>>>>>>>>>> PUMP 2 <<<<<<<<<<<<<<<<<<<<<<<<<<< + + If (data%State%Pump(2)%Open_Close==1) then + Call OpenPump2() + Else if (data%State%Pump(2)%Open_Close==0) then + Call ClosePump2() + End if + + data%Equipments%DrillingConsole%MP2BLWR = data%State%Pump(2)%BLWR + + Call SetSoundBlowerMP2( data%State%Pump(2)%SoundBlower ) + Call SetSoundMP2( data%State%Pump(2)%SoundSPM ) + + Call Set_MP2SPMGauge( sngl(1-data%State%Pump(2)%SPMGaugeMalf)*real((data%State%Pump(2)%Speed/data%State%Pump(2)%Trans_Ratio),8) ) + data%Equipments%DrillingWatch%SPM2 = data%Equipments%DataDisplayConsole%MP2SPMGauge + +!data%State%Pump(2)%Flow_Rate !to other modules + + + + + + +!!>>>>>>>>>>>>>>>>>>>>>>> PUMP 3 <<<<<<<<<<<<<<<<<<<<<<<<<<< + + If (data%State%Pump(3)%Open_Close==1) then + Call OpenCementPump() + Else if (data%State%Pump(3)%Open_Close==0) then + Call CloseCementPump() + End if + + Call SetSoundMP3( data%State%Pump(3)%SoundSPM ) + + if (data%State%Pump(3)%Switch==1) then + Call Set_MP1SPMGauge( real((data%State%Pump(3)%Speed/data%State%Pump(3)%Trans_Ratio),8) ) + data%Equipments%DrillingWatch%SPM1 = data%Equipments%DataDisplayConsole%MP1SPMGauge + end if + +!data%State%Pump(3)%Flow_Rate !to other modules + + + +!>>>>>>>>>>>>>>>>>>>>>>> Total Pumps <<<<<<<<<<<<<<<<<<<<<<<<<<< + +!data%State%MPumps%Total_Pump_Gpm = 100.d0 !??????????? +!data%State%MPumps%Total_Pump_SPM = 1000.d0 !????????????? + +!SCR1LED=1 +!SCR2LED=1 +!SCR3LED=1 +!SCR4LED=1 + + + + +end subroutine Pumps_Outputs diff --git a/Equipments/RotaryTable/RTable_INPUTS.f90 b/Equipments/RotaryTable/RTable_INPUTS.f90 index 7bf5086..f2972fc 100644 --- a/Equipments/RotaryTable/RTable_INPUTS.f90 +++ b/Equipments/RotaryTable/RTable_INPUTS.f90 @@ -20,10 +20,10 @@ subroutine RTable_INPUTS - data%State%RTable%AssignmentSwitch = data%EquipmentControl%DrillingConsole%AssignmentSwitch - data%State%RTable%Switch = data%EquipmentControl%DrillingConsole%RTSwitch + data%State%RTable%AssignmentSwitch = data%Equipments%DrillingConsole%AssignmentSwitch + data%State%RTable%Switch = data%Equipments%DrillingConsole%RTSwitch !data%State%RTable%GearsAbuse = RotaryGearsAbuse - data%State%RTable%Throttle = data%EquipmentControl%DrillingConsole%RTThrottle ![RPM] + data%State%RTable%Throttle = data%Equipments%DrillingConsole%RTThrottle ![RPM] data%State%RTable%String_Torque = data%State%TD_String%StringTorque*12.d0 ![lb.ft]*12 ---> [lb.in] ????????? !data%State%RTable%RpmGaugeMalf !:dar module haye C meghdardehi mishe diff --git a/Equipments/RotaryTable/RTable_Inputs.i90 b/Equipments/RotaryTable/RTable_Inputs.i90 new file mode 100644 index 0000000..99c41db --- /dev/null +++ b/Equipments/RotaryTable/RTable_Inputs.i90 @@ -0,0 +1,81 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/RotaryTable/RTable_Inputs.f90" +subroutine RTable_INPUTS + + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables +! use CSimulationVariables + use UnitySignalsModule +! use CTdsElevatorModesEnumVariables + use CHoistingVariables + use SimulationVariables + use SimulationVariables !@ + use TD_DrillStemComponents + use CUnityInputs + use CWarnings + use UnitySignalVariables + use UnitySignalsModule + + IMPLICIT NONE + integer :: i + + + + data%State%RTable%AssignmentSwitch = data%Equipments%DrillingConsole%AssignmentSwitch + data%State%RTable%Switch = data%Equipments%DrillingConsole%RTSwitch +!data%State%RTable%GearsAbuse = RotaryGearsAbuse + data%State%RTable%Throttle = data%Equipments%DrillingConsole%RTThrottle ![RPM] + data%State%RTable%String_Torque = data%State%TD_String%StringTorque*12.d0 ![lb.ft]*12 ---> [lb.in] ????????? +!data%State%RTable%RpmGaugeMalf !:dar module haye C meghdardehi mishe + + + + + data%State%RTable%N_new = data%State%RTable%Throttle + if ( data%State%RTable%MotorFaileMalf==1 ) then + data%State%RTable%N_new = 0.d0 + end if + data%State%RTable%String_Torque = 0.112984d0*data%State%RTable%String_Torque ![N.m] + + + +!===> String_JCoef Calculation + if ( data%Configuration%Hoisting%DriveType==0 ) then + if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_NOTHING ) then + data%State%RTable%RotaryMode = 1 + data%State%RTable%String_JCoef = 0.d0 + Do i = 1,data%State%TD_String%StringConfigurationCount + data%State%RTable%String_JCoef = data%State%RTable%String_JCoef+( (data%State%TD_DrillStem(i)%TotalWeight*((data%State%TD_DrillStem(i)%Id**2.d0)+(data%State%TD_DrillStem(i)%Od**2.d0)))/8.d0 ) ![lb.ft^2] , Jz=(1/2)*m*(r1^2+r2^2) + End Do + data%State%RTable%String_JCoef = data%State%RTable%String_JCoef*0.0421401d0 ![kg.m^2] + else if ( Get_Slips() /= SLIPS_SET_END ) then + data%State%RTable%RotaryMode = 2 + data%State%RTable%String_JCoef = 0.d0 + data%State%RTable%String_Torque = 0.d0 + else + data%State%RTable%RotaryMode = 3 + data%State%RTable%String_JCoef = 0.d0 + data%State%RTable%String_Torque = 0.d0 + end if + else if ( data%Configuration%Hoisting%DriveType==1 ) then + if ( Get_IsKellyBushingSetInTable() .or. Get_Slips() == SLIPS_SET_END ) then !if rotary connected to string + data%State%RTable%RotaryMode = 4 + data%State%RTable%String_JCoef = 0.d0 + Do i = 1,data%State%TD_String%StringConfigurationCount + data%State%RTable%String_JCoef = data%State%RTable%String_JCoef+( (data%State%TD_DrillStem(i)%TotalWeight*((data%State%TD_DrillStem(i)%Id**2.d0)+(data%State%TD_DrillStem(i)%Od**2.d0)))/8.d0 ) ![lb.ft^2] , Jz=(1/2)*m*(r1^2+r2^2) + End Do + data%State%RTable%String_JCoef = data%State%RTable%String_JCoef*0.0421401e0 ![kg.m^2] + else + data%State%RTable%RotaryMode = 5 + data%State%RTable%String_JCoef = 0.d0 + data%State%RTable%String_Torque = 0.d0 + end if + end if + + +!===> Transmission Mode + data%State%RTable%Conv_Ratio = data%State%RTable%High_Conv_Ratio + + + +end subroutine RTable_INPUTS diff --git a/Equipments/RotaryTable/RTable_Outputs.f90 b/Equipments/RotaryTable/RTable_Outputs.f90 index e950444..63b4166 100644 --- a/Equipments/RotaryTable/RTable_Outputs.f90 +++ b/Equipments/RotaryTable/RTable_Outputs.f90 @@ -13,7 +13,7 @@ subroutine RTable_Outputs - data%EquipmentControl%DrillingConsole%RTBLWR = data%State%RTable%BLWR + data%Equipments%DrillingConsole%RTBLWR = data%State%RTable%BLWR Call SetSoundBlowerRT(data%State%RTable%SoundBlower) !.true. or .false. Call SetSoundRT( data%State%RTable%SoundRPM ) ![RPM] , integer @@ -21,8 +21,8 @@ subroutine RTable_Outputs !data%State%RTable%Speed !to other modules Call Set_RotaryRPMGauge( sngl(1-data%State%RTable%RpmGaugeMalf)*real(data%State%RTable%RpmGaugeOutput,8) ) ![RPM] - data%EquipmentControl%DataDisplayConsole%RotaryTorqueGauge = data%State%RTable%TorqueGaugeOutput ![ft.lbf] - data%EquipmentControl%DrillingWatch%Torque = data%State%RTable%TorqueGaugeOutput + data%Equipments%DataDisplayConsole%RotaryTorqueGauge = data%State%RTable%TorqueGaugeOutput ![ft.lbf] + data%Equipments%DrillingWatch%Torque = data%State%RTable%TorqueGaugeOutput Call Set_RotaryTorque(sngl(1-data%State%RTable%TorqueGaugeMalf)*real(data%State%RTable%TorqueGaugeOutput,8)) ![ft.lbf] !RT_RPMUnityOutput = sngl(data%State%RTable%Switch)*-1.d0*RotaryRPMGauge diff --git a/Equipments/RotaryTable/RTable_Outputs.i90 b/Equipments/RotaryTable/RTable_Outputs.i90 new file mode 100644 index 0000000..08980fe --- /dev/null +++ b/Equipments/RotaryTable/RTable_Outputs.i90 @@ -0,0 +1,33 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/RotaryTable/RTable_Outputs.f90" +subroutine RTable_Outputs + + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables + use CDataDisplayConsole + use SimulationVariables + use SimulationVariables !@ + use SimulationVariables !@ + Use CSounds + + IMPLICIT NONE + + + + data%Equipments%DrillingConsole%RTBLWR = data%State%RTable%BLWR + + Call SetSoundBlowerRT(data%State%RTable%SoundBlower) !.true. or .false. + Call SetSoundRT( data%State%RTable%SoundRPM ) ![RPM] , integer + +!data%State%RTable%Speed !to other modules + Call Set_RotaryRPMGauge( sngl(1-data%State%RTable%RpmGaugeMalf)*real(data%State%RTable%RpmGaugeOutput,8) ) ![RPM] + + data%Equipments%DataDisplayConsole%RotaryTorqueGauge = data%State%RTable%TorqueGaugeOutput ![ft.lbf] + data%Equipments%DrillingWatch%Torque = data%State%RTable%TorqueGaugeOutput + Call Set_RotaryTorque(sngl(1-data%State%RTable%TorqueGaugeMalf)*real(data%State%RTable%TorqueGaugeOutput,8)) ![ft.lbf] + +!RT_RPMUnityOutput = sngl(data%State%RTable%Switch)*-1.d0*RotaryRPMGauge + + + +end subroutine RTable_Outputs diff --git a/Equipments/RotaryTable/RotaryTableMain.i90 b/Equipments/RotaryTable/RotaryTableMain.i90 new file mode 100644 index 0000000..2d75f64 --- /dev/null +++ b/Equipments/RotaryTable/RotaryTableMain.i90 @@ -0,0 +1,49 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/RotaryTable/RotaryTableMain.f90" +module RotaryTableMain + implicit none + public + contains + + subroutine RotaryTable_Setup() +!use CSimulationVariables +!call OnSimulationInitialization%Add(RotaryTable_Init) +!call OnSimulationStop%Add(RotaryTable_Init) +!call OnRotaryTableStep%Add(RotaryTable_Step) +!call OnRotaryTableOutput%Add(RotaryTable_Output) +!call OnRotaryTableMain%Add(RotaryTableMainBody) + end subroutine + + subroutine RotaryTable_Init + Call RTable_StartUp + end subroutine RotaryTable_Init + + subroutine RotaryTable_Step + Call Rtable_MainSolver + end subroutine RotaryTable_Step + + subroutine RotaryTable_Output + implicit none + end subroutine RotaryTable_Output + + + subroutine RotaryTableMainBody + + use SimulationVariables !@ + + implicit none + + + Call RTable_StartUp + + loopRtablestart : do + + Call RTable_MainSolver + + end do loopRtablestart + + + end subroutine RotaryTableMainBody + + + +end module RotaryTableMain diff --git a/Equipments/TopDrive/TopDrive_INPUTS.f90 b/Equipments/TopDrive/TopDrive_INPUTS.f90 index 3c5bd7e..72f3665 100644 --- a/Equipments/TopDrive/TopDrive_INPUTS.f90 +++ b/Equipments/TopDrive/TopDrive_INPUTS.f90 @@ -16,12 +16,12 @@ subroutine TopDrive_Inputs data%State%TDS%String_Torque = data%State%TD_String%StringTorque*12.d0 ![lb.ft]*12 ---> [lb.in] ????????? !data%State%TDS%String_Torque = 20000. data%State%TDS%String_Torque = 0.112984829d0*data%State%TDS%String_Torque ![N.m] - data%State%TDS%PowerState = data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerState - data%State%TDS%RpmKnob = data%EquipmentControl%TopDrivePanel%RpmKnob + data%State%TDS%PowerState = data%Equipments%TopDrivePanel%TopDriveTdsPowerState + data%State%TDS%RpmKnob = data%Equipments%TopDrivePanel%RpmKnob !data%State%TDS%MotorFaileMalf ! jayi meghdardehi nashode ?????????????????? data%State%TDS%RateChange = 193.d0 ![RPM/s] motaghayere voroudi ??? - data%State%TDS%DrillTorqueState = data%EquipmentControl%TopDrivePanel%TopDriveDrillTorqueState - data%State%TDS%TorqueLimitKnob = data%EquipmentControl%TopDrivePanel%TopDriveTorqueLimitKnob ! bayad hazf shavad??????????????/ + data%State%TDS%DrillTorqueState = data%Equipments%TopDrivePanel%TopDriveDrillTorqueState + data%State%TDS%TorqueLimitKnob = data%Equipments%TopDrivePanel%TopDriveTorqueLimitKnob ! bayad hazf shavad??????????????/ diff --git a/Equipments/TopDrive/TopDrive_Inputs.i90 b/Equipments/TopDrive/TopDrive_Inputs.i90 new file mode 100644 index 0000000..e5f26af --- /dev/null +++ b/Equipments/TopDrive/TopDrive_Inputs.i90 @@ -0,0 +1,46 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/TopDrive/TopDrive_Inputs.f90" +subroutine TopDrive_Inputs + +! Use CSimulationVariables + use CTopDrivePanelVariables + use SimulationVariables + use UnitySignalsModule + use SimulationVariables + Use TD_DrillStemComponents + + IMPLICIT NONE + + integer :: i + + + + data%State%TDS%String_Torque = data%State%TD_String%StringTorque*12.d0 ![lb.ft]*12 ---> [lb.in] ????????? +!data%State%TDS%String_Torque = 20000. + data%State%TDS%String_Torque = 0.112984829d0*data%State%TDS%String_Torque ![N.m] + data%State%TDS%PowerState = data%Equipments%TopDrivePanel%TopDriveTdsPowerState + data%State%TDS%RpmKnob = data%Equipments%TopDrivePanel%RpmKnob +!data%State%TDS%MotorFaileMalf ! jayi meghdardehi nashode ?????????????????? + data%State%TDS%RateChange = 193.d0 ![RPM/s] motaghayere voroudi ??? + data%State%TDS%DrillTorqueState = data%Equipments%TopDrivePanel%TopDriveDrillTorqueState + data%State%TDS%TorqueLimitKnob = data%Equipments%TopDrivePanel%TopDriveTorqueLimitKnob ! bayad hazf shavad??????????????/ + + + +!===> data%State%TDS%String_JCoef Calculation + if ( (data%State%TDS%DrillTorqueState==-1) .and. ((Get_TdsConnectionModes()==TDS_CONNECTION_STRING).or.(Get_TdsConnectionModes()==TDS_CONNECTION_SPINE)) ) then !if TopDrive connected to string + data%State%TDS%String_JCoef = 0.d0 + Do i = 1,data%State%TD_String%StringConfigurationCount + data%State%TDS%String_JCoef = data%State%TDS%String_JCoef+( (data%State%TD_DrillStem(i)%TotalWeight*((data%State%TD_DrillStem(i)%Id**2.d0)+(data%State%TD_DrillStem(i)%Od**2.d0)))/8.d0 ) ![lb.ft^2] , Jz=(1/2)*m*(r1^2+r2^2) + End Do + data%State%TDS%String_JCoef = data%State%TDS%String_JCoef*0.0421401d0 ![kg.m^2] + else + data%State%TDS%String_JCoef = 0.d0 + data%State%TDS%String_Torque = 0.d0 + end if + data%State%TDS%String_JCoef = data%State%TDS%String_JCoef/10.d0 !???????? /10: bi dalil, check it + + + + + +end subroutine diff --git a/Equipments/TopDrive/TopDrive_Outputs.f90 b/Equipments/TopDrive/TopDrive_Outputs.f90 index a745805..2c83a6d 100644 --- a/Equipments/TopDrive/TopDrive_Outputs.f90 +++ b/Equipments/TopDrive/TopDrive_Outputs.f90 @@ -8,13 +8,13 @@ Subroutine TopDrive_Outputs - data%EquipmentControl%TopDrivePanel%TopDriveTdsPowerLed = data%State%TDS%PowerLed - data%EquipmentControl%TopDrivePanel%TopDriveOperationFaultLed = data%State%TDS%OperationFaultLed + data%Equipments%TopDrivePanel%TopDriveTdsPowerLed = data%State%TDS%PowerLed + data%Equipments%TopDrivePanel%TopDriveOperationFaultLed = data%State%TDS%OperationFaultLed !data%State%TDS%Speed ! to other modules ![RPM] - data%EquipmentControl%TopDrivePanel%TopDriveRpmGauge = data%State%TDS%RpmGaugeOutput ![RPM] + data%Equipments%TopDrivePanel%TopDriveRpmGauge = data%State%TDS%RpmGaugeOutput ![RPM] - data%EquipmentControl%TopDrivePanel%TopDriveTorqueGauge = data%State%TDS%TorqueGaugeOutput ![ft.lbf] + data%Equipments%TopDrivePanel%TopDriveTorqueGauge = data%State%TDS%TorqueGaugeOutput ![ft.lbf] !data%State%TDS%SoundBlower !data%State%TDS%RPMUnityOutput diff --git a/Equipments/TopDrive/TopDrive_Outputs.i90 b/Equipments/TopDrive/TopDrive_Outputs.i90 new file mode 100644 index 0000000..a7bf58d --- /dev/null +++ b/Equipments/TopDrive/TopDrive_Outputs.i90 @@ -0,0 +1,25 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Equipments/TopDrive/TopDrive_Outputs.f90" +Subroutine TopDrive_Outputs + + use SimulationVariables + use CTopDrivePanelVariables + use SimulationVariables + + IMPLICIT NONE + + + + data%Equipments%TopDrivePanel%TopDriveTdsPowerLed = data%State%TDS%PowerLed + data%Equipments%TopDrivePanel%TopDriveOperationFaultLed = data%State%TDS%OperationFaultLed + +!data%State%TDS%Speed ! to other modules ![RPM] + data%Equipments%TopDrivePanel%TopDriveRpmGauge = data%State%TDS%RpmGaugeOutput ![RPM] + + data%Equipments%TopDrivePanel%TopDriveTorqueGauge = data%State%TDS%TorqueGaugeOutput ![ft.lbf] + +!data%State%TDS%SoundBlower +!data%State%TDS%RPMUnityOutput + + + +End Subroutine TopDrive_Outputs diff --git a/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90 b/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90 index 370f635..5ace983 100644 --- a/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90 +++ b/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90 @@ -65,7 +65,7 @@ IF (KickVARIABLES%WellHeadOpen .OR. KickVARIABLES%NoGasPocket == 0) THEN !! ( IF (KickVARIABLES%WellHeadWasOpen == .FALSE. .AND. KickVARIABLES%NoGasPocket > 0 .AND. KickIteration == 1) THEN IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN ! flow on choke line IF (data%State%FricPressDrop%TotalOpenChokeArea < 0.01 * data%State%Choke%ChokeAreaFullyOpen) THEN - WRITE (*,*) 'density , TotalOpenChokeArea' , DownHole%Density, data%State%FricPressDrop%TotalOpenChokeArea + WRITE (*,*) 'density , TotalOpenChokeArea' , "data%Equipments%DownHole%Density", data%State%FricPressDrop%TotalOpenChokeArea data%State%FricPressDrop%TotalOpenChokeArea = 0.01 * data%State%Choke%ChokeAreaFullyOpen END IF data%State%FricPressDrop%Kchoke = (KickVARIABLES%ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * data%State%FricPressDrop%TotalOpenChokeArea)**2)) * 4.0 ! *4.d0: seyyed gofte diff --git a/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.i90 b/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.i90 new file mode 100644 index 0000000..90c37a2 --- /dev/null +++ b/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.i90 @@ -0,0 +1,282 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/FluidFlow/Annulus_and_Openhole_Pressure_Distribution.f90" +SUBROUTINE PressureAnnAndOHDistribution + +!! Record of revisions +!! Date Programmer Discription of change +!! ------ ------------ ----------------------- +!! 1396/07/30 Sheikh Original code +!! + + USE FricPressDropVarsModule + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use PressureDisplayVARIABLESModule + USE GeoElements_FluidModule + USE Fluid_Flow_Startup_Vars + use KickVARIABLESModule + USE CMudPropertiesVariables + use SimulationVariables !@ + USE CReservoirVariables + use MudSystemModule + USE CHOKEVARIABLES +use SimulationVariables !@ + use CChokeManifoldVariables + use SimulationVariables + use SimulationVariables + USE CError + USE , INTRINSIC :: IEEE_ARITHMETIC + + + IMPLICIT NONE + + INTEGER :: i , j , k , l + INTEGER :: ifric + REAL :: Fraction + + + data%State%FricPressDrop%KBOP = 0.0 + + + +IF (KickVARIABLES%WellHeadOpen .OR. KickVARIABLES%NoGasPocket == 0) THEN !! (mud circulation is normal wellhead may be open or closed) OR (kick is in the well and well head is open) + + +!!!!! Determining flow rate in each section + i = data%State%FricPressDrop%AnnulusFirstEl + j = data%State%FricPressDrop%OpenholeFirstEl - 1 + +!!!!!!!!!!!!!!!!!!!!!!!!! flowrates due to external sources like pump and tripping + FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate = (ClingingFactor * FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%OpenholeFirstEl - 1)%Area + FlowEl(data%State%FricPressDrop%StringFirstEl)%Area) * KickVARIABLES%DrillStringSpeed * ConvMintoSec * Convft3toUSgal ! flowrate in annulus due to tripping + + FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate = FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate + REAL(data%State%MudSystem%MudVolume_InjectedToBH) * ConvMintoSec / dt ! flowrate in annulus due to pump + + IF (data%State%MudSystem%ShoeFractured) THEN ! reduction of flowrate due to formation fracture and lost circulation + + IF (ShoeFlowElNo > data%State%FricPressDrop%AnnulusLastEl) THEN ! shoe is in openhole + FlowEl(ShoeFlowElNo : data%State%FricPressDrop%NumbEl)%FlowRate = - data%State%MudSystem%Qlost + FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate = FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate - data%State%MudSystem%Qlost + ELSE ! shoe is in annulus + FlowEl(ShoeFlowElNo : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate = FlowEl(ShoeFlowElNo : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate - data%State%MudSystem%Qlost + END IF + END IF + + +!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!! initial guess flowrates for opening BOP or choke line + IF (KickVARIABLES%WellHeadWasOpen == .FALSE. .AND. KickVARIABLES%NoGasPocket > 0 .AND. KickIteration == 1) THEN + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN ! flow on choke line + IF (data%State%FricPressDrop%TotalOpenChokeArea < 0.01 * data%State%Choke%ChokeAreaFullyOpen) THEN + WRITE (*,*) 'density , TotalOpenChokeArea' , "data%Equipments%DownHole%Density", data%State%FricPressDrop%TotalOpenChokeArea + data%State%FricPressDrop%TotalOpenChokeArea = 0.01 * data%State%Choke%ChokeAreaFullyOpen + END IF + data%State%FricPressDrop%Kchoke = (KickVARIABLES%ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * data%State%FricPressDrop%TotalOpenChokeArea)**2)) * 4.0 ! *4.d0: seyyed gofte + GasPocketFlowInduced%Array(:) = MIN((0.6 / KickVARIABLES%NoGasPocket * SQRT(data%State%PressureDisplay%PressureGauges(2) / data%State%FricPressDrop%Kchoke)) , (0.05 * GasPocketNewVol%Array(:) * ConvFt3toUSgal / 60 / dt)) + WRITE (*,*) ' PressureGauges(2) , Kchoke' , data%State%PressureDisplay%PressureGauges(2) , data%State%FricPressDrop%Kchoke + WRITE (*,*) 'Initial guess after opening choke =', GasPocketFlowInduced%Array(1) + + WRITE (*,*) ' valve 49 ', Manifold%Valve(49)%Status + WRITE (*,*) ' valve 47 ', Manifold%Valve(47)%Status + WRITE (*,*) ' valve 26 ', Manifold%Valve(26)%Status + WRITE (*,*) ' valve 30 ', Manifold%Valve(30)%Status + WRITE (*,*) ' valve 34 ', Manifold%Valve(34)%Status + WRITE (*,*) ' valve 63 ', Manifold%Valve(63)%Status + WRITE (*,*) ' valve 28 ', Manifold%Valve(28)%Status + WRITE (*,*) ' valve 33 ', Manifold%Valve(33)%Status + WRITE (*,*) ' valve 62 ', Manifold%Valve(62)%Status + WRITE (*,*) ' valve 36 ', Manifold%Valve(36)%Status + WRITE (*,*) ' valve 38 ', Manifold%Valve(38)%Status + + ELSE ! flow through bell nipple + k = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + data%State%FricPressDrop%KBOP = FlowEl(data%State%FricPressDrop%AnnulusLastEl)%Density / ((2.0 * 89158.0) * (0.26 * 0.61 * data%State%ShearRAM%MinimumOpenArea_InBOP)**2) + GasPocketFlowInduced%Array(:) = MIN((0.1 / KickVARIABLES%NoGasPocket * SQRT(data%State%PressureDisplay%PressureGauges(6) / data%State%FricPressDrop%KBOP)) , (0.05 * GasPocketNewVol%Array(:) * ConvFt3toUSgal / 60 / dt)) + WRITE (*,*) 'PressureGauges(6), KBOP', data%State%PressureDisplay%PressureGauges(6), data%State%FricPressDrop%KBOP + WRITE (*,*) 'Initial guess after opening BOP =', GasPocketFlowInduced%Array(1) + END IF + END IF +!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!!!!!!! flowrates due to expansion of gas pockets or kick influx +!i = AnnulusFirstEl +!j = OpenholeFirstEl - 1 + IF (KickVARIABLES%NoGasPocket > 0) THEN + DO l = 1 , KickVARIABLES%NoGasPocket !GasPocketFlowEl + k = KickVARIABLES%GasPocketFlowEl(l , 1) +!WRITE (*,*) 'KickVARIABLES%GasPocketFlowEl(l , 1)', l, k, j + IF (k == 0) CALL ERRORSTOP('GasPocketFlowEl(l , 1) == 0', l) + + IF (k >= data%State%FricPressDrop%OpenholeFirstEl) THEN ! gas pocket is in open hole only + FlowEl(k : data%State%FricPressDrop%NumbEl)%FlowRate = FlowEl(k : data%State%FricPressDrop%NumbEl)%FlowRate + GasPocketFlowInduced%Array(l) ! openhole elements above pocket + FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate = FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate + GasPocketFlowInduced%Array(l) ! annulus and choke line elements + ELSE IF (k < data%State%FricPressDrop%OpenholeFirstEl) THEN ! gas pocket is in annulus ond/or choke line only + FlowEl(k : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate = FlowEl(k : data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate + GasPocketFlowInduced%Array(l) ! annulus or choke line elements above pocket + END IF + END DO + END IF + + +!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!! END - Determining flow rate in each section + +!!!!!!!!!!!!!!!!!!!!!!!!! effect of surge and swab on frictional pressure drop direction + DO l = data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%OpenholeFirstEl - 1 + IF (FlowEl(l)%FlowRate < 0.0) THEN + FlowEl(l)%FrictionDirection = -1 + IF (FlowEl(l)%FlowRate > -1.0 * PressFlowrateTolerance .AND. ALLOCATED(GasPocketWeight%Array)) FlowEl(l)%FlowRate = - PressFlowrateTolerance + ELSE + FlowEl(l)%FrictionDirection = 1 + IF (FlowEl(l)%FlowRate < PressFlowrateTolerance .AND. ALLOCATED(GasPocketWeight%Array)) FlowEl(l)%FlowRate = PressFlowrateTolerance + END IF + END DO +!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!!!!!!! Calculating Back Pressure, in well to pit path back pressure = 0 +! in well to choke manifold path back pressure is equal to pressure before choke not casing pressure + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN + + IF (FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate < 0.0) THEN + WRITE (*,*) ' Negative choke flowrate' + FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate = MAX((REAL(data%State%MudSystem%MudVolume_InjectedToBH) * ConvMintoSec / dt) , 10.0) + END IF + data%State%MudSystem%deltaPchoke = (data%State%FricPressDrop%Kchoke * FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate * ABS(FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%FlowRate)) * 1.d0 + IF (data%State%MudSystem%deltaPchoke < 0.d0) data%State%MudSystem%deltaPchoke = 0.d0 + data%State%FricPressDrop%BackPressure = REAL(data%State%MudSystem%deltaPchoke) + ELSE + data%State%FricPressDrop%BackPressure = 0.0 + END IF + IF (IEEE_IS_NaN(data%State%FricPressDrop%BackPressure)) CALL ErrorStop('NaN in calculating back pressure' , FlowEl(j)%FlowRate) +!write(*,*) 'BackPressure=' , BackPressure + +!!!!!!!!!!!!!!!!!!!!!!!!! when flow passes through choke manifold, solution process may be unstable + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN ! thus we should stabilize solution + IF (data%State%FricPressDrop%TotalOpenChokeArea > 0.5 * data%State%Choke%ChokeAreaFullyOpen) THEN + KickVARIABLES%KickCorrectionUnderRelaxation = 0.6 + ELSE IF (data%State%FricPressDrop%TotalOpenChokeArea > 0.1 * data%State%Choke%ChokeAreaFullyOpen) THEN + KickVARIABLES%KickCorrectionUnderRelaxation = 0.5 + ELSE ! TotalOpenChokeArea < 0.1 * ChokeAreaFullyOpen + KickVARIABLES%KickCorrectionUnderRelaxation = 0.4 + END IF + ELSE + KickVARIABLES%KickCorrectionUnderRelaxation = 0.6 + END IF +!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!!!!!!! calculating frictional pressure drop in annulus, chooke line and open hole elements + DO ifric = data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%NumbEl + CALL FricPressDrop(ifric) +!WRITE (*,*) ' element No, FlowRate , Density, FricPressLoss', ifric, FlowEl(ifric)%FlowRate, FlowEl(ifric)%Density, FlowEl(ifric)%FricPressLoss + IF (IEEE_IS_NaN(FlowEl(ifric)%FricPressLoss)) THEN + WRITE (*,*) 'H, S, A, Ch, O', data%State%FricPressDrop%NoHorizontalEl , data%State%FricPressDrop%NoStringEl , data%State%FricPressDrop%NoAnnulusEl , data%State%FricPressDrop%NoWellToChokeEl , data%State%FricPressDrop%NoOpenHoleEl + WRITE (*,*) 'Ann/Op start, end, density, Q, mu, Type' , FlowEl(ifric)%StartX, FlowEl(ifric)%EndX, FlowEl(ifric)%Density, FlowEl(ifric)%FlowRate, FlowEl(ifric)%mueff, FlowEl(ifric)%MaterialType + CALL ErrorStop('NaN in calculating pressure drop' , ifric) + END IF + + END DO + + +!!!!!!!!!!!!!!!!!!!!!!!!! Pressure distribution in annulus + j = data%State%FricPressDrop%OpenholeFirstEl - 1 + FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%EndPress = data%State%FricPressDrop%BackPressure + FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%StartPress = FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%EndPress + FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%FricPressLoss + FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%StaticPressDiff + + + DO l = data%State%FricPressDrop%OpenholeFirstEl - 2 , data%State%FricPressDrop%AnnulusFirstEl , -1 +!WRITE (*,*) '123' + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%FricPressLoss + FlowEl(l)%StaticPressDiff + END DO + + +!!!!!!!!!!!!!!!!! Pressure distribution in Open Hole + FlowEl(data%State%FricPressDrop%NumbEl)%EndPress = FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StartPress + FlowEl(data%State%FricPressDrop%NumbEl)%StartPress = FlowEl(data%State%FricPressDrop%NumbEl)%EndPress + FlowEl(data%State%FricPressDrop%NumbEl)%FricPressLoss + FlowEl(data%State%FricPressDrop%NumbEl)%StaticPressDiff + + DO l = data%State%FricPressDrop%NumbEl - 1 , data%State%FricPressDrop%OpenholeFirstEl , -1 +!WRITE(*,*) ' ope' + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%FricPressLoss + FlowEl(l)%StaticPressDiff +!WRITE (*,*) ' Length, static, frictional open' , FlowEl(i)%Length, FlowEl(i)%StaticPressDiff, FlowEl(i)%FricPressLoss + +!END IF + END DO + +ELSE ! wellhead is closed and kick is in the well +!WRITE (*,*) ' well head is closed' + k = KickVARIABLES%GasPocketFlowEl(KickVARIABLES%NoGasPocket , 1) +!WRITE (*,*) 'k, Pocket Press', k, GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) - StandardPress + i = data%State%FricPressDrop%AnnulusFirstEl + j = data%State%FricPressDrop%OpenholeFirstEl - 1 + FlowEl(k)%StartPress = GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) - StandardPress + FlowEl(k)%EndPress = GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) - StandardPress + IF (k > data%State%FricPressDrop%OpenholeFirstEl - 1) THEN ! Top pocket StartX is in Open hole +!WRITE (*,*) 'here 1' + DO l = k - 1 , data%State%FricPressDrop%OpenholeFirstEl , -1 ! below elements in openhole +!WRITE (*,*) 'here 1-1' + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff + END DO + + DO l = k + 1 , data%State%FricPressDrop%NumbEl ! Above elements in openhole +!WRITE (*,*) 'here 1-2' + FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress + FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff + END DO + + FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StartPress = FlowEl(data%State%FricPressDrop%NumbEl)%EndPress + FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%EndPress = FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StartPress - FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StaticPressDiff + + DO l = data%State%FricPressDrop%AnnulusFirstEl + 1 , data%State%FricPressDrop%OpenholeFirstEl - 1 + FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress + FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff + END DO + + ELSE ! Top pocket StartX is in annulus or choke line + + DO l = k - 1 , data%State%FricPressDrop%AnnulusFirstEl , -1 ! below elements in annnulus + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff + END DO + + DO l = k + 1 , data%State%FricPressDrop%OpenholeFirstEl - 1 ! Above elements in annulus + FlowEl(l)%StartPress = FlowEl(l - 1)%EndPress + FlowEl(l)%EndPress = FlowEl(l)%StartPress - FlowEl(l)%StaticPressDiff + END DO + + FlowEl(data%State%FricPressDrop%NumbEl)%EndPress = FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StartPress + FlowEl(data%State%FricPressDrop%NumbEl)%StartPress = FlowEl(data%State%FricPressDrop%NumbEl)%EndPress + FlowEl(data%State%FricPressDrop%NumbEl)%StaticPressDiff + + DO l = data%State%FricPressDrop%NumbEl - 1 , data%State%FricPressDrop%OpenholeFirstEl , -1 + FlowEl(l)%EndPress = FlowEl(l + 1)%StartPress + FlowEl(l)%StartPress = FlowEl(l)%EndPress + FlowEl(l)%StaticPressDiff + END DO + + END IF + +END IF + +!!!!!!!!!!!!!!!!!!!!!! checking pressure for preventing NaN in pressures + DO l = data%State%FricPressDrop%OpenholeFirstEl - 1 , data%State%FricPressDrop%AnnulusFirstEl , -1 ! annulus or choke elements +!WRITE (*,*) 'start, end' , FlowEl(i)%StartX, FlowEl(i)%EndX + IF (IEEE_IS_NaN(FlowEl(l)%EndPress)) THEN + WRITE (*,*) 'H, S, A, Ch, O', data%State%FricPressDrop%NoHorizontalEl , data%State%FricPressDrop%NoStringEl , data%State%FricPressDrop%NoAnnulusEl , data%State%FricPressDrop%NoWellToChokeEl , data%State%FricPressDrop%NoOpenHoleEl + WRITE (*,*) 'Ann/Ch start, end, density, Q, mu' , FlowEl(l)%StartX, FlowEl(l)%EndX, FlowEl(l)%Density, FlowEl(l)%FlowRate, FlowEl(l)%mueff, FlowEl(l)%MaterialType + CALL ERRORSTOP('NaN in EndPress', l) + END IF + END DO + + DO l = data%State%FricPressDrop%NumbEl , data%State%FricPressDrop%OpenholeFirstEl - 1 , -1 ! op elements +!WRITE (*,*) 'start, end' , FlowEl(i)%StartX, FlowEl(i)%EndX + IF (IEEE_IS_NaN(FlowEl(l)%EndPress)) THEN + WRITE (*,*) 'H, S, A, Ch, O', data%State%FricPressDrop%NoHorizontalEl , data%State%FricPressDrop%NoStringEl , data%State%FricPressDrop%NoAnnulusEl , data%State%FricPressDrop%NoWellToChokeEl , data%State%FricPressDrop%NoOpenHoleEl + WRITE (*,*) 'Op start, end, density, Q, mu' , FlowEl(l)%StartX, FlowEl(l)%EndX, FlowEl(l)%Density, FlowEl(l)%FlowRate, FlowEl(l)%mueff, FlowEl(l)%MaterialType + CALL ERRORSTOP('NaN in EndPress', l) + END IF + END DO +!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!!!! + KickVARIABLES%BottomHolePress = FlowEl(data%State%FricPressDrop%OpenholeFirstEl)%StartPress + +!!!!!!!!!!!!!!!!!!!!!! + +END SUBROUTINE diff --git a/FluidFlow/Flow_Startup.f90 b/FluidFlow/Flow_Startup.f90 index 04039a3..5049d0e 100644 --- a/FluidFlow/Flow_Startup.f90 +++ b/FluidFlow/Flow_Startup.f90 @@ -44,8 +44,8 @@ use SimulationVariables !@, pi4 => pi KickVARIABLES%WellHeadWasOpen = .TRUE. data%State%FricPressDrop%BackPressure = 0.0 KickVARIABLES%GasKickPumpFlowRate = 0.0 - DownHole%KickVolume = 0.0 - DownHole%InfluxRate = 0.0 + data%Equipments%DownHole%KickVolume = 0.0 + data%Equipments%DownHole%InfluxRate = 0.0 KickVARIABLES%ExitMass = 0.0 KickVARIABLES%MinAllowableKickVol = 1.0 * (42.0 / Convft3toUSgal) ! 1 bbl * 42 gal/bbl / 7.48 gal/ft^3 = ... ft^3 data%State%FricPressDrop%StCompressedMudVol = 0.0 @@ -72,7 +72,7 @@ use SimulationVariables !@, pi4 => pi SoundSpeed = 1530.0 / Convfttom data%State%PressureDisplay%PressureTimeStepDelay(1) = INT(2.0 * SUM(data%Configuration%StringConfiguration%StringConfigurations(2:)%ComponentLength) / SoundSpeed / dt) data%State%PressureDisplay%PressureTimeStepDelay(2) = INT(data%Configuration%Path%Items(SIZE(data%Configuration%Path%Items))%MeasuredDepth / SoundSpeed / dt) - data%State%PressureDisplay%PressureTimeStepDelay(3) = INT(Shoe%ShoeDepth / SoundSpeed / dt) + data%State%PressureDisplay%PressureTimeStepDelay(3) = INT(data%Configuration%Shoe%ShoeDepth / SoundSpeed / dt) !WRITE (*,*) SUM(StringConfigurations(2:)%ComponentLength), PathGenerations(SIZE(PathGenerations))%TotalVerticalDepth!, WellSurveyData(SIZE(WellSurveyData))%TotalVerticalDepth !WRITE (*,*) PathGenerations(SIZE(PathGenerations))%MeasuredDepth!, WellSurveyData(SIZE(WellSurveyData))%MeasuredDepth @@ -87,7 +87,7 @@ use SimulationVariables !@, pi4 => pi END DO DO i = 1 , data%State%PressureDisplay%PressureTimeStepDelay(3) - CALL ShoePressureDelay%AddToFirst(REAL(0.052 * data%Configuration%Mud%ActiveDensity * Shoe%ShoeDepth)) + CALL ShoePressureDelay%AddToFirst(REAL(0.052 * data%Configuration%Mud%ActiveDensity * data%Configuration%Shoe%ShoeDepth)) END DO diff --git a/FluidFlow/Flow_Startup.i90 b/FluidFlow/Flow_Startup.i90 new file mode 100644 index 0000000..6a5bdc7 --- /dev/null +++ b/FluidFlow/Flow_Startup.i90 @@ -0,0 +1,121 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/FluidFlow/Flow_Startup.f90" +SUBROUTINE FlowStartup + + USE Fluid_Flow_Startup_Vars + USE CStringConfigurationVariables + USE CMudPropertiesVariables + USE FricPressDropVarsModule + use KickVARIABLESModule + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use PressureDisplayVARIABLESModule + USE CShoeVariables + USE TD_DrillStemComponents + use SimulationVariables !@, pi3 => pi + use SimulationVariables !@ + USE CWellSurveyDataVariables + USE CHOKEVARIABLES +use SimulationVariables !@, pi4 => pi + use SimulationVariables + + IMPLICIT NONE + + INTEGER :: i + + data%State%PressureDisplay%PressureGauges(:) = 0.0 + + KickVARIABLES%KickSinglePocket = Reservoir%MakeKickSinglePacket + IF (KickVARIABLES%KickSinglePocket) THEN + KickVARIABLES%MaxGasPocket = 1 + ELSE + KickVARIABLES%MaxGasPocket = 4 + END IF + KickVARIABLES%MaxChokeDensityChange = 25.0 ! [ppg/min] + KickVARIABLES%ChokeMinDensity = 2.0 + + KickVARIABLES%ChokeDensity = data%Configuration%Mud%ActiveDensity + + KickVARIABLES%MinKickVol = 0.5 ! USGal + + KickVARIABLES%SecondaryKickVol = 0.0 + KickVARIABLES%SecondaryKickWeight = 0.0 + + KickVARIABLES%NoGasPocket = 0 ! No Kick + KickVARIABLES%WellHeadOpen = .TRUE. + KickVARIABLES%WellHeadWasOpen = .TRUE. + data%State%FricPressDrop%BackPressure = 0.0 + KickVARIABLES%GasKickPumpFlowRate = 0.0 + data%Equipments%DownHole%KickVolume = 0.0 + data%Equipments%DownHole%InfluxRate = 0.0 + KickVARIABLES%ExitMass = 0.0 + KickVARIABLES%MinAllowableKickVol = 1.0 * (42.0 / Convft3toUSgal) ! 1 bbl * 42 gal/bbl / 7.48 gal/ft^3 = ... ft^3 + data%State%FricPressDrop%StCompressedMudVol = 0.0 + data%State%FricPressDrop%AnnCompressedMudVol = 0.0 + KickVARIABLES%KickFlux = .FALSE. + KickVARIABLES%KickOffBottom = .FALSE. + KickVARIABLES%KickWasExitingThroughChoke = .FALSE. + data%State%FricPressDrop%FloatValveOpen = .TRUE. + + data%State%Choke%ChokeAreaFullyOpen = 123.0 / 64.0 ! fully open area is 123/64 in^2 = 0.01334635 ft^2 + data%State%FricPressDrop%ChokeBypassArea = PI / 4.0 * data%Configuration%BopStack%ChokeLineId**2 + data%State%FricPressDrop%BHPSafetyMargin = 150.0 + data%State%FricPressDrop%AChBHPTol = 15.0 + + + data%State%FricPressDrop%ManChoke1Plug = 0 + data%State%FricPressDrop%ManChoke2Plug = 0 + data%State%FricPressDrop%ManChoke1Washout = 0 + data%State%FricPressDrop%ManChoke2Washout = 0 + data%State%FricPressDrop%BitJetsPlugged = 0 + data%State%FricPressDrop%BitJetsWashedOut = 0 + data%State%FricPressDrop%CasingPressure_DataDisplayMalF = 0 + + SoundSpeed = 1530.0 / Convfttom + data%State%PressureDisplay%PressureTimeStepDelay(1) = INT(2.0 * SUM(data%Configuration%StringConfiguration%StringConfigurations(2:)%ComponentLength) / SoundSpeed / dt) + data%State%PressureDisplay%PressureTimeStepDelay(2) = INT(data%Configuration%Path%Items(SIZE(data%Configuration%Path%Items))%MeasuredDepth / SoundSpeed / dt) + data%State%PressureDisplay%PressureTimeStepDelay(3) = INT(data%Configuration%Shoe%ShoeDepth / SoundSpeed / dt) + +!WRITE (*,*) SUM(StringConfigurations(2:)%ComponentLength), PathGenerations(SIZE(PathGenerations))%TotalVerticalDepth!, WellSurveyData(SIZE(WellSurveyData))%TotalVerticalDepth +!WRITE (*,*) PathGenerations(SIZE(PathGenerations))%MeasuredDepth!, WellSurveyData(SIZE(WellSurveyData))%MeasuredDepth + WRITE (*,*) 'time step delay', data%State%PressureDisplay%PressureTimeStepDelay + + DO i = 1 , data%State%PressureDisplay%PressureTimeStepDelay(1) + CALL PumpPressureDelay%AddToFirst(0.0) + END DO + + DO i = 1 , data%State%PressureDisplay%PressureTimeStepDelay(2) + CALL BottomHolePressureDelay%AddToFirst(REAL(0.052 * data%Configuration%Mud%ActiveDensity * data%Configuration%Path%Items(SIZE(data%Configuration%Path%Items))%TotalVerticalDepth)) + END DO + + DO i = 1 , data%State%PressureDisplay%PressureTimeStepDelay(3) + CALL ShoePressureDelay%AddToFirst(REAL(0.052 * data%Configuration%Mud%ActiveDensity * data%Configuration%Shoe%ShoeDepth)) + END DO + + +!!!!!!! Methane Information + data%State%GasType(1)%CritPress = 673.0 + data%State%GasType(1)%CritTemp = 344.0 + data%State%GasType(1)%MolarWt = 16.04 + data%State%GasType(1)%StDensity = 0.04238 + data%State%GasType(1)%GasConstant = RUniversal / data%State%GasType(1)%MolarWt + +!!!!!!!! H2S Information + data%State%GasType(2)%CritPress = 1306.0 + data%State%GasType(2)%CritTemp = 673.0 + data%State%GasType(2)%MolarWt = 34.08 + data%State%GasType(2)%StDensity = 0.09087 + data%State%GasType(2)%GasConstant = RUniversal / data%State%GasType(2)%MolarWt + +!!!!!!!! CO2 Information + data%State%GasType(3)%CritPress = 1072.0 + data%State%GasType(3)%CritTemp = 548.0 + data%State%GasType(3)%MolarWt = 44.01 +!data%State%GasType(3)%StDensity = 00 + data%State%GasType(3)%GasConstant = RUniversal / data%State%GasType(2)%MolarWt + +!!!!!!!! Mud density and viscosity + Theta600Refrence = data%Configuration%Mud%ActiveThetaSixHundred + Theta300Refrence = data%Configuration%Mud%ActiveThetaThreeHundred + DensityRefrence = data%Configuration%Mud%ActiveDensity + + END SUBROUTINE diff --git a/FluidFlow/FluidFlowMain.i90 b/FluidFlow/FluidFlowMain.i90 new file mode 100644 index 0000000..598ff98 --- /dev/null +++ b/FluidFlow/FluidFlowMain.i90 @@ -0,0 +1,148 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/FluidFlow/FluidFlowMain.f90" +module FluidFlowMain + implicit none + public + contains +! +! subroutine FluidFlow_Setup() +! ! use CSimulationVariables +! implicit none +! !call OnSimulationInitialization%Add(FluidFlow_Init) +! call OnSimulationStop%Add(FluidFlow_Stop) +! call OnFluidFlowStart%Add(FluidFlow_Start) +! call OnFluidFlowStep%Add(FluidFlow_Step) +! !call OnFluidFlowOutput%Add(FluidFlow_Output) +! call OnFluidFlowMain%Add(FluidFlowMainBody) +! end subroutine + +! subroutine FluidFlow_Stop +! implicit none +! !WRITE (*,*) ' fluid flow done_Stop' +! call DEALLOCATE_ARRAYS_NormalCirculation() +! CALL DeallocateFlowTypes +! end subroutine FluidFlow_Stop + + subroutine FluidFlow_Init + USE Fluid_Flow_Startup_Vars + implicit none +!WRITE (*,*) ' fluid flow done_Start' + CALL NormalCirculation_StartUp() + CALL FlowStartup + + Call TD_StartUp + Call TD_WellReadData + Call TD_WellElementsReadData + Call TD_DrillStemReadData + Call TD_PipePropertiesReadData + end subroutine FluidFlow_Init + + subroutine FluidFlow_Step + implicit none + integer :: i, FlowDuration, SimulationStateOld + integer,dimension(8) :: FlowStartTime,FlowEndTime + +!WRITE (*,*) ' fluid flow done_Step' +!call Fluid_Flow_Solver + + + + + + + CALL DATE_AND_TIME(values=FlowStartTime) + call Fluid_Flow_Solver + + CALL DATE_AND_TIME(values=FlowEndTime) + + FlowDuration = 3600000 * (FlowEndTime(5) - FlowStartTime(5)) + 60000 * (FlowEndTime(6) - FlowStartTime(6)) + 1000 * (FlowEndTime(7) - FlowStartTime(7)) + (FlowEndTime(8) - FlowStartTime(8)) + + WRITE (*,*) 'FlowDuration (ms)=' , FlowDuration + + end subroutine FluidFlow_Step + +!subroutine FluidFlow_Output +! implicit none +!end subroutine FluidFlow_Output + +! subroutine FluidFlowMainBody +! ! +! use ifport +! use ifmt +! ! use CSimulationVariables +! USE Fluid_Flow_Startup_Vars +! !use general_info, only : reset_data +! !use well_info +! !use drilling_info +! use CLog1 +! ! +! implicit none + +!integer :: i, FlowDuration, SimulationStateOld +!integer,dimension(8) :: FlowStartTime,FlowEndTime +! +! +!CALL NormalCirculation_StartUp() +!CALL FlowStartup +! +!Call TD_StartUp +!Call TD_WellReadData +!Call TD_WellElementsReadData +!Call TD_DrillStemReadData +!Call TD_PipePropertiesReadData +! +! +!LoopSimulation: do +! !WRITE (*,*) ' fluid flow done 0' +!! +! CALL DATE_AND_TIME(values=FlowStartTime) +! !WRITE (*,*) 'FlowStartTime=', FlowStartTime +!! +! call Fluid_Flow_Solver +! +!! +! CALL DATE_AND_TIME(values=FlowEndTime) +!! +! !WRITE (*,*) ' fluid flow done 1' +! +! +! +! FlowDuration = 3600000 * (FlowEndTime(5) - FlowStartTime(5)) + 60000 * (FlowEndTime(6) - FlowStartTime(6)) + 1000 * (FlowEndTime(7) - FlowStartTime(7)) + (FlowEndTime(8) - FlowStartTime(8)) +! +! +! !call Log_1('FlowDuration=', FlowDuration) +! !WRITE (*,*) 'FlowDuration (ms)=' , FlowDuration +! +! if ((100 - FlowDuration) > 0) then +! !WRITE (*,*) 'fluid flow done 2' +! call sleepqq(100 - FlowDuration) +! !WRITE (*,*) ' fluid flow done 3' +! +! end if +! !WRITE (*,*) ' fluid flow done 4' +! +! +! +! !WRITE (*,*) "FlowDuration", FlowDuration +! !if(IsStopped) then +! ! EXIT LoopSimulation +! !ENDIF +! !write(*,*) 'IsStopped=' , IsStopped +! +! if(IsStopped) then +! !write(*,*) '44444444444' +! +! call DEALLOCATE_ARRAYS_NormalCirculation() +! CALL DeallocateFlowTypes +! call Quit() +! end if +! ! +! ! if(IsStopped) exit LoopSimulation +! ! +!end do LoopSimulation +!!call DEALLOCATE_ARRAYS_NormalCirculation() +!!CALL DeallocateFlowTypes +! +! +! end subroutine FluidFlowMainBody + +end module FluidFlowMain diff --git a/FluidFlow/Horizontal_and_String_Pressure_Distribution.f90 b/FluidFlow/Horizontal_and_String_Pressure_Distribution.f90 index fb04b9e..41552b7 100644 --- a/FluidFlow/Horizontal_and_String_Pressure_Distribution.f90 +++ b/FluidFlow/Horizontal_and_String_Pressure_Distribution.f90 @@ -16,12 +16,12 @@ use SimulationVariables !@@@ use KickVARIABLESModule USE CMudPropertiesVariables use CDataDisplayConsole - use SimulationVariables !, StandPipePressureDataDisplay=> data%EquipmentControl%ChokeControlPanel%StandPipePressure + use SimulationVariables !, StandPipePressureDataDisplay=> data%Equipments%ChokeControlPanel%StandPipePressure use CDataDisplayConsole use SimulationVariables !, CasingPressureDataDisplay=> CasingPressure use SimulationVariables !@ USE CShoeVariables - USE CDownHoleVariables! , OperationScenarioCommon%ElevatorConnection => DownHole%CasingPressure + USE CDownHoleVariables! , OperationScenarioCommon%ElevatorConnection => data%Equipments%DownHole%CasingPressure use SimulationVariables !@ USE CManifolds use SimulationVariables @@ -72,7 +72,7 @@ use SimulationVariables !@@@ data%State%FricPressDrop%AnnMudVol = SUM(FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%NumbEl)%Volume) * Convft3toUSGal - IF ( (DownHole%KickVolume > 2.0) .or. (KickVARIABLES%NoGasPocket>1) .or. (any(FlowEl(data%State%FricPressDrop%OpenholeFirstEl:data%State%FricPressDrop%NumbEl)%Materialtype==1)) .or. (data%State%ROP_Bit%RateofPenetration > 0.0) ) THEN + IF ( (data%Equipments%DownHole%KickVolume > 2.0) .or. (KickVARIABLES%NoGasPocket>1) .or. (any(FlowEl(data%State%FricPressDrop%OpenholeFirstEl:data%State%FricPressDrop%NumbEl)%Materialtype==1)) .or. (data%State%ROP_Bit%RateofPenetration > 0.0) ) THEN data%State%FricPressDrop%AnnCompressedMudVol = 0.0 data%State%FricPressDrop%AnnDeltaPDueToCompressibility = 0.0 @@ -330,7 +330,7 @@ use SimulationVariables !@@@ data%State%PressureDisplay%PressureGauges(1) = 0.0 !CALL Set_StandPipePressure(0.0d0) !StandPipePressureGauge = 0 END IF - DownHole%DrillPipePressure = real(data%State%PressureDisplay%PressureGauges(1), 8) + data%Equipments%DownHole%DrillPipePressure = real(data%State%PressureDisplay%PressureGauges(1), 8) !WRITE (*,*) 'Drillpipe Pressure', PressureGauges(1) !!!!!!!!!!!!!!!!! 2- Casing pressure gauge PressureGauge(2) @@ -378,7 +378,7 @@ use SimulationVariables !@@@ ! PressureGauges(2) = 0.0 !END IF CALL Set_CasingPressure(real(data%State%PressureDisplay%PressureGauges(2) , 8)) ! for display console - Downhole%CasingPressure = real(data%State%PressureDisplay%PressureGauges(2) , 8) + data%Equipments%DownHole%CasingPressure = real(data%State%PressureDisplay%PressureGauges(2) , 8) !!!!!!!!!!!!!!!!! 3- Bottom Hole Pressure PressureGauge(3) @@ -396,7 +396,7 @@ use SimulationVariables !@@@ KickVARIABLES%BottomHolePress = BottomHolePressureDelay%Array(data%State%PressureDisplay%PressureTimeStepDelay(2)) - DownHole%BottomHolePressure = REAL(data%State%PressureDisplay%PressureGauges(3) , 8) + data%Equipments%DownHole%BottomHolePressure = REAL(data%State%PressureDisplay%PressureGauges(3) , 8) !!!!!!!!!!!!!!!!! 4- Under Bit Pressure PressureGauges(4) data%State%PressureDisplay%PressureGauges(4) = FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StartPress @@ -407,12 +407,12 @@ use SimulationVariables !@@@ !!!!!!!!!!!!!!!!! 5- Casing Shoe Pressure PressureGauges(5) DO ShoeFlowElNo = data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%NumbEl - IF (FlowEl(ShoeFlowElNo)%StartX >= Shoe%ShoeDepth .AND. FlowEl(ShoeFlowElNo)%EndX < Shoe%ShoeDepth) EXIT + IF (FlowEl(ShoeFlowElNo)%StartX >= data%Configuration%Shoe%ShoeDepth .AND. FlowEl(ShoeFlowElNo)%EndX < data%Configuration%Shoe%ShoeDepth) EXIT END DO - CALL TVD_Calculator(Shoe%ShoeDepth , ShoeTVD) + CALL TVD_Calculator(data%Configuration%Shoe%ShoeDepth , ShoeTVD) IF (ShoeFlowElNo > data%State%FricPressDrop%NumbEl) THEN - WRITE (*,*) 'ShoeDepth =', Shoe%ShoeDepth + WRITE (*,*) 'ShoeDepth =', data%Configuration%Shoe%ShoeDepth DO i = data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%NumbEl WRITE (*,*) 'i, StartX, EndX', i, FlowEl(i)%StartX, FlowEl(i)%EndX END DO @@ -425,7 +425,7 @@ use SimulationVariables !@@@ !END IF CALL ShoePressureDelay%AddToFirst(REAL(FlowEl(ShoeFlowElNo)%StartPress & - - (FlowEl(ShoeFlowElNo)%StartX - Shoe%ShoeDepth) * FlowEl(ShoeFlowElNo)%dPdLfric & + - (FlowEl(ShoeFlowElNo)%StartX - data%Configuration%Shoe%ShoeDepth) * FlowEl(ShoeFlowElNo)%dPdLfric & - (FlowEl(ShoeFlowElNo)%StartTVD - ShoeTVD) * FlowEl(ShoeFlowElNo)%dPdLGrav)) CALL ShoePressureDelay%Remove(data%State%PressureDisplay%PressureTimeStepDelay(3) + 1) @@ -439,7 +439,7 @@ use SimulationVariables !@@@ !PressureGauges(5) = INT(ShoePressureDelay%Array(PressureTimeStepDelay(3))) - DownHole%ShoePressure = real(data%State%PressureDisplay%PressureGauges(5), 8) + data%Equipments%DownHole%ShoePressure = real(data%State%PressureDisplay%PressureGauges(5), 8) @@ -512,7 +512,7 @@ use SimulationVariables !@@@ !WRITE (*,*) ' SecondaryKickWeight', KickVARIABLES%SecondaryKickWeight !WRITE (*,*) ' SecondaryKickVol', KickVARIABLES%SecondaryKickVol - DownHole%SecondKickVolume = KickVARIABLES%SecondaryKickVol + data%Equipments%DownHole%SecondKickVolume = KickVARIABLES%SecondaryKickVol diff --git a/FluidFlow/Horizontal_and_String_Pressure_Distribution.i90 b/FluidFlow/Horizontal_and_String_Pressure_Distribution.i90 new file mode 100644 index 0000000..fce03c8 --- /dev/null +++ b/FluidFlow/Horizontal_and_String_Pressure_Distribution.i90 @@ -0,0 +1,624 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/FluidFlow/Horizontal_and_String_Pressure_Distribution.f90" +SUBROUTINE PressureHorizAndStringDistribution + + +!! Record of revisions +!! Date Programmer Discription of change +!! ------ ------------ ----------------------- +!! 1396/07/30 Sheikh Original code +!! + + USE FricPressDropVarsModule + use PressureDisplayVARIABLESModule + USE MudSystemVARIABLES +use SimulationVariables !@@@ + USE GeoElements_FluidModule + USE Fluid_Flow_Startup_Vars + use KickVARIABLESModule + USE CMudPropertiesVariables + use CDataDisplayConsole + use SimulationVariables !, StandPipePressureDataDisplay=> data%Equipments%ChokeControlPanel%StandPipePressure + use CDataDisplayConsole + use SimulationVariables !, CasingPressureDataDisplay=> CasingPressure + use SimulationVariables !@ + USE CShoeVariables + USE CDownHoleVariables! , OperationScenarioCommon%ElevatorConnection => data%Equipments%DownHole%CasingPressure + use SimulationVariables !@ + USE CManifolds + use SimulationVariables + USE CError + use UTUBEVARSModule + use OperationScenariosModule + use SimulationVariables + USE , INTRINSIC :: IEEE_ARITHMETIC + Use TD_DrillStemComponents + Use sROP_Variables + + + + IMPLICIT NONE + + INTEGER :: i , j , l + INTEGER :: ifric + INTEGER :: OldCasingPressure + REAL :: PressBelowFloatValve , PressAboveFloatValve ![psi] + REAL :: PumpMinDischargedVol = 0.0050 ! [gal] + REAL :: FloatValveBottomToUpAreaRatio = 1.1 ![-] + REAL :: ZeroHeight , StaticHeadOnBit + REAL(8) :: ShoeTVD +!REAL(8) , DIMENSION(5) :: MDObserve , TVDObserve , StPressObserve , AnnPressObserve , NomMD + + KickVARIABLES%ExitMass = 0.0 + BitPressLoss = 0.0 + + KickVARIABLES%WellHeadWasOpen = KickVARIABLES%WellHeadOpen + KickVARIABLES%WellToChokeManifoldWasOpen = data%State%MudSystem%WellToChokeManifoldOpen + KickVARIABLES%KickWasExitingThroughChoke = .FALSE. + + + IF (data%State%MudSystem%UtubeMode1Activated .OR. data%State%FricPressDrop%FloatValveWasOpen == .FALSE.) THEN ! Horizontal line flow rate + FlowEl(1 : data%State%FricPressDrop%NoHorizontalEl)%FlowRate = 0.0 + ELSE ! connection and line is open + FlowEl(1 : data%State%FricPressDrop%NoHorizontalEl)%FlowRate = data%State%MudSystem%StringFlowRate ! pump flow rate [gpm] + END IF + +!WRITE (*,*) 'a)A/B P Bit', StaticHeadOnBit , FlowEl(AnnulusFirstEl)%StartPress , SUM(FlowEl(StringFirstEl : StringLastEl)%StaticPressDiff) +!IF (FloatValveIn == .FALSE.) FloatValveOpen = .TRUE. + data%State%FricPressDrop%FloatValveWasOpen = data%State%FricPressDrop%FloatValveOpen + + PressBelowFloatValve = FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StartPress + + data%State%FricPressDrop%StMudVol = SUM(FlowEl(1 : data%State%FricPressDrop%StringLastEl)%Volume) * Convft3toUSGal + data%State%FricPressDrop%StDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * data%State%FricPressDrop%StMudVol) + + data%State%FricPressDrop%AnnMudVol = SUM(FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%NumbEl)%Volume) * Convft3toUSGal + + IF ( (data%Equipments%DownHole%KickVolume > 2.0) .or. (KickVARIABLES%NoGasPocket>1) .or. (any(FlowEl(data%State%FricPressDrop%OpenholeFirstEl:data%State%FricPressDrop%NumbEl)%Materialtype==1)) .or. (data%State%ROP_Bit%RateofPenetration > 0.0) ) THEN + data%State%FricPressDrop%AnnCompressedMudVol = 0.0 + data%State%FricPressDrop%AnnDeltaPDueToCompressibility = 0.0 + + ELSE IF (KickVARIABLES%WellHeadOpen) THEN + data%State%FricPressDrop%AnnDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * data%State%FricPressDrop%AnnMudVol) + + data%State%FricPressDrop%AnnCompressedMudVol = data%State%FricPressDrop%BackPressure / data%State%FricPressDrop%AnnDeltaPtoDeltaVCompressibility + data%State%FricPressDrop%AnnDeltaPDueToCompressibility = data%State%FricPressDrop%AnnCompressedMudVol / (MudCompressibility * data%State%FricPressDrop%AnnMudVol) + + ELSE ! No gas pocket, wellhead is closed and mud is compressed based on volume pumped into annulus + data%State%FricPressDrop%AnnDeltaPtoDeltaVCompressibility = 1.0 / (MudCompressibility * data%State%FricPressDrop%AnnMudVol) + data%State%FricPressDrop%AnnCompressedMudVol = data%State%FricPressDrop%AnnCompressedMudVol + REAL(data%State%MudSystem%Ann_Saved_MudDischarged_Volume_Final) !!!!!!!!! + data%State%FricPressDrop%AnnCompressedMudVol = MAX((data%State%FricPressDrop%AnnCompressedMudVol - REAL(data%State%MudSystem%Qlost / ConvMinToSec / dt)) , 0.0) + data%State%FricPressDrop%AnnDeltaPDueToCompressibility = data%State%FricPressDrop%AnnCompressedMudVol / (MudCompressibility * data%State%FricPressDrop%AnnMudVol) + END IF + + IF (data%State%FricPressDrop%FloatValveIn == .FALSE. .OR. KickVARIABLES%NoGasPocket == 0 .OR. (data%State%FricPressDrop%FloatValveWasOpen .AND. REAL(data%State%MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol)) THEN ! float valve remains open + data%State%FricPressDrop%FloatValveOpen = .TRUE. + + FlowEl(data%State%FricPressDrop%StringFirstEl : data%State%FricPressDrop%StringLastEl)%FlowRate = REAL(data%State%MudSystem%St_Saved_MudDischarged_Volume_Final) / dt * ConvMinToSec !data%State%MudSystem%StringFlowRate ! String flow rate pump flow rate [gpm] + +!!!!!!!!!!!!!!! Calculating frictional pressure loss + IF (KickVARIABLES%WellHeadOpen) THEN + DO ifric = 1 , data%State%FricPressDrop%StringLastEl + CALL FricPressDrop(ifric) +!WRITE (*,*) ' element No, FlowRate , Density, FricPressLoss', ifric, FlowEl(ifric)%FlowRate, FlowEl(ifric)%Density, FlowEl(ifric)%FricPressLoss + IF (IEEE_IS_NaN(FlowEl(ifric)%FricPressLoss)) THEN + WRITE (*,*) 'Hz/St start, end, density, Q, mu, Type' , FlowEl(ifric)%StartX, FlowEl(ifric)%EndX, FlowEl(ifric)%Density, FlowEl(ifric)%FlowRate, FlowEl(ifric)%mueff, FlowEl(ifric)%MaterialType + CALL ErrorStop('NaN in calculating pressure drop' , ifric) + END IF + END DO + END IF + +!!!!!!!!!!!!!!! + + +!IF (ABS(MudVolume_InjectedToBH - St_Saved_MudDischarged_Volume_Final)> PumpMinDischargedVol) WRITE (*,*) 'Injected to BH & St Saved Mud', MudVolume_InjectedToBH , St_Saved_MudDischarged_Volume_Final + IF (data%State%FricPressDrop%BitTotallyPluged) THEN + data%State%MudSystem%MudVolume_InjectedToBH = 0.d0 + data%State%FricPressDrop%StCompressedMudVol = data%State%FricPressDrop%StCompressedMudVol + REAL(data%State%MudSystem%St_Saved_MudDischarged_Volume_Final) + data%State%FricPressDrop%StDeltaPDueToCompressibility = data%State%FricPressDrop%StCompressedMudVol * data%State%FricPressDrop%StDeltaPtoDeltaVCompressibility + + ELSE IF (KickVARIABLES%WellHeadOpen .OR. KickVARIABLES%NoGasPocket > 0) THEN + IF (REAL(data%State%MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN + + data%State%MudSystem%MudVolume_InjectedToBH = data%State%MudSystem%St_Saved_MudDischarged_Volume_Final +!WRITE (*,*) 'MudVolume_InjectedToBH,BitTrue', MudVolume_InjectedToBH + +!IF (BitTrue .AND. UtubeMode1Activated == .FALSE.) THEN + IF (BitTrue) THEN + BitPressLoss = data%State%FricPressDrop%KBit * (data%State%MudSystem%MudVolume_InjectedToBH * ConvMinToSec / dt)**2 +!WRITE (*,*) 'BitPressLoss', BitPressLoss + END IF + + data%State%FricPressDrop%StCompressedMudVol = BitPressLoss / data%State%FricPressDrop%StDeltaPtoDeltaVCompressibility + + ELSE + data%State%MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , REAL((data%State%FricPressDrop%StDeltaPDueToCompressibility + SUM(FlowEl(data%State%FricPressDrop%StringFirstEl : data%State%FricPressDrop%StringLastEl)%StaticPressDiff - PressBelowFloatValve - data%State%FricPressDrop%AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & + / data%State%FricPressDrop%StDeltaPtoDeltaVCompressibility ) * 1.d0)) + data%State%MudSystem%MudVolume_InjectedToBH = MIN(data%State%MudSystem%MudVolume_InjectedToBH , data%State%FricPressDrop%StCompressedMudVol) + data%State%FricPressDrop%StCompressedMudVol = data%State%FricPressDrop%StCompressedMudVol - data%State%MudSystem%MudVolume_InjectedToBH + + END IF + + data%State%FricPressDrop%StDeltaPDueToCompressibility = data%State%FricPressDrop%StCompressedMudVol / (MudCompressibility * data%State%FricPressDrop%StMudVol) + + ELSE ! IF (NoGasPocket == 0 .AND. WellHeadOpen == .FALSE.) THEN + data%State%FricPressDrop%StCompressedMudVol = data%State%FricPressDrop%StCompressedMudVol + REAL(data%State%MudSystem%St_Saved_MudDischarged_Volume_Final) + data%State%FricPressDrop%StDeltaPDueToCompressibility = data%State%FricPressDrop%StCompressedMudVol * data%State%FricPressDrop%StDeltaPtoDeltaVCompressibility + data%State%MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , REAL((data%State%FricPressDrop%StDeltaPDueToCompressibility - data%State%FricPressDrop%AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & + / (data%State%FricPressDrop%StDeltaPtoDeltaVCompressibility + data%State%FricPressDrop%AnnDeltaPtoDeltaVCompressibility)) * 1.d0) + data%State%MudSystem%MudVolume_InjectedToBH = MIN(data%State%MudSystem%MudVolume_InjectedToBH , data%State%FricPressDrop%StCompressedMudVol) + data%State%FricPressDrop%StCompressedMudVol = data%State%FricPressDrop%StCompressedMudVol - REAL(data%State%MudSystem%MudVolume_InjectedToBH) + data%State%FricPressDrop%StDeltaPDueToCompressibility = data%State%FricPressDrop%StCompressedMudVol / (MudCompressibility * data%State%FricPressDrop%StMudVol) + FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%NumbEl)%StartPress = FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%NumbEl)%StartPress + data%State%FricPressDrop%StDeltaPDueToCompressibility + FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%NumbEl)%EndPress = FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%NumbEl)%EndPress + data%State%FricPressDrop%StDeltaPDueToCompressibility + + END IF + + FlowEl(data%State%FricPressDrop%StringLastEl)%EndPress = FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StartPress + BitPressLoss + FloatValveMinOpenPressure +!WRITE (*,*) 'BitPressLoss=', BitPressLoss + FlowEl(data%State%FricPressDrop%StringLastEl)%StartPress = FlowEl(data%State%FricPressDrop%StringLastEl)%EndPress + FlowEl(data%State%FricPressDrop%StringLastEl)%FricPressLoss - FlowEl(data%State%FricPressDrop%StringLastEl)%StaticPressDiff + DO i = data%State%FricPressDrop%StringLastEl - 1 , data%State%FricPressDrop%StringFirstEl , -1 + FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress + FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss - FlowEl(i)%StaticPressDiff + END DO + +!!!!!!!!!!!!!!!!!!!!!!!!!!!! Float valve was open and remains open + + ELSE IF (REAL(data%State%MudSystem%St_Saved_MudDischarged_Volume_Final) < PumpMinDischargedVol) THEN ! NoGasPocket > 0 + data%State%FricPressDrop%FloatValveOpen = data%State%FricPressDrop%FloatValveWasOpen ! remains in its former status + + IF (data%State%FricPressDrop%FloatValveOpen) THEN + PressAboveFloatValve = MAX(FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StartPress , SUM(FlowEl(data%State%FricPressDrop%StringFirstEl : data%State%FricPressDrop%StringLastEl)%StaticPressDiff) + 0.052 * FlowEl(data%State%FricPressDrop%StringFirstEl)%Density * FlowEl(data%State%FricPressDrop%StringFirstEl)%StartTVD) + ELSE + PressAboveFloatValve = SUM(FlowEl(data%State%FricPressDrop%StringFirstEl : data%State%FricPressDrop%StringLastEl)%StaticPressDiff) + data%State%FricPressDrop%StDeltaPDueToCompressibility + data%State%MudSystem%MudVolume_InjectedToBH = 0.d0 + END IF + + + IF (PressBelowFloatValve >= PressAboveFloatValve .AND. KickVARIABLES%KickFlux) THEN + data%State%FricPressDrop%FloatValveOpen = .FALSE. + IF (data%State%FricPressDrop%FloatValveOpen /= data%State%FricPressDrop%FloatValveWasOpen) THEN ! float valve was open and now closed + WRITE (*,*) 'Float valve was open and now closed' + WRITE (*,*) 'PressAboveFloatValve=', PressAboveFloatValve + WRITE (*,*) 'PressBelowFloatValve=', PressBelowFloatValve + END IF + + END IF + + IF (data%State%FricPressDrop%FloatValveOpen) THEN + data%State%MudSystem%MudVolume_InjectedToBH = MAX( 0.d0 , 0.1 * REAL((PressAboveFloatValve - PressBelowFloatValve - data%State%FricPressDrop%AnnDeltaPDueToCompressibility - FloatValveMinOpenPressure) & + / data%State%FricPressDrop%StDeltaPtoDeltaVCompressibility ) * 1.d0) + data%State%MudSystem%MudVolume_InjectedToBH = MIN(data%State%MudSystem%MudVolume_InjectedToBH , data%State%FricPressDrop%StCompressedMudVol) +!WRITE (*,*) 'MudVolume_InjectedToBH (No Pump)', MudVolume_InjectedToBH + + data%State%FricPressDrop%StCompressedMudVol = data%State%FricPressDrop%StCompressedMudVol - data%State%MudSystem%MudVolume_InjectedToBH + data%State%FricPressDrop%StDeltaPDueToCompressibility = data%State%FricPressDrop%StCompressedMudVol / (MudCompressibility * data%State%FricPressDrop%StMudVol) +!WRITE (*,*) 'StDeltaPDueToCompressibility(No Pump)', StDeltaPDueToCompressibility + + END IF + + IF (KickVARIABLES%NoGasPocket == 0 .AND. KickVARIABLES%WellHeadOpen == .FALSE.) THEN !*********** + FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%NumbEl)%StartPress = FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%NumbEl)%StartPress + data%State%FricPressDrop%AnnDeltaPDueToCompressibility + FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%NumbEl)%EndPress = FlowEl(data%State%FricPressDrop%AnnulusFirstEl : data%State%FricPressDrop%NumbEl)%EndPress + data%State%FricPressDrop%AnnDeltaPDueToCompressibility + END IF + + + + IF (data%State%FricPressDrop%FloatValveOpen) THEN + FlowEl(data%State%FricPressDrop%StringLastEl)%EndPress = MAX(FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StartPress , SUM(FlowEl(data%State%FricPressDrop%StringFirstEl : data%State%FricPressDrop%StringLastEl)%StaticPressDiff) + 0.052 * FlowEl(data%State%FricPressDrop%StringFirstEl)%Density * FlowEl(data%State%FricPressDrop%StringFirstEl)%StartTVD) + ELSE + FlowEl(data%State%FricPressDrop%StringLastEl)%EndPress = data%State%FricPressDrop%StDeltaPDueToCompressibility + SUM(FlowEl(data%State%FricPressDrop%StringFirstEl : data%State%FricPressDrop%StringLastEl)%StaticPressDiff) + END IF + + FlowEl(data%State%FricPressDrop%StringLastEl)%StartPress = FlowEl(data%State%FricPressDrop%StringLastEl)%EndPress - FlowEl(data%State%FricPressDrop%StringLastEl)%StaticPressDiff + DO i = data%State%FricPressDrop%StringLastEl - 1 , data%State%FricPressDrop%StringFirstEl , -1 + FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress + FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss - FlowEl(i)%StaticPressDiff + END DO + + + +!!!!!!!!!!!!!!!!!!!!!!!!!!!! Float valve was open (close) and maybe remains open (close) or maybe closed + + ELSE IF(data%State%FricPressDrop%FloatValveWasOpen == .FALSE. .AND. REAL(data%State%MudSystem%St_Saved_MudDischarged_Volume_Final) >= PumpMinDischargedVol) THEN + data%State%FricPressDrop%FloatValveOpen = .FALSE. + data%State%MudSystem%MudVolume_InjectedToBH = 0.d0 + + data%State%FricPressDrop%StCompressedMudVol = data%State%FricPressDrop%StCompressedMudVol + REAL(data%State%MudSystem%St_Saved_MudDischarged_Volume_Final) + data%State%FricPressDrop%StDeltaPDueToCompressibility = data%State%FricPressDrop%StCompressedMudVol * data%State%FricPressDrop%StDeltaPtoDeltaVCompressibility + PressAboveFloatValve = SUM(FlowEl(data%State%FricPressDrop%StringFirstEl : data%State%FricPressDrop%StringLastEl)%StaticPressDiff) + data%State%FricPressDrop%StDeltaPDueToCompressibility + + + IF (PressAboveFloatValve > FloatValveBottomToUpAreaRatio * PressBelowFloatValve) THEN ! float valve was open and now closed + data%State%FricPressDrop%FloatValveOpen = .TRUE. + WRITE (*,*) 'Float valve was closed and now opened' + WRITE (*,*) 'PressAboveFloatValve=', PressAboveFloatValve + WRITE (*,*) 'PressBelowFloatValve=', PressBelowFloatValve + END IF + + + FlowEl(data%State%FricPressDrop%StringLastEl)%EndPress = PressAboveFloatValve + FlowEl(data%State%FricPressDrop%StringLastEl)%StartPress = FlowEl(data%State%FricPressDrop%StringLastEl)%EndPress - FlowEl(data%State%FricPressDrop%StringLastEl)%StaticPressDiff + DO i = data%State%FricPressDrop%StringLastEl - 1 , data%State%FricPressDrop%StringFirstEl , -1 + FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress + FlowEl(i)%StartPress = FlowEl(i)%EndPress - FlowEl(i)%StaticPressDiff +!WRITE(*,*) "STRING: Start , End Pressure", FlowEl(i)%StartPress , FlowEl(i)%EndPress +!WRITE(*,*) "STRING: Start , End X", FlowEl(i)%StartX , FlowEl(i)%EndX + END DO + + + + + END IF + + IF ((data%State%MudSystem%UtubePossibility == .TRUE. .AND. Get_KellyConnection() /= KELLY_CONNECTION_STRING) .OR. data%State%MudSystem%NewPipeFilling == 0) THEN + FlowEl(data%State%FricPressDrop%NoHorizontalEl)%EndPress = 0.0 + ELSE IF (KickVARIABLES%WellHeadOpen == .FALSE.) THEN + FlowEl(data%State%FricPressDrop%NoHorizontalEl)%EndPress = FlowEl(data%State%FricPressDrop%StringFirstEl)%StartPress - 0.052 * FlowEl(data%State%FricPressDrop%NoHorizontalEl)%Density * FlowEl(data%State%FricPressDrop%StringFirstEl)%StartTVD + ELSE IF (KickVARIABLES%WellHeadOpen) THEN + FlowEl(data%State%FricPressDrop%NoHorizontalEl)%EndPress = FlowEl(data%State%FricPressDrop%StringFirstEl)%StartPress - 2.0 * 0.052 * FlowEl(data%State%FricPressDrop%NoHorizontalEl)%Density * FlowEl(data%State%FricPressDrop%StringFirstEl)%StartTVD + END IF + + FlowEl(data%State%FricPressDrop%NoHorizontalEl)%StartPress = FlowEl(data%State%FricPressDrop%NoHorizontalEl)%EndPress + FlowEl(data%State%FricPressDrop%NoHorizontalEl)%FricPressLoss + DO i = data%State%FricPressDrop%NoHorizontalEl - 1 , 1 , -1 + FlowEl(i)%EndPress = FlowEl(i + 1)%StartPress + FlowEl(i)%StartPress = FlowEl(i)%EndPress + FlowEl(i)%FricPressLoss + END DO + + + +!!!!!!!!!!!!!!!!!!!!! Pressure distribution in string and horizontal pump to string line + + + IF (data%State%RamLine%ShearBop_Situation_forTD == 1) THEN + FlowEl(1 : data%State%FricPressDrop%NoHorizontalEl)%EndPress = 0.0 + FlowEl(1 : data%State%FricPressDrop%NoHorizontalEl)%StartPress = 0.0 + FlowEl(1 : data%State%FricPressDrop%NoHorizontalEl)%FricPressLoss = 0.0 + END IF + +!!!!!!!!!!!!!!!!!!!!!!!!! + + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + + + + + IF (data%State%MudSystem%UtubePossibility== .true. .and. Get_KellyConnection() /= KELLY_CONNECTION_STRING .and. KickVARIABLES%WellHeadOpen) THEN + data%State%MudSystem%MudVolume_InjectedToBH = 0.d0 + data%State%MudSystem%MudVolume_InjectedFromAnn = 0.d0 + + END IF + + + +110 FORMAT (I6 , 4X , F6.2 , 7X , F4.2 , 3X , F4.1 , 2X , F4.2) + + + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!! Kick Information Reports + + +!!!!!!!!!!!!!!!!! 1- Stand pipe pressure gauge PressureGauges(1) + +!ElementTrueDepth = STpipeGauge_Height/Convfttom +!DistancetoRefrence = -170.7 ! 165 ft after pump and 100 ft before string + i = 1 + DO WHILE (NOT(FlowEl(i)%EndX >= -170 .AND. FlowEl(i)%StartX <= -170)) + i = i + 1 + IF (i > data%State%FricPressDrop%NoHorizontalEl) EXIT + END DO + CALL PumpPressureDelay%AddToFirst(REAL(FlowEl(i)%StartPress - 0.052 * (data%State%MudSystem%STpipeGauge_Height / Convfttom) * FlowEl(i)%Density + (FlowEl(i)%StartX + 170) * FlowEl(i)%dPdLFric)) + CALL PumpPressureDelay%Remove(data%State%PressureDisplay%PressureTimeStepDelay(1) + 1) +!IF (ANY(data%State%Pump(:)%PowerFailMalf == 1)) PumpPressureDelay%Array(1 : PressureTimeStepDelay(1) / 2) = 0.0 !seyyed goft vaghti pumpfailure mishavad feshar dasti 0 nashavad, be in dalil in khat comment shod. + + DO j = data%State%PressureDisplay%PressureTimeStepDelay(1) , 1 , -1 + IF (NOT(IEEE_IS_NaN(PumpPressureDelay%Array(j)))) THEN + data%State%PressureDisplay%PressureGauges(1) = INT(PumpPressureDelay%Array(j)) + EXIT + END IF + END DO + +!PressureGauges(1) = INT(PumpPressureDelay%Array(PressureTimeStepDelay(1))) + + IF (i > data%State%FricPressDrop%NoHorizontalEl) THEN + WRITE (*,*) ' Error in calculating standpipe pressure ' + END IF + + IF (data%State%PressureDisplay%PressureGauges(1) < 0) THEN +!CALL Set_StandPipePressure(real(PressureGauges(1) , 8)) ! for display console + data%State%PressureDisplay%PressureGauges(1) = 0.0 +!CALL Set_StandPipePressure(0.0d0) !StandPipePressureGauge = 0 + END IF + data%Equipments%DownHole%DrillPipePressure = real(data%State%PressureDisplay%PressureGauges(1), 8) +!WRITE (*,*) 'Drillpipe Pressure', PressureGauges(1) + +!!!!!!!!!!!!!!!!! 2- Casing pressure gauge PressureGauge(2) +!WRITE (*,*) 'here 1', (WelltoPitsOpen == .FALSE. .AND. WellToChokeManifoldOpen) , (Valve(26)%Status == .TRUE. .AND. Valve(47)%Status == .TRUE. .AND. Valve(49)%Status == .TRUE.), BackPressure +!WRITE (*,*) Valve(26)%Status , Valve(47)%Status , Valve(49)%Status +!WRITE (*,*) (Valve(26)%Status == .TRUE.) , (Valve(47)%Status == .TRUE.) , (Valve(49)%Status == .TRUE.) + +!!! in normal mode changes in choke position immidiately observes in casing pressure +!! but when pumps off due to failure, casing pressure will drop after a delay time + IF (data%State%MudSystem%WellToChokeManifoldOpen .OR. data%State%MudSystem%WellToChokeLineGauge) THEN +!WRITE (*,*) 'Here 1' + CALL CasingPressureDelay%AddToFirst(FlowEl(data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + data%State%FricPressDrop%NoWellToChokeEl)%EndPress) + CALL CasingPressureDelay%Remove(data%State%PressureDisplay%PressureTimeStepDelay(1) + 1) + + DO j = 1 , data%State%PressureDisplay%PressureTimeStepDelay(1) + IF (NOT(IEEE_IS_NaN(CasingPressureDelay%Array(j)))) THEN + data%State%PressureDisplay%PressureGauges(2) = INT(CasingPressureDelay%Array(j)) + EXIT + END IF + END DO + +!PressureGauges(2) = INT(CasingPressureDelay%Array(1)) + IF (ANY(data%State%Pump(:)%PowerFailMalf == 1)) THEN + DO j = data%State%PressureDisplay%PressureTimeStepDelay(1) , 1 , -1 + IF (NOT(IEEE_IS_NaN(CasingPressureDelay%Array(j)))) THEN + data%State%PressureDisplay%PressureGauges(2) = INT(CasingPressureDelay%Array(j)) + EXIT + END IF + END DO + END IF + + + + +!IF (ANY(data%State%Pump(:)%PowerFailMalf == 1)) PressureGauges(2) = INT(CasingPressureDelay%Array(PressureTimeStepDelay(1))) + + ELSE !IF (ChokeLineGaugeToTanks) THEN + data%State%PressureDisplay%PressureGauges(2) = 0 +!WRITE (*,*) 'Here 2' + END IF + + +!WRITE (*,*) 'GaugePoint(2)%Pressure =' , GaugePoint(2)%Pressure +!IF (PressureGauges(2) < 0) THEN +! PressureGauges(2) = 0.0 +!END IF + CALL Set_CasingPressure(real(data%State%PressureDisplay%PressureGauges(2) , 8)) ! for display console + data%Equipments%DownHole%CasingPressure = real(data%State%PressureDisplay%PressureGauges(2) , 8) + +!!!!!!!!!!!!!!!!! 3- Bottom Hole Pressure PressureGauge(3) + + CALL BottomHolePressureDelay%AddToFirst(FlowEl(data%State%FricPressDrop%OpenholeFirstEl)%StartPress) + CALL BottomHolePressureDelay%Remove(data%State%PressureDisplay%PressureTimeStepDelay(2) + 1) +!PressureGauges(3) = INT(BottomHolePressureDelay%Array(PressureTimeStepDelay(2))) + + DO j = data%State%PressureDisplay%PressureTimeStepDelay(2) , 1 , -1 + IF (NOT(IEEE_IS_NaN(BottomHolePressureDelay%Array(j)))) THEN + data%State%PressureDisplay%PressureGauges(3) = INT(BottomHolePressureDelay%Array(j)) + EXIT + END IF + END DO + + + KickVARIABLES%BottomHolePress = BottomHolePressureDelay%Array(data%State%PressureDisplay%PressureTimeStepDelay(2)) + + data%Equipments%DownHole%BottomHolePressure = REAL(data%State%PressureDisplay%PressureGauges(3) , 8) +!!!!!!!!!!!!!!!!! 4- Under Bit Pressure PressureGauges(4) + + data%State%PressureDisplay%PressureGauges(4) = FlowEl(data%State%FricPressDrop%AnnulusFirstEl)%StartPress + +!!!!!!!!!!!!!!!!! + + +!!!!!!!!!!!!!!!!! 5- Casing Shoe Pressure PressureGauges(5) + + DO ShoeFlowElNo = data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%NumbEl + IF (FlowEl(ShoeFlowElNo)%StartX >= data%Configuration%Shoe%ShoeDepth .AND. FlowEl(ShoeFlowElNo)%EndX < data%Configuration%Shoe%ShoeDepth) EXIT + END DO + CALL TVD_Calculator(data%Configuration%Shoe%ShoeDepth , ShoeTVD) + + IF (ShoeFlowElNo > data%State%FricPressDrop%NumbEl) THEN + WRITE (*,*) 'ShoeDepth =', data%Configuration%Shoe%ShoeDepth + DO i = data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%NumbEl + WRITE (*,*) 'i, StartX, EndX', i, FlowEl(i)%StartX, FlowEl(i)%EndX + END DO + + CALL ErrorSTOP ('Error in finding location of shoe') + END IF + +!ELSE +! WRITE (*,*) ' Error in calculating shoe pressure ' +!END IF + + CALL ShoePressureDelay%AddToFirst(REAL(FlowEl(ShoeFlowElNo)%StartPress & + - (FlowEl(ShoeFlowElNo)%StartX - data%Configuration%Shoe%ShoeDepth) * FlowEl(ShoeFlowElNo)%dPdLfric & + - (FlowEl(ShoeFlowElNo)%StartTVD - ShoeTVD) * FlowEl(ShoeFlowElNo)%dPdLGrav)) + CALL ShoePressureDelay%Remove(data%State%PressureDisplay%PressureTimeStepDelay(3) + 1) + +!data%State%FricPressDrop%FlowrateNearShoe = FlowEl(ShoeFlowElNo)%FlowRate + DO j = data%State%PressureDisplay%PressureTimeStepDelay(3) , 1 , -1 + IF (NOT(IEEE_IS_NaN(ShoePressureDelay%Array(j)))) THEN + data%State%PressureDisplay%PressureGauges(5) = INT(ShoePressureDelay%Array(j)) + EXIT + END IF + END DO + + +!PressureGauges(5) = INT(ShoePressureDelay%Array(PressureTimeStepDelay(3))) + data%Equipments%DownHole%ShoePressure = real(data%State%PressureDisplay%PressureGauges(5), 8) + + + + + data%State%MudSystem%ShoeMudViscosity = FlowEl(ShoeFlowElNo)%MuEff + data%State%MudSystem%ShoeMudDensity = FlowEl(ShoeFlowElNo)%Density + + + + + +!!!!!!!!!!!!!!!!! + +!!!!!!!!! 6- Pressure Before Bop + + data%State%PressureDisplay%PressureGauges(6) = FlowEl(data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl)%EndPress + +!!!!!!!!!!!!!!!!! +101 FORMAT(4X, I2, 8X, (F8.1), 12X, (F8.3), 7X, (F8.2)) + + + IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN + END IF + + + +!WRITE (*,*) 'Horiz 1' + + KickVARIABLES%KickInFluxConditions = (Reservoir%FormationTop < data%State%TD_WellGeneral%WellTotalVerticalLength) .AND. (NOT(Reservoir%InactiveInflux)) .AND. (KickVARIABLES%FormPressure > KickVARIABLES%BottomHolePress + 5.0) + IF (KickVARIABLES%KickInFluxConditions) THEN + KickVARIABLES%KickFlux = .TRUE. + + CALL NewGasKick + +!WRITE (*,*) 'Kick Flux top' , KickFlux +!WRITE (*,*) 'KickVARIABLES%FormPressure, BottomHolePress, FormationTop, data%State%TD_WellGeneral%WellTotalVerticalLength' , FormPressure, BottomHolePress, FormationTop, data%State%TD_WellGeneral%WellTotalVerticalLength + + ELSE + IF (ALLOCATED(GasPocketWeight%Array) .AND. KickVARIABLES%KickFlux) THEN + KickVARIABLES%KickOffBottom = .TRUE. + WRITE (*,*) 'Kick Off Bottom' + WRITE (*,*) 'FormPressure , BottomHolePress' , KickVARIABLES%FormPressure , KickVARIABLES%BottomHolePress +!WRITE (*,*) 'No Press(psia) Vol(gal) Weight(lbm) Flow Induced(gpm) Flow El Press(psia)' + DO i = 1 , KickVARIABLES%NoGasPocket + WRITE (*,102) i , GasPocketNewPress%Array(i), GasPocketNewVol%Array(i) * Convft3toUSgal, GasPocketWeight%Array(i), GasPocketFlowInduced%Array(i), FlowEl(KickVARIABLES%GasPocketFlowEl(i , 1))%StartPress + StandardPress + END DO + END IF + KickVARIABLES%KickFlux = .FALSE. + END IF + + IF (ALLOCATED(KickVARIABLES%KickJacobian)) KickVARIABLES%OldKickJacobian = KickVARIABLES%KickJacobian + +102 FORMAT (I2, 3X, (F8.1), 2X, (F8.2), 2X, (F8.3), 8X, (F8.2), 10X, (F8.1)) + +!!!!!!!! Auto Choke Procedure +! DO i = 1 , 5 +! AreaChange = -1.0 * (BottomHolePressure - (KickVARIABLES%FormPressure + BHPSafetyMargin)) / FlowEl(OpenholeFirstEl - 1)%Flowrare**2 * 89158.0 & +! * (0.26 * 0.61)**2 * TotalOpenChokeArea**3 / (4.0 * KickVARIABLES%ChokeDensity) +! data%State%CHOOKE(1)%AreaChokeFinal = data%State%CHOOKE(1)%AreaChokeFinal + AreaChange / * Convfttoinch**2 +! +! +! +! END DO +! +! +! +! +! + + +!WRITE (*,*) ' SecondaryKickWeight', KickVARIABLES%SecondaryKickWeight +!WRITE (*,*) ' SecondaryKickVol', KickVARIABLES%SecondaryKickVol + data%Equipments%DownHole%SecondKickVolume = KickVARIABLES%SecondaryKickVol + + + + IF (KickVARIABLES%WellHeadOpen == .FALSE. .OR. (FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%Flowrate < PressFlowrateTolerance .AND. FlowEl(data%State%FricPressDrop%AnnulusLastEl)%Flowrate < PressFlowrateTolerance)) THEN + data%State%FricPressDrop%OnShakerDensity = 0.0 + ELSE IF (FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%MaterialType == 1 .AND. KickVARIABLES%ChokeKroneckerDelta == 1) THEN + data%State%FricPressDrop%OnShakerDensity = 2.0 + ELSE IF (KickVARIABLES%ChokeKroneckerDelta == 0) THEN + data%State%FricPressDrop%OnShakerDensity = FlowEl(data%State%FricPressDrop%AnnulusLastEl)%Density + ELSE IF (KickVARIABLES%ChokeKroneckerDelta == 1) THEN !!!(FlowEl(OpenholeFirstEl - 1)%Flowrate > PressFlowrateTolerance .AND. FlowEl(AnnulusLastEl)%Flowrate < PressFlowrateTolerance) THEN + data%State%FricPressDrop%OnShakerDensity = FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%Density + ELSE + data%State%FricPressDrop%OnShakerDensity = (FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%Density * FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%Flowrate & + + FlowEl(data%State%FricPressDrop%AnnulusLastEl)%Density * FlowEl(data%State%FricPressDrop%AnnulusLastEl)%Flowrate) / (FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%Flowrate + FlowEl(data%State%FricPressDrop%AnnulusLastEl)%Flowrate) + END IF +!WRITE (*,*) 'ANINT(OnShakerDensity * 100) / 100', ANINT(OnShakerDensity * 100) / 100 , OnShakerDensity + CALL Set_MudWeightOut(ANINT(data%State%FricPressDrop%OnShakerDensity * 100) / 100) + + + IF (ALLOCATED(FinalFlowEl)) DEALLOCATE(FinalFlowEl) + ALLOCATE(FinalFlowEl(data%State%FricPressDrop%NumbEl)) + + FinalFlowEl(:)%StartX = FlowEl(:)%StartX + FinalFlowEl(:)%EndX = FlowEl(:)%EndX + FinalFlowEl(:)%StartTVD = FlowEl(:)%StartTVD + FinalFlowEl(:)%EndTVD = FlowEl(:)%EndTVD + FinalFlowEl(:)%Length = FlowEl(:)%Length + FinalFlowEl(:)%DepthDiff = FlowEl(:)%DepthDiff + FinalFlowEl(:)%density = FlowEl(:)%density + FinalFlowEl(:)%StartPress = FlowEl(:)%StartPress + FinalFlowEl(:)%EndPress = FlowEl(:)%EndPress + FinalFlowEl(:)%dPdLFric = FlowEl(:)%dPdLFric + FinalFlowEl(:)%dPdLGrav = FlowEl(:)%dPdLGrav + + + + + END SUBROUTINE + + + +SUBROUTINE SOLVE_LINEAR_EQUATIONS(A , x , b , error, dim) + +!!! This subroutine solves a linear systems of equations Ax=b +!! if vaiable erorr changed its value to .FALSE. means that the system of equations cab not be solved +!! I use this subroutine to solve the linearized equations which uprising in calculation of volume and pressure of gas kick pockets + + use KickVARIABLESModule + + IMPLICIT NONE + INTEGER , INTENT(IN) :: dim + REAL(8) , DIMENSION(dim,dim) , INTENT(in) :: A + REAL , DIMENSION(dim) , INTENT(OUT) :: x + REAL(8) , DIMENSION(dim) , INTENT(in) :: b + LOGICAL , INTENT(OUT) :: error + REAL(8) , DIMENSION(:,:) , ALLOCATABLE :: m + INTEGER , DIMENSION(1) :: max_loc + REAL(8) , DIMENSION(:) , ALLOCATABLE :: temp_row + INTEGER :: n , k + +!WRITE (*,*) 'SIZE(A , dim = 1), SIZE(A , dim = 2), SIZE(b)', SIZE(A , dim = 1), SIZE(A , dim = 2), SIZE(b) + error = (SIZE(A , dim = 1) /= SIZE(b)) .OR. (SIZE(A , dim = 2) /= SIZE(b)) +!WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 1' , error + + IF (error) THEN + x = 0.0d0 + RETURN + END IF + n = SIZE(b) + + ALLOCATE (m(n , n + 1) , temp_row(n + 1)) + m(1:n , 1:n) = A + m(1:n , n + 1) = b +!WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 2' , m +! Triangularization phase + TRIANG_LOOP: DO k = 1 , n + max_loc = MAXLOC(ABS(m(k:n , k))) + temp_row(k:n + 1) = m(k , k:n + 1) + m(k , k:n+1) = m(k-1+max_loc(1) , k:n+1) + m(k - 1 + max_loc(1) , k:n + 1) = temp_row(k:n + 1) +!WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 3' , max_loc + + IF (m(k , k) == 0) THEN + error = .TRUE. +!WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 4' + EXIT TRIANG_LOOP + ELSE +!WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 5' + m(k , k : n + 1) = m(k , k : n + 1) / m(k , k) + m(k + 1 : n , k + 1 : n + 1) = m(k + 1 : n , k + 1 : n + 1) - SPREAD(m(k , k + 1:n + 1) , 1, n - k) * SPREAD(m(k + 1:n , k) , 2 , n - k + 1) + END IF + END DO TRIANG_LOOP +!WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 6' + +! Back substitution phase + IF (error) THEN + x = 0.0 + ELSE + DO k = n , 1 , -1 + x(k) = REAL(m(k , n + 1) - SUM(m(k , k + 1 : n) * x(k + 1 : n))) +!WRITE (*,*) 'SOLVE_LINEAR_EQUATIONS 7' + END DO + END IF + + DEALLOCATE(m , temp_row) + +END SUBROUTINE solve_linear_equations + diff --git a/FluidFlow/Well_Pressure_Data_Transfer.f90 b/FluidFlow/Well_Pressure_Data_Transfer.f90 index 4729195..7f810ad 100644 --- a/FluidFlow/Well_Pressure_Data_Transfer.f90 +++ b/FluidFlow/Well_Pressure_Data_Transfer.f90 @@ -324,10 +324,10 @@ SUBROUTINE WellPressureDataTransfer !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - data%State%MudSystem%OpenArea32 = ((data%EquipmentControl%ChokeManifold%LeftManualChoke * (1.0 - data%State%FricPressDrop%ManChoke1Plug * REAL(data%problems%ChokeProblems%ManualChoke1PluggedPercent)) / 100.0) + 0.5 * data%State%FricPressDrop%ManChoke1Washout) * data%State%Choke%ChokeAreaFullyOpen + data%State%MudSystem%OpenArea32 = ((data%Equipments%ChokeManifold%LeftManualChoke * (1.0 - data%State%FricPressDrop%ManChoke1Plug * REAL(data%problems%ChokeProblems%ManualChoke1PluggedPercent)) / 100.0) + 0.5 * data%State%FricPressDrop%ManChoke1Washout) * data%State%Choke%ChokeAreaFullyOpen data%State%MudSystem%OpenArea33 = data%State%CHOOKE(1)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - data%State%CHOOKE(1)%PercentClose) * ChokeAreaFullyOpen data%State%MudSystem%OpenArea34 = data%State%CHOOKE(2)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - data%State%CHOOKE(2)%PercentClose) * ChokeAreaFullyOpen - data%State%MudSystem%OpenArea35 = ((data%EquipmentControl%ChokeManifold%RightManualChoke * (1.0 - data%State%FricPressDrop%ManChoke2Plug * REAL(data%problems%ChokeProblems%ManualChoke2PluggedPercent)) / 100.0) + 0.5 * data%State%FricPressDrop%ManChoke2Washout) * data%State%Choke%ChokeAreaFullyOpen + data%State%MudSystem%OpenArea35 = ((data%Equipments%ChokeManifold%RightManualChoke * (1.0 - data%State%FricPressDrop%ManChoke2Plug * REAL(data%problems%ChokeProblems%ManualChoke2PluggedPercent)) / 100.0) + 0.5 * data%State%FricPressDrop%ManChoke2Washout) * data%State%Choke%ChokeAreaFullyOpen !write(*,*) 'OpenArea32=' , OpenArea32, active32, ManChoke1Plug, ManualChoke1PluggedPercent, ManChoke1Washout !write(*,*) 'OpenArea33=' , OpenArea33, active33 !write(*,*) 'OpenArea34=' , OpenArea34, active34, !HydraulicChoke2PluggedPercent @@ -553,7 +553,7 @@ use SimulationVariables !@@@ !WRITE (*,*) 'Kick density (ppg)=' , GasPocketDensity(1) - DownHole%InfluxRate = MAX(((KickVARIABLES%KickmdotACoef * (KickVARIABLES%KickmdotBCoef - GasPocketNewPress%Array(1))) / GasPocketDensity%Array(1) * ConvMinToSec) , 0.0) + data%Equipments%DownHole%InfluxRate = MAX(((KickVARIABLES%KickmdotACoef * (KickVARIABLES%KickmdotBCoef - GasPocketNewPress%Array(1))) / GasPocketDensity%Array(1) * ConvMinToSec) , 0.0) !WRITE (*,*) ' InfluxRate (gpm) =', InfluxRate i = data%State%FricPressDrop%OpenholeFirstEl - 1 @@ -627,7 +627,7 @@ use SimulationVariables !@@@ - DownHole%KickVolume = INT(SUM(GasPocketOldVol%Array(:)) * convft3toUSgal / 42. * 10.0) / 10.0 + data%Equipments%DownHole%KickVolume = INT(SUM(GasPocketOldVol%Array(:)) * convft3toUSgal / 42. * 10.0) / 10.0 !WRITE (*,*) ' Gas Kick Pressure (psi) = ' , GasPocketOldPress(1) , INT((GasPocketNewVol(1) / GasPocketOldVol(1)) * 1000.d0) / 1000.d0 @@ -695,8 +695,8 @@ use SimulationVariables !@@@ CALL GasPocketWeight%Empty CALL GasPocketDensity%Empty - DownHole%InfluxRate = 0.0 - DownHole%KickVolume = 0.0 + data%Equipments%DownHole%InfluxRate = 0.0 + data%Equipments%DownHole%KickVolume = 0.0 END IF diff --git a/FluidFlow/Well_Pressure_Data_Transfer.i90 b/FluidFlow/Well_Pressure_Data_Transfer.i90 new file mode 100644 index 0000000..cce7882 --- /dev/null +++ b/FluidFlow/Well_Pressure_Data_Transfer.i90 @@ -0,0 +1,713 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/FluidFlow/Well_Pressure_Data_Transfer.f90" +SUBROUTINE WellPressureDataTransfer + +!! This subroutine calculates pressure distribution in well +!! We divide well hydraulic system to 4 zones. 1- pump to string zone; this zone is horizontal +!! 2- string zone; this zone includes drill pipes and collars and is vertical or neraly vertical +!! 3- annulus zone; this zone includes annulus space between string and openhole or casing +!! 4- Openhole zone; this zone includes spaces under bit to bottom of the wellbore +!! The last two zone includes annulus space and open hole, are influenced by kicks and have crucial role in +!! computing pressure distribution because reference point (back pressure in well head open condition +!! and bottomhole pressure in well head closed condition) are in one of them. because of this, pressure +!! distribution calculates in two subroutines : PressureAnnAndOHDistribution and PressurePumptoBitDistribution +!! pressure change through well consist of pressure change due to friction, change of elevation and acceleration +!! frictional pressure drop calculated by subroutine Sub_Press_Drop_Calculator +!! This subroutine includes hydrostatic pressure and later will include effect of corss-section area change +!! which causes acceleration or decceleration of flow + + USE FricPressDropVarsModule + use MudSystemModule + USE MudSystemVARIABLES + use SimulationVariables !@@@ + USE GeoElements_FluidModule + USE Fluid_Flow_Startup_Vars + use KickVARIABLESModule +! USE CMudPropertiesVariables +! USE CBopStackVariables +! USE sROP_Variables +! USE CHOKEVARIABLES +! use CChokeManifoldVariables +! use SimulationVariables +! USE CBitProblemsVariables +! USE CChokeProblemsVariables +! USE CStringConfigurationVariables +! use CDataDisplayConsole + + IMPLICIT NONE + + INTEGER :: i , j + REAL :: InstantaneousTotalOpenChokeArea , VolumeDensityProduct + + KickVARIABLES%ChokeIsClosing = .FALSE. + data%State%FricPressDrop%Kchoke = 0.0 + data%State%FricPressDrop%KBit = 0.0 + + +!!!!!!!!!!!!!!!! bit is present + BitTrue = data%Configuration%StringConfiguration%StringConfigurations(1)%ComponentType == Bit_ComponentType ! Bit_ComponentType = 0 + BitCd = 0.98 + BitNozzDia = 32.0 * data%Configuration%StringConfiguration%BitDefinition%BitNozzleSize ! nozzle diameter in 1/32 in + BitNozzleArea = 7.6699E-4 * BitNozzDia**2 + BitNozzleNum = data%Configuration%StringConfiguration%BitDefinition%BitNozzleNo - data%State%FricPressDrop%BitJetsPlugged * data%problems%BitProblems%PlugJetsCount + BitTotNozzArea = BitNozzleNum * BitNozzleArea + 0.5 * data%State%FricPressDrop%BitJetsWashedOut * data%problems%BitProblems%JetWashoutCount * BitNozzleArea + IF (BitNozzleNum == 0) THEN + data%State%FricPressDrop%BitTotallyPluged = .TRUE. + ELSE + data%State%FricPressDrop%BitTotallyPluged = .FALSE. + END IF + + data%State%FricPressDrop%FloatValveIn = data%Configuration%StringConfiguration%BitDefinition%FloatValve +!FloatValveOpen = .TRUE. +!IF (JetWashoutCount > 0 .OR. PlugJetsCount > 0) THEN +! WRITE (*,*) 'PlugJetsCount' , PlugJetsCount +! WRITE (*,*) 'JetWashoutCount', JetWashoutCount +!END IF + +!WRITE (*,*) 'BitNozzleNum', BitNozzleNum +!WRITE (*,*) 'BitTotNozzArea', BitTotNozzArea +!WRITE (*,*) 'Float Valve??', BitDefinition%FloatValve + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + IF(ALLOCATED(KickVARIABLES%GasPocketFlowEl)) DEALLOCATE(KickVARIABLES%GasPocketFlowEl) + +!!!!!!!!!!!!!!!!!!!! Well Head Condition ( Open or Closed ) + KickVARIABLES%ChokeKroneckerDelta = 0 + + + IF (data%State%MudSystem%WellToPitsOpen == .FALSE. .AND. data%State%MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN + + KickVARIABLES%WellHeadOpen = .FALSE. +!WRITE (*,*) ' Well Head is closed ' + ELSE + KickVARIABLES%WellHeadOpen = .TRUE. + END IF + + IF (data%State%MudSystem%WellToPitsOpen == .FALSE. .AND. data%State%MudSystem%WellToChokeManifoldOpen) KickVARIABLES%ChokeKroneckerDelta = 1 +!WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + + data%State%FricPressDrop%NoHorizontalEl = data%State%MudSystem%NoHorizontalMudElements + data%State%FricPressDrop%NoStringEl = data%State%MudSystem%NoStringMudElements + data%State%FricPressDrop%NoAnnulusEl = data%State%MudSystem%NoCasingMudElements + data%State%FricPressDrop%NoWellToChokeEl = 0 + IF (KickVARIABLES%ChokeKroneckerDelta == 1) data%State%FricPressDrop%NoWellToChokeEl = data%State%MudSystem%ChokeLine_Density%Length() + data%State%FricPressDrop%NoOpenHoleEl = data%State%MudSystem%NoBottomHoleMudElements + data%State%FricPressDrop%NumbEl = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + data%State%FricPressDrop%NoWellToChokeEl + data%State%FricPressDrop%NoOpenHoleEl + IF(ALLOCATED(FlowEl)) DEALLOCATE(FlowEl) + ALLOCATE(FlowEl(data%State%FricPressDrop%NumbEl)) + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Transfering Data from module:MudSystemVARIABLES to module:FricPressDropVars to calculate Pressure distribution in flow path +!!!!!!!!!!!!!!!!!!!!!!! Horizontal line +!WRITE (*,*) 'H', NoHorizontalEl + DO i = 1 , data%State%FricPressDrop%NoHorizontalEl + FlowEl(i)%StartX = data%State%MudSystem%Xstart_MudElement%Array(i) + FlowEl(i)%EndX = data%State%MudSystem%Xend_MudElement%Array(i) + FlowEl(i)%StartTVD = 0.d0 + FlowEl(i)%EndTVD = 0.d0 + FlowEl(i)%Id = 0.0 + FlowEl(i)%Od = data%State%MudSystem%PipeOD_MudElement%Array(i) + FlowEl(i)%density = data%State%MudSystem%Density_MudElement%Array(i) + + FlowEl(i)%Dhyd = FlowEl(i)%Od + FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX) + FlowEl(i)%DepthDiff = 0.d0 + FlowEl(i)%Volume = PI / 4.0 * FlowEl(i)%Od**2 * REAL(FlowEl(i)%Length) / Convfttoinch**2 + IF (data%State%MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air + FlowEl(i)%MaterialType = 0 + ELSE IF (data%State%MudSystem%MudType_MudElement%Array(i) == 4) THEN + FlowEl(i)%MaterialType = 4 + ELSE + FlowEl(i)%MaterialType = 1 + END IF + + FlowEl(i)%dPdLgrav = 0.0 + FlowEl(i)%StaticPressDiff = 0.0 + + + + END DO +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!!!!!!! String + data%State%FricPressDrop%StringFirstEl = data%State%FricPressDrop%NoHorizontalEl + 1 + data%State%FricPressDrop%StringLastEl = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + DO i = data%State%FricPressDrop%NoHorizontalEl + 1 , data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl +!WRITE (*,*) 'ST , i' , i + FlowEl(i)%StartX = data%State%MudSystem%Xstart_MudElement%Array(i) +!WRITE (*,*) 'StartX', FlowEl(i)%StartX + FlowEl(i)%EndX = data%State%MudSystem%Xend_MudElement%Array(i) +!WRITE (*,*) 'EndX', FlowEl(i)%EndX + FlowEl(i)%StartTVD = data%State%MudSystem%TVDstart_MudElement%Array(i) +!WRITE (*,*) 'StartTVD', FlowEl(i)%StartTVD + FlowEl(i)%EndTVD = data%State%MudSystem%TVDend_MudElement%Array(i) +!WRITE (*,*) 'EndTVD', FlowEl(i)%EndTVD + FlowEl(i)%Id = 0.0 +!WRITE (*,*) 'Id', FlowEl(i)%Id + FlowEl(i)%Od = data%State%MudSystem%PipeOD_MudElement%Array(i) +!WRITE (*,*) 'Od', FlowEl(i)%Od + FlowEl(i)%Density = data%State%MudSystem%Density_MudElement%Array(i) +!WRITE (*,*) 'Density', FlowEl(i)%Density + + + FlowEl(i)%Dhyd = FlowEl(i)%Od + FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX) +!WRITE (*,*) 'Length', FlowEl(i)%Length + FlowEl(i)%DepthDiff = ABS(FlowEl(i)%StartTVD - FlowEl(i)%EndTVD) +!WRITE (*,*) 'DepthDiff', FlowEl(i)%DepthDiff + FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2 + FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length) + IF (data%State%MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air + FlowEl(i)%MaterialType = 0 + ELSE IF (data%State%MudSystem%MudType_MudElement%Array(i) == 4) THEN + FlowEl(i)%MaterialType = 4 + ELSE + FlowEl(i)%MaterialType = 1 + END IF + + IF (FlowEl(i)%MaterialType == 1 .OR. FlowEl(i)%MaterialType == 4) THEN + FlowEl(i)%dPdLgrav = 0.0 + ELSE + FlowEl(i)%dPdLgrav = 0.052 * FlowEl(i)%Density + END IF + FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff) + + + + + END DO +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!!!!!!!!!! Annulus + data%State%FricPressDrop%AnnulusFirstEl = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + 1 + data%State%FricPressDrop%AnnulusLastEl = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + DO i = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + 1 , data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + FlowEl(i)%StartX = data%State%MudSystem%Xstart_MudElement%Array(i) + FlowEl(i)%EndX = data%State%MudSystem%Xend_MudElement%Array(i) + FlowEl(i)%StartTVD = data%State%MudSystem%TVDstart_MudElement%Array(i) + FlowEl(i)%EndTVD = data%State%MudSystem%TVDend_MudElement%Array(i) + FlowEl(i)%Id = data%State%MudSystem%PipeID_MudElement%Array(i) + FlowEl(i)%Od = data%State%MudSystem%PipeOD_MudElement%Array(i) + FlowEl(i)%Density = data%State%MudSystem%Density_MudElement%Array(i) + + FlowEl(i)%Dhyd = FlowEl(i)%Od - FlowEl(i)%Id + FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX) + FlowEl(i)%DepthDiff = ABS(FlowEl(i)%StartTVD - FlowEl(i)%EndTVD) + FlowEl(i)%Area = PI / 4.0 * (FlowEl(i)%Od**2 - FlowEl(i)%Id**2) / Convfttoinch**2 + FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length) + IF (data%State%MudSystem%MudType_MudElement%Array(i) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air + FlowEl(i)%MaterialType = 0 + ELSE IF (data%State%MudSystem%MudType_MudElement%Array(i) == 4) THEN + FlowEl(i)%MaterialType = 4 + ELSE + FlowEl(i)%MaterialType = 1 + END IF + + IF (FlowEl(i)%MaterialType == 1 .OR. FlowEl(i)%MaterialType == 4) THEN + FlowEl(i)%dPdLgrav = 0.0 + ELSE + FlowEl(i)%dPdLgrav = 0.052 * FlowEl(i)%density + END IF + FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff) + + + + END DO +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!! Well to choke manifold path + j = 1 + DO i = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + 1 , data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + data%State%FricPressDrop%NoWelltoChokeEl + FlowEl(i)%StartX = data%State%MudSystem%ChokeLine_Mud_Backhead_X%Array(j) + FlowEl(i)%EndX = data%State%MudSystem%ChokeLine_Mud_Forehead_X%Array(j) + FlowEl(i)%StartTVD = 0.d0 + FlowEl(i)%EndTVD = 0.d0 + FlowEl(i)%Id = 0.0 + FlowEl(i)%Od = data%Configuration%BopStack%ChokeLineId + FlowEl(i)%density = data%State%MudSystem%ChokeLine_Density%Array(j) + + FlowEl(i)%Dhyd = FlowEl(i)%Od + FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX) + FlowEl(i)%DepthDiff = 0.d0 + FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2 + FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length) + IF (data%State%MudSystem%ChokeLine_MudOrKick%Array(j) == 0 .OR. data%State%MudSystem%ChokeLine_MudOrKick%Array(j) == 4) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air + FlowEl(i)%MaterialType = data%State%MudSystem%ChokeLine_MudOrKick%Array(j) + ELSE + FlowEl(i)%MaterialType = 1 + END IF + + + FlowEl(i)%dPdLgrav = 0.0 + FlowEl(i)%StaticPressDiff = 0.0 + +!WRITE (*,*) 'Ch density, length, Type' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType + + j = j + 1 + + END DO + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!! Open Hole + data%State%FricPressDrop%OpenholeFirstEl = data%State%FricPressDrop%NoHorizontalEl + data%State%FricPressDrop%NoStringEl + data%State%FricPressDrop%NoAnnulusEl + data%State%FricPressDrop%NoWelltoChokeEl + 1 + j = 1 + DO i = data%State%FricPressDrop%OpenholeFirstEl , data%State%FricPressDrop%NumbEl ! = NoHorizontalEl + NoStringEl + NoCasingEl + NoOpenHoleEl + FlowEl(i)%StartX = data%State%MudSystem%Xstart_OpMudElement%Array(j) + FlowEl(i)%EndX = data%State%MudSystem%Xend_OpMudElement%Array(j) + FlowEl(i)%StartTVD = data%State%MudSystem%TVDstart_OpMudElement%Array(j) + FlowEl(i)%EndTVD = data%State%MudSystem%TVDend_OpMudElement%Array(j) + FlowEl(i)%Id = 0.0 + FlowEl(i)%Od = data%State%MudSystem%PipeOD_OpMudElement%Array(j) + FlowEl(i)%density = data%State%MudSystem%Density_OpMudElement%Array(j) + FlowEl(i)%MaterialType = data%State%MudSystem%MudTypeOp_MudElement%Array(j) ! = 0 for mud, = 1 for gas kick, = 4 for air + + FlowEl(i)%Dhyd = FlowEl(i)%Od + FlowEl(i)%Length = ABS(FlowEl(i)%EndX - FlowEl(i)%StartX) + FlowEl(i)%DepthDiff = ABS(FlowEl(i)%StartTVD - FlowEl(i)%EndTVD) + FlowEl(i)%Area = PI / 4.0 * FlowEl(i)%Od**2 / Convfttoinch**2 + FlowEl(i)%Volume = FlowEl(i)%Area * REAL(FlowEl(i)%Length) + IF (data%State%MudSystem%MudTypeOp_MudElement%Array(j) == 0) THEN ! = 0 for mud, = 1 for gas kick, = 4 for air + FlowEl(i)%MaterialType = 0 + ELSE IF (data%State%MudSystem%MudTypeOp_MudElement%Array(j) == 4) THEN + FlowEl(i)%MaterialType = 4 + ELSE + FlowEl(i)%MaterialType = 1 + END IF + + j = j + 1 + IF (FlowEl(i)%MaterialType == 1) THEN + FlowEl(i)%dPdLgrav = 0.0 + ELSE + FlowEl(i)%dPdLgrav = 0.052 * FlowEl(i)%density + END IF + FlowEl(i)%StaticPressDiff = FlowEl(i)%dPdLgrav * REAL(FlowEl(i)%DepthDiff) + +!WRITE (*,*) 'O density, length, Type of ith element' , i, FlowEl(i)%density , FlowEl(i)%length, FlowEl(i)%MaterialType + + END DO +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!! Mud Element Viscosity Calculation + + DO i = 1 , data%State%FricPressDrop%NumbEl + IF (FlowEl(i)%MaterialType /= 0) CYCLE + IF (FlowEl(i)%density < 8.33) THEN + WRITE (*,*) 'H, S, A, Ch, O', data%State%FricPressDrop%NoHorizontalEl , data%State%FricPressDrop%StringFirstEl , data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%NoWellToChokeEl , data%State%FricPressDrop%OpenHoleFirstEl + + WRITE (*,*) 'Element No, Volume(gal), Density(ppg), Type' + DO j = 1 , data%State%FricPressDrop%NumbEl + WRITE (*,*) j, FlowEl(j)%Volume * ConvFt3toUSGal , FlowEl(j)%Density, FlowEl(j)%MaterialType + END DO + + CALL ErrorStop('Density below water density (8.33)', i) + CYCLE + END IF + + FlowEl(i)%Theta600 = Theta600Refrence + 11.0 * (MAX(FlowEl(i)%density , 8.33) - DensityRefrence) + FlowEl(i)%Theta300 = Theta300Refrence + 6.0 * (MAX(FlowEl(i)%density , 8.33) - DensityRefrence) +!WRITE (*,*) 'i, Theta600, Theta600', i, FlowEl(i)%Theta600, FlowEl(i)%Theta300 + END DO +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + + FlowEl(:)%FlowRate = 0.0 + FlowEl(:)%StartPress = 0.0 + FlowEl(:)%EndPress = 0.0 + +!WRITE (*,*) 'NoGasPocket=' , SIZE(GasPocketWeight%Array) + + + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + data%State%MudSystem%OpenArea32 = ((data%Equipments%ChokeManifold%LeftManualChoke * (1.0 - data%State%FricPressDrop%ManChoke1Plug * REAL(data%problems%ChokeProblems%ManualChoke1PluggedPercent)) / 100.0) + 0.5 * data%State%FricPressDrop%ManChoke1Washout) * data%State%Choke%ChokeAreaFullyOpen + data%State%MudSystem%OpenArea33 = data%State%CHOOKE(1)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - data%State%CHOOKE(1)%PercentClose) * ChokeAreaFullyOpen + data%State%MudSystem%OpenArea34 = data%State%CHOOKE(2)%AreaChokeFinal * Convfttoinch**2 ! (1.d0 - data%State%CHOOKE(2)%PercentClose) * ChokeAreaFullyOpen + data%State%MudSystem%OpenArea35 = ((data%Equipments%ChokeManifold%RightManualChoke * (1.0 - data%State%FricPressDrop%ManChoke2Plug * REAL(data%problems%ChokeProblems%ManualChoke2PluggedPercent)) / 100.0) + 0.5 * data%State%FricPressDrop%ManChoke2Washout) * data%State%Choke%ChokeAreaFullyOpen +!write(*,*) 'OpenArea32=' , OpenArea32, active32, ManChoke1Plug, ManualChoke1PluggedPercent, ManChoke1Washout +!write(*,*) 'OpenArea33=' , OpenArea33, active33 +!write(*,*) 'OpenArea34=' , OpenArea34, active34, !HydraulicChoke2PluggedPercent +!write(*,*) 'OpenArea35=' , OpenArea35, active35, ManChoke2Plug, ManualChoke2PluggedPercent, ManChoke2Washout + InstantaneousTotalOpenChokeArea = data%State%MudSystem%OpenArea32 * active32 + data%State%MudSystem%OpenArea33 * active33 + data%State%MudSystem%OpenArea34 * active34 + data%State%MudSystem%OpenArea35 * active35 + data%State%FricPressDrop%ChokeBypassArea * active29 + data%State%FricPressDrop%OldTotalOpenChokeArea = data%State%FricPressDrop%TotalOpenChokeArea +!WRITE (*,*) 'Instantaneous / Old TotalOpenChokeArea', InstantaneousTotalOpenChokeArea, OldTotalOpenChokeArea + IF (data%State%FricPressDrop%OldTotalOpenChokeArea <= 0.01 * data%State%Choke%ChokeAreaFullyOpen) data%State%FricPressDrop%OldTotalOpenChokeArea = 0.01 * data%State%Choke%ChokeAreaFullyOpen + IF (InstantaneousTotalOpenChokeArea <= 0.01 * data%State%Choke%ChokeAreaFullyOpen) THEN + data%State%MudSystem%WellToChokeManifoldOpen = .FALSE. + data%State%FricPressDrop%OldTotalOpenChokeArea = 0.01 * data%State%Choke%ChokeAreaFullyOpen +!WRITE (*,*) ' Choke Controler Here 2' + + ELSE IF (InstantaneousTotalOpenChokeArea > 0.5 * data%State%Choke%ChokeAreaFullyOpen .OR. data%State%MudSystem%WellToPitsOpen) THEN +! mud flows through well to bell nipple, or choke is rather open + data%State%FricPressDrop%TotalOpenChokeArea = InstantaneousTotalOpenChokeArea +!WRITE (*,*) ' Choke Controler Here 1' + ELSE + IF (InstantaneousTotalOpenChokeArea > data%State%FricPressDrop%OldTotalOpenChokeArea) THEN + data%State%FricPressDrop%TotalOpenChokeArea = MIN(1.1 * data%State%FricPressDrop%OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea) + WRITE (*,*) ' Choke is opening' !, TotalOpenChokeArea, OldTotalOpenChokeArea, InstantaneousTotalOpenChokeArea + ELSE IF (InstantaneousTotalOpenChokeArea < data%State%FricPressDrop%OldTotalOpenChokeArea) THEN + data%State%FricPressDrop%TotalOpenChokeArea = MAX(0.9 * data%State%FricPressDrop%OldTotalOpenChokeArea , InstantaneousTotalOpenChokeArea) + WRITE (*,*) ' Choke is closing' !, TotalOpenChokeArea, OldTotalOpenChokeArea, InstantaneousTotalOpenChokeArea + ELSE + data%State%FricPressDrop%TotalOpenChokeArea = InstantaneousTotalOpenChokeArea + END IF + END IF +!WRITE (*,*) 'TotalOpenChokeArea=', TotalOpenChokeArea + + + + + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!! Well Head Condition ( Open or Closed ) + KickVARIABLES%ChokeKroneckerDelta = 0 +!WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen +!WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen + IF (data%State%MudSystem%WellToPitsOpen == .FALSE. .AND. data%State%MudSystem%WellToChokeManifoldOpen == .FALSE.) THEN +!WRITE (*,*) ' WelltoPitsOpen = ', WelltoPitsOpen +!WRITE (*,*) ' WellToChokeManifoldOpen = ', WellToChokeManifoldOpen + + KickVARIABLES%WellHeadOpen = .FALSE. +!WRITE (*,*) ' Well Head is closed ' + ELSE + KickVARIABLES%WellHeadOpen = .TRUE. + END IF + + IF (data%State%MudSystem%WellToPitsOpen == .FALSE. .AND. data%State%MudSystem%WellToChokeManifoldOpen) KickVARIABLES%ChokeKroneckerDelta = 1 +!WRITE (*,*) ' WelltoPitsOpen=' , WelltoPitsOpen, 'WellToChokeManifoldOpen= ' , WellToChokeManifoldOpen +!WRITE (*,*) 'WellToChokeOpen , WellToChokeWasOpen', WellToChokeManifoldOpen, KickVARIABLES%WellToChokeManifoldWasOpen +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + IF (KickVARIABLES%NoGasPocket > 0) THEN + IF (data%State%MudSystem%Choke_Kick_Saved_Volume_Final > 0.d0) THEN +!WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', Choke_Kick_Saved_Volume_Final, (GasPocketModifiedVol%Array(NoGasPocket) * Convft3ToUSgal) + KickVARIABLES%ExitMass = REAL(data%State%MudSystem%Choke_Kick_Saved_Volume_Final / (GasPocketModifiedVol%Array(KickVARIABLES%NoGasPocket) * Convft3ToUSgal)) * GasPocketWeight%Array(KickVARIABLES%NoGasPocket) +!IF (NoGasPocket > 1) ExitMass = ExitMass + (SUM(GasPocketDeltaVol%Array(1 : NoGasPocket - 1)) / GasPocketNewVol%Array(NoGasPocket)) * GasPocketWeight%Array(NoGasPocket) +!WRITE (*,*) 'Total Exit mass=' , ExitMass !, DeltaVolumePipe, data%State%MudSystem%StringFlowRate * dt / ConvMinToSec + IF (FlowEl(data%State%FricPressDrop%OpenholeFirstEl - 1)%MaterialType /= 1) THEN + CALL RemoveGasPocket(KickVARIABLES%NoGasPocket) + WRITE (*,*) 'Choke_Kick_Saved_Volume_Final=', data%State%MudSystem%Choke_Kick_Saved_Volume_Final + END IF + + END IF + + +!NoGasPocket = SIZE(GasPocketWeight%Array) + IF (KickVARIABLES%NoGasPocket > 0) CALL GasPocketFlowElementTransformer + END IF + + IF (data%State%FricPressDrop%NoWelltoChokeEl > 0) THEN + KickVARIABLES%OldChokeDensity = KickVARIABLES%ChokeDensity + VolumeDensityProduct = 0.0 + Do i = data%State%FricPressDrop%AnnulusLastEl + 1 , data%State%FricPressDrop%OpenholeFirstEl - 1 + VolumeDensityProduct = VolumeDensityProduct + ((MAX(FlowEl(i)%Density , KickVARIABLES%ChokeMinDensity)) * FlowEl(i)%Volume) + End Do + KickVARIABLES%ChokeDensity = VolumeDensityProduct / SUM(FlowEl(data%State%FricPressDrop%AnnulusLastEl + 1 : data%State%FricPressDrop%OpenholeFirstEl - 1)%Volume) + +!WRITE (*,*) 'ChokeDensity=', KickVARIABLES%ChokeDensity + data%State%FricPressDrop%Kchoke = (KickVARIABLES%ChokeDensity / ((2.0 * 89158.0) * (0.26 * 0.61 * data%State%FricPressDrop%TotalOpenChokeArea)**2)) * 4.d0 ! *4.d0: seyyed gofte + END IF + + IF (data%State%FricPressDrop%BitTotallyPluged == .FALSE.) THEN + data%State%FricPressDrop%KBit = FlowEl(data%State%FricPressDrop%StringLastEl)%density / 12042.0 / BitCd**2 / BitTotNozzArea**2 + END IF + + + +END SUBROUTINE WellPressureDataTransfer + + +SUBROUTINE GasPocketFlowElementTransformer + +!! This Subroutine makes relationship between fluid flow elements and gas pocket elements +!! The main variable of this subroutine is GasPocketFlowEl +!! For each gas pocket, GasPocketFlowEl has a row, which columns are numbers of flow elements which are contains that gas pocket +!! For example, if we have two gas pockets and they are in (7,8) and (12,3,4) flow elements respectively, +!! GasPocketFlowEl(1,:) = [12 , 3 , 4] and GasPocketFlowEl(2,:) = [7 , 8 , 0] + + + USE FricPressDropVarsModule + USE MudSystemVARIABLES +use SimulationVariables !@@@ + USE GeoElements_FluidModule + USE Fluid_Flow_Startup_Vars + use KickVARIABLESModule + USE CMudPropertiesVariables + USE CBopStackVariables + USE CDownHoleVariables + USE CError + + IMPLICIT NONE + + INTEGER :: i , j , k + REAL :: PressureCorrection + PressureCorrection = 1.0 + + ALLOCATE(KickVARIABLES%GasPocketFlowEl(KickVARIABLES%NoGasPocket , 1)) + KickVARIABLES%GasPocketFlowEl(:,:) = 0 +!WRITE (*,*) 'NoGasPocket=' , NoGasPocket + + i = 1 + j = 1 + DO k = data%State%FricPressDrop%OpenholeFirstEl , data%State%FricPressDrop%NumbEl + IF (FlowEl(k)%MaterialType == 1) THEN + IF (j > 1) THEN + IF (KickVARIABLES%GasPocketFlowEl(i , j - 1) /= k - 1) THEN + i = i + 1 + j = 1 + END IF + END IF + + IF (SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2) < j) THEN + ALLOCATE(KickVARIABLES%tempGasPocketFlowEl(SIZE(KickVARIABLES%GasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2))) + KickVARIABLES%tempGasPocketFlowEl = KickVARIABLES%GasPocketFlowEl + DEALLOCATE(KickVARIABLES%GasPocketFlowEl) + ALLOCATE(KickVARIABLES%GasPocketFlowEl(SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2) + 1)) + KickVARIABLES%GasPocketFlowEl(: , 1 : SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2)) = KickVARIABLES%tempGasPocketFlowEl + KickVARIABLES%GasPocketFlowEl(: , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)) = 0 + DEALLOCATE(KickVARIABLES%tempGasPocketFlowEl) + END IF + + KickVARIABLES%GasPocketFlowEl(i , j) = k + j = j + 1 + END IF + END DO +!WRITE (*,*) 'GasPocketFlowEl=' , GasPocketFlowEl + + DO k = data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%OpenholeFirstEl - 1 + IF (FlowEl(k)%MaterialType == 1) THEN + IF (j > 1) THEN + IF (k == data%State%FricPressDrop%AnnulusFirstEl .AND. KickVARIABLES%GasPocketFlowEl(i , j - 1) == data%State%FricPressDrop%NumbEl) THEN +!WRITE (*,*) 'Kick is Around Bit' + ELSE IF (KickVARIABLES%GasPocketFlowEl(i , j - 1) /= k - 1) THEN + i = i + 1 + j = 1 +!WRITE (*,*) 'i, j, k', i, j, k, FlowEl(k)%MaterialType + END IF + END IF + + IF (j > SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)) THEN + ALLOCATE(KickVARIABLES%tempGasPocketFlowEl(SIZE(KickVARIABLES%GasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2))) + KickVARIABLES%tempGasPocketFlowEl = KickVARIABLES%GasPocketFlowEl + DEALLOCATE(KickVARIABLES%GasPocketFlowEl) + ALLOCATE(KickVARIABLES%GasPocketFlowEl(SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2) + 1)) + KickVARIABLES%GasPocketFlowEl(: , 1 : SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2)) = KickVARIABLES%tempGasPocketFlowEl + KickVARIABLES%GasPocketFlowEl(: , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2)) = 0 + DEALLOCATE(KickVARIABLES%tempGasPocketFlowEl) + END IF + IF (i > KickVARIABLES%NoGasPocket) THEN + WRITE (*,*) 'GasPocketFlowEl', KickVARIABLES%GasPocketFlowEl + WRITE (*,*) 'i , j , k', i, j, k + WRITE (*,*) 'H, S, A, Ch, O', data%State%FricPressDrop%NoHorizontalEl , data%State%FricPressDrop%StringFirstEl , data%State%FricPressDrop%AnnulusFirstEl , data%State%FricPressDrop%NoWellToChokeEl , data%State%FricPressDrop%OpenHoleFirstEl + + WRITE (*,*) 'Element No, Volume(gal), Density(ppg), Type' + DO j = 1 , data%State%FricPressDrop%NumbEl + WRITE (*,*) j, FlowEl(j)%Volume * ConvFt3toUSGal , FlowEl(j)%Density, FlowEl(j)%MaterialType + END DO + + CALL ErrorStop('Error in calculating GasPocketFlowEl') + END IF + + KickVARIABLES%GasPocketFlowEl(i , j) = k +!WRITE (*,*) 'GasPocketFlowEl=' , GasPocketFlowEl + j = j + 1 + + END IF +!IF (i > NoGasPocket) CALL ErrorStop('Error in GasPocketFlowEl' , i) + END DO + + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + GasPocketModifiedVol%Array(:) = 0.d0 + + DO i = 1 , KickVARIABLES%NoGasPocket +!WRITE(*,*) 'GasPocketFlowEl Data' , i , GasPocketFlowEl(: , i) + DO j = 1 , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2) + IF (KickVARIABLES%GasPocketFlowEl(i , j) > 0) GasPocketModifiedVol%Array(i) = GasPocketModifiedVol%Array(i) + FlowEl(KickVARIABLES%GasPocketFlowEl(i , j))%Volume + END DO + END DO + i = data%State%FricPressDrop%AnnulusLastEl + j = data%State%FricPressDrop%OpenholeFirstEl - 1 + + + GasPocketOldVol%Array(:) = GasPocketModifiedVol%Array(:) + + GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:) +!WRITE (*,*) ' GasPocketweight%Array(1)', GasPocketweight%Array(1) + IF (GasPocketWeight%Array(1) < 0.0) CALL ErrorStop(' Error in Calculating Mass ' , KickVARIABLES%KickmdotBCoef) + + + GasPocketDensity%Array(:) = (GasPocketweight%Array(:) / GasPocketModifiedVol%Array(:)) / convft3toUSgal ! [lbm/ft^3 to ppg] + DO i = 1 , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 1) + DO j = 1 , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2) + IF (KickVARIABLES%GasPocketFlowEl(i , j) > 0) FlowEl(KickVARIABLES%GasPocketFlowEl(i , j))%Density = GasPocketDensity%Array(i) + END DO + END DO + + +!WRITE (*,*) 'Kick density (ppg)=' , GasPocketDensity(1) + data%Equipments%DownHole%InfluxRate = MAX(((KickVARIABLES%KickmdotACoef * (KickVARIABLES%KickmdotBCoef - GasPocketNewPress%Array(1))) / GasPocketDensity%Array(1) * ConvMinToSec) , 0.0) +!WRITE (*,*) ' InfluxRate (gpm) =', InfluxRate + + i = data%State%FricPressDrop%OpenholeFirstEl - 1 + IF (data%State%MudSystem%Choke_Kick_Saved_Volume_Final > 0.d0 .AND. KickVARIABLES%WellHeadOpen) THEN + WRITE (*,*) 'Kick is exiting through the choke' +!KickVARIABLES%ExitMass = GasPocketDensity%Array(NoGasPocket) * (SUM(GasPocketFlowInduced%Array(:)) + (DeltaVolumePipe * ConvMinToSec / dt) + data%State%MudSystem%StringFlowRate) / ConvMinToSec * dt + GasPocketWeight%Array(KickVARIABLES%NoGasPocket) = GasPocketweight%Array(KickVARIABLES%NoGasPocket) - KickVARIABLES%ExitMass + IF (GasPocketWeight%Array(KickVARIABLES%NoGasPocket) > 0.0) THEN + GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) = GasPocketWeight%Array(KickVARIABLES%NoGasPocket) * data%State%GasType(KickVARIABLES%KickGasType)%GasConstant * & + GasPocketCompressibility%Array(KickVARIABLES%NoGasPocket) * GasPocketNewTemp%Array(KickVARIABLES%NoGasPocket) / GasPocketModifiedVol%Array(KickVARIABLES%NoGasPocket) + GasPocketDensity%Array(KickVARIABLES%NoGasPocket) = (GasPocketweight%Array(KickVARIABLES%NoGasPocket) / GasPocketModifiedVol%Array(KickVARIABLES%NoGasPocket)) / convft3toUSgal + GasPocketNewVol%Array(:) = GasPocketOldVol%Array(:) + ELSE ! gas pocket is escaped from the well completely + WRITE (*,*) ' Last Pocket Removed' + WRITE (*,*) ' GasPocketFlowEl', KickVARIABLES%GasPocketFlowEl + CALL RemoveGasPocket(KickVARIABLES%NoGasPocket) + +!WRITE (*,*) ' GasPocketFlowEl', GasPocketFlowEl + + END IF + + ELSE IF (KickVARIABLES%NoGasPocket == 1 .OR. KickVARIABLES%WellHeadOpen) THEN ! kick is not last element of choke line or well head is closed + GasPocketNewPress%Array(:) = GasPocketNewPress%Array(:) * REAL(GasPocketNewVol%Array(:) / GasPocketOldVol%Array(:)) + GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:) + GasPocketNewVol%Array(:) = GasPocketOldVol%Array(:) + + ELSE ! Many gas pocket is in the well and well head is closed + +103 FORMAT (2I, 4X, (F9.3), 5X, (F9.3)) + + GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) = GasPocketOldPress%Array(KickVARIABLES%NoGasPocket) + GasPocketNewVol%Array(KickVARIABLES%NoGasPocket) = GasPocketCompressibility%Array(KickVARIABLES%NoGasPocket) * data%State%GasType(KickVARIABLES%KickGasType)%GasConstant * & + GasPocketNewTemp%Array(KickVARIABLES%NoGasPocket) * GasPocketWeight%Array(KickVARIABLES%NoGasPocket) / GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) + + + +!WRITE (*,*) 'Mid' + DO WHILE (ABS(PressureCorrection * 10.0) > KickConvergenceTolerance) + DO j = KickVARIABLES%NoGasPocket - 1 , 1 , -1 + CALL KickFunctionsCalculator(GasPocketNewPress%Array(j) , j , 5) + GasPocketNewVol%Array(j) = GasPocketCompressibility%Array(j) * data%State%GasType(KickVARIABLES%KickGasType)%GasConstant * & + GasPocketNewTemp%Array(j) * GasPocketWeight%Array(j) / GasPocketNewPress%Array(j) +!WRITE (*,*) j, REAL(GasPocketNewPress%Array(j)), REAL(GasPocketNewVol%Array(j) * Convft3toUSgal) + END DO + PressureCorrection = (SUM(GasPocketNewVol%Array(:)) - SUM(GasPocketOldVol%Array(:))) / SUM(GasPocketNewVol%Array(:) / GasPocketNewPress%Array(:)) + GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) = GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) + PressureCorrection + GasPocketNewVol%Array(KickVARIABLES%NoGasPocket) = GasPocketCompressibility%Array(KickVARIABLES%NoGasPocket) * data%State%GasType(KickVARIABLES%KickGasType)%GasConstant * & + GasPocketNewTemp%Array(KickVARIABLES%NoGasPocket) * GasPocketWeight%Array(KickVARIABLES%NoGasPocket) / GasPocketNewPress%Array(KickVARIABLES%NoGasPocket) + j = KickVARIABLES%NoGasPocket +!WRITE (*,*) j, REAL(GasPocketNewPress%Array(j)), REAL(GasPocketNewVol%Array(j) * Convft3toUSgal) + END DO + +!WRITE (*,*) 'Pressure Correction = ', PressureCorrection + WRITE (*,*) 'After' + DO i = 1 , KickVARIABLES%NoGasPocket + WRITE (*,*) i, REAL(GasPocketNewPress%Array(i)), REAL((GasPocketNewVol%Array(i) * Convft3toUSgal)) + END DO + + GasPocketOldPress%Array(:) = GasPocketNewPress%Array(:) + + END IF + + + IF (KickVARIABLES%GasPocketFlowEl(KickVARIABLES%NoGasPocket , 1) == 0) THEN + CALL RemoveGasPocket(1) + +!WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl + WRITE (*,*) 'First Pocket Removed' +!WRITE (*,*) 'GasPocketFlowEl', GasPocketFlowEl + END IF + + + + data%Equipments%DownHole%KickVolume = INT(SUM(GasPocketOldVol%Array(:)) * convft3toUSgal / 42. * 10.0) / 10.0 + + +!WRITE (*,*) ' Gas Kick Pressure (psi) = ' , GasPocketOldPress(1) , INT((GasPocketNewVol(1) / GasPocketOldVol(1)) * 1000.d0) / 1000.d0 +!WRITE (*,*) ' b) GasPocketNewVol (ft^3) = ' , GasPocketOldVol(1) + + + + END SUBROUTINE + + +SUBROUTINE RemoveGasPocket(ilocal) + + use KickVARIABLESModule + USE MudSystemVARIABLES +use SimulationVariables !@@@ + + IMPLICIT NONE + + INTEGER :: ilocal + + DEALLOCATE(KickVARIABLES%KickJacobian , KickVARIABLES%OldKickJacobian , KickVARIABLES%KickVandPFunction , KickVARIABLES%KickUnknownVector , KickVARIABLES%KickCorrectionVector) + + + WRITE (*,*) 'Gas Pocket Will be Removed', ilocal + call GasPocketOldPress%Remove(ilocal) + call GasPocketNewPress%Remove(ilocal) + call GasPocketOldTemp%Remove(ilocal) + call GasPocketNewTemp%Remove(ilocal) + call GasPocketOldVol%Remove(ilocal) + call GasPocketNewVol%Remove(ilocal) + call GasPocketDeltaVol%Remove(ilocal) + call GasPocketFlowInduced%Remove(ilocal) + call GasPocketModifiedVol%Remove(ilocal) + call GasPocketWeight%Remove(ilocal) + call GasPocketDensity%Remove(ilocal) + call GasPocketCompressibility%Remove(ilocal) + + KickVARIABLES%NoGasPocket = KickVARIABLES%NoGasPocket - 1 + + IF (KickVARIABLES%NoGasPocket > 0) THEN + ALLOCATE(KickVARIABLES%KickJacobian(2 * KickVARIABLES%NoGasPocket , 2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%OldKickJacobian(2 * KickVARIABLES%NoGasPocket , 2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%KickVandPFunction(2 * KickVARIABLES%NoGasPocket)) + ALLOCATE(KickVARIABLES%KickUnknownVector(2 * KickVARIABLES%NoGasPocket) , KickVARIABLES%KickCorrectionVector(2 * KickVARIABLES%NoGasPocket)) + + IF (ALLOCATED(KickVARIABLES%GasPocketFlowEl)) THEN + ALLOCATE(KickVARIABLES%tempGasPocketFlowEl(KickVARIABLES%NoGasPocket , SIZE(KickVARIABLES%GasPocketFlowEl , dim = 2))) + KickVARIABLES%tempGasPocketFlowEl = KickVARIABLES%GasPocketFlowEl(1 : KickVARIABLES%NoGasPocket , :) + DEALLOCATE(KickVARIABLES%GasPocketFlowEl) + ALLOCATE(KickVARIABLES%GasPocketFlowEl(SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 1) , SIZE(KickVARIABLES%tempGasPocketFlowEl , dim = 2))) + KickVARIABLES%GasPocketFlowEl = KickVARIABLES%tempGasPocketFlowEl + DEALLOCATE(KickVARIABLES%tempGasPocketFlowEl) + END IF + + ELSE ! NoGasPocket = 0 + + + CALL GasPocketOldPress%Empty + CALL GasPocketNewPress%Empty + CALL GasPocketOldTemp%Empty + CALL GasPocketNewTemp%Empty + CALL GasPocketOldVol%Empty + CALL GasPocketNewVol%Empty + CALL GasPocketDeltaVol%Empty + CALL GasPocketFlowInduced%Empty + CALL GasPocketModifiedVol%Empty + CALL GasPocketWeight%Empty + CALL GasPocketDensity%Empty + + data%Equipments%DownHole%InfluxRate = 0.0 + data%Equipments%DownHole%KickVolume = 0.0 + + END IF + +!WRITE (*,*) 'Gas Pocket Removed', NoGasPocket + 1, ALLOCATED(GasPocketWeight%Array) + +END SUBROUTINE + + + + + + + diff --git a/FluidFlow/kick/Formation_Information.f90 b/FluidFlow/kick/Formation_Information.f90 index 004dcc8..f55ef5f 100644 --- a/FluidFlow/kick/Formation_Information.f90 +++ b/FluidFlow/kick/Formation_Information.f90 @@ -77,14 +77,14 @@ use SimulationVariables !@@@ end if !PermeabilityExposedHeight = KickVARIABLES%KickFormLength * FormationPermeability - DownHole%PermeabilityExposedHeight = data%State%MudSystem%FluidFlowCounter - data%State%MudSystem%MudSys_timeCounter + data%Equipments%DownHole%PermeabilityExposedHeight = data%State%MudSystem%FluidFlowCounter - data%State%MudSystem%MudSys_timeCounter !==================================================== ! Reservoir Data !==================================================== KickVARIABLES%FormPermeability = Reservoir%FormationPermeability ! [mD] KickVARIABLES%FormPressure = data%State%TD_WellGeneral%WellTotalVerticalLength * data%Configuration%Formation%Formations(Reservoir%FormationNo)%PorePressureGradient ![psia] - DownHole%FormationPressure = INT(KickVARIABLES%FormPressure) + data%Equipments%DownHole%FormationPressure = INT(KickVARIABLES%FormPressure) !CALL Log_2('FormPressure =' , KickVARIABLES%FormPressure) !print*, 'Formations(FormationNo)%PorePressureGradient=', Formations(FormationNo)%PorePressureGradient !print * , 'FormationNo=' , FormationNo diff --git a/FluidFlow/kick/Formation_Information.i90 b/FluidFlow/kick/Formation_Information.i90 new file mode 100644 index 0000000..f7f9c33 --- /dev/null +++ b/FluidFlow/kick/Formation_Information.i90 @@ -0,0 +1,126 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/FluidFlow/kick/Formation_Information.f90" +SUBROUTINE FormationInformationCalculator + + use KickVARIABLESModule + use SimulationVariables !@ + Use CReservoirVariables + Use CFormationVariables + USE Fluid_Flow_Startup_Vars + USE CLog2 + USE CDownHoleVariables + USE MudSystemVARIABLES +use SimulationVariables !@@@ + use SimulationVariables + + IMPLICIT NONE + + INTEGER :: i + REAL(8) :: WellGeoTopTVD + + KickVARIABLES%KickGasType = 1 ! methane + +!==================================================== +! Formation Length Calculation +!==================================================== + + WellGeoTopTVD = 0. + KickVARIABLES%KickFormTopMD = 0. + KickVARIABLES%KickFormDownMD = 0. +!===> Top Measured Depth of Formation + Do i = 1 , data%State%TD_WellGeneral%WellIntervalsCount + if ( Reservoir%FormationTop >= data%State%TD_WellGeo(i)%VerticalDepth ) then + KickVARIABLES%KickFormTopMD = KickVARIABLES%KickFormTopMD + data%State%TD_WellGeo(i)%IntervalLength +!WRITE (*,*) ' here 11' , data%State%TD_WellGeo(i)%IntervalLength +!WRITE (*,*) ' here v11' , data%State%TD_WellGeo(i)%VerticalDepth + + WellGeoTopTVD = data%State%TD_WellGeo(i)%VerticalDepth + else if ( Reservoir%FormationTop < data%State%TD_WellGeo(i)%VerticalDepth ) then + if ( data%State%TD_WellGeo(i)%HoleType == 0 ) then + KickVARIABLES%KickFormTopMD = KickVARIABLES%KickFormTopMD + ((Reservoir%FormationTop - WellGeoTopTVD)& + / cos(data%State%TD_WellGeo(i)%StartAngle)) +!WRITE (*,*) ' here 12' , (FormationTop - WellGeoTopTVD) / cos(data%State%TD_WellGeo(i)%StartAngle) + + else + KickVARIABLES%KickFormTopMD = KickVARIABLES%KickFormTopMD + (data%State%TD_WellGeo(i)%RCurvature & + * Asin((Reservoir%FormationTop - WellGeoTopTVD) / data%State%TD_WellGeo(i)%RCurvature)) +!WRITE (*,*) ' here 13' , data%State%TD_WellGeo(i)%RCurvature * Asin((FormationTop - WellGeoTopTVD) / data%State%TD_WellGeo(i)%RCurvature) + + end if + exit + end if + End Do + +!!===> Down Measured Depth of Formation + WellGeoTopTVD = 0. + Do i = 1 , data%State%TD_WellGeneral%WellIntervalsCount + if ( (Reservoir%FormationTop + data%Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness)>=data%State%TD_WellGeo(i)%VerticalDepth ) then + KickVARIABLES%KickFormDownMD = KickVARIABLES%KickFormDownMD + data%State%TD_WellGeo(i)%IntervalLength + WellGeoTopTVD = data%State%TD_WellGeo(i)%VerticalDepth + else if ( (Reservoir%FormationTop+data%Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness) Determination of Formation Length for Kick Modeling + if (data%State%TD_WellGeneral%WellTotalVerticalLength >= Reservoir%FormationTop .AND. data%State%TD_WellGeneral%WellTotalVerticalLength < (Reservoir%FormationTop+data%Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness)) then + KickVARIABLES%KickFormLength = data%State%TD_WellGeneral%WellTotalLength - KickVARIABLES%KickFormTopMD ![ft] + else if ( data%State%TD_WellGeneral%WellTotalVerticalLength >= (Reservoir%FormationTop + data%Configuration%Formation%Formations(Reservoir%FormationNo)%Thickness) ) then + KickVARIABLES%KickFormLength = KickVARIABLES%KickFormDownMD - KickVARIABLES%KickFormTopMD ![ft] + else + KickVARIABLES%KickFormLength = 0. + end if + +!PermeabilityExposedHeight = KickVARIABLES%KickFormLength * FormationPermeability + data%Equipments%DownHole%PermeabilityExposedHeight = data%State%MudSystem%FluidFlowCounter - data%State%MudSystem%MudSys_timeCounter +!==================================================== +! Reservoir Data +!==================================================== + KickVARIABLES%FormPermeability = Reservoir%FormationPermeability ! [mD] + + KickVARIABLES%FormPressure = data%State%TD_WellGeneral%WellTotalVerticalLength * data%Configuration%Formation%Formations(Reservoir%FormationNo)%PorePressureGradient ![psia] + data%Equipments%DownHole%FormationPressure = INT(KickVARIABLES%FormPressure) +!CALL Log_2('FormPressure =' , KickVARIABLES%FormPressure) +!print*, 'Formations(FormationNo)%PorePressureGradient=', Formations(FormationNo)%PorePressureGradient +!print * , 'FormationNo=' , FormationNo +!print * , 'data%State%TD_WellGeneral%WellTotalVerticalLength=' , data%State%TD_WellGeneral%WellTotalVerticalLength + KickVARIABLES%FormTemperature = 600 ! [Ra] +!WRITE (*,*) ' Formation pressure ' , KickVARIABLES%FormPressure + + +!==================================================== +! Gas Properties (Methane Gas) +!==================================================== + + KickVARIABLES%GasResTemperature = KickVARIABLES%FormTemperature + KickVARIABLES%GasResPressure = KickVARIABLES%FormPressure + +!!!! Methane , Gas type =1 + KickVARIABLES%GasKickMolarMass = data%State%GasType(KickVARIABLES%KickGasType)%MolarWt ! Methane Gas [gr/mol] + KickVARIABLES%GasSpecGravity = KickVARIABLES%GasKickMolarMass / GasDensityRefrence + + KickVARIABLES%KickTc = data%State%GasType(KickVARIABLES%KickGasType)%CritTemp + KickVARIABLES%KickPc = data%State%GasType(KickVARIABLES%KickGasType)%CritPress + +!!!!!!!! Calculating Compressibility, viscosity for influx condition (Average of reservoir and bottomhole) + KickVARIABLES%KickTr = KickVARIABLES%GasResTemperature / KickVARIABLES%KickTc + KickVARIABLES%KickPr = KickVARIABLES%GasResPressure / KickVARIABLES%KickPc + + KickVARIABLES%K_A_Res = 3.53 * KickVARIABLES%KickPr + KickVARIABLES%K_B_Res = 10.0**(0.9813 * KickVARIABLES%KickTr) + KickVARIABLES%K_C_Res = 0.274 * (KickVARIABLES%KickPr**2) + KickVARIABLES%K_D_Res = 10.0**(0.8157 * KickVARIABLES%KickTr) + + KickVARIABLES%GasResCompressibility = 0.98 !1. - (K_A_Res / K_B_Res) + (K_C_Res / K_D_Res) + + KickVARIABLES%GasReservoirDensity = KickVARIABLES%GasResPressure / (KickVARIABLES%GasResCompressibility * & + KickVARIABLES%GasResTemperature * data%State%GasType(KickVARIABLES%KickGasType)%GasConstant) / Convft3toUSgal ! [ppg] + +END SUBROUTINE + diff --git a/Makefile b/Makefile index 86c7bbe..484aa1e 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ OBJ_DIR = $(TOP_DIR)/obj # FCFLAGS = -g -J$(MOD_DIR) -fimplicit-none -Wall -cpp -ffree-line-length-256 # FCFLAGS = /module:$(MOD_DIR) /fpp -FCFLAGS = -module $(MOD_DIR) -fpp +FCFLAGS = -module $(MOD_DIR) -fpp -debug all -g -traceback TARGET = SimulationCore2 @@ -372,12 +372,12 @@ SRCS_F =\ Equipments/MudSystem/Circulation_Code_Select.f90 \ TorqueDrag/TD_DrillingSubs/TD_StringConnectionModes.f90 \ FluidFlow/kick/Gas_Kick_Calculator.f90 \ + Redis/Redis_Interface.f90 \ Simulator.f90 \ TorqueDrag/TD_MainCalculations.f90 \ FluidFlow/Well_Pressure_Data_Transfer.f90 \ Equipments/MudSystem/Plot_Final_Mud_Elements.f90 \ FluidFlow/Fluid_Flow_Solver.f90\ - Redis/Redis_Interface.f90 \ # SimulationCore2.f90 \ @@ -392,18 +392,24 @@ all: $(TARGET) $(TARGET): $(OBJS_F) @echo "make TARGET" cc Redis/redis_io.c -c -o obj/redis_io.o - $(FC) -o $@ $(FCFLAGS) $(OBJS_F) obj/redis_io.o lib/libjsonfortran.a lib/libhiredis.a $@.f90 - ./$@ + $(FC) -o $@ $(FCFLAGS) -traceback $(OBJS_F) obj/redis_io.o lib/libjsonfortran.a lib/libhiredis.a $@.f90 -# $(OBJS_F): $(SRCS_F) -# $(FC) $(FCFLAGS) -c -o $@ $< +writevars: $(OBJS_F) + @echo "make writevars" + cc Redis/redis_io.c -c -o obj/redis_io.o + $(FC) -o write_vars $(FCFLAGS) $(OBJS_F) obj/redis_io.o lib/libjsonfortran.a lib/libhiredis.a Test/write_vars.f90 + # ./write_vars config-remote.json +debug: + @echo "DEBUGGING" + cc Redis/redis_io.c -c -o obj/redis_io.o + $(FC) -o SimulationCore2_DEBUG $(FCFLAGS) $(OBJS_F) obj/redis_io.o lib/libjsonfortran.a lib/libhiredis.a SimulationCore2.f90 $(OBJ_DIR)/%.o: %.f90 $(FC) $(FCFLAGS) -c -o $@ $< testjson: - $(FC) -o Test_Json $(FCFLAGS) testjson.f90 lib/libjsonfortran.a + $(FC) -o Test_Json $(FCFLAGS) Test/testJson.f90 lib/libjsonfortran.a ./Test_Json testredis: @@ -413,6 +419,9 @@ testredis: $(FC) $(FCFLAGS) -o Test_Redis obj/redis_io.o obj/Redis_Interface.o lib/libhiredis.a Test/test_redis.f90 ./Test_Redis +testjson2: + ifort -o test_json -module ./mod -fpp obj/Redis_Interface.o Test/testJson.f90 lib/libjsonfortran.a obj/redis_io.o lib/libhiredis.a + ./test_json clean: rm $(OBJ_DIR)/*.o SimulationCore2 diff --git a/Redis/Redis_Interface.f90 b/Redis/Redis_Interface.f90 index 2032dd6..7d0aae5 100644 --- a/Redis/Redis_Interface.f90 +++ b/Redis/Redis_Interface.f90 @@ -7,12 +7,17 @@ Module RedisInterface INTEGER(C_INT) :: a, b END SUBROUTINE addnums - SUBROUTINE initConnection() BIND(C, name='initConnection') - END SUBROUTINE initConnection + SUBROUTINE initConnection_C(address,port,password,datakey) BIND(C, name='initConnection') + use iso_c_binding, only: c_char,c_int + character(kind=c_char) :: address(*) + integer(kind=c_int)::port + character(kind=c_char) :: password(*),datakey(*) + END SUBROUTINE initConnection_C - SUBROUTINE setData_C(str) BIND(C,name='setData') + SUBROUTINE setData_C(part,str) BIND(C,name='setData') use iso_c_binding, only: c_char character(kind=c_char) :: str(*) + character(kind=c_char) :: part(*) END SUBROUTINE setData_C FUNCTION getData_C(len) BIND(C,name='getData') @@ -24,35 +29,104 @@ Module RedisInterface SUBROUTINE deallocateData() BIND(C, name='deallocData') END SUBROUTINE deallocateData - End Interface + End Interface contains - SUBROUTINE setData(str) + SUBROUTINE initConnection(configFilename) + use json_module + use iso_c_binding, only: c_null_char,c_char + character(len=*) :: configFilename + integer::port + type(json_file) :: jsonfile + type(json_value),pointer :: jsonvalue,jsonvalue2 + type(json_core) :: jsoncore + logical :: is_found + character(len=:),allocatable :: password,address,datakey + character(len=:),allocatable::c_address,c_password,c_datakey + + call jsonfile%initialize() + print *,"Initilized: ",configFilename + call jsonfile%load_file(configFilename); + if (jsonfile%failed()) then + print *,"can not open config file: ",configFilename ; + stop + endif + print *,"file read" + call jsonfile%json_file_get_root(jsonvalue) + call jsoncore%get(jsonvalue,'redis',jsonvalue2) + call jsoncore%get(jsonvalue2,"address",address); + call jsoncore%get(jsonvalue2,"port",port); + call jsoncore%get(jsonvalue2,"password",password); + call jsoncore%get(jsonvalue2,"datakey",datakey); + + c_datakey = datakey//c_null_char + c_password = password//c_null_char + c_address = address//c_null_char + call initConnection_C(c_address,port,c_password,c_datakey) + print *,"returned to initConnection" + END SUBROUTINE initConnection + + SUBROUTINE setData(str) use iso_c_binding, only: c_null_char character(len=*):: str character(len=len_trim(str)+1)::c_str + character(len=4)::part + part = "out"//c_null_char c_str = str//c_null_char - call setData_C(c_str) - END SUBROUTINE setData - - SUBROUTINE getData(string) !result(string) - use iso_c_binding, only: c_char,c_ptr,c_f_pointer - ! character(:),allocatable :: getData2 - character(:),allocatable :: string - integer :: string_shape(1) - type(c_ptr) :: c_string - integer::l - ! print *,"reading data (getData2)" - c_string = getData_C(l) - ! string = c_str - ! len = int(c_len,kind=kind(len)) - string_shape(1) = int(l,kind=kind(integer)) - if(.not. allocated(string)) allocate(character(l) :: string) - call c_f_pointer(c_string, string, string_shape) - ! print *,len_trim(string), "chars read." - ! print *,string(1:l) - ! getData2=string - END SUBROUTINE getData + print *,"setting Data: ",len_trim(str) + call setData_C(part,c_str) + END SUBROUTINE setData + + SUBROUTINE setInput(str) + use iso_c_binding, only: c_null_char + character(len=*):: str + character(len=len_trim(str)+1)::c_str + character(len=4)::part + part = "in"//c_null_char + c_str = str//c_null_char + print *,"setting Data: ",len_trim(str) + call setData_C(part,c_str) + END SUBROUTINE setInput + + SUBROUTINE getData(string) !result(string) + use iso_c_binding, only: c_char,c_ptr,c_f_pointer,c_null_ptr + ! character(:),allocatable :: getData2 + character(:),allocatable :: string + integer :: string_shape(1) + type(c_ptr) :: c_string + integer::l + ! print *,"reading data (getData2)" + c_string = getData_C(l) + ! string = c_str + ! len = int(c_len,kind=kind(len)) + string_shape(1) = int(l,kind=kind(integer)) + if(.not. allocated(string)) allocate(character(l) :: string) + call c_f_pointer(c_string, string, string_shape) + c_string=c_null_ptr + ! print *,len_trim(string), "chars read." + ! print *,string(1:l) + ! getData2=string + END SUBROUTINE getData + + SUBROUTINE getData2(string) !result(string) + use iso_c_binding, only: c_char,c_ptr,c_f_pointer,c_null_ptr + ! character(:),allocatable :: getData2 + character(:),allocatable :: string + integer :: string_shape(1) + type(c_ptr) :: c_string + integer::l + ! print *,"reading data (getData2)" + c_string = getData_C(l) + ! string = c_str + ! len = int(c_len,kind=kind(len)) + string_shape(1) = int(l,kind=kind(integer)) + if(.not. allocated(string)) allocate(character(l) :: string) + call c_f_pointer(c_string, string, string_shape) + c_string=c_null_ptr + ! print *,len_trim(string), "chars read." + ! print *,string(1:l) + ! getData2=string + END SUBROUTINE getData2 END Module RedisInterface \ No newline at end of file diff --git a/Redis/Redis_Interface.i90 b/Redis/Redis_Interface.i90 new file mode 100644 index 0000000..75db901 --- /dev/null +++ b/Redis/Redis_Interface.i90 @@ -0,0 +1,133 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Redis/Redis_Interface.f90" +Module RedisInterface +! use iso_c_binding, only: c_char + Interface + SUBROUTINE addnums(a, b) BIND(C,name='addnums') + USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT + IMPLICIT NONE + INTEGER(C_INT) :: a, b + END SUBROUTINE addnums + + SUBROUTINE initConnection_C(address,port,password,datakey) BIND(C, name='initConnection') + use iso_c_binding, only: c_char,c_int + character(kind=c_char) :: address(*) + integer(kind=c_int)::port + character(kind=c_char) :: password(*),datakey(*) + END SUBROUTINE initConnection_C + + SUBROUTINE setData_C(part,str) BIND(C,name='setData') + use iso_c_binding, only: c_char + character(kind=c_char) :: str(*) + character(kind=c_char) :: part(*) + END SUBROUTINE setData_C + + FUNCTION getData_C(len) BIND(C,name='getData') + use iso_c_binding, only: c_ptr,c_int + integer(kind=c_int)::len + type(c_ptr) :: getData_C + END FUNCTION getData_C + + SUBROUTINE deallocateData() BIND(C, name='deallocData') + END SUBROUTINE deallocateData + + End Interface + + contains + + SUBROUTINE initConnection(configFilename) + use json_module + use iso_c_binding, only: c_null_char,c_char + character(len=*) :: configFilename + integer::port + type(json_file) :: jsonfile + type(json_value),pointer :: jsonvalue,jsonvalue2 + type(json_core) :: jsoncore + logical :: is_found + character(len=:),allocatable :: password,address,datakey + character(len=:),allocatable::c_address,c_password,c_datakey + + call jsonfile%initialize() + print *,"Initilized: ",configFilename + call jsonfile%load_file(configFilename); + if (jsonfile%failed()) then + print *,"can not open config file: ",configFilename ; + stop + endif + print *,"file read" + call jsonfile%json_file_get_root(jsonvalue) + call jsoncore%get(jsonvalue,'redis',jsonvalue2) + call jsoncore%get(jsonvalue2,"address",address); + call jsoncore%get(jsonvalue2,"port",port); + call jsoncore%get(jsonvalue2,"password",password); + call jsoncore%get(jsonvalue2,"datakey",datakey); + + c_datakey = datakey//c_null_char + c_password = password//c_null_char + c_address = address//c_null_char + call initConnection_C(c_address,port,c_password,c_datakey) + print *,"returned to initConnection" + END SUBROUTINE initConnection + + SUBROUTINE setData(str) + use iso_c_binding, only: c_null_char + character(len=*):: str + character(len=len_trim(str)+1)::c_str + character(len=4)::part + part = "out"//c_null_char + c_str = str//c_null_char + print *,"setting Data: ",len_trim(str) + call setData_C(part,c_str) + END SUBROUTINE setData + + SUBROUTINE setInput(str) + use iso_c_binding, only: c_null_char + character(len=*):: str + character(len=len_trim(str)+1)::c_str + character(len=4)::part + part = "in"//c_null_char + c_str = str//c_null_char + print *,"setting Data: ",len_trim(str) + call setData_C(part,c_str) + END SUBROUTINE setInput + + SUBROUTINE getData(string) !result(string) + use iso_c_binding, only: c_char,c_ptr,c_f_pointer,c_null_ptr +! character(:),allocatable :: getData2 + character(:),allocatable :: string + integer :: string_shape(1) + type(c_ptr) :: c_string + integer::l +! print *,"reading data (getData2)" + c_string = getData_C(l) +! string = c_str +! len = int(c_len,kind=kind(len)) + string_shape(1) = int(l,kind=kind(integer)) + if(.not. allocated(string)) allocate(character(l) :: string) + call c_f_pointer(c_string, string, string_shape) + c_string=c_null_ptr +! print *,len_trim(string), "chars read." +! print *,string(1:l) +! getData2=string + END SUBROUTINE getData + + SUBROUTINE getData2(string) !result(string) + use iso_c_binding, only: c_char,c_ptr,c_f_pointer,c_null_ptr +! character(:),allocatable :: getData2 + character(:),allocatable :: string + integer :: string_shape(1) + type(c_ptr) :: c_string + integer::l +! print *,"reading data (getData2)" + c_string = getData_C(l) +! string = c_str +! len = int(c_len,kind=kind(len)) + string_shape(1) = int(l,kind=kind(integer)) + if(.not. allocated(string)) allocate(character(l) :: string) + call c_f_pointer(c_string, string, string_shape) + c_string=c_null_ptr +! print *,len_trim(string), "chars read." +! print *,string(1:l) +! getData2=string + END SUBROUTINE getData2 + +END Module RedisInterface diff --git a/Redis/redis_io.c b/Redis/redis_io.c index 53680d7..77405f2 100644 --- a/Redis/redis_io.c +++ b/Redis/redis_io.c @@ -4,16 +4,17 @@ #include "../include/hiredis.h" redisContext *context; -char *result; +char *result,*key; void addnums( int* a, int* b ) { int c = (*a) + (*b); /* convert pointers to values, then add them */ printf("sum of %i and %i is %i\n", (*a), (*b), c ); } -void initConnection() +void initConnection(char *address, int *port,char * password,char *datakey) { - context = redisConnect("127.0.0.1", 6379); + printf("Intializing Connection with %s@%s:%d\n",password,address,*port); + context = redisConnect(address,*port);//"127.0.0.1", 6379); if (context == NULL || context->err) { if (context) { printf("Error: %s\n", context->errstr); @@ -22,16 +23,28 @@ void initConnection() printf("Can't allocate redis context\n"); } } + printf("Connection Stablished to %s",address); + if(strlen(password)>0) + { + redisReply *reply= redisCommand(context, "AUTH %s", password); + if (reply->type == REDIS_REPLY_ERROR) { + printf("Authentication failed.\n"); + } + printf("Authentication is done.\n"); + freeReplyObject(reply); + } + // key = datakey; + key = malloc(sizeof(char) * (strlen(datakey)+1)); + strcpy(key,datakey); + printf("datakey = %s with len %ld\n",datakey,strlen(datakey)); + printf("..."); } -void setData(char *data) +void setData(char *part, char *data) { redisReply *reply; - // printf("Writing data to redis\n"); - // printf("First char =%c \n",data[0]); - printf("%zu chars written\n",strlen(data)); - reply = redisCommand(context, "SET data %s",data); - // printf("data written to redis: %s\n",reply->str); + // printf("%zu chars written\n",strlen(data)); + reply = redisCommand(context, "SET %s.%s %s",key,part,data); freeReplyObject(reply); } @@ -39,7 +52,7 @@ char *getData(int *len) { redisReply *reply; // printf("reading data from redis(c function)\n"); - reply = redisCommand(context, "GET data"); + reply = redisCommand(context, "GET %s.in",key); // printf("data read from redis: %s\n",reply->str); // printf("reply->str: %s\n",reply->str); @@ -54,4 +67,5 @@ void deallocData() { free(result); free(context); + free(key); } \ No newline at end of file diff --git a/Rop/ROP_MainCalculation.f90 b/Rop/ROP_MainCalculation.f90 index ec2bda0..513bc7f 100644 --- a/Rop/ROP_MainCalculation.f90 +++ b/Rop/ROP_MainCalculation.f90 @@ -49,7 +49,7 @@ use SimulationVariables !@@@ - if ( data%State%ROP_Spec%FormationNumber/=0 .and. data%EquipmentControl%DrillingConsole%HideDrillingBrake==1 ) then ! Hide Drilling Brake Mode + if ( data%State%ROP_Spec%FormationNumber/=0 .and. data%Equipments%DrillingConsole%HideDrillingBrake==1 ) then ! Hide Drilling Brake Mode data%State%ROP_Spec%FormationNumber = data%State%ROP_Spec%FormationNumber else do i= 1,data%State%ROP_Bit%NoOfFormations diff --git a/Rop/ROP_MainCalculation.i90 b/Rop/ROP_MainCalculation.i90 new file mode 100644 index 0000000..66670ea --- /dev/null +++ b/Rop/ROP_MainCalculation.i90 @@ -0,0 +1,245 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Rop/ROP_MainCalculation.f90" +subroutine ROP_MainCalculation + use SimulationVariables + use sROP_Other_Variables + use sROP_Variables + use CStringConfigurationVariables + use CformationVariables +! use CSimulationVariables + use CDataDisplayConsole + use SimulationVariables + use CDrillingConsoleVariables + use SimulationVariables + use SimulationVariables + use CmudPropertiesVariables + use CHoistingVariables + use SimulationVariables +! use CDrillingConsole + use SimulationVariables !@ + use SimulationVariables !@, only: RTable + use TD_DrillStemComponents + use SimulationVariables !@ + use PressureDisplayVARIABLESModule + USE MudSystemVARIABLES +use SimulationVariables !@@@ + USE FricPressDropVarsModule + use CReservoirVariables + use CWarnings +! use ConfigurationVariables, only: TDS + use SimulationVariables !@ + + implicit none + + Integer :: i , zero_ROPcount +!Real(8) :: data%State%ROP_Bit%SetROPGauge + + zero_ROPcount = 0 + data%State%ROP_Bit%NoOfFormations = data%Configuration%Formation%Count + data%State%ROP_Bit%DrillingVerticalDepth = data%State%TD_WellGeneral%WellTotalVerticalLength + + + +!===> MaximumWellDepthExceeded Warning + if ( data%State%ROP_Bit%DrillingVerticalDepth>=(data%Configuration%Formation%Formations(data%Configuration%Formation%Count)%Top+data%Configuration%Formation%Formations(data%Configuration%Formation%Count)%Thickness) ) then + data%State%ROP_Bit%RateOfPenetration = 0.0d0 + Call Set_ROP(data%State%ROP_Bit%RateOfPenetration) + Call Activate_MaximumWellDepthExceeded() + return + end if +!===================================== + + + + if ( data%State%ROP_Spec%FormationNumber/=0 .and. data%Equipments%DrillingConsole%HideDrillingBrake==1 ) then ! Hide Drilling Brake Mode + data%State%ROP_Spec%FormationNumber = data%State%ROP_Spec%FormationNumber + else + do i= 1,data%State%ROP_Bit%NoOfFormations + data%State%ROP_Spec%FormationTopDepth = data%Configuration%Formation%Formations(i)%Top + if (data%State%ROP_Bit%DrillingVerticalDepth>=data%State%ROP_Spec%FormationTopDepth) then + data%State%ROP_Spec%FormationNumber = i + end if + end do + end if + + + + +!!===> Hide Drilling Brake Mode +!if ( data%State%ROP_Spec%FormationNumber==FormationNo .and. HideDrillingBrake==1 ) then !???????????? +! data%State%ROP_Spec%FormationNumber = FormationNo-1 +!end if +!!============================= + + + + +!data%State%ROP_Spec%BitClass = BitDefinition%BitCode !???????????? + call Bit_Specification + + + + +! $$$$$**$$$$$**$$$$$**$$$$$**$$$$$** Variables Initialization: *$$$$$**$$$$$**$$$$$**$$$$$**$$$$$ + data%State%ROP_Spec%DiameterOfBit = data%Configuration%StringConfiguration%BitDefinition%BitSize ! unit : [in.] (Typical Range: 3.0 to 30.0) + data%State%ROP_Spec%NumberOfBitNozzles = data%Configuration%StringConfiguration%BitDefinition%BitNozzleNo ! (Typical Values: 1 to 10) + data%State%ROP_Spec%DiameterOfBitNozzle = data%Configuration%StringConfiguration%BitDefinition%BitNozzleSize ! unit : [inch] *** basic input: [1/32 in.] (Typical Range: 8.0 to 32.0) + data%State%ROP_Spec%CriticalMudDensity = data%Configuration%Formation%Formations(data%State%ROP_Spec%FormationNumber)%PorePressureGradient/.465d0*9.d0 ! ????????? delete ,unit : [ppg] or [lb/gal] (Typical Range: 0 to 10.0) + data%State%ROP_Bit%FormationMudDensity = data%Configuration%Formation%Formations(data%State%ROP_Spec%FormationNumber)%PorePressureGradient/0.052d0 + data%State%ROP_Bit%BottomHolePressure = data%State%PressureDisplay%PressureGauges(3) !5200 [psi] + data%State%ROP_Bit%ECD = data%State%ROP_Bit%BottomHolePressure/(0.052*data%State%ROP_Bit%DrillingVerticalDepth) + data%State%ROP_Spec%CriticalWeightOnBit = (data%Configuration%Formation%Formations(data%State%ROP_Spec%FormationNumber)%ThresholdWeight/5.d0)-(.06d0*(data%Configuration%Formation%Formations(data%State%ROP_Spec%FormationNumber)%ThresholdWeight-10.d0)) ! unit : [klb/in] (Typical Range: 0 to 10 ----> 0.6 to 2) +!IF (ALLOCATED(FlowEl)) THEN +! data%State%ROP_Bit%MudViscosity = FlowEl(NoHorizontalEl + NoStringEl)%mueff !13.5 [cP] + data%State%ROP_Bit%MudDensity = data%State%MudSystem%BitMudDensity ! [ppg] +!ELSE + data%State%ROP_Bit%MudViscosity = 13.5 ! [cP] +!data%State%ROP_Bit%MudDensity = 9.2 ! [ppg] +!END IF + data%State%ROP_Bit%MudFlowrate = data%State%MudSystem%StringFlowRateFinal ! [gpm] + data%State%ROP_Spec%ReynoldsNumber = data%State%ROP_Bit%MudFlowrate*data%State%ROP_Bit%MudDensity/(data%State%ROP_Bit%MudViscosity*data%State%ROP_Spec%NumberOfBitNozzles*data%State%ROP_Spec%DiameterOfBitNozzle) ! unit : [dimensionless] (Typical Range: 0.1 to 1000.0) +! $$$$$**$$$$$**$$$$$**$$$$$**$$$$ End of Variable Initialization $$$$$**$$$$$**$$$$$**$$$$$**$$$$$ + + + + + +! -----**-----**-----**-----**-----* data%State%ROP_Bit%RateofPenetration Model Coefficients: *-----**-----**-----**-----**----- + data%State%ROP_Spec%a1 = log(data%Configuration%Formation%Formations(data%State%ROP_Spec%FormationNumber)%Drillablity) + data%State%ROP_Spec%a2 = 1.2799d-04 + data%State%ROP_Spec%a3 = 1.7952d-04 + data%State%ROP_Spec%a4 = 4.0656d-05 + data%State%ROP_Spec%a5 = 2.9021d-01 + data%State%ROP_Spec%a6 = 9.4882d-02 + data%State%ROP_Spec%a7 = 2.1837d-01 + data%State%ROP_Spec%a8 = 4.4915d-01 + data%State%ROP_Spec%dt = 0.1d0 ![s] + data%State%ROP_Spec%TouH = data%Configuration%Formation%Formations(data%State%ROP_Spec%FormationNumber)%Abrasiveness*3600.d0 ! [hr]--->[s] ( Typical Range: 1=0.d0 ) then + data%State%ROP_Spec%f4 = exp(2.303d0*data%State%ROP_Spec%a4*data%State%ROP_Bit%DrillingVerticalDepth*(data%State%ROP_Bit%FormationMudDensity-data%State%ROP_Bit%ECD)) ! Underbalance Drilling Variable + else + data%State%ROP_Spec%f4 = 1.0d0 + end if + + + if (data%State%TD_String%WeightOnBit>0.d0) then + data%State%ROP_Bit%WeightOnBit = data%State%TD_String%WeightOnBit/1000.d0 ![klb] + else + data%State%ROP_Bit%WeightOnBit = 0.d0 + end if + + if ( (data%State%ROP_Bit%WeightOnBit/data%State%ROP_Spec%DiameterOfBit)0.d0) then + data%State%ROP_Bit%RotarySpeed = data%State%RTable%Speed ![rpm] + else if (data%Configuration%Hoisting%DriveType==0 .and. (data%State%TDS%Speed>0. .or. data%State%RTable%Speed>0.)) then + data%State%ROP_Bit%RotarySpeed = data%State%TDS%Speed+data%State%RTable%Speed ![rpm] + else + data%State%ROP_Bit%RotarySpeed = 0.0d0 + end if + data%State%ROP_Spec%f6 = (data%State%ROP_Bit%RotarySpeed/100.d0)**data%State%ROP_Spec%a6 + + + data%State%ROP_Spec%f7 = exp(-data%State%ROP_Spec%a7*data%State%ROP_Bit%BitWearing) + + + Call JetImpactForce + data%State%ROP_Spec%f8 = data%State%ROP_Bit%JetImpactForce/1000.d0 + + + + + data%State%ROP_Bit%RateOfPenetration = (data%State%ROP_Spec%f1*data%State%ROP_Spec%f2*data%State%ROP_Spec%f3*data%State%ROP_Spec%f4*data%State%ROP_Spec%f5*data%State%ROP_Spec%f6*data%State%ROP_Spec%f7*data%State%ROP_Spec%f8) ![ft/h] + data%State%ROP_Bit%RateOfPenetration = (DINT(data%State%ROP_Bit%RateOfPenetration*10.d0))/10.d0 + + if ( (data%State%TD_WellGeneral%WellTotalLength==data%Configuration%Path%Items(data%Configuration%Path%ItemCount)%MeasuredDepth) ) then + data%State%ROP_Bit%SetROPGauge = data%State%ROP_Bit%RateOfPenetration + Call Set_ROP(data%State%ROP_Bit%SetROPGauge) ![ft/h] + data%State%ROP_Bit%OldROPValue(4) = data%State%ROP_Bit%RateOfPenetration +!print* , 'first rop=' , data%State%ROP_Bit%OldROPValue , data%State%ROP_Bit%RateOfPenetration ,& +! zero_ROPcount , data%State%ROP_Bit%SetROPGauge , data%State%ROP_Bit%OldROPDepth , data%State%TD_WellGeneral%WellTotalLength , PathGenerations(PathGenerationCount)%MeasuredDepth + else if ( ((data%State%TD_WellGeneral%WellTotalLength+(data%State%ROP_Bit%RateOfPenetration*data%State%TD_General%TimeStep/3600.d0))-data%State%ROP_Bit%OldROPDepth)>=0.1 ) then + do i= 1,4 + if ( data%State%ROP_Bit%OldROPValue(i)==0. ) then + zero_ROPcount = zero_ROPcount+1 + end if + end do + data%State%ROP_Bit%SetROPGauge = (data%State%ROP_Bit%RateOfPenetration+data%State%ROP_Bit%OldROPValue(1)+data%State%ROP_Bit%OldROPValue(2)+data%State%ROP_Bit%OldROPValue(3)+data%State%ROP_Bit%OldROPValue(4))/sngl(5-zero_ROPcount) + Call Set_ROP(data%State%ROP_Bit%SetROPGauge) ![ft/h] + do i= 2,4 + data%State%ROP_Bit%OldROPValue(i-1) = data%State%ROP_Bit%OldROPValue(i) + end do + data%State%ROP_Bit%OldROPValue(4) = data%State%ROP_Bit%RateOfPenetration + data%State%ROP_Bit%OldROPDepth = data%State%TD_WellGeneral%WellTotalLength+(data%State%ROP_Bit%RateOfPenetration*data%State%TD_General%TimeStep/3600.d0) +!print* , 'new rop=' , data%State%ROP_Bit%OldROPValue , data%State%ROP_Bit%RateOfPenetration ,& +! zero_ROPcount , data%State%ROP_Bit%SetROPGauge , data%State%ROP_Bit%OldROPDepth , data%State%TD_WellGeneral%WellTotalLength , PathGenerations(PathGenerationCount)%MeasuredDepth + else + Call Set_ROP(data%State%ROP_Bit%SetROPGauge) ![ft/h] +!print* , 'old rop=' , data%State%ROP_Bit%OldROPValue , data%State%ROP_Bit%RateOfPenetration ,& +! zero_ROPcount , data%State%ROP_Bit%SetROPGauge , data%State%ROP_Bit%OldROPDepth , data%State%TD_WellGeneral%WellTotalLength , PathGenerations(PathGenerationCount)%MeasuredDepth + end if + + + + + + + if (data%State%ROP_Bit%RotarySpeed > 0.d0) THEN + data%State%ROP_Bit%BitTorque = ( 3.79d0 + 19.17d0*sqrt( data%State%ROP_Bit%RateOfPenetration / (data%State%ROP_Bit%RotarySpeed*data%State%ROP_Spec%DiameterOfBit)) ) * data%State%ROP_Spec%DiameterOfBit * data%State%ROP_Bit%WeightOnBit * ( 1.d0 / ( 1.d0 + 0.00021d0*data%State%ROP_Bit%DrillingVerticalDepth) ) +!data%State%ROP_Bit%BitTorque = data%State%ROP_Bit%BitTorque/3. !bi dalil taghsim bar 3 shode(chon adad bozorg bude), baadan az rabete check shavad (seyyed gofte) + else + data%State%ROP_Bit%BitTorque = 0.d0 + end if + + + + if ( (data%State%ROP_Bit%WeightOnBit/data%State%ROP_Spec%DiameterOfBit)<(data%State%ROP_Spec%wdmax) ) then + data%State%ROP_Bit%BitWearing = data%State%ROP_Bit%BitWearing +( (data%State%ROP_Spec%dt*data%State%ROP_Spec%H3/data%State%ROP_Spec%TouH)*((data%State%ROP_Bit%RotarySpeed/100.d0)**data%State%ROP_Spec%H1)*((data%State%ROP_Spec%wdmax-4.d0)/(data%State%ROP_Spec%wdmax-(data%State%ROP_Bit%WeightOnBit/data%State%ROP_Spec%DiameterOfBit)))*((1.d0+(data%State%ROP_Spec%H2/2.d0))/(1.d0+(data%State%ROP_Spec%H2*data%State%ROP_Bit%BitWearing))) ) + else + data%State%ROP_Bit%BitWearing = 1.0d0 !( Typical Range: 0<=data%State%ROP_Bit%BitWearing<=1 ) + end if + + + + data%State%ROP_Bit%BearingWear = data%State%ROP_Bit%BearingWear+(data%State%ROP_Spec%dt/3600.d0)*(data%State%ROP_Bit%RotarySpeed/100.d0/data%State%ROP_Spec%BrCoef)*((data%State%ROP_Bit%WeightOnBit/4.d0/data%State%ROP_Spec%DiameterOfBit)**1.5d0) + + +!print*, 'data%State%ROP_Bit%RateOfPenetration=', data%State%ROP_Bit%RateOfPenetration +!!print*, 'data%State%ROP_Bit%FormationMudDensity=', data%State%ROP_Bit%FormationMudDensity +!!print*, 'data%State%ROP_Bit%ECD=', data%State%ROP_Bit%ECD +!!print*, 'data%State%ROP_Bit%DrillingVerticalDepth=', data%State%ROP_Bit%DrillingVerticalDepth +!!print*, 'power=', (2.303*data%State%ROP_Spec%a4*data%State%ROP_Bit%DrillingVerticalDepth*(data%State%ROP_Bit%FormationMudDensity-data%State%ROP_Bit%ECD)) +!print*, 'data%State%ROP_Bit%RotarySpeed=', data%State%ROP_Bit%RotarySpeed +!! +!print*, 'data%State%ROP_Spec%f1=', data%State%ROP_Spec%f1 +!print*, 'data%State%ROP_Spec%f2=', data%State%ROP_Spec%f2 +!print*, 'data%State%ROP_Spec%f3=', data%State%ROP_Spec%f3 +!print*, 'data%State%ROP_Spec%f4=', data%State%ROP_Spec%f4 +!print*, 'data%State%ROP_Spec%f5=', data%State%ROP_Spec%f5 +!print*, 'data%State%ROP_Spec%f6=', data%State%ROP_Spec%f6 +!print*, 'data%State%ROP_Spec%f7=', data%State%ROP_Spec%f7 +!print*, 'data%State%ROP_Spec%f8=', data%State%ROP_Spec%f8 +!print*, '***********************' + + + + + +end subroutine diff --git a/Simulation/SimulationVariables.f90 b/Simulation/SimulationVariables.f90 index 169df62..7d907f2 100644 --- a/Simulation/SimulationVariables.f90 +++ b/Simulation/SimulationVariables.f90 @@ -98,9 +98,9 @@ module SimulationVariables Type(HookType)::Hook type(StandPipeManifoldType)::StandPipeManifold Type(TopDrivePanelType)::TopDrivePanel - Type(DrillingWatchType)::DrillingWatch Type(TankType)::Tank + type(DownHoleType):: DownHole end type EquipmentControlType type SimulationStateType @@ -111,7 +111,6 @@ module SimulationVariables type(UnitySignalsType):: unitySignals type(StudentStationType)::StudentStation type(SoftwareInputsType):: softwareInputs - !Bop type(BopStackInputType)::BopStackInput type(BopStackAccType)::BopStackAcc @@ -203,12 +202,13 @@ module SimulationVariables type SimulationDataType type(WarmingsType)::Warnings type(SimulationStateType)::State - type(EquipmentControlType)::EquipmentControl + type(EquipmentControlType)::Equipments type(ConfigurationType)::Configuration type(ProblemsType)::problems end type SimulationDataType type(SimulationDataType)::data + integer::logging=0 contains -end module SimulationVariables +end module SimulationVariables \ No newline at end of file diff --git a/Simulation/SimulationVariables.i90 b/Simulation/SimulationVariables.i90 new file mode 100644 index 0000000..0a11f07 --- /dev/null +++ b/Simulation/SimulationVariables.i90 @@ -0,0 +1,215 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Simulation/SimulationVariables.f90" +module SimulationVariables + use Constants + use json_module + + use COperationScenariosVariables + use CStringConfigurationVariables + use CFormationVariables + use CReservoirVariables + use CShoeVariables + use CAccumulatorVariables + use CBopStackVariables + use CHoistingVariables + use CPowerVariables + use CPumpsVariables + use CRigSizeVariables + use CCasingLinerChokeVariables + use CPathGenerationVariables + use CWellSurveyDataVariables + use CMudPropertiesVariables + + use CBopControlPanelVariables + use CChokeControlPanelVariables + use CChokeManifoldVariables + use CDataDisplayConsoleVariables + use CDrillingConsoleVariables + use CHookVariables + use CStandPipeManifoldVariables + use CTopDrivePanelVariables + use CDrillWatchVariables + use CTanksVariables + use COperationScenariosVariables + use NotificationVariables + use PermissionsVariables + use UnitySignalVariables + use SoftwareInputsVariables + + use CBitProblemsVariables + use CBopProblemsVariables + use CChokeProblemsVariables + use CDrillStemProblemsVariables + use CGaugesProblemsVariables + use CHoistingProblemsVariables + use CKickProblemsVariables + use CLostProblemsVariables + use CMudTreatmentProblemsVariables + use COtherProblemsVariables + use CPumpProblemsVariables + use CRotaryProblemsVariables + + use CStudentStationVariables + use CWarningsVariables + + use BopVariables + use Pumps_VARIABLES + use RTable_VARIABLES + use TopDrive_VARIABLES + use CHOKEVARIABLES + use Drawworks_VARIABLES + USE MudSystemVARIABLES + use Fluid_Flow_Startup_Vars + use PressureDisplayVARIABLESModule + use FricPressDropVarsModule + + use sROP_Other_Variables + use sROP_Variables + + use GeoElements_FluidModule + use TD_DrillStemComponents + use TD_GeneralData + use TD_StringConnectionData + use TD_WellElements + use TD_WellGeometry + + type ConfigurationType + Type(StringConfigurationType)::StringConfiguration + Type(FormationType) :: Formation + Type(ReservoirType)::Reservoir + Type(ShoeType)::Shoe + Type(AccumulatorType)::Accumulator + Type(BopStackSpecificationType)::BopStack + Type(HoistingType)::Hoisting + Type(PowerType)::Power + Type(PumpSpecificationType)::Pumps + Type(RigSizeType)::RigSize + Type(CasingLinerChokeType)::CasingLinerChoke + Type(PathGenerationType)::Path +! Type(WellSurveyDataType)::WellSurveyData + Type(MudPropertiesType)::Mud + end type ConfigurationType + + type EquipmentControlType +! Control Panels + type(BopControlPanelType) :: BopControlPanel + Type(ChokeControlPanelType)::ChokeControlPanel + Type(ChokeManifoldType)::ChokeManifold + Type(DataDisplayConsoleType) :: DataDisplayConsole + TYPE(DrillingConsoleType) :: DrillingConsole + Type(HookType)::Hook + type(StandPipeManifoldType)::StandPipeManifold + Type(TopDrivePanelType)::TopDrivePanel + Type(DrillingWatchType)::DrillingWatch + Type(TankType)::Tank + type(DownHoleType):: DownHole + end type EquipmentControlType + + type SimulationStateType +! Type(HoistingType)::Hoisting !This ds placed twice in data (onece in configuration, once in state) + type(OperationScenarioType)::OperationScenario + type(NotificationType)::notifications + type(PermissionsType):: permissions + type(UnitySignalsType):: unitySignals + type(StudentStationType)::StudentStation + type(SoftwareInputsType):: softwareInputs +!Bop + type(BopStackInputType)::BopStackInput + type(BopStackAccType)::BopStackAcc + type(RamLineType)::RamLine + type(AnnularComputationalType)::AnnularComputational + type(AnnularType)::Annular + type(PipeRams1Type)::PipeRam1 + type(ShearRamType)::ShearRam + type(PipeRam2Type)::PipeRam2 + type(ChokeLineType)::ChokeLine + type(KillLineType)::KillLine + type(PumpsType)::Pumps + TYPE(BOP_TypeVars), DIMENSION(1:6) :: RAM + TYPE(BOP_TypeVars2D) :: RAMS +!Choke + type(ChokeType)::Choke + type(AirDrivenPumpType)::AirDrivenPump + type(AirPumpLineType)::AirPumpLine + TYPE(CHOKE_TypeVars), DIMENSION(1:2) :: CHOOKE +! +!!Drawworks + TYPE(Drawworks_Var) :: Drawworks +!! +!!!MudSystem + type(MudSystemType)::MudSystem + TYPE(MUD_TypeVars), DIMENSION(1:10) :: MUD + +!!Pumps + Type(Pumps_Var) :: MPumps + TYPE(Pump_Var), DIMENSION(1:3) :: PUMP +! + TYPE(RTable_Var) :: RTable + TYPE(TDS_Var) :: TDS +! +!! FluidFlow + TYPE(GasData) :: GasType(3) ! 1 = methane , 2 = Hydrogen sulfide , 3 = Carbon dioxid + TYPE(PressureDisplayVARIABLESTYPE) :: PressureDisplay +! TYPE(ObservationAndGaugePointsInformations) , ALLOCATABLE :: ObservationPoint(:) + TYPE(FricPressDropVarsTYPE) :: FricPressDrop +! +!Rop + TYPE(ROPSpecificationInfo) :: ROP_Spec + TYPE(ROPInfo) :: ROP_Bit + +!TD + TYPE(Geo_Data) :: TDGeo + TYPE(F_StringData) , Allocatable :: F_String(:) + TYPE(F_IntervalsCountsData):: F_Counts + TYPE(F_IntervalData) , Allocatable :: F_Interval(:) + TYPE(OD_AnnulusData) :: OD_Annulus(4) + + TYPE(TD_DrillStemInfo), ALLOCATABLE, DIMENSION(:) :: TD_DrillStem + TYPE(TD_SeparatedDrillStemInfo), ALLOCATABLE, DIMENSION(:) :: TD_DrillStems + TYPE(TD_StringInfo) :: TD_String + TYPE(TD_AddRemoveInfo) :: TD_Count + TYPE(CStringComponents), ALLOCATABLE, DIMENSION(:) :: G_StringElement + TYPE(TD_RemovedVolumeInfo) :: TD_Vol + TYPE(TD_GeneralInfo) :: TD_General + TYPE(TD_BOPInfo) :: TD_BOP + TYPE(CBopElement) :: TD_BOPElement(4) + TYPE(TD_StringconnectionInfo) :: TD_StConn + TYPE(TD_LoadInfo) :: TD_Load + TYPE(TD_WellElementsInfo) :: TD_WellEl + TYPE(TD_CasingInfo), ALLOCATABLE, DIMENSION(:) :: TD_Casing + TYPE(TD_LinerInfo), ALLOCATABLE, DIMENSION(:) :: TD_Liner + TYPE(TD_OpenHoleInfo), ALLOCATABLE, DIMENSION(:) :: TD_OpenHole + TYPE(TD_ROPHoleInfo), ALLOCATABLE, DIMENSION(:) :: TD_ROPHole + TYPE(TD_WellGeneralInfo) :: TD_WellGeneral + TYPE(TD_WellGeometryData), Allocatable :: TD_WellGeo(:) + + + end type SimulationStateType + + type ProblemsType + type(BitProblemsType)::BitProblems + type(BopProblemsType)::BopProblems + type(ChokeProblemsType)::ChokeProblems + type(DrillStemProblemsType)::DrillStemProblems + type(GaugesProblemsType)::GaugesProblems + type(HoistingProblemsType):: HoistingProblems + type(KickProblemsType)::KickProblems + type(LostProblemsType)::LostProblems + type(MudTreatmentProblemsType)::MudTreatmentProblems + type(OtherProblemsType)::OtherProblems + type(PumpProblemsType)::PumpProblems + type(RotaryProblemsType)::RotaryProblems + end type ProblemsType + + type SimulationDataType + type(WarmingsType)::Warnings + type(SimulationStateType)::State + type(EquipmentControlType)::Equipments + type(ConfigurationType)::Configuration + type(ProblemsType)::problems + end type SimulationDataType + + type(SimulationDataType)::data + integer::logging=0 +contains + +end module SimulationVariables diff --git a/SimulationCore2 b/SimulationCore2 index 570399a..7f64c08 100644 Binary files a/SimulationCore2 and b/SimulationCore2 differ diff --git a/SimulationCore2.f90 b/SimulationCore2.f90 index 05bdd6f..fc2b631 100644 --- a/SimulationCore2.f90 +++ b/SimulationCore2.f90 @@ -17,14 +17,18 @@ program SimulationCore2 use RedisInterface !use testRedisModule implicit none - ! character(len=200)::s - + character(len=50)::configFilename = "config-local.json" ! Variables ! Body of SimulationCore2 ! print *, 'Hello World' ! call read_variables() - call simulate() + if(command_argument_count()>0) then + call get_command_argument(1, configFilename) + endif + ! print *,"config-file at SimCore= ",configFilename + ! call initSimulation() + call simulate(configFilename) ! Initialise the json_file object. ! call testRedis() ! pause diff --git a/SimulationCore2_DEBUG b/SimulationCore2_DEBUG new file mode 100644 index 0000000..c43d6de Binary files /dev/null and b/SimulationCore2_DEBUG differ diff --git a/Simulator.f90 b/Simulator.f90 index 575c51f..da7ae08 100644 --- a/Simulator.f90 +++ b/Simulator.f90 @@ -1,674 +1,806 @@ -module Simulator - use RedisInterface - use Bop - use PumpsMain - use RopMain - use RotaryTableMain - use DrawworksMain - use FluidFlowMain - use TorqueDragMain - use MudSystemMain - use PipeRams1Main - use PipeRams2Main - use KillLineMain - use ChokeLineMain - use BlindRamsMain - use AnnularMain - use TopDriveMain - use CManifolds - use GeoMain - use ChokeControlMain - use COperationScenariosMain - - ! For Json read and write - use CStringConfiguration - use CFormation - use CReservoir - use CShoe - use CAccumulator - use CBopStack - use CHoisting - use CPower - use CPumpsVariables - use CRigSize - use CCasingLinerChoke - use CPathGeneration - use CWellSurveyData - use MudPropertiesModule - - use CBitProblems - use CBopProblems - use CChokeProblems - use CDrillStemProblems - use CGaugesProblems - use CHoistingProblems - use CKickProblems - use CLostProblems - use CMudTreatmentProblems - use COtherProblems - use CPumpProblems - use CRotaryProblems - - use OperationScenariosModule - use PermissionsModule - use UnitySignalsModule - - use CBopControlPanel - use CChokeControlPanel - use CChokeManifold - use CDataDisplayConsole - use CDrillingConsole - use CHook - use CStandPipeManifold - use CTopDrivePanel - use DrillingWatchModule - use CTanks - - use :: json_module, rk => json_rk - - implicit none - type(json_file) :: jsonfile - type(json_value),pointer :: jsonvalue - type(json_core) :: jsoncore - logical :: is_found - character(len=:),allocatable::redisContent - - contains - subroutine Simulate - integer :: t - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - t=0 - ! call initConnection() - ! print *,"redis exmaple program" - - ! call jsoncore%create_object(jsonvalue,'') - ! call ConfigurationToJson(jsonvalue) - ! call WarningsToJson(jsonvalue) - ! call ProblemsToJson(jsonvalue) - ! print *,"write starts" - ! call jsoncore%serialize(jsonvalue,redisContent) - ! ! s = "Test redis write!" - ! call setData(redisContent) - ! print *,"write ends len=",len(redisContent) - - ! call getData(s2) - ! print *,"len(read)=",len(s2) - ! print *, s2(1:10),' .... ', s2(len(s2)-10:len(s2)) - ! call deallocateData() - ! ! print *,"S2 = ",s2 - ! deallocate(s2) - - call jsoncore%create_object(jsonvalue,'') - call initConnection() - call write_variables() - call read_variables() - call jsoncore%print(jsonvalue,'test.json') - call jsoncore%destroy(jsonvalue) - - ! print *,"s2=",redisContent - ! call deallocateData() - ! print *,"redisContent Deallocated!" - ! print *,"s2=",redisContent - ! call init_modules() - ! call cpu_time(T1) - ! do while (t<0) - ! !!read variable from shared file - ! call read_variables() - ! exit - ! !! Tarmigh, Now merged with TorqueDrag (FluidFlow) - ! ! call Rop_Step() - - ! !! Rafiee, nothing changed - ! call BopStack_Step() - - ! !! Tarmigh, now is rewritten - ! call Pump1_Step() - ! !call Pump2_Step() - - ! !! Rafiee - ! call ChokeControl_Step() - - ! !! Location ./Equipment/Rotarytable - ! !! Variables: - ! !! Does not have step function - ! !! Call RTable_StartUp in the start - ! !! Again has a loop in each step - ! !! Tarmigh, now is rewritten - ! call RotaryTable_Step() - - ! !! Location ./Equipment/Drawworks - ! !! Variables: - ! !! Does not have step function - ! !! Call ..._StartUp in the start - ! !! Again has a loop in each step - ! !! Tarmigh, now is rewritten - ! call Drawworks_Step() - - ! !! Empty nothing called - ! !! Merged in FluidFlow - ! ! call TorqueDrag_Step() - - ! !! Location: ./Equipment/MudSystem - ! !! Variables: MudSystem_variables.f90 and MudSystem.f90 - ! !! Step function simply calls LineupAndPath in MudSystem.f90 - ! !! had not startUp - ! !! Rafiee - ! call MudSystem_Step() - - ! !! Location ./Equipment/BopStack - ! !! Variables: VARIABLES,CBopStackVariables,CBopControlPanelVariables,CEquipmentsConstants - ! !! Step function added, only call PIPE_RAMS1 and 2 function - ! !! BOP_StartUp commented - ! !! Rafiee - ! call PipeRams1_Step() - ! call PipeRams2_Step() - - - ! !! Location ./Equipment/BopStack - ! !! Variables: VARIABLES,CBopStackVariables,CBopControlPanelVariables,CEquipmentsConstants,CAccumulatorVariables,CSimulationVariables - ! !! Step function added, only call PIPE_RAMS1 and PIPE_RAMS2 function - ! !! BOP_StartUp commented - ! !! Rafiee - ! call KillLine_Step() - - ! !! Probably like other bopstack equipments - ! !! Rafiee - ! call ChokeLine_Step() - ! call BlindRams_Step() - ! call Annular_Step() - - ! !!Tarmigh. Step must rewrittem - ! call TopDrive_Step() - - ! !!Empty - ! ! call Geo_Step() - - ! !!Ahmadi - ! call PathFinding_Step() - ! !! Sheikh - ! call FluidFlow_Step() - - ! !! Ahmadi - ! call OperationScenarios_Step() - - ! !! Write variables to shared files - ! call write_variables() - - ! print *,"t=",t - ! t = t + 1 - ! end do - ! call jsoncore%destroy(jsonvalue) - ! call cpu_time(T2) - ! print *,"Total Execution Time =",t2-t1 - end subroutine Simulate - - subroutine write_variables() - use CAccumulator - use json_module - implicit none - ! character(len=:),allocatable::s - - call ConfigurationToJson(jsonvalue) - call WarningsToJson(jsonvalue) - call ProblemsToJson(jsonvalue) - call EquipmentsToJson(jsonvalue) - - print *,"write starts" - call jsoncore%serialize(jsonvalue,redisContent) - ! s = "Test redis write!" - call setData(redisContent) - print *,"write ends" - end subroutine - - subroutine read_variables() - - ! call getData(redisContent) - ! call jsoncore%deserialize(jsonvalue,redisContent) - - call jsonfile%initialize() - call jsonfile%load_file('data-witharray.json'); if (jsonfile%failed()) stop - call jsonfile%json_file_get_root(jsonvalue) - - call ConfigurationFromJson(jsonvalue) - ! call WarningsFromJson(jsonvalue) - ! call ProblemsFromJson(jsonvalue) - ! call EquipmentsToJson(jsonvalue) - ! print *,"Read from Redix:",redisContent - ! ! Load the file. - ! call jsonfile%load_file('config.json'); if (jsonfile%failed()) stop - ! print *,"read complete" - ! call jsonfile%get('t0', a1, is_found); if (.not. is_found) return - ! call jsonfile%get('dt', a2, is_found); if (.not. is_found) return - ! call jsonfile%get('tf', a3, is_found); if (.not. is_found) return - ! call jsonfile%get('mu', a4, is_found); if (.not. is_found) return - ! call jsonfile%get('x0', x0, is_found); if (.not. is_found) return - - ! if (is_found) then - ! print *, a1,a2,a3,a4 - ! print *, x0 - ! end if - - ! call jsonfile%destroy() - end subroutine - - subroutine init_modules - !Tarmigh - call Pump1_Init() - !call Pump2_Step() - call RotaryTable_Init() - call Drawworks_Init() - call TopDrive_Init() - !Nothing in init (and step) - ! call Rop_Init() - ! call TorqueDrag_Init() - ! call Geo_Step() - - !! Rafiee - call BopStack_Init() - call ChokeControl_Init() - call MudSystem_Init() - !Again calls Bop_Startup - ! call PipeRams1_Init() - ! call PipeRams2_Step() - ! call KillLine_Step() - ! call ChokeLine_Step() - ! call BlindRams_Step() - ! call Annular_Step() - - !! Sheikh - call FluidFlow_Init() - - !! Ahmadi - call PathFinding_Init() - ! Calls OSInitialization and that sub only subscribes some notif - ! call OperationScenarios_Init() - end subroutine init_modules - - subroutine EquipmentsToJson(parent) - - type(json_value),pointer :: parent - type(json_core) :: json - type(json_value),pointer :: p - - ! 1. create new node - call json%create_object(p,'Equipments') - - ! 2. add member of data type to new node - call BopControlPanelToJson(p) - call ChokeControlPanelToJson(p) - call ChokeManifoldToJson(p) - call DataDisplayConsoleToJson(p) - call DrillingConsoleToJson(p) - call HookToJson(p) - call StandPipeManifoldToJson(p) - call TopDrivePanelToJson(p) - call DrillingWatchToJson(p) - call TankToJson(p) - - ! 3. add new node to parent - call json%add(parent,p) - end subroutine - - subroutine ConfigurationToJson(parent) - - type(json_value),pointer :: parent - type(json_core) :: json - type(json_value),pointer :: p - - ! 1. create new node - call json%create_object(p,'Configuration') - - ! 2. add member of data type to new node - call StringConfigurationToJson(p) - call FormationToJson(p) - call ReservoirToJson(p) - call ShoeToJson(p) - call AccumulatorToJson(p) - call BopStackToJson(p) - call HoistingToJson(p) - call PowerToJson(p) - call PumpsToJson(p) - call RigSizeToJson(p) - call CasingLinerChokeToJson(p) - call PathGenerationToJson(p) - ! call WellSurveyDataToJson(p) - call MudPropertiesToJson(p) - - ! 3. add new node to parent - call json%add(parent,p) - end subroutine - - subroutine WarningsToJson(parent) - type(json_value),pointer :: parent - type(json_core) :: json - type(json_value),pointer :: p - - ! 1. create new node - call json%create_object(p,'Warnings') - - ! 2. add member of data type to new node - call json%add(p,"PumpWithKellyDisconnected",data%Warnings%PumpWithKellyDisconnected) - call json%add(p,"PumpWithTopdriveDisconnected",data%Warnings%PumpWithTopdriveDisconnected) - call json%add(p,"Pump1PopOffValveBlown",data%Warnings%Pump1PopOffValveBlown) - call json%add(p,"Pump1Failure",data%Warnings%Pump1Failure) - call json%add(p,"Pump2PopOffValveBlown",data%Warnings%Pump2PopOffValveBlown) - call json%add(p,"Pump2Failure",data%Warnings%Pump2Failure) - call json%add(p,"Pump3PopOffValveBlown",data%Warnings%Pump3PopOffValveBlown) - call json%add(p,"Pump3Failure",data%Warnings%Pump3Failure) - call json%add(p,"DrawworksGearsAbuse",data%Warnings%DrawworksGearsAbuse) - call json%add(p,"RotaryGearsAbuse",data%Warnings%RotaryGearsAbuse) - call json%add(p,"HoistLineBreak",data%Warnings%HoistLineBreak) - call json%add(p,"PartedDrillString",data%Warnings%PartedDrillString) - call json%add(p,"ActiveTankOverflow",data%Warnings%ActiveTankOverflow) - call json%add(p,"ActiveTankUnderVolume",data%Warnings%ActiveTankUnderVolume) - call json%add(p,"TripTankOverflow",data%Warnings%TripTankOverflow) - call json%add(p,"DrillPipeTwistOff",data%Warnings%DrillPipeTwistOff) - call json%add(p,"DrillPipeParted",data%Warnings%DrillPipeParted) - call json%add(p,"TripWithSlipsSet",data%Warnings%TripWithSlipsSet) - call json%add(p,"Blowout",data%Warnings%Blowout) - call json%add(p,"UndergroundBlowout",data%Warnings%UndergroundBlowout) - call json%add(p,"MaximumWellDepthExceeded",data%Warnings%MaximumWellDepthExceeded) - call json%add(p,"CrownCollision",data%Warnings%CrownCollision) - call json%add(p,"FloorCollision",data%Warnings%FloorCollision) - call json%add(p,"TopdriveRotaryTableConfilict",data%Warnings%TopdriveRotaryTableConfilict) - - ! 3. add new node to parent - call json%add(parent,p) - end subroutine - - subroutine ProblemsToJson(parent) - type(json_value),pointer :: parent - type(json_core) :: json - type(json_value),pointer :: p - - ! 1. create new node - call json%create_object(p,'Problems') - - ! 2. add member of data type to new node - call BitProblemsToJson(p) - call BopProblemsToJson(p) - call ChokeProblemsToJson(p) - call DrillStemProblemsToJson(p) - call GaugesProblemsToJson(p) - call HoistingProblemsToJson(p) - call KickProblemsToJson(p) - call LostProblemsToJson(p) - call MudTreatmentProblemsToJson(p) - call OtherProblemsToJson(p) - call PumpProblemsToJson(p) - call RotaryProblemsToJson(p) - - ! 3. add new node to parent - call json%add(parent,p) - end subroutine - - subroutine StateToJson(parent) - - type(json_value),pointer :: parent - type(json_core) :: json - type(json_value),pointer :: p - - ! 1. create new node - call json%create_object(p,'State') - - ! call OperationScenarioToJson(p) - call notificationsToJson(p) - ! call permissionsToJson(p) - ! call unitySignalsToJson(p) - ! call StudentStationToJson(p) - ! call BopStackInputToJson(p) - ! call BopStackAccToJson(p) - ! call RamLineToJson(p) - ! call AnnularComputationalToJson(p) - ! call AnnularToJson(p) - ! call PipeRam1ToJson(p) - ! call ShearRamToJson(p) - ! call PipeRam2ToJson(p) - ! call ChokeLineToJson(p) - ! call KillLineToJson(p) - ! call PumpsToJson(p) - ! call RAMToJson(p) - ! call RAMSToJson(p) - ! call ChokeToJson(p) - ! call AirDrivenPumpToJson(p) - ! call AirPumpLineToJson(p) - ! call CHOOKEToJson(p) - ! call DrawworksToJson(p) - ! call MudSystemToJson(p) - ! call MUDToJson(p) - ! call MPumpsToJson(p) - ! call PUMPToJson(p) - ! call RTableToJson(p) - ! call TDSToJson(p) - ! call GasType(3)ToJson(p) - ! call PressureDisplayToJson(p) - ! call FricPressDropToJson(p) - ! call ROP_SpecToJson(p) - ! call ROP_BitToJson(p) - ! call TDGeoToJson(p) - ! call F_String(:)ToJson(p) - ! call F_CountsToJson(p) - ! call F_Interval(:)ToJson(p) - ! call OD_Annulus(4)ToJson(p) - ! call TD_DrillStemToJson(p) - ! call TD_DrillStemsToJson(p) - ! call TD_StringToJson(p) - ! call TD_CountToJson(p) - ! call G_StringElementToJson(p) - ! call TD_VolToJson(p) - ! call TD_GeneralToJson(p) - ! call TD_BOPToJson(p) - ! call TD_BOPElement(4)ToJson(p) - ! call TD_StConnToJson(p) - ! call TD_LoadToJson(p) - ! call TD_WellElToJson(p) - ! call TD_CasingToJson(p) - ! call TD_LinerToJson(p) - ! call TD_OpenHoleToJson(p) - ! call TD_ROPHoleToJson(p) - ! call TD_WellGeneralToJson(p) - ! call TD_WellGeo(:)ToJson(p) - - ! 2. add member of data type to new node - - ! 3. add new node to parent - call json%add(parent,p) - end subroutine - - !use this as a template - subroutine notificationsToJson(parent) - - type(json_value),pointer :: parent - type(json_core) :: json - type(json_value),pointer :: p - - ! 1. create new node - call json%create_object(p,'Notifications') - - ! 2. add member of data type to new node - - ! 3. add new node to parent - call json%add(parent,p) - end subroutine - - subroutine ConfigurationFromJson(parent) - type(json_value),pointer :: parent - type(json_core) :: json - type(json_value),pointer :: p - - ! 1. get related root - call jsonfile%get('Configuration',p,is_found) - - call StringConfigurationFromJson(p) - call FormationFromJson(p) - call ReservoirFromJson(p) - call ShoeFromJson(p) - call AccumulatorFromJson(p) - call BopStackFromJson(p) - call HoistingFromJson(p) - call PowerFromJson(p) - call PumpsFromJson(p) - call RigSizeFromJson(p) - call CasingLinerChokeFromJson(p) - call PathGenerationFromJson(p) - call MudPropertiesFromJson(p) - - ! 3. add new node to parent - call json%add(parent,p) - end subroutine - - subroutine WarningsFromJson(parent) - type(json_value),pointer :: parent - type(json_core) :: json - type(json_value),pointer :: p - - ! 1. create new node - ! call json%create_object(p,'Warnings') - - ! ! 2. add member of data type to new node - ! call json%add(p,"PumpWithKellyDisconnected",data%Warnings%PumpWithKellyDisconnected) - ! call json%add(p,"PumpWithTopdriveDisconnected",data%Warnings%PumpWithTopdriveDisconnected) - ! call json%add(p,"Pump1PopOffValveBlown",data%Warnings%Pump1PopOffValveBlown) - ! call json%add(p,"Pump1Failure",data%Warnings%Pump1Failure) - ! call json%add(p,"Pump2PopOffValveBlown",data%Warnings%Pump2PopOffValveBlown) - ! call json%add(p,"Pump2Failure",data%Warnings%Pump2Failure) - ! call json%add(p,"Pump3PopOffValveBlown",data%Warnings%Pump3PopOffValveBlown) - ! call json%add(p,"Pump3Failure",data%Warnings%Pump3Failure) - ! call json%add(p,"DrawworksGearsAbuse",data%Warnings%DrawworksGearsAbuse) - ! call json%add(p,"RotaryGearsAbuse",data%Warnings%RotaryGearsAbuse) - ! call json%add(p,"HoistLineBreak",data%Warnings%HoistLineBreak) - ! call json%add(p,"PartedDrillString",data%Warnings%PartedDrillString) - ! call json%add(p,"ActiveTankOverflow",data%Warnings%ActiveTankOverflow) - ! call json%add(p,"ActiveTankUnderVolume",data%Warnings%ActiveTankUnderVolume) - ! call json%add(p,"TripTankOverflow",data%Warnings%TripTankOverflow) - ! call json%add(p,"DrillPipeTwistOff",data%Warnings%DrillPipeTwistOff) - ! call json%add(p,"DrillPipeParted",data%Warnings%DrillPipeParted) - ! call json%add(p,"TripWithSlipsSet",data%Warnings%TripWithSlipsSet) - ! call json%add(p,"Blowout",data%Warnings%Blowout) - ! call json%add(p,"UndergroundBlowout",data%Warnings%UndergroundBlowout) - ! call json%add(p,"MaximumWellDepthExceeded",data%Warnings%MaximumWellDepthExceeded) - ! call json%add(p,"CrownCollision",data%Warnings%CrownCollision) - ! call json%add(p,"FloorCollision",data%Warnings%FloorCollision) - ! call json%add(p,"TopdriveRotaryTableConfilict",data%Warnings%TopdriveRotaryTableConfilict) - - ! ! 3. add new node to parent - ! call json%add(parent,p) - end subroutine - - subroutine ProblemsFromJson(parent) - type(json_value),pointer :: parent - type(json_core) :: json - type(json_value),pointer :: p - - ! 1. create new node - ! call json%create_object(p,'Problems') - - ! ! 2. add member of data type to new node - ! call BitProblemsFromJson(p) - ! call BopProblemsFromJson(p) - ! call ChokeProblemsFromJson(p) - ! call DrillStemProblemsFromJson(p) - ! call GaugesProblemsFromJson(p) - ! call HoistingProblemsFromJson(p) - ! call KickProblemsFromJson(p) - ! call LostProblemsFromJson(p) - ! call MudTreatmentProblemsFromJson(p) - ! call OtherProblemsFromJson(p) - ! call PumpProblemsFromJson(p) - ! call RotaryProblemsFromJson(p) - - ! ! 3. add new node to parent - ! call json%add(parent,p) - end subroutine - - subroutine StateFromJson(parent) - - type(json_value),pointer :: parent - type(json_core) :: json - type(json_value),pointer :: p - - ! 1. create new node - ! call json%create_object(p,'State') - - ! ! call OperationScenarioFromJson(p) - ! call notificationsFromJson(p) - ! call permissionsFromJson(p) - ! call unitySignalsFromJson(p) - ! call StudentStationFromJson(p) - ! call BopStackInputFromJson(p) - ! call BopStackAccFromJson(p) - ! call RamLineFromJson(p) - ! call AnnularComputationalFromJson(p) - ! call AnnularFromJson(p) - ! call PipeRam1FromJson(p) - ! call ShearRamFromJson(p) - ! call PipeRam2FromJson(p) - ! call ChokeLineFromJson(p) - ! call KillLineFromJson(p) - ! call PumpsFromJson(p) - ! call RAMFromJson(p) - ! call RAMSFromJson(p) - ! call ChokeFromJson(p) - ! call AirDrivenPumpFromJson(p) - ! call AirPumpLineFromJson(p) - ! call CHOOKEFromJson(p) - ! call DrawworksFromJson(p) - ! call MudSystemFromJson(p) - ! call MUDFromJson(p) - ! call MPumpsFromJson(p) - ! call PUMPFromJson(p) - ! call RTableFromJson(p) - ! call TDSFromJson(p) - ! call GasType(3)FromJson(p) - ! call PressureDisplayFromJson(p) - ! call FricPressDropFromJson(p) - ! call ROP_SpecFromJson(p) - ! call ROP_BitFromJson(p) - ! call TDGeoFromJson(p) - ! call F_String(:)FromJson(p) - ! call F_CountsFromJson(p) - ! call F_Interval(:)FromJson(p) - ! call OD_Annulus(4)FromJson(p) - ! call TD_DrillStemFromJson(p) - ! call TD_DrillStemsFromJson(p) - ! call TD_StringFromJson(p) - ! call TD_CountFromJson(p) - ! call G_StringElementFromJson(p) - ! call TD_VolFromJson(p) - ! call TD_GeneralFromJson(p) - ! call TD_BOPFromJson(p) - ! call TD_BOPElement(4)FromJson(p) - ! call TD_StConnFromJson(p) - ! call TD_LoadFromJson(p) - ! call TD_WellElFromJson(p) - ! call TD_CasingFromJson(p) - ! call TD_LinerFromJson(p) - ! call TD_OpenHoleFromJson(p) - ! call TD_ROPHoleFromJson(p) - ! call TD_WellGeneralFromJson(p) - ! call TD_WellGeo(:)FromJson(p) - - ! 2. add member of data type to new node - - ! 3. add new node to parent - call json%add(parent,p) - end subroutine - - !use this as a template - subroutine notificationsFromJson(parent) - - type(json_value),pointer :: parent - ! type(json_core) :: json - ! type(json_value),pointer :: p - - ! 1. create new node - ! call json%create_object(p,'Notifications') - - ! ! 2. add member of data type to new node - - ! ! 3. add new node to parent - ! call json%add(parent,p) - end subroutine - - -end module Simulator +module Simulator + use RedisInterface + use Bop + use PumpsMain + use RopMain + use RotaryTableMain + use DrawworksMain + use FluidFlowMain + use TorqueDragMain + use MudSystemMain + use PipeRams1Main + use PipeRams2Main + use KillLineMain + use ChokeLineMain + use BlindRamsMain + use AnnularMain + use TopDriveMain + use CManifolds + use GeoMain + use ChokeControlMain + use COperationScenariosMain + + ! For Json read and write + use CStringConfiguration + use CFormation + use CReservoir + use CShoe + use CAccumulator + use CBopStack + use CHoisting + use CPower + use CPumpsVariables + use CRigSize + use CCasingLinerChoke + use CPathGeneration + use CWellSurveyData + use MudPropertiesModule + + use CBitProblems + use CBopProblems + use CChokeProblems + use CDrillStemProblems + use CGaugesProblems + use CHoistingProblems + use CKickProblems + use CLostProblems + use CMudTreatmentProblems + use COtherProblems + use CPumpProblems + use CRotaryProblems + + use OperationScenariosModule + use PermissionsModule + use UnitySignalsModule + + use CBopControlPanel + use CChokeControlPanel + use CChokeManifold + use CDataDisplayConsole + use CDrillingConsole + use CHook + use CStandPipeManifold + use CTopDrivePanel + use DrillingWatchModule + use CTanks + + implicit none + type(json_file) :: jsonfile + type(json_core):: json + integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep + integer,dimension(8)::timearray + real :: stepTime !time for each step + character(len=:),allocatable::redisInput,redisOutput + enum, bind(c) + enumerator :: PLAY = 1 + enumerator :: PAUSE = 2 + enumerator :: STOP = 3 + enumerator :: PLAY_TO_DETERMINED_TIME = 4 + end enum + + contains + + subroutine Simulate(configFilename) + character(*)::configFilename + integer::t0,t1,t2,t3,t_read=0,t_write=0,t_exec=0,i + integer,dimension(12)::t,t_modules + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + do i=1,size(t_modules) + t_modules(i)=0 + end do + print *,"config-file at Simulate = ",configFilename + call initSimulation(configFilename) + call initConnection(configFilename) + call read_configuration() + ! call read_variables() + print *,"connection initialized" + call init_modules() + print *,"modules initialized" + ! call cpu_time(T1) + simulationStep = 1 + do while (.true.) + print *,"simulationStep=",simulationStep + call date_and_time(values=timearray) + t0 = timearray(8)+timearray(7)*1000+timearray(6)*60000 + print *,"start reading." + call read_variables() + if(simulationStatus==PLAY_TO_DETERMINED_TIME .and. simulationStep>simulationEnd) exit + if(simulationStatus==STOP) exit + if(simulationStatus==PAUSE) cycle + if(logging>4) print *,"end reading" + call date_and_time(values=timearray) + t1 = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_read = t_read+t1-t0 + print *,"read completed" + !! Rafiee, nothing changed + call BopStack_Step() + call date_and_time(values=timearray) + t(1) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(1) = t_modules(1)+t(1)-t1 + !! Tarmigh, now is rewritten + call Pump1_Step() + call date_and_time(values=timearray) + t(2) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(2) = t_modules(2)+t(2)-t(1) + !call Pump2_Step() + !! Rafiee + call ChokeControl_Step() + call date_and_time(values=timearray) + t(3) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(3) = t_modules(3)+t(3)-t(2) + + !! Tarmigh, now is rewritten + call RotaryTable_Step() + call date_and_time(values=timearray) + t(4) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(4) = t_modules(4)+t(4)-t(3) + + !! Tarmigh, now is rewritten + call Drawworks_Step() + call date_and_time(values=timearray) + t(5) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(5) = t_modules(5)+t(5)-t(4) + + !! Rafiee + call MudSystem_Step() + + !! Rafiee + call PipeRams1_Step() + call PipeRams2_Step() + + !! Rafiee + call KillLine_Step() + call date_and_time(values=timearray) + t(6) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(6) = t_modules(6)+t(6)-t(5) + + !! Rafiee + call ChokeLine_Step() + call date_and_time(values=timearray) + t(7) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(7) = t_modules(7)+t(7)-t(6) + + call BlindRams_Step() + call date_and_time(values=timearray) + t(8) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(8) = t_modules(8)+t(8)-t(7) + + call Annular_Step() + call date_and_time(values=timearray) + t(9) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(9) = t_modules(9)+t(9)-t(8) + + !!Tarmigh. Step must rewrittem + call TopDrive_Step() + call date_and_time(values=timearray) + t(10) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(10) = t_modules(10)+t(10)-t(9) + + ! call Geo_Step() + !!Ahmadi + call PathFinding_Step() + call date_and_time(values=timearray) + t(11) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(11) = t_modules(11)+t(11)-t(10) + + !! Sheikh + ! call FluidFlow_Step() + !! Ahmadi + call OperationScenarios_Step() + !! Write variables to shared files + call date_and_time(values=timearray) + t2 = timearray(8)+timearray(7)*1000+timearray(6)*60000 + ! stepTime = t2-t1 + t_modules(12) = t_modules(12)+t2-t(11) + + t_exec = t_exec+t2-t1 + ! call date_and_time(values=timearray) + ! t0 = timearray(8)+timearray(7)*1000+timearray(6)*60000 + print *,"exec completed" + call write_variables() + call date_and_time(values=timearray) + t3 = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_write = t_write+t3-t2 + print *,"write completed" + ! print *,"t=",t + simulationStep = simulationStep + 1 + end do + ! call write_variables() + ! call json%print(jsonroot,'test.json') + ! call json%destroy(jsonroot) + do i=1,size(t) + print *,"t_modules(",i,")=",t_modules(i) + end do + print *,"Number of steps =",simulationStep-1 + print *,"Read Time (from redis) =",t_read + print *,"Write Time (to redis)=",t_write + print *,"Simulation Time =",t_exec + print *,"Total Time =",t_read+t_write+t_exec + end subroutine Simulate + + subroutine initSimulation(configFilename) + use json_module + use iso_c_binding, only: c_null_char,c_char + character(len=*) :: configFilename + ! type(json_file) :: jsonfile + type(json_value),pointer :: jsonvalue + type(json_core) :: jsoncore + logical :: is_found + ! character(len=:),allocatable :: password,address,datakey + ! character(len=:),allocatable::c_address,c_password,c_datakey + + call jsonfile%initialize() + print *,"init simulation with ",configFilename + call jsonfile%load_file(configFilename); + if (jsonfile%failed()) then + print *,"can not open config file: ",configFilename ; + stop + endif + print *,"file read" + call jsonfile%json_file_get_root(jsonvalue) + call jsoncore%get(jsonvalue,'logging',logging) + print *,"logging=",logging + print *,"simulationEnd =",simulationEnd + end subroutine + + subroutine write_variables() + use CAccumulator + use json_module + implicit none + type(json_value),pointer :: jsonroot + character(len=20)::fn + ! integer::n_children + + call json%initialize() + call json%create_object(jsonroot,'') + ! print *,"status=",simulationStatus + ! call json%add(jsonroot,'status',simulationStatus) + ! call json%add(jsonroot,'speed',simulationSpeed) + ! call json%add(jsonroot,'endstep',simulationEnd) + call json%add(jsonroot,'step',simulationStep) + + ! call ConfigurationToJson(jsonroot) + call WarningsToJson(jsonroot) + ! call ProblemsToJson(jsonroot) + call EquipmentsToJson(jsonroot) + + print *,"write starts" + write (fn,*) "data",simulationStep + ! call json%print(jsonroot,trim(fn)//".json") + call json%serialize(jsonroot,redisInput) + ! call compress_string(redisContent) + print *,"Writing to redis:",len(redisInput) + call setData(redisInput) + ! nullify(redisContent) + ! deallocate(redisContent) + ! call json%destroy(pval) + call json%destroy(jsonroot) + print *,"write ends" + end subroutine + + subroutine read_configuration() + type(json_value),pointer :: jsonroot + + call getData(redisOutput) + print *,len(redisOutput)," bytes read from redis" + ! open(1,file="redisContent.json",status="REPLACE") + ! write(1,"(A)") redisContent + ! close(1) + call json%initialize() + call json%deserialize(jsonroot,redisOutput) + + ! call jsonfile%initialize() + ! call jsonfile%load_file('redisContent.json'); if (jsonfile%failed()) stop + ! call jsonfile%json_file_get_root(jsonvalue) + ! call json%info(jsonvalue, n_children=n_children) + ! print *,"n_children =",n_children + ! call json%get(jsonroot,'status',pval) + ! call json%get(pval,simulationStatus) + ! call json%get(jsonroot,'speed',pval) + ! call json%get(pval,simulationSpeed) + ! if(simulationSpeed==0) simulationSpeed = 1 + ! msPerStep = 100/simulationSpeed + ! call json%get(jsonroot,'endstep',pval) + ! call json%get(pval,simulationEnd) + call ConfigurationFromJson(jsonroot) + ! call WarningsFromJson(jsonroot) + ! call ProblemsFromJson(jsonvalue) + ! call EquipmentsFromJson(jsonroot) + ! deallocate(redisContent) + ! call json%destroy(pval) + ! call json%destroy(jsonroot) + end subroutine + + subroutine read_variables() + type(json_value),pointer :: jsonroot,pval + + call getData(redisOutput) + print *,len(redisOutput)," bytes read from redis" + ! open(1,file="redisContent.json",status="REPLACE") + ! write(1,"(A)") redisContent + ! close(1) + call json%initialize() + call json%deserialize(jsonroot,redisOutput) + + ! call jsonfile%initialize() + ! call jsonfile%load_file('redisContent.json'); if (jsonfile%failed()) stop + ! call jsonfile%json_file_get_root(jsonvalue) + ! call json%info(jsonvalue, n_children=n_children) + ! print *,"n_children =",n_children + call json%get(jsonroot,'status',pval) + call json%get(pval,simulationStatus) + call json%get(jsonroot,'speed',pval) + call json%get(pval,simulationSpeed) + if(simulationSpeed==0) simulationSpeed = 1 + msPerStep = 100/simulationSpeed + call json%get(jsonroot,'endstep',pval) + call json%get(pval,simulationEnd) + ! call ConfigurationFromJson(jsonroot) + ! call WarningsFromJson(jsonroot) + call ProblemsFromJson(jsonroot) + call EquipmentsFromJson(jsonroot) + ! deallocate(redisContent) + ! call json%destroy(pval) + ! call json%destroy(jsonroot) + end subroutine + + subroutine init_modules + print *,"initializing modules" + !Tarmigh + call Pump1_Init() + print *,"pump1 initialized" + !call Pump2_Init() + call RotaryTable_Init() + print *,"RT initialized" + call Drawworks_Init() + call TopDrive_Init() + print *,"TD initialized" + + !Nothing in init (and step) + ! call Rop_Init() + ! call TorqueDrag_Init() + ! call Geo_Step() + + !! Rafiee + call BopStack_Init() + call ChokeControl_Init() + call MudSystem_Init() + print *,"Mudsystem initialized" + !Again calls Bop_Startup + ! call PipeRams1_Init() + ! call PipeRams2_Step() + ! call KillLine_Step() + ! call ChokeLine_Step() + ! call BlindRams_Step() + ! call Annular_Step() + + !! Sheikh + ! call FluidFlow_Init() + ! print *,"Mudsystem initialized" + + !! Ahmadi + call PathFinding_Init() + ! Calls OSInitialization and that sub only subscribes some notif + ! call OperationScenarios_Init() + end subroutine init_modules + + subroutine EquipmentsFromJson(parent) + type(json_value),pointer :: parent + + type(json_value),pointer :: p + + ! 1. get related root + call json%get(parent,"Equipments",p) + + ! 2. add member of data type to new node + call BopControlPanelFromJson(p) + call ChokeControlPanelFromJson(p) + call ChokeManifoldFromJson(p) + call DataDisplayConsoleFromJson(p) + call DrillingConsoleFromJson(p) + ! call HookFromJson(p) + call StandPipeManifoldFromJson(p) + call TopDrivePanelFromJson(p) + ! call DrillingWatchFromJson(p) + call TankFromJson(p) + end subroutine + + subroutine EquipmentsToJson(parent) + + type(json_value),pointer :: parent + + type(json_value),pointer :: p + + ! 1. create new node + call json%create_object(p,'Equipments') + + ! 2. add member of data type to new node + call BopControlPanelToJson(p) + call ChokeControlPanelToJson(p) + call ChokeManifoldToJson(p) + call DataDisplayConsoleToJson(p) + call DrillingConsoleToJson(p) + call HookToJson(p) + call StandPipeManifoldToJson(p) + call TopDrivePanelToJson(p) + call DrillingWatchToJson(p) + ! call TankToJson(p) + + ! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ConfigurationToJson(parent) + type(json_value),pointer :: parent + type(json_value),pointer :: p + + ! 1. create new node + call json%create_object(p,'Configuration') + + ! 2. add member of data type to new node + call StringConfigurationToJson(p) + call FormationToJson(p) + call ReservoirToJson(p) + call ShoeToJson(p) + call AccumulatorToJson(p) + call BopStackToJson(p) + call HoistingToJson(p) + call PowerToJson(p) + call PumpsToJson(p) + call RigSizeToJson(p) + call CasingLinerChokeToJson(p) + call PathGenerationToJson(p) + ! call WellSurveyDataToJson(p) + call MudPropertiesToJson(p) + + ! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine WarningsToJson(parent) + type(json_value),pointer :: parent + + type(json_value),pointer :: p + + ! 1. create new node + call json%create_object(p,'Warnings') + + ! 2. add member of data type to new node + call json%add(p,"PumpWithKellyDisconnected",data%Warnings%PumpWithKellyDisconnected) + call json%add(p,"PumpWithTopdriveDisconnected",data%Warnings%PumpWithTopdriveDisconnected) + call json%add(p,"Pump1PopOffValveBlown",data%Warnings%Pump1PopOffValveBlown) + call json%add(p,"Pump1Failure",data%Warnings%Pump1Failure) + call json%add(p,"Pump2PopOffValveBlown",data%Warnings%Pump2PopOffValveBlown) + call json%add(p,"Pump2Failure",data%Warnings%Pump2Failure) + call json%add(p,"Pump3PopOffValveBlown",data%Warnings%Pump3PopOffValveBlown) + call json%add(p,"Pump3Failure",data%Warnings%Pump3Failure) + call json%add(p,"DrawworksGearsAbuse",data%Warnings%DrawworksGearsAbuse) + call json%add(p,"RotaryGearsAbuse",data%Warnings%RotaryGearsAbuse) + call json%add(p,"HoistLineBreak",data%Warnings%HoistLineBreak) + call json%add(p,"PartedDrillString",data%Warnings%PartedDrillString) + call json%add(p,"ActiveTankOverflow",data%Warnings%ActiveTankOverflow) + call json%add(p,"ActiveTankUnderVolume",data%Warnings%ActiveTankUnderVolume) + call json%add(p,"TripTankOverflow",data%Warnings%TripTankOverflow) + call json%add(p,"DrillPipeTwistOff",data%Warnings%DrillPipeTwistOff) + call json%add(p,"DrillPipeParted",data%Warnings%DrillPipeParted) + call json%add(p,"TripWithSlipsSet",data%Warnings%TripWithSlipsSet) + call json%add(p,"Blowout",data%Warnings%Blowout) + call json%add(p,"UndergroundBlowout",data%Warnings%UndergroundBlowout) + call json%add(p,"MaximumWellDepthExceeded",data%Warnings%MaximumWellDepthExceeded) + call json%add(p,"CrownCollision",data%Warnings%CrownCollision) + call json%add(p,"FloorCollision",data%Warnings%FloorCollision) + call json%add(p,"TopdriveRotaryTableConfilict",data%Warnings%TopdriveRotaryTableConfilict) + + ! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProblemsToJson(parent) + type(json_value),pointer :: parent + + type(json_value),pointer :: p + + ! 1. create new node + call json%create_object(p,'Problems') + + ! 2. add member of data type to new node + call BitProblemsToJson(p) + call BopProblemsToJson(p) + call ChokeProblemsToJson(p) + call DrillStemProblemsToJson(p) + call GaugesProblemsToJson(p) + call HoistingProblemsToJson(p) + call KickProblemsToJson(p) + call LostProblemsToJson(p) + call MudTreatmentProblemsToJson(p) + call OtherProblemsToJson(p) + call PumpProblemsToJson(p) + call RotaryProblemsToJson(p) + + ! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine StateToJson(parent) + + type(json_value),pointer :: parent + + type(json_value),pointer :: p + + ! 1. create new node + call json%create_object(p,'State') + + ! call OperationScenarioToJson(p) + call notificationsToJson(p) + ! call permissionsToJson(p) + ! call unitySignalsToJson(p) + ! call StudentStationToJson(p) + ! call BopStackInputToJson(p) + ! call BopStackAccToJson(p) + ! call RamLineToJson(p) + ! call AnnularComputationalToJson(p) + ! call AnnularToJson(p) + ! call PipeRam1ToJson(p) + ! call ShearRamToJson(p) + ! call PipeRam2ToJson(p) + ! call ChokeLineToJson(p) + ! call KillLineToJson(p) + ! call PumpsToJson(p) + ! call RAMToJson(p) + ! call RAMSToJson(p) + ! call ChokeToJson(p) + ! call AirDrivenPumpToJson(p) + ! call AirPumpLineToJson(p) + ! call CHOOKEToJson(p) + ! call DrawworksToJson(p) + ! call MudSystemToJson(p) + ! call MUDToJson(p) + ! call MPumpsToJson(p) + ! call PUMPToJson(p) + ! call RTableToJson(p) + ! call TDSToJson(p) + ! call GasType(3)ToJson(p) + ! call PressureDisplayToJson(p) + ! call FricPressDropToJson(p) + ! call ROP_SpecToJson(p) + ! call ROP_BitToJson(p) + ! call TDGeoToJson(p) + ! call F_String(:)ToJson(p) + ! call F_CountsToJson(p) + ! call F_Interval(:)ToJson(p) + ! call OD_Annulus(4)ToJson(p) + ! call TD_DrillStemToJson(p) + ! call TD_DrillStemsToJson(p) + ! call TD_StringToJson(p) + ! call TD_CountToJson(p) + ! call G_StringElementToJson(p) + ! call TD_VolToJson(p) + ! call TD_GeneralToJson(p) + ! call TD_BOPToJson(p) + ! call TD_BOPElement(4)ToJson(p) + ! call TD_StConnToJson(p) + ! call TD_LoadToJson(p) + ! call TD_WellElToJson(p) + ! call TD_CasingToJson(p) + ! call TD_LinerToJson(p) + ! call TD_OpenHoleToJson(p) + ! call TD_ROPHoleToJson(p) + ! call TD_WellGeneralToJson(p) + ! call TD_WellGeo(:)ToJson(p) + + ! 2. add member of data type to new node + + ! 3. add new node to parent + call json%add(parent,p) + end subroutine + + !use this as a template + subroutine notificationsToJson(parent) + + type(json_value),pointer :: parent + + type(json_value),pointer :: p + + ! 1. create new node + call json%create_object(p,'Notifications') + + ! 2. add member of data type to new node + + ! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ConfigurationFromJson(parent) + type(json_value),pointer :: parent + + type(json_value),pointer :: p + + ! 1. get related root + call json%get(parent,"Configuration",p) + + call StringConfigurationFromJson(p) + call FormationFromJson(p) + call ReservoirFromJson(p) + call ShoeFromJson(p) + call AccumulatorFromJson(p) + call BopStackFromJson(p) + call HoistingFromJson(p) + call PowerFromJson(p) + call PumpsFromJson(p) + call RigSizeFromJson(p) + call CasingLinerChokeFromJson(p) + call PathGenerationFromJson(p) + call MudPropertiesFromJson(p) + + ! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine WarningsFromJson(parent) + type(json_value),pointer :: parent + type(json_value),pointer :: p + type(json_value),pointer :: pval + + ! 1. get node + call json%get(parent,'Warnings',p) + + ! ! 2. add member of data type to new node + call json%get(p,'PumpWithKellyDisconnected',pval) + call json%get(pval,data%Warnings%PumpWithKellyDisconnected) + call json%get(p,'PumpWithTopdriveDisconnected',pval) + call json%get(pval,data%Warnings%PumpWithTopdriveDisconnected) + call json%get(p,'Pump1PopOffValveBlown',pval) + call json%get(pval,data%Warnings%Pump1PopOffValveBlown) + call json%get(p,'Pump1Failure',pval) + call json%get(pval,data%Warnings%Pump1Failure) + call json%get(p,'Pump2PopOffValveBlown',pval) + call json%get(pval,data%Warnings%Pump2PopOffValveBlown) + call json%get(p,'Pump2Failure',pval) + call json%get(pval,data%Warnings%Pump2Failure) + call json%get(p,'Pump3PopOffValveBlown',pval) + call json%get(pval,data%Warnings%Pump3PopOffValveBlown) + call json%get(p,'Pump3Failure',pval) + call json%get(pval,data%Warnings%Pump3Failure) + call json%get(p,'DrawworksGearsAbuse',pval) + call json%get(pval,data%Warnings%DrawworksGearsAbuse) + call json%get(p,'RotaryGearsAbuse',pval) + call json%get(pval,data%Warnings%RotaryGearsAbuse) + call json%get(p,'HoistLineBreak',pval) + call json%get(pval,data%Warnings%HoistLineBreak) + call json%get(p,'PartedDrillString',pval) + call json%get(pval,data%Warnings%PartedDrillString) + call json%get(p,'ActiveTankOverflow',pval) + call json%get(pval,data%Warnings%ActiveTankOverflow) + call json%get(p,'ActiveTankUnderVolume',pval) + call json%get(pval,data%Warnings%ActiveTankUnderVolume) + call json%get(p,'TripTankOverflow',pval) + call json%get(pval,data%Warnings%TripTankOverflow) + call json%get(p,'DrillPipeTwistOff',pval) + call json%get(pval,data%Warnings%DrillPipeTwistOff) + call json%get(p,'DrillPipeParted',pval) + call json%get(pval,data%Warnings%DrillPipeParted) + call json%get(p,'TripWithSlipsSet',pval) + call json%get(pval,data%Warnings%TripWithSlipsSet) + call json%get(p,'Blowout',pval) + call json%get(pval,data%Warnings%Blowout) + call json%get(p,'UndergroundBlowout',pval) + call json%get(pval,data%Warnings%UndergroundBlowout) + call json%get(p,'MaximumWellDepthExceeded',pval) + call json%get(pval,data%Warnings%MaximumWellDepthExceeded) + call json%get(p,'CrownCollision',pval) + call json%get(pval,data%Warnings%CrownCollision) + call json%get(p,'FloorCollision',pval) + call json%get(pval,data%Warnings%FloorCollision) + call json%get(p,'TopdriveRotaryTableConfilict',pval) + call json%get(pval,data%Warnings%TopdriveRotaryTableConfilict) + end subroutine + + subroutine ProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_value),pointer :: p + + call json%get(parent,'Warnings',p) + + call BitProblemsToJson(p) + call BopProblemsFromJson(p) + call ChokeProblemsFromJson(p) + call DrillStemProblemsFromJson(p) + call GaugesProblemsFromJson(p) + call HoistingProblemsFromJson(p) + call KickProblemsFromJson(p) + call LostProblemsFromJson(p) + call MudTreatmentProblemsFromJson(p) + call OtherProblemsFromJson(p) + call PumpProblemsFromJson(p) + call RotaryProblemsFromJson(p) + end subroutine + + subroutine StateFromJson(parent) + type(json_value),pointer :: parent + type(json_value),pointer :: p + + ! 1. create new node + ! call json%create_object(p,'State') + + ! ! call OperationScenarioFromJson(p) + ! call notificationsFromJson(p) + ! call permissionsFromJson(p) + ! call unitySignalsFromJson(p) + ! call StudentStationFromJson(p) + ! call BopStackInputFromJson(p) + ! call BopStackAccFromJson(p) + ! call RamLineFromJson(p) + ! call AnnularComputationalFromJson(p) + ! call AnnularFromJson(p) + ! call PipeRam1FromJson(p) + ! call ShearRamFromJson(p) + ! call PipeRam2FromJson(p) + ! call ChokeLineFromJson(p) + ! call KillLineFromJson(p) + ! call PumpsFromJson(p) + ! call RAMFromJson(p) + ! call RAMSFromJson(p) + ! call ChokeFromJson(p) + ! call AirDrivenPumpFromJson(p) + ! call AirPumpLineFromJson(p) + ! call CHOOKEFromJson(p) + ! call DrawworksFromJson(p) + ! call MudSystemFromJson(p) + ! call MUDFromJson(p) + ! call MPumpsFromJson(p) + ! call PUMPFromJson(p) + ! call RTableFromJson(p) + ! call TDSFromJson(p) + ! call GasType(3)FromJson(p) + ! call PressureDisplayFromJson(p) + ! call FricPressDropFromJson(p) + ! call ROP_SpecFromJson(p) + ! call ROP_BitFromJson(p) + ! call TDGeoFromJson(p) + ! call F_String(:)FromJson(p) + ! call F_CountsFromJson(p) + ! call F_Interval(:)FromJson(p) + ! call OD_Annulus(4)FromJson(p) + ! call TD_DrillStemFromJson(p) + ! call TD_DrillStemsFromJson(p) + ! call TD_StringFromJson(p) + ! call TD_CountFromJson(p) + ! call G_StringElementFromJson(p) + ! call TD_VolFromJson(p) + ! call TD_GeneralFromJson(p) + ! call TD_BOPFromJson(p) + ! call TD_BOPElement(4)FromJson(p) + ! call TD_StConnFromJson(p) + ! call TD_LoadFromJson(p) + ! call TD_WellElFromJson(p) + ! call TD_CasingFromJson(p) + ! call TD_LinerFromJson(p) + ! call TD_OpenHoleFromJson(p) + ! call TD_ROPHoleFromJson(p) + ! call TD_WellGeneralFromJson(p) + ! call TD_WellGeo(:)FromJson(p) + + ! 2. add member of data type to new node + + ! 3. add new node to parent + call json%add(parent,p) + end subroutine + + !use this as a template + subroutine notificationsFromJson(parent) + + type(json_value),pointer :: parent + ! + ! type(json_value),pointer :: p + + ! 1. create new node + ! call json%create_object(p,'Notifications') + + ! ! 2. add member of data type to new node + + ! ! 3. add new node to parent + ! call json%add(parent,p) + end subroutine + + +end module Simulator diff --git a/Simulator.i90 b/Simulator.i90 new file mode 100644 index 0000000..c6c8988 --- /dev/null +++ b/Simulator.i90 @@ -0,0 +1,807 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Simulator.f90" +module Simulator + use RedisInterface + use Bop + use PumpsMain + use RopMain + use RotaryTableMain + use DrawworksMain + use FluidFlowMain + use TorqueDragMain + use MudSystemMain + use PipeRams1Main + use PipeRams2Main + use KillLineMain + use ChokeLineMain + use BlindRamsMain + use AnnularMain + use TopDriveMain + use CManifolds + use GeoMain + use ChokeControlMain + use COperationScenariosMain + +! For Json read and write + use CStringConfiguration + use CFormation + use CReservoir + use CShoe + use CAccumulator + use CBopStack + use CHoisting + use CPower + use CPumpsVariables + use CRigSize + use CCasingLinerChoke + use CPathGeneration + use CWellSurveyData + use MudPropertiesModule + + use CBitProblems + use CBopProblems + use CChokeProblems + use CDrillStemProblems + use CGaugesProblems + use CHoistingProblems + use CKickProblems + use CLostProblems + use CMudTreatmentProblems + use COtherProblems + use CPumpProblems + use CRotaryProblems + + use OperationScenariosModule + use PermissionsModule + use UnitySignalsModule + + use CBopControlPanel + use CChokeControlPanel + use CChokeManifold + use CDataDisplayConsole + use CDrillingConsole + use CHook + use CStandPipeManifold + use CTopDrivePanel + use DrillingWatchModule + use CTanks + + implicit none + type(json_file) :: jsonfile + type(json_core):: json + integer :: simulationStatus,simulationSpeed,msPerStep,simulationEnd,simulationStep + integer,dimension(8)::timearray + real :: stepTime !time for each step + character(len=:),allocatable::redisInput,redisOutput + enum, bind(c) + enumerator :: PLAY = 1 + enumerator :: PAUSE = 2 + enumerator :: STOP = 3 + enumerator :: PLAY_TO_DETERMINED_TIME = 4 + end enum + + contains + + subroutine Simulate(configFilename) + character(*)::configFilename + integer::t0,t1,t2,t3,t_read=0,t_write=0,t_exec=0,i + integer,dimension(12)::t,t_modules +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + do i=1,size(t_modules) + t_modules(i)=0 + end do + print *,"config-file at Simulate = ",configFilename + call initSimulation(configFilename) + call initConnection(configFilename) + call read_configuration() +! call read_variables() + print *,"connection initialized" + call init_modules() + print *,"modules initialized" +! call cpu_time(T1) + simulationStep = 1 + do while (.true.) + print *,"simulationStep=",simulationStep + call date_and_time(values=timearray) + t0 = timearray(8)+timearray(7)*1000+timearray(6)*60000 + print *,"start reading." + call read_variables() + if(simulationStatus==PLAY_TO_DETERMINED_TIME .and. simulationStep>simulationEnd) exit + if(simulationStatus==STOP) exit + if(simulationStatus==PAUSE) cycle + if(logging>4) print *,"end reading" + call date_and_time(values=timearray) + t1 = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_read = t_read+t1-t0 + print *,"read completed" +!! Rafiee, nothing changed + call BopStack_Step() + call date_and_time(values=timearray) + t(1) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(1) = t_modules(1)+t(1)-t1 +!! Tarmigh, now is rewritten + call Pump1_Step() + call date_and_time(values=timearray) + t(2) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(2) = t_modules(2)+t(2)-t(1) +!call Pump2_Step() +!! Rafiee + call ChokeControl_Step() + call date_and_time(values=timearray) + t(3) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(3) = t_modules(3)+t(3)-t(2) + +!! Tarmigh, now is rewritten + call RotaryTable_Step() + call date_and_time(values=timearray) + t(4) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(4) = t_modules(4)+t(4)-t(3) + +!! Tarmigh, now is rewritten + call Drawworks_Step() + call date_and_time(values=timearray) + t(5) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(5) = t_modules(5)+t(5)-t(4) + +!! Rafiee + call MudSystem_Step() + +!! Rafiee + call PipeRams1_Step() + call PipeRams2_Step() + +!! Rafiee + call KillLine_Step() + call date_and_time(values=timearray) + t(6) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(6) = t_modules(6)+t(6)-t(5) + +!! Rafiee + call ChokeLine_Step() + call date_and_time(values=timearray) + t(7) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(7) = t_modules(7)+t(7)-t(6) + + call BlindRams_Step() + call date_and_time(values=timearray) + t(8) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(8) = t_modules(8)+t(8)-t(7) + + call Annular_Step() + call date_and_time(values=timearray) + t(9) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(9) = t_modules(9)+t(9)-t(8) + +!!Tarmigh. Step must rewrittem + call TopDrive_Step() + call date_and_time(values=timearray) + t(10) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(10) = t_modules(10)+t(10)-t(9) + +! call Geo_Step() +!!Ahmadi + call PathFinding_Step() + call date_and_time(values=timearray) + t(11) = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_modules(11) = t_modules(11)+t(11)-t(10) + +!! Sheikh +! call FluidFlow_Step() +!! Ahmadi + call OperationScenarios_Step() +!! Write variables to shared files + call date_and_time(values=timearray) + t2 = timearray(8)+timearray(7)*1000+timearray(6)*60000 +! stepTime = t2-t1 + t_modules(12) = t_modules(12)+t2-t(11) + + t_exec = t_exec+t2-t1 +! call date_and_time(values=timearray) +! t0 = timearray(8)+timearray(7)*1000+timearray(6)*60000 + print *,"exec completed" + call write_variables() + call date_and_time(values=timearray) + t3 = timearray(8)+timearray(7)*1000+timearray(6)*60000 + t_write = t_write+t3-t2 + print *,"write completed" +! print *,"t=",t + simulationStep = simulationStep + 1 + end do +! call write_variables() +! call json%print(jsonroot,'test.json') +! call json%destroy(jsonroot) + do i=1,size(t) + print *,"t_modules(",i,")=",t_modules(i) + end do + print *,"Number of steps =",simulationStep-1 + print *,"Read Time (from redis) =",t_read + print *,"Write Time (to redis)=",t_write + print *,"Simulation Time =",t_exec + print *,"Total Time =",t_read+t_write+t_exec + end subroutine Simulate + + subroutine initSimulation(configFilename) + use json_module + use iso_c_binding, only: c_null_char,c_char + character(len=*) :: configFilename +! type(json_file) :: jsonfile + type(json_value),pointer :: jsonvalue + type(json_core) :: jsoncore + logical :: is_found +! character(len=:),allocatable :: password,address,datakey +! character(len=:),allocatable::c_address,c_password,c_datakey + + call jsonfile%initialize() + print *,"init simulation with ",configFilename + call jsonfile%load_file(configFilename); + if (jsonfile%failed()) then + print *,"can not open config file: ",configFilename ; + stop + endif + print *,"file read" + call jsonfile%json_file_get_root(jsonvalue) + call jsoncore%get(jsonvalue,'logging',logging) + print *,"logging=",logging + print *,"simulationEnd =",simulationEnd + end subroutine + + subroutine write_variables() + use CAccumulator + use json_module + implicit none + type(json_value),pointer :: jsonroot + character(len=20)::fn +! integer::n_children + + call json%initialize() + call json%create_object(jsonroot,'') +! print *,"status=",simulationStatus +! call json%add(jsonroot,'status',simulationStatus) +! call json%add(jsonroot,'speed',simulationSpeed) +! call json%add(jsonroot,'endstep',simulationEnd) + call json%add(jsonroot,'step',simulationStep) + +! call ConfigurationToJson(jsonroot) + call WarningsToJson(jsonroot) +! call ProblemsToJson(jsonroot) + call EquipmentsToJson(jsonroot) + + print *,"write starts" + write (fn,*) "data",simulationStep +! call json%print(jsonroot,trim(fn)//".json") + call json%serialize(jsonroot,redisInput) +! call compress_string(redisContent) + print *,"Writing to redis:",len(redisInput) + call setData(redisInput) +! nullify(redisContent) +! deallocate(redisContent) +! call json%destroy(pval) + call json%destroy(jsonroot) + print *,"write ends" + end subroutine + + subroutine read_configuration() + type(json_value),pointer :: jsonroot + + call getData(redisOutput) + print *,len(redisOutput)," bytes read from redis" +! open(1,file="redisContent.json",status="REPLACE") +! write(1,"(A)") redisContent +! close(1) + call json%initialize() + call json%deserialize(jsonroot,redisOutput) + +! call jsonfile%initialize() +! call jsonfile%load_file('redisContent.json'); if (jsonfile%failed()) stop +! call jsonfile%json_file_get_root(jsonvalue) +! call json%info(jsonvalue, n_children=n_children) +! print *,"n_children =",n_children +! call json%get(jsonroot,'status',pval) +! call json%get(pval,simulationStatus) +! call json%get(jsonroot,'speed',pval) +! call json%get(pval,simulationSpeed) +! if(simulationSpeed==0) simulationSpeed = 1 +! msPerStep = 100/simulationSpeed +! call json%get(jsonroot,'endstep',pval) +! call json%get(pval,simulationEnd) + call ConfigurationFromJson(jsonroot) +! call WarningsFromJson(jsonroot) +! call ProblemsFromJson(jsonvalue) +! call EquipmentsFromJson(jsonroot) +! deallocate(redisContent) +! call json%destroy(pval) +! call json%destroy(jsonroot) + end subroutine + + subroutine read_variables() + type(json_value),pointer :: jsonroot,pval + + call getData(redisOutput) + print *,len(redisOutput)," bytes read from redis" +! open(1,file="redisContent.json",status="REPLACE") +! write(1,"(A)") redisContent +! close(1) + call json%initialize() + call json%deserialize(jsonroot,redisOutput) + +! call jsonfile%initialize() +! call jsonfile%load_file('redisContent.json'); if (jsonfile%failed()) stop +! call jsonfile%json_file_get_root(jsonvalue) +! call json%info(jsonvalue, n_children=n_children) +! print *,"n_children =",n_children + call json%get(jsonroot,'status',pval) + call json%get(pval,simulationStatus) + call json%get(jsonroot,'speed',pval) + call json%get(pval,simulationSpeed) + if(simulationSpeed==0) simulationSpeed = 1 + msPerStep = 100/simulationSpeed + call json%get(jsonroot,'endstep',pval) + call json%get(pval,simulationEnd) +! call ConfigurationFromJson(jsonroot) +! call WarningsFromJson(jsonroot) + call ProblemsFromJson(jsonroot) + call EquipmentsFromJson(jsonroot) +! deallocate(redisContent) +! call json%destroy(pval) +! call json%destroy(jsonroot) + end subroutine + + subroutine init_modules + print *,"initializing modules" +!Tarmigh + call Pump1_Init() + print *,"pump1 initialized" +!call Pump2_Init() + call RotaryTable_Init() + print *,"RT initialized" + call Drawworks_Init() + call TopDrive_Init() + print *,"TD initialized" + +!Nothing in init (and step) +! call Rop_Init() +! call TorqueDrag_Init() +! call Geo_Step() + +!! Rafiee + call BopStack_Init() + call ChokeControl_Init() + call MudSystem_Init() + print *,"Mudsystem initialized" +!Again calls Bop_Startup +! call PipeRams1_Init() +! call PipeRams2_Step() +! call KillLine_Step() +! call ChokeLine_Step() +! call BlindRams_Step() +! call Annular_Step() + +!! Sheikh +! call FluidFlow_Init() +! print *,"Mudsystem initialized" + +!! Ahmadi + call PathFinding_Init() +! Calls OSInitialization and that sub only subscribes some notif +! call OperationScenarios_Init() + end subroutine init_modules + + subroutine EquipmentsFromJson(parent) + type(json_value),pointer :: parent + + type(json_value),pointer :: p + +! 1. get related root + call json%get(parent,"Equipments",p) + +! 2. add member of data type to new node + call BopControlPanelFromJson(p) + call ChokeControlPanelFromJson(p) + call ChokeManifoldFromJson(p) + call DataDisplayConsoleFromJson(p) + call DrillingConsoleFromJson(p) +! call HookFromJson(p) + call StandPipeManifoldFromJson(p) + call TopDrivePanelFromJson(p) +! call DrillingWatchFromJson(p) + call TankFromJson(p) + end subroutine + + subroutine EquipmentsToJson(parent) + + type(json_value),pointer :: parent + + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Equipments') + +! 2. add member of data type to new node + call BopControlPanelToJson(p) + call ChokeControlPanelToJson(p) + call ChokeManifoldToJson(p) + call DataDisplayConsoleToJson(p) + call DrillingConsoleToJson(p) + call HookToJson(p) + call StandPipeManifoldToJson(p) + call TopDrivePanelToJson(p) + call DrillingWatchToJson(p) +! call TankToJson(p) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ConfigurationToJson(parent) + type(json_value),pointer :: parent + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Configuration') + +! 2. add member of data type to new node + call StringConfigurationToJson(p) + call FormationToJson(p) + call ReservoirToJson(p) + call ShoeToJson(p) + call AccumulatorToJson(p) + call BopStackToJson(p) + call HoistingToJson(p) + call PowerToJson(p) + call PumpsToJson(p) + call RigSizeToJson(p) + call CasingLinerChokeToJson(p) + call PathGenerationToJson(p) +! call WellSurveyDataToJson(p) + call MudPropertiesToJson(p) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine WarningsToJson(parent) + type(json_value),pointer :: parent + + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Warnings') + +! 2. add member of data type to new node + call json%add(p,"PumpWithKellyDisconnected",data%Warnings%PumpWithKellyDisconnected) + call json%add(p,"PumpWithTopdriveDisconnected",data%Warnings%PumpWithTopdriveDisconnected) + call json%add(p,"Pump1PopOffValveBlown",data%Warnings%Pump1PopOffValveBlown) + call json%add(p,"Pump1Failure",data%Warnings%Pump1Failure) + call json%add(p,"Pump2PopOffValveBlown",data%Warnings%Pump2PopOffValveBlown) + call json%add(p,"Pump2Failure",data%Warnings%Pump2Failure) + call json%add(p,"Pump3PopOffValveBlown",data%Warnings%Pump3PopOffValveBlown) + call json%add(p,"Pump3Failure",data%Warnings%Pump3Failure) + call json%add(p,"DrawworksGearsAbuse",data%Warnings%DrawworksGearsAbuse) + call json%add(p,"RotaryGearsAbuse",data%Warnings%RotaryGearsAbuse) + call json%add(p,"HoistLineBreak",data%Warnings%HoistLineBreak) + call json%add(p,"PartedDrillString",data%Warnings%PartedDrillString) + call json%add(p,"ActiveTankOverflow",data%Warnings%ActiveTankOverflow) + call json%add(p,"ActiveTankUnderVolume",data%Warnings%ActiveTankUnderVolume) + call json%add(p,"TripTankOverflow",data%Warnings%TripTankOverflow) + call json%add(p,"DrillPipeTwistOff",data%Warnings%DrillPipeTwistOff) + call json%add(p,"DrillPipeParted",data%Warnings%DrillPipeParted) + call json%add(p,"TripWithSlipsSet",data%Warnings%TripWithSlipsSet) + call json%add(p,"Blowout",data%Warnings%Blowout) + call json%add(p,"UndergroundBlowout",data%Warnings%UndergroundBlowout) + call json%add(p,"MaximumWellDepthExceeded",data%Warnings%MaximumWellDepthExceeded) + call json%add(p,"CrownCollision",data%Warnings%CrownCollision) + call json%add(p,"FloorCollision",data%Warnings%FloorCollision) + call json%add(p,"TopdriveRotaryTableConfilict",data%Warnings%TopdriveRotaryTableConfilict) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ProblemsToJson(parent) + type(json_value),pointer :: parent + + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Problems') + +! 2. add member of data type to new node + call BitProblemsToJson(p) + call BopProblemsToJson(p) + call ChokeProblemsToJson(p) + call DrillStemProblemsToJson(p) + call GaugesProblemsToJson(p) + call HoistingProblemsToJson(p) + call KickProblemsToJson(p) + call LostProblemsToJson(p) + call MudTreatmentProblemsToJson(p) + call OtherProblemsToJson(p) + call PumpProblemsToJson(p) + call RotaryProblemsToJson(p) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine StateToJson(parent) + + type(json_value),pointer :: parent + + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'State') + +! call OperationScenarioToJson(p) + call notificationsToJson(p) +! call permissionsToJson(p) +! call unitySignalsToJson(p) +! call StudentStationToJson(p) +! call BopStackInputToJson(p) +! call BopStackAccToJson(p) +! call RamLineToJson(p) +! call AnnularComputationalToJson(p) +! call AnnularToJson(p) +! call PipeRam1ToJson(p) +! call ShearRamToJson(p) +! call PipeRam2ToJson(p) +! call ChokeLineToJson(p) +! call KillLineToJson(p) +! call PumpsToJson(p) +! call RAMToJson(p) +! call RAMSToJson(p) +! call ChokeToJson(p) +! call AirDrivenPumpToJson(p) +! call AirPumpLineToJson(p) +! call CHOOKEToJson(p) +! call DrawworksToJson(p) +! call MudSystemToJson(p) +! call MUDToJson(p) +! call MPumpsToJson(p) +! call PUMPToJson(p) +! call RTableToJson(p) +! call TDSToJson(p) +! call GasType(3)ToJson(p) +! call PressureDisplayToJson(p) +! call FricPressDropToJson(p) +! call ROP_SpecToJson(p) +! call ROP_BitToJson(p) +! call TDGeoToJson(p) +! call F_String(:)ToJson(p) +! call F_CountsToJson(p) +! call F_Interval(:)ToJson(p) +! call OD_Annulus(4)ToJson(p) +! call TD_DrillStemToJson(p) +! call TD_DrillStemsToJson(p) +! call TD_StringToJson(p) +! call TD_CountToJson(p) +! call G_StringElementToJson(p) +! call TD_VolToJson(p) +! call TD_GeneralToJson(p) +! call TD_BOPToJson(p) +! call TD_BOPElement(4)ToJson(p) +! call TD_StConnToJson(p) +! call TD_LoadToJson(p) +! call TD_WellElToJson(p) +! call TD_CasingToJson(p) +! call TD_LinerToJson(p) +! call TD_OpenHoleToJson(p) +! call TD_ROPHoleToJson(p) +! call TD_WellGeneralToJson(p) +! call TD_WellGeo(:)ToJson(p) + +! 2. add member of data type to new node + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + +!use this as a template + subroutine notificationsToJson(parent) + + type(json_value),pointer :: parent + + type(json_value),pointer :: p + +! 1. create new node + call json%create_object(p,'Notifications') + +! 2. add member of data type to new node + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine ConfigurationFromJson(parent) + type(json_value),pointer :: parent + + type(json_value),pointer :: p + +! 1. get related root + call json%get(parent,"Configuration",p) + + call StringConfigurationFromJson(p) + call FormationFromJson(p) + call ReservoirFromJson(p) + call ShoeFromJson(p) + call AccumulatorFromJson(p) + call BopStackFromJson(p) + call HoistingFromJson(p) + call PowerFromJson(p) + call PumpsFromJson(p) + call RigSizeFromJson(p) + call CasingLinerChokeFromJson(p) + call PathGenerationFromJson(p) + call MudPropertiesFromJson(p) + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + + subroutine WarningsFromJson(parent) + type(json_value),pointer :: parent + type(json_value),pointer :: p + type(json_value),pointer :: pval + +! 1. get node + call json%get(parent,'Warnings',p) + +! ! 2. add member of data type to new node + call json%get(p,'PumpWithKellyDisconnected',pval) + call json%get(pval,data%Warnings%PumpWithKellyDisconnected) + call json%get(p,'PumpWithTopdriveDisconnected',pval) + call json%get(pval,data%Warnings%PumpWithTopdriveDisconnected) + call json%get(p,'Pump1PopOffValveBlown',pval) + call json%get(pval,data%Warnings%Pump1PopOffValveBlown) + call json%get(p,'Pump1Failure',pval) + call json%get(pval,data%Warnings%Pump1Failure) + call json%get(p,'Pump2PopOffValveBlown',pval) + call json%get(pval,data%Warnings%Pump2PopOffValveBlown) + call json%get(p,'Pump2Failure',pval) + call json%get(pval,data%Warnings%Pump2Failure) + call json%get(p,'Pump3PopOffValveBlown',pval) + call json%get(pval,data%Warnings%Pump3PopOffValveBlown) + call json%get(p,'Pump3Failure',pval) + call json%get(pval,data%Warnings%Pump3Failure) + call json%get(p,'DrawworksGearsAbuse',pval) + call json%get(pval,data%Warnings%DrawworksGearsAbuse) + call json%get(p,'RotaryGearsAbuse',pval) + call json%get(pval,data%Warnings%RotaryGearsAbuse) + call json%get(p,'HoistLineBreak',pval) + call json%get(pval,data%Warnings%HoistLineBreak) + call json%get(p,'PartedDrillString',pval) + call json%get(pval,data%Warnings%PartedDrillString) + call json%get(p,'ActiveTankOverflow',pval) + call json%get(pval,data%Warnings%ActiveTankOverflow) + call json%get(p,'ActiveTankUnderVolume',pval) + call json%get(pval,data%Warnings%ActiveTankUnderVolume) + call json%get(p,'TripTankOverflow',pval) + call json%get(pval,data%Warnings%TripTankOverflow) + call json%get(p,'DrillPipeTwistOff',pval) + call json%get(pval,data%Warnings%DrillPipeTwistOff) + call json%get(p,'DrillPipeParted',pval) + call json%get(pval,data%Warnings%DrillPipeParted) + call json%get(p,'TripWithSlipsSet',pval) + call json%get(pval,data%Warnings%TripWithSlipsSet) + call json%get(p,'Blowout',pval) + call json%get(pval,data%Warnings%Blowout) + call json%get(p,'UndergroundBlowout',pval) + call json%get(pval,data%Warnings%UndergroundBlowout) + call json%get(p,'MaximumWellDepthExceeded',pval) + call json%get(pval,data%Warnings%MaximumWellDepthExceeded) + call json%get(p,'CrownCollision',pval) + call json%get(pval,data%Warnings%CrownCollision) + call json%get(p,'FloorCollision',pval) + call json%get(pval,data%Warnings%FloorCollision) + call json%get(p,'TopdriveRotaryTableConfilict',pval) + call json%get(pval,data%Warnings%TopdriveRotaryTableConfilict) + end subroutine + + subroutine ProblemsFromJson(parent) + type(json_value),pointer :: parent + type(json_value),pointer :: p + + call json%get(parent,'Warnings',p) + + call BitProblemsToJson(p) + call BopProblemsFromJson(p) + call ChokeProblemsFromJson(p) + call DrillStemProblemsFromJson(p) + call GaugesProblemsFromJson(p) + call HoistingProblemsFromJson(p) + call KickProblemsFromJson(p) + call LostProblemsFromJson(p) + call MudTreatmentProblemsFromJson(p) + call OtherProblemsFromJson(p) + call PumpProblemsFromJson(p) + call RotaryProblemsFromJson(p) + end subroutine + + subroutine StateFromJson(parent) + type(json_value),pointer :: parent + type(json_value),pointer :: p + +! 1. create new node +! call json%create_object(p,'State') + +! ! call OperationScenarioFromJson(p) +! call notificationsFromJson(p) +! call permissionsFromJson(p) +! call unitySignalsFromJson(p) +! call StudentStationFromJson(p) +! call BopStackInputFromJson(p) +! call BopStackAccFromJson(p) +! call RamLineFromJson(p) +! call AnnularComputationalFromJson(p) +! call AnnularFromJson(p) +! call PipeRam1FromJson(p) +! call ShearRamFromJson(p) +! call PipeRam2FromJson(p) +! call ChokeLineFromJson(p) +! call KillLineFromJson(p) +! call PumpsFromJson(p) +! call RAMFromJson(p) +! call RAMSFromJson(p) +! call ChokeFromJson(p) +! call AirDrivenPumpFromJson(p) +! call AirPumpLineFromJson(p) +! call CHOOKEFromJson(p) +! call DrawworksFromJson(p) +! call MudSystemFromJson(p) +! call MUDFromJson(p) +! call MPumpsFromJson(p) +! call PUMPFromJson(p) +! call RTableFromJson(p) +! call TDSFromJson(p) +! call GasType(3)FromJson(p) +! call PressureDisplayFromJson(p) +! call FricPressDropFromJson(p) +! call ROP_SpecFromJson(p) +! call ROP_BitFromJson(p) +! call TDGeoFromJson(p) +! call F_String(:)FromJson(p) +! call F_CountsFromJson(p) +! call F_Interval(:)FromJson(p) +! call OD_Annulus(4)FromJson(p) +! call TD_DrillStemFromJson(p) +! call TD_DrillStemsFromJson(p) +! call TD_StringFromJson(p) +! call TD_CountFromJson(p) +! call G_StringElementFromJson(p) +! call TD_VolFromJson(p) +! call TD_GeneralFromJson(p) +! call TD_BOPFromJson(p) +! call TD_BOPElement(4)FromJson(p) +! call TD_StConnFromJson(p) +! call TD_LoadFromJson(p) +! call TD_WellElFromJson(p) +! call TD_CasingFromJson(p) +! call TD_LinerFromJson(p) +! call TD_OpenHoleFromJson(p) +! call TD_ROPHoleFromJson(p) +! call TD_WellGeneralFromJson(p) +! call TD_WellGeo(:)FromJson(p) + +! 2. add member of data type to new node + +! 3. add new node to parent + call json%add(parent,p) + end subroutine + +!use this as a template + subroutine notificationsFromJson(parent) + + type(json_value),pointer :: parent +! +! type(json_value),pointer :: p + +! 1. create new node +! call json%create_object(p,'Notifications') + +! ! 2. add member of data type to new node + +! ! 3. add new node to parent +! call json%add(parent,p) + end subroutine + + +end module Simulator diff --git a/Test/testJson.f90 b/Test/testJson.f90 new file mode 100644 index 0000000..b89aec4 --- /dev/null +++ b/Test/testJson.f90 @@ -0,0 +1,39 @@ +program testjson + use json_module + use RedisInterface + use iso_c_binding, only: c_null_char,c_char + integer::n_children + logical :: is_found + character(len=:),allocatable::redisContent + type(json_file) :: jsonfile + type(json_value),pointer :: jsonvalue,p + type(json_core) :: jsoncore,json + character(len=:),allocatable::name + + + ! call initConnection("config-remote.json") + ! call getData(redisContent) + ! print *,len(redisContent)," bytes read from redis" + ! open(1,file="redisContent.json",status="REPLACE") + ! write(1,"(A)") redisContent + ! close(1) + ! call jsoncore%initialize() + ! call jsoncore%deserialize(jsonvalue,redisContent) + + ! ! call jsonfile%initialize() + ! ! call jsonfile%load_file('redisContent.json'); if (jsonfile%failed()) stop + ! ! call jsonfile%json_file_get_root(jsonvalue) + + ! call jsoncore%info(jsonvalue, n_children=n_children) + ! print *,"n_children =",n_children + ! call jsoncore%info(jsonvalue, name=name) + ! print *,"name = ",name + call json%initialize(allow_duplicate_keys=.false.) + call json%create_object(p,'') !create the root + call json%add(p,'year',1805) !add some data + call json%add(p,'year',2000) !add some data + call json%add(p,'value',1.0) !add some data + call json%print(p,'test.json') !write it to a file + call json%destroy(p) !cleanup + +end program testjson \ No newline at end of file diff --git a/Test/testJson.i90 b/Test/testJson.i90 new file mode 100644 index 0000000..1f0fd29 --- /dev/null +++ b/Test/testJson.i90 @@ -0,0 +1,40 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Test/testJson.f90" +program testjson + use json_module + use RedisInterface + use iso_c_binding, only: c_null_char,c_char + integer::n_children + logical :: is_found + character(len=:),allocatable::redisContent + type(json_file) :: jsonfile + type(json_value),pointer :: jsonvalue,p + type(json_core) :: jsoncore,json + character(len=:),allocatable::name + + +! call initConnection("config-remote.json") +! call getData(redisContent) +! print *,len(redisContent)," bytes read from redis" +! open(1,file="redisContent.json",status="REPLACE") +! write(1,"(A)") redisContent +! close(1) +! call jsoncore%initialize() +! call jsoncore%deserialize(jsonvalue,redisContent) + +! ! call jsonfile%initialize() +! ! call jsonfile%load_file('redisContent.json'); if (jsonfile%failed()) stop +! ! call jsonfile%json_file_get_root(jsonvalue) + +! call jsoncore%info(jsonvalue, n_children=n_children) +! print *,"n_children =",n_children +! call jsoncore%info(jsonvalue, name=name) +! print *,"name = ",name + call json%initialize(allow_duplicate_keys=.false.) + call json%create_object(p,'') !create the root + call json%add(p,'year',1805) !add some data + call json%add(p,'year',2000) !add some data + call json%add(p,'value',1.0) !add some data + call json%print(p,'test.json') !write it to a file + call json%destroy(p) !cleanup + +end program testjson diff --git a/Test/write_vars.f90 b/Test/write_vars.f90 new file mode 100644 index 0000000..3266647 --- /dev/null +++ b/Test/write_vars.f90 @@ -0,0 +1,82 @@ +module writevarsmodule + use Simulator + use RedisInterface + + contains + subroutine InitDummyData() + print *,"Initialize Dummy StringConfiguration ..." + allocate(data%Configuration%StringConfiguration%StringConfigurations(2)) + data%Configuration%StringConfiguration%StringConfigurationCount =2 + data%Configuration%StringConfiguration%StringConfigurations(1)%Grade='A' + data%Configuration%StringConfiguration%StringConfigurations(2)%Grade='B' + + print *,"Initialize Dummy Data ..." + allocate(data%Configuration%Formation%Formations(2)) + data%Configuration%Formation%Count = 2 + data%Configuration%Formation%Formations(1)%Top = 0 + data%Configuration%Formation%Formations(2)%Top = 1000 + + print *,"Initialize Dummy Data ..." + allocate(data%Configuration%Path%Items(2)) + data%Configuration%Path%ItemCount = 2 + data%Configuration%Path%Items(1)%Length =1000 + data%Configuration%Path%Items(2)%Length =2000 + print *,"Initialize Dummy Data ..." + + end subroutine + + subroutine write_input_variables() + use CAccumulator + use json_module + implicit none + type(json_value),pointer :: jsonroot + character(len=20)::fn + ! integer::n_children + + call InitDummyData() + + ! ! allocate(data%Configuration%Path%DataPoints(3)) + ! allocate(data) + call json%initialize() + call json%create_object(jsonroot,'') + call json%add(jsonroot,'status',simulationStatus) + call json%add(jsonroot,'speed',simulationSpeed) + call json%add(jsonroot,'endstep',simulationEnd) + + call ConfigurationToJson(jsonroot) + ! call WarningsToJson(jsonroot) + call ProblemsToJson(jsonroot) + call EquipmentsToJson(jsonroot) + + ! call json%print(jsonroot,trim(fn)//".json") + call json%serialize(jsonroot,redisInput) + ! print *,"Writing to redis:",len(redisInput) + ! nullify(redisContent) + ! deallocate(redisContent) + ! call json%destroy(pval) + call setInput(redisInput) + call json%print(jsonroot,'test.json') + call json%destroy(jsonroot) + print *,"write ends" + end subroutine + +end module writevarsmodule + +program writeWars + use json_module + use writevarsmodule + use RedisInterface + + + implicit none + character(len=50)::configFilename = "config-local.json" + + if(command_argument_count()>0) then + call get_command_argument(1, configFilename) + endif + + call initSimulation(configFilename) + call initConnection(configFilename) + ! call init_modules() + call write_input_variables() +end program writeWars \ No newline at end of file diff --git a/Test/write_vars.i90 b/Test/write_vars.i90 new file mode 100644 index 0000000..bb20915 --- /dev/null +++ b/Test/write_vars.i90 @@ -0,0 +1,83 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/Test/write_vars.f90" +module writevarsmodule + use Simulator + use RedisInterface + + contains + subroutine InitDummyData() + print *,"Initialize Dummy StringConfiguration ..." + allocate(data%Configuration%StringConfiguration%StringConfigurations(2)) + data%Configuration%StringConfiguration%StringConfigurationCount =2 + data%Configuration%StringConfiguration%StringConfigurations(1)%Grade='A' + data%Configuration%StringConfiguration%StringConfigurations(2)%Grade='B' + + print *,"Initialize Dummy Data ..." + allocate(data%Configuration%Formation%Formations(2)) + data%Configuration%Formation%Count = 2 + data%Configuration%Formation%Formations(1)%Top = 0 + data%Configuration%Formation%Formations(2)%Top = 1000 + + print *,"Initialize Dummy Data ..." + allocate(data%Configuration%Path%Items(2)) + data%Configuration%Path%ItemCount = 2 + data%Configuration%Path%Items(1)%Length =1000 + data%Configuration%Path%Items(2)%Length =2000 + print *,"Initialize Dummy Data ..." + + end subroutine + + subroutine write_input_variables() + use CAccumulator + use json_module + implicit none + type(json_value),pointer :: jsonroot + character(len=20)::fn +! integer::n_children + + call InitDummyData() + +! ! allocate(data%Configuration%Path%DataPoints(3)) +! allocate(data) + call json%initialize() + call json%create_object(jsonroot,'') + call json%add(jsonroot,'status',simulationStatus) + call json%add(jsonroot,'speed',simulationSpeed) + call json%add(jsonroot,'endstep',simulationEnd) + + call ConfigurationToJson(jsonroot) +! call WarningsToJson(jsonroot) + call ProblemsToJson(jsonroot) + call EquipmentsToJson(jsonroot) + +! call json%print(jsonroot,trim(fn)//".json") + call json%serialize(jsonroot,redisInput) +! print *,"Writing to redis:",len(redisInput) +! nullify(redisContent) +! deallocate(redisContent) +! call json%destroy(pval) + call setInput(redisInput) + call json%print(jsonroot,'test.json') + call json%destroy(jsonroot) + print *,"write ends" + end subroutine + +end module writevarsmodule + +program writeWars + use json_module + use writevarsmodule + use RedisInterface + + + implicit none + character(len=50)::configFilename = "config-local.json" + + if(command_argument_count()>0) then + call get_command_argument(1, configFilename) + endif + + call initSimulation(configFilename) + call initConnection(configFilename) +! call init_modules() + call write_input_variables() +end program writeWars diff --git a/Test_Json b/Test_Json index d859f95..773ffee 100644 Binary files a/Test_Json and b/Test_Json differ diff --git a/Text1.txt b/Text1.txt index f873bc5..a304744 100644 --- a/Text1.txt +++ b/Text1.txt @@ -1,6 +1,2 @@ - integer :: DriveType - real(8) :: TravelingBlockWeight - real(8) :: TopDriveWeight - real(8) :: KellyWeight - integer :: NumberOfLine - real(8) :: DrillingLineBreakingLoad \ No newline at end of file + logical :: AnnDrillMud + logical :: AnnCirculateMud diff --git a/TorqueDrag/TD_DrillingSubs/MeshGeneration_FluidModule.i90 b/TorqueDrag/TD_DrillingSubs/MeshGeneration_FluidModule.i90 new file mode 100644 index 0000000..67727fe --- /dev/null +++ b/TorqueDrag/TD_DrillingSubs/MeshGeneration_FluidModule.i90 @@ -0,0 +1,517 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/TorqueDrag/TD_DrillingSubs/MeshGeneration_FluidModule.f90" +subroutine MeshGeneration_FluidModule + + Use TD_DrillStemComponents + use SimulationVariables !@ + use SimulationVariables !@ + Use TD_StringConnectionData + Use GeoElements_FluidModule + use CPumpsVariables + use CPumps + Use CStringConfigurationVariables + Use CBopStackVariables +!use ConfigurationVariables !@ , only: Drawworks + + implicit none + + Integer :: ii , jj , semijj , kk , k , m , s + Integer :: ElementsCount , StringConfigCount + REAL(8) :: mm , nn , dl , StartAngle , EndAngle + REAL(8) :: A(30) !?????????10 + REAL(8) :: TD_ElementLength + + + + + A = 0.d0 + A(1) = data%Configuration%BopStack%AboveAnnularHeight ! WellHead[ft] + jj = 1 + + + + + + + +!==================================================== +! Mesh Generation of DrillStem Components +!==================================================== + +!data%State%TD_String%StringConfigurationCount = StringConfigurationCount !??????????? + StringConfigCount = data%State%TD_String%StringConfigurationCount + if (allocated(data%State%F_String)) Deallocate(data%State%F_String) + if (data%State%TD_DrillStem(1)%ComponentType==0) then + Allocate (data%State%F_String(StringConfigCount-1)) + else + Allocate (data%State%F_String(StringConfigCount)) + end if + + + if (data%State%TD_DrillStem(1)%ComponentType==0) then + ElementsCount = 1 + Do ii=1,(StringConfigCount-1) + data%State%F_String(ii)%ID = data%State%TD_DrillStem(ii+1)%Id*12.d0 ![inch] + data%State%F_String(ii)%OD = data%State%TD_DrillStem(ii+1)%Od*12.d0 ![inch] + data%State%F_String(ii)%FirstElement = ElementsCount+1 + data%State%F_String(ii)%LastElement = data%State%F_String(ii)%FirstElement+(data%State%TD_DrillStem(ii+1)%Numbs-1) + data%State%F_String(ii)%ElType = data%State%TD_DrillStem(ii+1)%ComponentType + ElementsCount = data%State%F_String(ii)%LastElement + End Do + StringConfigCount = StringConfigCount-1 + else + ElementsCount = 0 + Do ii=1,StringConfigCount + data%State%F_String(ii)%ID = data%State%TD_DrillStem(ii)%Id*12.d0 ![inch] + data%State%F_String(ii)%OD = data%State%TD_DrillStem(ii)%Od*12.d0 ![inch] + data%State%F_String(ii)%FirstElement = ElementsCount+1 + data%State%F_String(ii)%LastElement = data%State%F_String(ii)%FirstElement+(data%State%TD_DrillStem(ii)%Numbs-1) + data%State%F_String(ii)%ElType = data%State%TD_DrillStem(ii)%ComponentType + ElementsCount = data%State%F_String(ii)%LastElement + End Do + end if + + + Do ii=1,StringConfigCount + data%State%F_String(ii)%TopDepth = data%State%TD_DrillStems(data%State%F_String(ii)%LastElement)%TopDepthIni ![ft] + data%State%F_String(ii)%DownDepth = data%State%TD_DrillStems(data%State%F_String(ii)%FirstElement)%DownDepthIni ![ft] + + if (data%State%F_String(ii)%DownDepth>A(1)) then + jj = jj+1 + A(jj) = data%State%F_String(ii)%DownDepth + end if + End Do + + + +!=========> Removed Volume Calculation in DrillStem + TD_ElementLength = data%State%F_String(StringConfigCount)%DownDepth-data%State%F_String(StringConfigCount)%TopDepth + if ( StringConfigCount==data%State%TD_Vol%PreCount ) then + if ( data%State%TD_Vol%PreElementLength>TD_ElementLength ) then + data%State%TD_Vol%RemoveVolume = (data%State%TD_Vol%PreElementLength-TD_ElementLength)*((pi*((data%State%F_String(StringConfigCount)%ID/12.d0)**2))/4.d0) ![ft^3] + else + data%State%TD_Vol%RemoveVolume = 0.d0 + end if + else if ( StringConfigCount Out of Well Intervals + data%State%F_Interval(1)%StartTVD = 0.0d0 !?????????????? + data%State%F_Interval(1)%EndTVD = -data%State%TD_StConn%ConnectionHeight + data%State%F_Interval(1)%StartAngle = 0.d0 !??????????????????????? + data%State%F_Interval(1)%EndAngle = 0.d0 !??????????????????????? + data%State%F_Counts%OutOfWellIntervalCounts = 1 + Do ii= 2 , StringConfigCount+1 + if ( data%State%F_Interval(ii)%StartDepth<=0.d0 ) then + data%State%F_Interval(ii)%StartTVD = data%State%F_Interval(ii)%StartDepth + data%State%F_Interval(ii)%StartAngle = 0.0d0 + end if + if ( data%State%F_Interval(ii)%EndDepth<=0.d0 ) then + data%State%F_Interval(ii)%EndTVD = data%State%F_Interval(ii)%EndDepth + data%State%F_Interval(ii)%EndAngle = 0.0d0 + data%State%F_Counts%OutOfWellIntervalCounts = data%State%F_Counts%OutOfWellIntervalCounts+1 + end if + End Do + + +!=========> + if (allocated(data%State%TDGeo%TVD)) Deallocate(data%State%TDGeo%TVD) + Allocate (data%State%TDGeo%TVD(jj)) + if (allocated(data%State%TDGeo%Angle)) Deallocate(data%State%TDGeo%Angle) + Allocate (data%State%TDGeo%Angle(jj)) + data%State%TDGeo%TVD(1) = data%State%TD_WellGeneral%WellTotalVerticalLength !????? +!print*, 'data%State%TD_WellGeneral%WellTotalVerticalLength=' ,data%State%TD_WellGeneral%WellTotalVerticalLength + data%State%TDGeo%TVD(jj) = data%Configuration%BopStack%AboveAnnularHeight ! WellHead[ft] !0.d0 ???????????????? + + k = 1 + mm = 0.d0 + nn = 0.d0 + EndAngle = data%State%TD_WellGeo(1)%StartAngle !??????????????? + data%State%TDGeo%Angle(jj) = EndAngle + Do ii = jj-1,1,-1 !???1or2 + do kk = k, data%State%TD_WellGeneral%WellIntervalsCount + StartAngle = EndAngle + if ( data%State%TDGeo%MD(ii)>data%State%TD_WellGeo(kk)%TopDepth ) then + if ( data%State%TDGeo%MD(ii)>data%State%TD_WellGeo(kk)%DownDepth ) then + dl = data%State%TD_WellGeo(kk)%DownDepth-nn ![ft] + nn = data%State%TD_WellGeo(kk)%DownDepth + if ( data%State%TD_WellGeo(kk)%HoleType==0 ) then + EndAngle = StartAngle +!print*, 'StartAngle1=' ,ii , kk, StartAngle +!print*, 'EndAngle1=' ,ii , kk, EndAngle + data%State%TDGeo%TVD(ii) = mm+(dl*cos(data%State%TD_WellGeo(kk)%StartAngle)) ![ft] + data%State%TDGeo%Angle(ii) = EndAngle +!print*, 'data%State%TDGeo%TVD(ii)1=' ,ii , kk, data%State%TDGeo%TVD(ii) + else if ( data%State%TD_WellGeo(kk)%HoleType==1 ) then + EndAngle = StartAngle+(dl/data%State%TD_WellGeo(kk)%RCurvature) !????????????????? +!print*, 'StartAngle2=' ,ii , kk, StartAngle +!print*, 'EndAngle2=' ,ii , kk, EndAngle + data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle))*cos(abs(StartAngle)))-(data%State%TD_WellGeo(kk)%RCurvature*(1.-cos(abs(EndAngle)-abs(StartAngle)))*sin(abs(StartAngle))) +!data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle))) + data%State%TDGeo%Angle(ii) = EndAngle +!print*, 'data%State%TDGeo%TVD(ii)2=' , ii , kk, data%State%TDGeo%TVD(ii) + else if ( data%State%TD_WellGeo(kk)%HoleType==2 ) then + EndAngle = StartAngle-(dl/data%State%TD_WellGeo(kk)%RCurvature) !????????????????? +!print*, 'StartAngle22=' ,ii , kk, StartAngle +!print*, 'EndAngle22=' ,ii , kk, EndAngle + data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(abs(EndAngle)-abs(StartAngle)))*cos(abs(StartAngle)))+(data%State%TD_WellGeo(kk)%RCurvature*(1.-cos(abs(abs(EndAngle)-abs(StartAngle))))*sin(abs(StartAngle))) +!data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle))) + data%State%TDGeo%Angle(ii) = EndAngle +!print*, 'data%State%TDGeo%TVD(ii)22=' , ii , kk, data%State%TDGeo%TVD(ii) + end if + mm = data%State%TDGeo%TVD(ii) + else + dl = data%State%TDGeo%MD(ii)-nn + nn = data%State%TDGeo%MD(ii) + if ( data%State%TD_WellGeo(kk)%HoleType==0 ) then + EndAngle = StartAngle +!print*, 'StartAngle3=' ,ii , kk, StartAngle +!print*, 'EndAngle3=' ,ii , kk, EndAngle + data%State%TDGeo%TVD(ii) = mm+(dl*cos(data%State%TD_WellGeo(kk)%StartAngle)) + data%State%TDGeo%Angle(ii) = EndAngle +!print*, 'data%State%TDGeo%TVD(ii)3=' ,ii , kk, data%State%TDGeo%TVD(ii) + else if ( data%State%TD_WellGeo(kk)%HoleType==1 ) then + EndAngle = StartAngle+(dl/data%State%TD_WellGeo(kk)%RCurvature) !??????????????????? +!print*, 'StartAngle4=' ,ii , kk, StartAngle +!print*, 'EndAngle4=' ,ii , kk, EndAngle + data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle))*cos(abs(StartAngle)))-(data%State%TD_WellGeo(kk)%RCurvature*(1.-cos(abs(EndAngle)-abs(StartAngle)))*sin(abs(StartAngle))) + data%State%TDGeo%Angle(ii) = EndAngle +!data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle))) +!print*, 'mm=' ,mm +!print*, 'data%State%TDGeo%TVD(ii)4=' ,ii , kk, data%State%TDGeo%TVD(ii) + else if ( data%State%TD_WellGeo(kk)%HoleType==2 ) then + EndAngle = StartAngle-(dl/data%State%TD_WellGeo(kk)%RCurvature) !??????????????????? +!print*, 'StartAngle44=' ,ii , kk, StartAngle +!print*, 'EndAngle44=' ,ii , kk, EndAngle + data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(abs(EndAngle)-abs(StartAngle)))*cos(abs(StartAngle)))+(data%State%TD_WellGeo(kk)%RCurvature*(1.-cos(abs(abs(EndAngle)-abs(StartAngle))))*sin(abs(StartAngle))) + data%State%TDGeo%Angle(ii) = EndAngle +!data%State%TDGeo%TVD(ii) = mm+(data%State%TD_WellGeo(kk)%RCurvature*sin(abs(EndAngle)-abs(StartAngle))) +!print*, 'mm=' ,mm , (data%State%TD_WellGeo(kk)%RCurvature*sin(abs(abs(EndAngle)-abs(StartAngle)))*cos(abs(StartAngle)))+(data%State%TD_WellGeo(kk)%RCurvature*(1.-cos(abs(abs(EndAngle)-abs(StartAngle))))*sin(abs(StartAngle))) +!print*, 'data%State%TDGeo%TVD(ii)44=' ,ii , kk, data%State%TDGeo%TVD(ii) + end if + mm = data%State%TDGeo%TVD(ii) + k = kk + exit + end if + end if + end do + End Do + + + +!if (data%State%F_Counts%OutOfWellIntervalCounts==1) then +! s = 2 +!else +! s = data%State%F_Counts%OutOfWellIntervalCounts +!end if +! + + Do ii = (data%State%F_Counts%OutOfWellIntervalCounts+1),data%State%F_Counts%IntervalsTotalCounts + do kk = jj,1,-1 + if ( data%State%F_Interval(ii)%StartDepth==data%State%TDGeo%MD(kk) ) then + data%State%F_Interval(ii)%StartTVD = data%State%TDGeo%TVD(kk) ![ft] + data%State%F_Interval(ii)%StartAngle = data%State%TDGeo%Angle(kk) ![rad] + end if + if ( data%State%F_Interval(ii)%EndDepth==data%State%TDGeo%MD(kk) ) then + data%State%F_Interval(ii)%EndTVD = data%State%TDGeo%TVD(kk) ![ft] + data%State%F_Interval(ii)%EndAngle = data%State%TDGeo%Angle(kk) ![rad] + end if + end do + End Do + + + +!Do ii=1,(data%State%F_Counts%IntervalsTotalCounts) +! print*, 'data%State%F_Interval(ii)%StartTVD=' , ii , data%State%F_Interval(ii)%StartTVD +! print*, 'data%State%F_Interval(ii)%EndTVD=' , ii , data%State%F_Interval(ii)%EndTVD +! print*, 'data%State%F_Interval(ii)%StartAngle=' , ii , data%State%F_Interval(ii)%StartAngle +! print*, 'data%State%F_Interval(ii)%EndAngle=' , ii , data%State%F_Interval(ii)%EndAngle +!end do +! +! +!Do ii=1,data%State%TD_WellGeneral%WellIntervalsCount +! print*, 'data%State%TD_WellGeo(kk)%TopDepth=' , ii , data%State%TD_WellGeo(ii)%TopDepth +! print*, 'data%State%TD_WellGeo(kk)%DownDepth=' , ii , data%State%TD_WellGeo(ii)%DownDepth +! print*, 'data%State%TD_WellGeo(kk)%HoleType=' , ii , data%State%TD_WellGeo(ii)%HoleType +! print*, 'data%State%TD_WellGeo(kk)%RCurvature=' , ii , data%State%TD_WellGeo(ii)%RCurvature +! print*, 'data%State%TD_WellGeo(kk)%EndAngle=' , ii , data%State%TD_WellGeo(ii)%EndAngle +! print*, 'data%State%TD_WellGeo(kk)%StartAngle=' , ii , data%State%TD_WellGeo(ii)%StartAngle +!end do + + + + + +end subroutine diff --git a/TorqueDrag/TD_DrillingSubs/TD_BOPDiamCalculation.i90 b/TorqueDrag/TD_DrillingSubs/TD_BOPDiamCalculation.i90 new file mode 100644 index 0000000..8c89d33 --- /dev/null +++ b/TorqueDrag/TD_DrillingSubs/TD_BOPDiamCalculation.i90 @@ -0,0 +1,182 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/TorqueDrag/TD_DrillingSubs/TD_BOPDiamCalculation.f90" +subroutine TD_BOPDiamCalculation + + Use TD_DrillStemComponents + use SimulationVariables !@ + use SimulationVariables !@ + use SimulationVariables !@ + Use TD_StringConnectionData + Use CBopStackVariables + use SimulationVariables + use DownHoleModule + + + Integer :: i , j , n , m , TD_Numbs + Real(8) :: TD_LimitUp , TD_LimitDown , TD_OldFillingValue , TD_AnnTjDiff , TD_AnnularFilling + Real(8) :: TD_ElToolJoints(2,2) + + + + + +!data%State%TD_String%ToolJointRange = 0.4005d0*3.28 ! [ft] + +!==================================================== +! Read BOP Data +!==================================================== + + data%State%TD_BOP%BOPHeight(5) = data%Configuration%BopStack%AboveAnnularHeight + data%State%TD_BOP%BOPHeight(1) = data%Configuration%BopStack%AnnularPreventerHeight + data%State%TD_BOP%BOPHeight(2) = data%Configuration%BopStack%UpperRamHeight + data%State%TD_BOP%BOPHeight(3) = data%Configuration%BopStack%BlindRamHeight + data%State%TD_BOP%BOPHeight(6) = data%Configuration%BopStack%KillHeight + data%State%TD_BOP%BOPHeight(4) = data%Configuration%BopStack%LowerRamHeight + + + data%State%TD_BOP%BOPRamDiam(1) = data%State%ShearRAM%IDAnnularfinal + data%State%TD_BOP%BOPRamDiam(2) = data%State%ShearRAM%IDPipeRam1final + data%State%TD_BOP%BOPRamDiam(3) = data%State%ShearRAM%IDshearBopfinal + data%State%TD_BOP%BOPRamDiam(4) = data%State%ShearRAM%IDPipeRam2final + + + + + + +!==================================================== +! Element Counts in BOPStack Domain +!==================================================== + +!if (data%State%TD_String%DrillStemComponentsNumbs>5) then + TD_Numbs = data%State%TD_String%DrillStemComponentsNumbs-7 ! 7 Elements from the Top of DrillStem +!else +! TD_Numbs = 1 +!end if + + + + + + + + + +!==================================================== +! Determination of Elements Diameter in BOPStack Domain +!==================================================== + + data%State%TD_BOP%BOPDiam = 0.d0 + TD_OldFillingValue = 0.d0 + Do i = data%State%TD_String%DrillStemComponentsNumbs,TD_Numbs,-1 + + TD_LimitUp = data%State%TD_DrillStems(i)%TopDepth+data%State%TD_DrillStems(i)%ToolJointRange + TD_LimitDown = data%State%TD_DrillStems(i)%DownDepth-data%State%TD_DrillStems(i)%ToolJointRange + TD_ElToolJoints(1,1) = data%State%TD_DrillStems(i)%TopDepth ! TD_ElToolJoints(i,j) , i=top & down tooljoints of element , j=top & down tooljoints Depth + TD_ElToolJoints(1,2) = TD_LimitUp + TD_ElToolJoints(2,1) = TD_LimitDown + TD_ElToolJoints(2,2) = data%State%TD_DrillStems(i)%DownDepth + + +!===> che meghdar az fazaye annular ba tooljoint por mishavad (for BOP Module) + Do m = 1,2 + TD_AnnTjDiff = min(TD_ElToolJoints(m,2),(data%State%TD_BOP%BOPHeight(1)+data%State%TD_BOP%BOPThickness))-max(TD_ElToolJoints(m,1),(data%State%TD_BOP%BOPHeight(1)-data%State%TD_BOP%BOPThickness)) + if (TD_AnnTjDiff<0.) then ! tooljoint is not in the annular range + TD_AnnTjDiff = 0.d0 + end if + TD_AnnularFilling = TD_OldFillingValue+(TD_AnnTjDiff/(data%State%TD_BOP%BOPThickness*2.d0)) ! 0=TD_LimitUp .and. (data%State%TD_BOP%BOPHeight(j)+data%State%TD_BOP%BOPThickness)0. ) then +! Print*, '*** UnSet Slips ***' !??????????????????? +!end if + data%State%TD_StConn%ElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%ElevatorConst !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + else + data%State%TD_StConn%ElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%ElevatorConst + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%ElevatorConst+(LengthSum+data%State%TD_StConn%ElevatorECG) !(LengthSum+data%State%TD_DrillStems(kk)%ToolJointRange) + data%State%TD_StConn%StringVelocity = data%State%TD_StConn%HookVelocity + end if + + else if ( Get_ElevatorConnection() == ELEVATOR_CONNECTION_NOTHING ) then + data%State%TD_StConn%StringConnectionMode = 5 + if (data%State%TD_Count%KellyOldStatus(4)==1 .and. data%State%TD_Count%KellyNewStatus(5)/=data%State%TD_Count%KellyOldStatus(5)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(5) = data%State%TD_Count%KellyNewStatus(5) + data%State%TD_Count%KellyOldStatus(4) = 0 + else if (data%State%TD_Count%KellyOldStatus(6)==1 .and. data%State%TD_Count%KellyNewStatus(5)/=data%State%TD_Count%KellyOldStatus(5)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(5) = data%State%TD_Count%KellyNewStatus(5) + data%State%TD_Count%KellyOldStatus(6) = 0 + else if (data%State%TD_Count%KellyOldStatus(7)==1 .and. data%State%TD_Count%KellyNewStatus(5)/=data%State%TD_Count%KellyOldStatus(5)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(5) = data%State%TD_Count%KellyNewStatus(5) + data%State%TD_Count%KellyOldStatus(7) = 0 + else if (data%State%TD_Count%KellyOldStatus(8)==1 .and. data%State%TD_Count%KellyNewStatus(5)/=data%State%TD_Count%KellyOldStatus(5)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(5) = data%State%TD_Count%KellyNewStatus(5) + data%State%TD_Count%KellyOldStatus(8) = 0 + else if (data%State%TD_Count%KellyOldStatus(2)==1 .and. data%State%TD_Count%KellyNewStatus(5)/=data%State%TD_Count%KellyOldStatus(5)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(5) = data%State%TD_Count%KellyNewStatus(5) + data%State%TD_Count%KellyOldStatus(2) = 0 + end if + data%State%TD_StConn%ElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%ElevatorConst + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + + else if ( Get_ElevatorConnection() == ELEVATOR_CONNECTION_STAND ) then + data%State%TD_StConn%StringConnectionMode = 6 + if (data%State%TD_Count%KellyOldStatus(4)==1 .and. data%State%TD_Count%KellyNewStatus(6)/=data%State%TD_Count%KellyOldStatus(6)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight-(3.*data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_Count%KellyOldStatus(6) = data%State%TD_Count%KellyNewStatus(6) + data%State%TD_Count%KellyOldStatus(4) = 0 + else if (data%State%TD_Count%KellyOldStatus(5)==1 .and. data%State%TD_Count%KellyNewStatus(6)/=data%State%TD_Count%KellyOldStatus(6)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(6) = data%State%TD_Count%KellyNewStatus(6) + data%State%TD_Count%KellyOldStatus(5) = 0 + else if (data%State%TD_Count%KellyOldStatus(7)==1 .and. data%State%TD_Count%KellyNewStatus(6)/=data%State%TD_Count%KellyOldStatus(6)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(6) = data%State%TD_Count%KellyNewStatus(6) + data%State%TD_Count%KellyOldStatus(7) = 0 + else if (data%State%TD_Count%KellyOldStatus(8)==1 .and. data%State%TD_Count%KellyNewStatus(6)/=data%State%TD_Count%KellyOldStatus(6)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(6) = data%State%TD_Count%KellyNewStatus(6) + data%State%TD_Count%KellyOldStatus(8) = 0 + end if + data%State%TD_StConn%ElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%ElevatorConst-(3.*data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + + else if ( Get_ElevatorConnection() == ELEVATOR_CONNECTION_SINGLE ) then + data%State%TD_StConn%StringConnectionMode = 7 + if (data%State%TD_Count%KellyOldStatus(4)==1 .and. data%State%TD_Count%KellyNewStatus(7)/=data%State%TD_Count%KellyOldStatus(7)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight-data%State%TD_DrillStems(kk)%LengthIni + data%State%TD_Count%KellyOldStatus(7) = data%State%TD_Count%KellyNewStatus(7) + data%State%TD_Count%KellyOldStatus(4) = 0 + else if (data%State%TD_Count%KellyOldStatus(5)==1 .and. data%State%TD_Count%KellyNewStatus(7)/=data%State%TD_Count%KellyOldStatus(7)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(7) = data%State%TD_Count%KellyNewStatus(7) + data%State%TD_Count%KellyOldStatus(5) = 0 + else if (data%State%TD_Count%KellyOldStatus(6)==1 .and. data%State%TD_Count%KellyNewStatus(7)/=data%State%TD_Count%KellyOldStatus(7)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(7) = data%State%TD_Count%KellyNewStatus(7) + data%State%TD_Count%KellyOldStatus(6) = 0 + else if (data%State%TD_Count%KellyOldStatus(8)==1 .and. data%State%TD_Count%KellyNewStatus(7)/=data%State%TD_Count%KellyOldStatus(7)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(7) = data%State%TD_Count%KellyNewStatus(7) + data%State%TD_Count%KellyOldStatus(8) = 0 + end if + data%State%TD_StConn%ElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%ElevatorConst-data%State%TD_DrillStems(kk)%LengthIni + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + + else if ( Get_ElevatorConnection() == ELEVATOR_LATCH_STRING ) then + data%State%TD_StConn%StringConnectionMode = 8 + if (data%State%TD_Count%KellyOldStatus(4)==1 .and. data%State%TD_Count%KellyNewStatus(8)/=data%State%TD_Count%KellyOldStatus(8)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(8) = data%State%TD_Count%KellyNewStatus(8) + data%State%TD_Count%KellyOldStatus(4) = 0 + else if (data%State%TD_Count%KellyOldStatus(5)==1 .and. data%State%TD_Count%KellyNewStatus(8)/=data%State%TD_Count%KellyOldStatus(8)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(8) = data%State%TD_Count%KellyNewStatus(8) + data%State%TD_Count%KellyOldStatus(5) = 0 + else if (data%State%TD_Count%KellyOldStatus(6)==1 .and. data%State%TD_Count%KellyNewStatus(8)/=data%State%TD_Count%KellyOldStatus(8)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(8) = data%State%TD_Count%KellyNewStatus(8) + data%State%TD_Count%KellyOldStatus(6) = 0 + else if (data%State%TD_Count%KellyOldStatus(7)==1 .and. data%State%TD_Count%KellyNewStatus(8)/=data%State%TD_Count%KellyOldStatus(8)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(8) = data%State%TD_Count%KellyNewStatus(8) + data%State%TD_Count%KellyOldStatus(7) = 0 + end if + data%State%TD_StConn%ElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%ElevatorConst + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + + else if ( Get_ElevatorConnection() == ELEVATOR_LATCH_SINGLE ) then + data%State%TD_StConn%StringConnectionMode = 18 + if (data%State%TD_Count%KellyOldStatus(5)==1 .and. data%State%TD_Count%KellyNewStatus(18)/=data%State%TD_Count%KellyOldStatus(18)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(18) = data%State%TD_Count%KellyNewStatus(18) + data%State%TD_Count%KellyOldStatus(5) = 0 + else if (data%State%TD_Count%KellyOldStatus(7)==1 .and. data%State%TD_Count%KellyNewStatus(18)/=data%State%TD_Count%KellyOldStatus(18)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(18) = data%State%TD_Count%KellyNewStatus(18) + data%State%TD_Count%KellyOldStatus(7) = 0 + else if (data%State%TD_Count%KellyOldStatus(8)==1 .and. data%State%TD_Count%KellyNewStatus(18)/=data%State%TD_Count%KellyOldStatus(18)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(18) = data%State%TD_Count%KellyNewStatus(18) + data%State%TD_Count%KellyOldStatus(8) = 0 + end if + data%State%TD_StConn%ElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%ElevatorConst + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + + else if ( Get_ElevatorConnection() == ELEVATOR_LATCH_STAND ) then + data%State%TD_StConn%StringConnectionMode = 19 + if (data%State%TD_Count%KellyOldStatus(5)==1 .and. data%State%TD_Count%KellyNewStatus(19)/=data%State%TD_Count%KellyOldStatus(19)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(19) = data%State%TD_Count%KellyNewStatus(19) + data%State%TD_Count%KellyOldStatus(5) = 0 + else if (data%State%TD_Count%KellyOldStatus(6)==1 .and. data%State%TD_Count%KellyNewStatus(19)/=data%State%TD_Count%KellyOldStatus(19)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(19) = data%State%TD_Count%KellyNewStatus(19) + data%State%TD_Count%KellyOldStatus(6) = 0 + else if (data%State%TD_Count%KellyOldStatus(8)==1 .and. data%State%TD_Count%KellyNewStatus(19)/=data%State%TD_Count%KellyOldStatus(19)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(19) = data%State%TD_Count%KellyNewStatus(19) + data%State%TD_Count%KellyOldStatus(8) = 0 + end if + data%State%TD_StConn%ElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%ElevatorConst + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + end if + + else if ( data%State%TD_StConn%KellyDriveTypeMode==2 ) then + + if( Get_TdsConnectionModes()==TDS_CONNECTION_SPINE ) then + data%State%TD_Count%KellyNewStatus(9) = 1 + else + data%State%TD_Count%KellyNewStatus(9) = 0 +!data%State%TD_Count%KellyOldStatus(9) = 0 + end if + + if( Get_TdsConnectionModes()==TDS_CONNECTION_STRING ) then + data%State%TD_Count%KellyNewStatus(10) = 1 + else + data%State%TD_Count%KellyNewStatus(10) = 0 +!data%State%TD_Count%KellyOldStatus(10) = 0 + end if + + if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_STRING ) then + data%State%TD_Count%KellyNewStatus(11) = 1 + else + data%State%TD_Count%KellyNewStatus(11) = 0 +!data%State%TD_Count%KellyOldStatus(11) = 0 + end if + + if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_STRING ) then + data%State%TD_Count%KellyNewStatus(12) = 1 + else + data%State%TD_Count%KellyNewStatus(12) = 0 +!data%State%TD_Count%KellyOldStatus(12) = 0 + end if + + if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_NOTHING ) then + data%State%TD_Count%KellyNewStatus(13) = 1 + else + data%State%TD_Count%KellyNewStatus(13) = 0 +!data%State%TD_Count%KellyOldStatus(13) = 0 + end if + + if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_STAND ) then + data%State%TD_Count%KellyNewStatus(14) = 1 + else + data%State%TD_Count%KellyNewStatus(14) = 0 +!data%State%TD_Count%KellyOldStatus(14) = 0 + end if + + if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_SINGLE ) then + data%State%TD_Count%KellyNewStatus(15) = 1 + else + data%State%TD_Count%KellyNewStatus(15) = 0 +!data%State%TD_Count%KellyOldStatus(15) = 0 + end if + + if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_SINGLE ) then + data%State%TD_Count%KellyNewStatus(16) = 1 + else + data%State%TD_Count%KellyNewStatus(16) = 0 +!data%State%TD_Count%KellyOldStatus(16) = 0 + end if + + if( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_STAND ) then + data%State%TD_Count%KellyNewStatus(17) = 1 + else + data%State%TD_Count%KellyNewStatus(17) = 0 +!data%State%TD_Count%KellyOldStatus(17) = 0 + end if + + if ( Get_TdsConnectionModes()==TDS_CONNECTION_SPINE ) then + data%State%TD_StConn%StringConnectionMode = 9 + if (data%State%TD_Count%KellyOldStatus(10)==1 .and. data%State%TD_Count%KellyNewStatus(9)/=data%State%TD_Count%KellyOldStatus(9)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(9) = data%State%TD_Count%KellyNewStatus(9) + data%State%TD_Count%KellyOldStatus(10) = 0 + else if (data%State%TD_Count%KellyOldStatus(11)==1 .and. data%State%TD_Count%KellyNewStatus(9)/=data%State%TD_Count%KellyOldStatus(9)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(9) = data%State%TD_Count%KellyNewStatus(9) + data%State%TD_Count%KellyOldStatus(11) = 0 + else if (data%State%TD_Count%KellyOldStatus(13)==1 .and. data%State%TD_Count%KellyNewStatus(9)/=data%State%TD_Count%KellyOldStatus(9)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(9) = data%State%TD_Count%KellyNewStatus(9) + data%State%TD_Count%KellyOldStatus(13) = 0 + end if + if ( Get_Slips() == SLIPS_SET_END ) then +!if ( data%State%TD_StConn%HookVelocity>0. ) then +! Print*, '*** UnSet Slips ***' !??????????????????? +!end if + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength-data%State%TD_StConn%TDSToolJointLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + else + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength-data%State%TD_StConn%TDSToolJointLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%TDSHeight + data%State%TD_StConn%StringVelocity = data%State%TD_StConn%HookVelocity + end if + + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_STRING ) then + data%State%TD_StConn%StringConnectionMode = 10 + if (data%State%TD_Count%KellyOldStatus(9)==1 .and. data%State%TD_Count%KellyNewStatus(10)/=data%State%TD_Count%KellyOldStatus(10)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(10) = data%State%TD_Count%KellyNewStatus(10) + data%State%TD_Count%KellyOldStatus(9) = 0 + end if + if ( Get_Slips() == SLIPS_SET_END ) then +!if ( data%State%TD_StConn%HookVelocity>0. ) then +! Print*, '*** UnSet Slips ***' !??????????????????? +!end if + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength-data%State%TD_StConn%TDSToolJointLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + else + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength-data%State%TD_StConn%TDSToolJointLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%TDSHeight + data%State%TD_StConn%StringVelocity = data%State%TD_StConn%HookVelocity + end if + + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_STRING ) then + data%State%TD_StConn%StringConnectionMode = 11 + if (data%State%TD_Count%KellyOldStatus(9)==1 .and. data%State%TD_Count%KellyNewStatus(11)/=data%State%TD_Count%KellyOldStatus(11)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(11) = data%State%TD_Count%KellyNewStatus(11) + data%State%TD_Count%KellyOldStatus(9) = 0 + else if (data%State%TD_Count%KellyOldStatus(12)==1 .and. data%State%TD_Count%KellyNewStatus(11)/=data%State%TD_Count%KellyOldStatus(11)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(11) = data%State%TD_Count%KellyNewStatus(11) + data%State%TD_Count%KellyOldStatus(12) = 0 + else if (data%State%TD_Count%KellyOldStatus(13)==1 .and. data%State%TD_Count%KellyNewStatus(11)/=data%State%TD_Count%KellyOldStatus(11)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(11) = data%State%TD_Count%KellyNewStatus(11) + data%State%TD_Count%KellyOldStatus(13) = 0 + else if (data%State%TD_Count%KellyOldStatus(16)==1 .and. data%State%TD_Count%KellyNewStatus(11)/=data%State%TD_Count%KellyOldStatus(11)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight+(data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_Count%KellyOldStatus(11) = data%State%TD_Count%KellyNewStatus(11) + data%State%TD_Count%KellyOldStatus(16) = 0 + else if (data%State%TD_Count%KellyOldStatus(17)==1 .and. data%State%TD_Count%KellyNewStatus(11)/=data%State%TD_Count%KellyOldStatus(11)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight+(3.d0*data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_Count%KellyOldStatus(11) = data%State%TD_Count%KellyNewStatus(11) + data%State%TD_Count%KellyOldStatus(17) = 0 + end if + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_STRING ) then + data%State%TD_StConn%StringConnectionMode = 12 + if (data%State%TD_Count%KellyOldStatus(11)==1 .and. data%State%TD_Count%KellyNewStatus(12)/=data%State%TD_Count%KellyOldStatus(12)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(12) = data%State%TD_Count%KellyNewStatus(12) + data%State%TD_Count%KellyOldStatus(11) = 0 + else if (data%State%TD_Count%KellyOldStatus(14)==1 .and. data%State%TD_Count%KellyNewStatus(12)/=data%State%TD_Count%KellyOldStatus(12)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight+(3.d0*data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_Count%KellyOldStatus(12) = data%State%TD_Count%KellyNewStatus(12) + data%State%TD_Count%KellyOldStatus(14) = 0 + else if (data%State%TD_Count%KellyOldStatus(15)==1 .and. data%State%TD_Count%KellyNewStatus(12)/=data%State%TD_Count%KellyOldStatus(12)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight+(data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_Count%KellyOldStatus(12) = data%State%TD_Count%KellyNewStatus(12) + data%State%TD_Count%KellyOldStatus(15) = 0 + end if + if ( Get_Slips() == SLIPS_SET_END ) then +!if ( data%State%TD_StConn%HookVelocity>0. ) then +! Print*, '*** UnSet Slips ***' !??????????????????? +!end if + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + else + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength+(LengthSum+data%State%TD_StConn%TDSElevatorECG) !????????????? + data%State%TD_StConn%StringVelocity = data%State%TD_StConn%HookVelocity + end if + + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_NOTHING ) then + data%State%TD_StConn%StringConnectionMode = 13 + if (data%State%TD_Count%KellyOldStatus(9)==1 .and. data%State%TD_Count%KellyNewStatus(13)/=data%State%TD_Count%KellyOldStatus(13)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(13) = data%State%TD_Count%KellyNewStatus(13) + data%State%TD_Count%KellyOldStatus(9) = 0 + else if (data%State%TD_Count%KellyOldStatus(11)==1 .and. data%State%TD_Count%KellyNewStatus(13)/=data%State%TD_Count%KellyOldStatus(13)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(13) = data%State%TD_Count%KellyNewStatus(13) + data%State%TD_Count%KellyOldStatus(11) = 0 + else if (data%State%TD_Count%KellyOldStatus(12)==1 .and. data%State%TD_Count%KellyNewStatus(13)/=data%State%TD_Count%KellyOldStatus(13)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(13) = data%State%TD_Count%KellyNewStatus(13) + data%State%TD_Count%KellyOldStatus(12) = 0 + else if (data%State%TD_Count%KellyOldStatus(14)==1 .and. data%State%TD_Count%KellyNewStatus(13)/=data%State%TD_Count%KellyOldStatus(13)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(13) = data%State%TD_Count%KellyNewStatus(13) + data%State%TD_Count%KellyOldStatus(14) = 0 + else if (data%State%TD_Count%KellyOldStatus(15)==1 .and. data%State%TD_Count%KellyNewStatus(13)/=data%State%TD_Count%KellyOldStatus(13)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(13) = data%State%TD_Count%KellyNewStatus(13) + data%State%TD_Count%KellyOldStatus(15) = 0 + else if (data%State%TD_Count%KellyOldStatus(16)==1 .and. data%State%TD_Count%KellyNewStatus(13)/=data%State%TD_Count%KellyOldStatus(13)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(13) = data%State%TD_Count%KellyNewStatus(13) + data%State%TD_Count%KellyOldStatus(16) = 0 + end if + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_STAND ) then + data%State%TD_StConn%StringConnectionMode = 14 + if (data%State%TD_Count%KellyOldStatus(12)==1 .and. data%State%TD_Count%KellyNewStatus(14)/=data%State%TD_Count%KellyOldStatus(14)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight-(3.d0*data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_Count%KellyOldStatus(14) = data%State%TD_Count%KellyNewStatus(14) + data%State%TD_Count%KellyOldStatus(12) = 0 + else if (data%State%TD_Count%KellyOldStatus(13)==1 .and. data%State%TD_Count%KellyNewStatus(14)/=data%State%TD_Count%KellyOldStatus(14)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(14) = data%State%TD_Count%KellyNewStatus(14) + data%State%TD_Count%KellyOldStatus(13) = 0 + else if (data%State%TD_Count%KellyOldStatus(17)==1 .and. data%State%TD_Count%KellyNewStatus(14)/=data%State%TD_Count%KellyOldStatus(14)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(14) = data%State%TD_Count%KellyNewStatus(14) + data%State%TD_Count%KellyOldStatus(17) = 0 + end if + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_CONNECTION_SINGLE ) then + data%State%TD_StConn%StringConnectionMode = 15 + if (data%State%TD_Count%KellyOldStatus(12)==1 .and. data%State%TD_Count%KellyNewStatus(15)/=data%State%TD_Count%KellyOldStatus(15)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight-(data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_Count%KellyOldStatus(15) = data%State%TD_Count%KellyNewStatus(15) + data%State%TD_Count%KellyOldStatus(12) = 0 + else if (data%State%TD_Count%KellyOldStatus(13)==1 .and. data%State%TD_Count%KellyNewStatus(15)/=data%State%TD_Count%KellyOldStatus(15)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(15) = data%State%TD_Count%KellyNewStatus(15) + data%State%TD_Count%KellyOldStatus(13) = 0 + else if (data%State%TD_Count%KellyOldStatus(16)==1 .and. data%State%TD_Count%KellyNewStatus(15)/=data%State%TD_Count%KellyOldStatus(15)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(15) = data%State%TD_Count%KellyNewStatus(15) + data%State%TD_Count%KellyOldStatus(16) = 0 + end if + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_SINGLE ) then + data%State%TD_StConn%StringConnectionMode = 16 + if (data%State%TD_Count%KellyOldStatus(11)==1 .and. data%State%TD_Count%KellyNewStatus(16)/=data%State%TD_Count%KellyOldStatus(16)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight-(data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_Count%KellyOldStatus(16) = data%State%TD_Count%KellyNewStatus(16) + data%State%TD_Count%KellyOldStatus(11) = 0 + else if (data%State%TD_Count%KellyOldStatus(13)==1 .and. data%State%TD_Count%KellyNewStatus(16)/=data%State%TD_Count%KellyOldStatus(16)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(16) = data%State%TD_Count%KellyNewStatus(16) + data%State%TD_Count%KellyOldStatus(13) = 0 + else if (data%State%TD_Count%KellyOldStatus(15)==1 .and. data%State%TD_Count%KellyNewStatus(16)/=data%State%TD_Count%KellyOldStatus(16)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_Count%KellyOldStatus(16) = data%State%TD_Count%KellyNewStatus(16) + data%State%TD_Count%KellyOldStatus(15) = 0 + end if + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + + else if ( Get_TdsConnectionModes()==TDS_CONNECTION_NOTHING .and. Get_TdsElevatorModes()==TDS_ELEVATOR_LATCH_STAND ) then + data%State%TD_StConn%StringConnectionMode = 17 + if (data%State%TD_Count%KellyOldStatus(11)==1 .and. data%State%TD_Count%KellyNewStatus(17)/=data%State%TD_Count%KellyOldStatus(17)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight-(3.d0*data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_Count%KellyOldStatus(17) = data%State%TD_Count%KellyNewStatus(17) + data%State%TD_Count%KellyOldStatus(11) = 0 + else if (data%State%TD_Count%KellyOldStatus(14)==1 .and. data%State%TD_Count%KellyNewStatus(17)/=data%State%TD_Count%KellyOldStatus(17)) then + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight+(3.d0*data%State%TD_DrillStems(kk)%LengthIni) + data%State%TD_Count%KellyOldStatus(17) = data%State%TD_Count%KellyNewStatus(17) + data%State%TD_Count%KellyOldStatus(14) = 0 + end if + data%State%TD_StConn%TDSHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSLength !????????????? + data%State%TD_StConn%TDSElevatorHeight = data%State%TD_StConn%HookHeight-data%State%TD_StConn%TDSElevatorLength !????????????? + data%State%TD_StConn%ConnectionHeight = data%State%TD_StConn%ConnectionHeight + data%State%TD_StConn%StringVelocity = 0.0d0 + end if + + + end if + +!Print*, 'data%State%TD_StConn%StringConnectionMode=' , data%State%TD_StConn%StringConnectionMode +!print* , 'data%State%TD_StConn%ConnectionHeight=' , data%State%TD_StConn%ConnectionHeight +!Print*, 'data%State%TD_StConn%StringConnectionMode=' , data%State%TD_StConn%StringConnectionMode +!print*, 'data%State%TD_String%DrillStemComponentsNumbs=' , data%State%TD_String%DrillStemComponentsNumbs +!!Print*, 'data%State%TD_Count%KellyNewStatus(1)=' , data%State%TD_Count%KellyNewStatus(1) +!Print*, 'data%State%TD_Count%KellyOldStatus(1)=' , data%State%TD_Count%KellyOldStatus(1) +!Print*, 'data%State%TD_Count%KellyNewStatus(2)=' , data%State%TD_Count%KellyNewStatus(2) +!Print*, 'data%State%TD_Count%KellyOldStatus(2)=' , data%State%TD_Count%KellyOldStatus(2) +!Print*, 'data%State%TD_Count%KellyNewStatus(3)=' , data%State%TD_Count%KellyNewStatus(3) +!Print*, 'data%State%TD_Count%KellyOldStatus(3)=' , data%State%TD_Count%KellyOldStatus(3) + + + + + + + if ( (any(data%State%TD_StConn%StringConnectionMode==(/1,9,10/))) .or. data%Equipments%DrillingConsole%CloseSafetyValve==.true. ) then !for fluid module + data%State%TD_StConn%FluidStringConnectionMode = 1 !string is connected +!else if ( (any(data%State%TD_StConn%StringConnectionMode==(/1,9,10/))) .or. data%Equipments%DrillingConsole%CloseSafetyValve==.true. ) then +! + else + data%State%TD_StConn%FluidStringConnectionMode = 0 !string is not connected + end if + + + + + + +!==================================================== +! Zero String Speed +!==================================================== + if ( abs(data%State%TD_StConn%StringVelocity)<=0.05d0 ) then ! [ft/s] + data%State%TD_Load%ZeroStringSpeed = 1 + Call Set_ZeroStringSpeed(.true.) + else + data%State%TD_Load%ZeroStringSpeed = 0 + Call Set_ZeroStringSpeed(.false.) + end if + + + + + + + +end subroutine diff --git a/TorqueDrag/TD_Forces/TD_HookLoadCalculation.i90 b/TorqueDrag/TD_Forces/TD_HookLoadCalculation.i90 new file mode 100644 index 0000000..7b85046 --- /dev/null +++ b/TorqueDrag/TD_Forces/TD_HookLoadCalculation.i90 @@ -0,0 +1,290 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/TorqueDrag/TD_Forces/TD_HookLoadCalculation.f90" +subroutine TD_HookLoadCalculation + + Use TD_DrillStemComponents + use SimulationVariables !@ + use SimulationVariables !@ + use SimulationVariables !@ + Use TD_StringConnectionData + use SimulationVariables !@, only: Drawworks + use CDataDisplayConsole + use SimulationVariables + use CHoistingVariables + use SimulationVariables +! Use CSlipsEnumVariables + use UnitySignalVariables + use UnitySignalsModule + Use CBopStackVariables + use SimulationVariables + Use CUnityInputs + + + implicit none + + Integer :: i , kk + Real(8) :: TD_eConst=0.98d0 , TD_SumWeight + + + + +!==================================================== +! Torque & Hook Load Calculation +!==================================================== + +!=========> HookLoad + data%State%TD_String%HookLoad = data%State%TD_DrillStems(data%State%TD_String%DrillStemComponentsNumbs)%Force2 ! [lb] +!print* , 'data%State%TD_String%HookLoad1=' , data%State%TD_String%HookLoad + + if ( data%State%Drawworks%motion==1 ) then + if ( data%State%PipeRam1%Situation_forTD==1 ) then !Upper Ram + data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+data%Configuration%BopStack%RamStringDrag + end if + if ( data%State%PipeRam2%Situation_forTD==1 ) then !Lower Ram + data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+data%Configuration%BopStack%RamStringDrag + end if + if ( data%State%RamLine%ShearBop_Situation_forTD==1 ) then !Blind Ram + data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+data%Configuration%BopStack%RamStringDrag !???????????????????? + end if + if ( data%State%Annular%Annular_Situation_forTD==1 ) then !Annular Preventer + data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+(data%State%AnnularComputational%p_annular*data%Configuration%BopStack%AnnularStringDrag) + end if + else if ( data%State%Drawworks%motion==-1 ) then + if ( data%State%PipeRam1%Situation_forTD==1 ) then !Upper Ram + data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-data%Configuration%BopStack%RamStringDrag + end if + if ( data%State%PipeRam2%Situation_forTD==1 ) then !Lower Ram + data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-data%Configuration%BopStack%RamStringDrag + end if + if ( data%State%RamLine%ShearBop_Situation_forTD==1 ) then !Blind Ram + data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-data%Configuration%BopStack%RamStringDrag !???????????????????? + end if + if ( data%State%Annular%Annular_Situation_forTD==1 ) then !Annular Preventer + data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-(data%State%AnnularComputational%p_annular*data%Configuration%BopStack%AnnularStringDrag) + end if + end if + +!print* , 'data%State%TD_String%HookLoad2=' , data%State%TD_String%HookLoad + + + + + +!if ( UpperRamClose_withPossibility==1 ) then +! if ( data%State%Drawworks%motion==1 ) then +! data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+RamStringDrag +! else if ( data%State%Drawworks%motion==-1 ) then +! data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-RamStringDrag +! end if +!end if +!if ( LowerRamClose_withPossibility==1 ) then +! if ( data%State%Drawworks%motion==1 ) then +! data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+RamStringDrag +! else if ( data%State%Drawworks%motion==-1 ) then +! data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-RamStringDrag +! end if +!end if +!if ( BlindRamClose_withPossibility==1 ) then +! if ( data%State%Drawworks%motion==1 ) then +! data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+RamStringDrag +! else if ( data%State%Drawworks%motion==-1 ) then +! data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-RamStringDrag +! end if +!end if +!if ( AnnularPreventerClose_withPossibility==1 ) then +! if ( data%State%Drawworks%motion==1 ) then +! data%State%TD_String%HookLoad = data%State%TD_String%HookLoad+AnnularStringDrag +! else if ( data%State%Drawworks%motion==-1 ) then +! data%State%TD_String%HookLoad = data%State%TD_String%HookLoad-AnnularStringDrag +! end if +!end if + + + + + + + + +!=========> Torque + data%State%TD_String%StringTorque = data%State%TD_String%TotalTorque ![lb.ft] ?????????? +!print* , 'data%State%TD_String%StringTorque=' , data%State%TD_String%StringTorque + + + + + +!==================================================== +! Weight Indicator Calculation +!==================================================== + + kk = 0 + Do i = data%State%TD_String%DrillStemComponentsNumbs , 1 , -1 + if (data%State%TD_DrillStems(i)%ComponentType==3) then + kk = i + exit + end if + End Do + + + + + + if ( data%State%TD_StConn%KellyDriveTypeMode==0 ) then + + if ( data%State%TD_StConn%StringConnectionMode == 1 ) then + if ( Get_Slips() == SLIPS_SET_END ) then + TD_SumWeight = data%State%TD_Load%WeightTB+data%State%TD_Load%KellyWeight + else + TD_SumWeight = data%State%TD_String%HookLoad+data%State%TD_Load%WeightTB+data%State%TD_Load%KellyWeight ! data%State%TD_String%HookLoad = String Weight + end if + + else if ( data%State%TD_StConn%StringConnectionMode == 2 ) then + if ( Get_JointConnectionPossible() ) then + TD_SumWeight = data%State%TD_Load%WeightTB + else + TD_SumWeight = data%State%TD_Load%WeightTB+data%State%TD_Load%KellyWeight + end if + + else if ( data%State%TD_StConn%StringConnectionMode == 3 ) then + if ( Get_JointConnectionPossible() ) then + TD_SumWeight = data%State%TD_Load%WeightTB + else + TD_SumWeight = data%State%TD_Load%WeightTB+data%State%TD_Load%KellyWeight+data%State%TD_DrillStems(kk)%Weight + end if + + end if + + else if ( data%State%TD_StConn%KellyDriveTypeMode==1 ) then + + if ( data%State%TD_StConn%StringConnectionMode == 4 ) then + if ( Get_Slips() == SLIPS_SET_END ) then + TD_SumWeight = data%State%TD_Load%WeightTB + else + TD_SumWeight = data%State%TD_String%HookLoad+data%State%TD_Load%WeightTB + end if + + else if ( data%State%TD_StConn%StringConnectionMode == 5 ) then + TD_SumWeight = data%State%TD_Load%WeightTB + + else if ( data%State%TD_StConn%StringConnectionMode == 6 ) then + if ( Get_JointConnectionPossible() ) then + TD_SumWeight = data%State%TD_Load%WeightTB + else + TD_SumWeight = data%State%TD_Load%WeightTB+(3.d0*data%State%TD_DrillStems(kk)%Weight) + end if + + else if ( data%State%TD_StConn%StringConnectionMode == 7 ) then + if ( Get_JointConnectionPossible() ) then + TD_SumWeight = data%State%TD_Load%WeightTB + else + TD_SumWeight = data%State%TD_Load%WeightTB+data%State%TD_DrillStems(kk)%Weight + end if + + else if ( data%State%TD_StConn%StringConnectionMode == 8 ) then + TD_SumWeight = data%State%TD_Load%WeightTB + + else if ( data%State%TD_StConn%StringConnectionMode == 18 ) then + TD_SumWeight = data%State%TD_Load%WeightTB + + else if ( data%State%TD_StConn%StringConnectionMode == 19 ) then + TD_SumWeight = data%State%TD_Load%WeightTB + + end if + + else if ( data%State%TD_StConn%KellyDriveTypeMode==2 ) then + + if ( data%State%TD_StConn%StringConnectionMode == 9 ) then + if ( Get_Slips() == SLIPS_SET_END ) then + TD_SumWeight = data%State%TD_Load%WeightTD + else + TD_SumWeight = data%State%TD_String%HookLoad+data%State%TD_Load%WeightTD + end if + + else if ( data%State%TD_StConn%StringConnectionMode == 10 ) then + if ( Get_Slips() == SLIPS_SET_END ) then + TD_SumWeight = data%State%TD_Load%WeightTD + else + TD_SumWeight = data%State%TD_String%HookLoad+data%State%TD_Load%WeightTD + end if + + else if ( data%State%TD_StConn%StringConnectionMode == 11 ) then + TD_SumWeight = data%State%TD_Load%WeightTD + + else if ( data%State%TD_StConn%StringConnectionMode == 12 ) then + if ( Get_Slips() == SLIPS_SET_END ) then + TD_SumWeight = data%State%TD_Load%WeightTD + else + TD_SumWeight = data%State%TD_String%HookLoad+data%State%TD_Load%WeightTD + end if + + else if ( data%State%TD_StConn%StringConnectionMode == 13 ) then + TD_SumWeight = data%State%TD_Load%WeightTD + + else if ( data%State%TD_StConn%StringConnectionMode == 14 ) then + TD_SumWeight = data%State%TD_Load%WeightTD+(3.d0*data%State%TD_DrillStems(kk)%Weight) + + else if ( data%State%TD_StConn%StringConnectionMode == 15 ) then + TD_SumWeight = data%State%TD_Load%WeightTD+(data%State%TD_DrillStems(kk)%Weight) + + else if ( data%State%TD_StConn%StringConnectionMode == 16 ) then + TD_SumWeight = data%State%TD_Load%WeightTD + + else if ( data%State%TD_StConn%StringConnectionMode == 17 ) then + TD_SumWeight = data%State%TD_Load%WeightTD + + end if + + end if + + + +!print* , 'data%State%TD_String%HookLoad3=' , data%State%TD_String%HookLoad + + + + +!if ( data%Configuration%Hoisting%DriveType==1 ) then !==> Kelly_DriveType +! +! if ( data%State%TD_String%DrillStemForceType==1 .or. data%State%TD_String%DrillStemForceType==2 ) then +! data%State%TD_Load%WeightIndicator = ( sngl(data%State%TD_Load%NumOfCables)*(TD_eConst-1.d0)*(TD_SumWeight) )& +! /( TD_eConst*(1.d0-(1.d0/(TD_eConst**data%State%TD_Load%NumOfCables))) ) +! else if ( data%State%TD_String%DrillStemForceType==3 .or. data%State%TD_String%DrillStemForceType==4 ) then +! data%State%TD_Load%WeightIndicator = ( sngl(data%State%TD_Load%NumOfCables)*(1.d0-TD_eConst)*(TD_SumWeight) )& +! /( 1.d0-(TD_eConst**data%State%TD_Load%NumOfCables) ) +! else if ( data%State%TD_String%DrillStemForceType==5 ) then + data%State%TD_Load%WeightIndicator = TD_SumWeight +! end if +! +! +!else if ( data%Configuration%Hoisting%DriveType==0 ) then !==> TopDrive_DriveType ?????????????? +! +! if ( data%State%TD_String%DrillStemForceType==1 .or. data%State%TD_String%DrillStemForceType==2 ) then +! data%State%TD_Load%WeightIndicator = ( sngl(data%State%TD_Load%NumOfCables)*(TD_eConst-1.d0)*(TD_SumWeight) )& +! /( TD_eConst*(1.d0-(1.d0/(TD_eConst**data%State%TD_Load%NumOfCables))) ) +! else if ( data%State%TD_String%DrillStemForceType==3 .or. data%State%TD_String%DrillStemForceType==4 ) then +! data%State%TD_Load%WeightIndicator = ( sngl(data%State%TD_Load%NumOfCables)*(1.d0-TD_eConst)*(TD_SumWeight) )& +! /( 1.d0-(TD_eConst**data%State%TD_Load%NumOfCables) ) +! else if ( data%State%TD_String%DrillStemForceType==5 ) then +! data%State%TD_Load%WeightIndicator = TD_SumWeight +! end if +! +!!else +!!data%State%TD_Load%WeightIndicator = 0. !????????????????? +! +!end if + + + + + + data%State%TD_Load%DrawworksLoadInput = data%State%TD_Load%WeightIndicator/(sngl(data%State%TD_Load%NumOfCables)) ! [lb] +!print* , 'data%State%TD_String%HookLoad4=' , data%State%TD_String%HookLoad +!HookLoadPointer = data%State%TD_Load%WeightIndicator/1.0d3 ! [klb] + call Set_HookLoad ((1-data%State%TD_General%WeightIndicatorMalf)*AINT(data%State%TD_Load%WeightIndicator/1.0d3)) ! [klb] + + + + + + +end subroutine diff --git a/TorqueDrag/TD_Modules/GeoElements_FluidModule.i90 b/TorqueDrag/TD_Modules/GeoElements_FluidModule.i90 new file mode 100644 index 0000000..0e2ca88 --- /dev/null +++ b/TorqueDrag/TD_Modules/GeoElements_FluidModule.i90 @@ -0,0 +1,59 @@ +# 1 "/mnt/c/Projects/VSIM/SimulationCore2/TorqueDrag/TD_Modules/GeoElements_FluidModule.f90" +MODULE GeoElements_FluidModule + + IMPLICIT NONE + PUBLIC + + + +!************************************************************************************************************************************ + TYPE , PUBLIC :: Geo_Data + REAL(8) , Allocatable :: MD(:) , TVD(:) , Angle(:) + END TYPE Geo_Data +!************************************************************************************************************************************ + + + +!************************************************************************************************************************************ +!==================================================== +! Well Geometrical Elements Info (for fluid module) +!==================================================== + TYPE , PUBLIC :: F_StringData + INTEGER :: FirstElement , LastElement , ElType + REAL(8) :: ID , OD , TopDepth , DownDepth + END TYPE F_StringData +!************************************************************************************************************************************ + + + +!************************************************************************************************************************************ + TYPE , PUBLIC :: F_IntervalsCountsData + INTEGER :: IntervalsTotalCounts , StringIntervalCounts , BottomHoleIntervalCounts , AnnulusIntervalCounts + INTEGER :: OutOfWellIntervalCounts + END TYPE F_IntervalsCountsData +!************************************************************************************************************************************ + + + +!************************************************************************************************************************************ + TYPE , PUBLIC :: F_IntervalData + INTEGER :: Number , GeoType + REAL(8) :: ID , OD , StartDepth , EndDepth , HydDiameter , Volume + REAL(8) :: StartTVD , EndTVD , StartAngle , EndAngle + END TYPE F_IntervalData +!####data%State%F_Interval(:)%GeoType = +! 0 : String Interval +! 1 : BottomHole Interval +! 2 : Annulus Interval +!************************************************************************************************************************************ + + + +!************************************************************************************************************************************ + TYPE , PUBLIC :: OD_AnnulusData + REAL(8) :: ODValue , StartMD , EndMD + END TYPE OD_AnnulusData +!************************************************************************************************************************************ + + +END MODULE GeoElements_FluidModule diff --git a/config-debug.json b/config-debug.json new file mode 100644 index 0000000..4ad6002 --- /dev/null +++ b/config-debug.json @@ -0,0 +1,9 @@ +{ + "redis":{ + "address":"127.0.0.1", + "port":6379, + "password":"", + "datakey":"data" + }, + "logging":5 +} \ No newline at end of file diff --git a/config-local.json b/config-local.json new file mode 100644 index 0000000..1193862 --- /dev/null +++ b/config-local.json @@ -0,0 +1,9 @@ +{ + "redis":{ + "address":"127.0.0.1", + "port":6379, + "password":"", + "datakey":"data" + }, + "logging":5 +} \ No newline at end of file diff --git a/config-remote.json b/config-remote.json new file mode 100644 index 0000000..4634b30 --- /dev/null +++ b/config-remote.json @@ -0,0 +1,9 @@ +{ + "redis":{ + "address":"aberama.iran.liara.ir", + "port":32815, + "password":"4YKFnubfFFjfh4yTK7b0Rg9X", + "datakey":"data" + }, + "logging":5 +} \ No newline at end of file diff --git a/config.json b/config.json deleted file mode 100644 index fcec172..0000000 --- a/config.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "t0": 0.0, - "dt": 1.0, - "tf": 86400.0, - "mu": 398600.4418, - "x0": [ - 10000.0, - 10000.0, - 10000.0, - 1.0, - 2.0, - 3.0 - ] -} \ No newline at end of file diff --git a/helper.ipynb b/helper.ipynb index 0779bcf..3efd9dd 100644 --- a/helper.ipynb +++ b/helper.ipynb @@ -913,46 +913,31 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\t\tcall json%get(p,'NumberOfBottels',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%NumberOfBottels)\n", - "\t\tcall json%get(p,'AccumulatorSystemSize',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%AccumulatorSystemSize)\n", - "\t\tcall json%get(p,'OilTankVolume',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%OilTankVolume)\n", - "\t\tcall json%get(p,'PrechargePressure',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%PrechargePressure)\n", - "\t\tcall json%get(p,'AccumulatorMinimumOperatingPressure',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%AccumulatorMinimumOperatingPressure)\n", - "\t\tcall json%get(p,'ElectricPumpOutput',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%ElectricPumpOutput)\n", - "\t\tcall json%get(p,'StartPressure',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%StartPressure)\n", - "\t\tcall json%get(p,'StopPressure',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%StopPressure)\n", - "\t\tcall json%get(p,'AirPlungerPumpOutput',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%AirPlungerPumpOutput)\n", - "\t\tcall json%get(p,'StartPressure2',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%StartPressure2)\n", - "\t\tcall json%get(p,'StopPressure2',pval)\n", - "\t\tcall json%get(pval,data%Configuration%Accumulator%StopPressure2)\n" + "\t\tcall json%get(p,'AnnDrillMud',pval)\n", + "\t\tcall json%get(pval,data%Equipments%DownHole%AnnDrillMud)\n", + "\t\tcall json%get(p,'AnnCirculateMud',pval)\n", + "\t\tcall json%get(pval,data%Equipments%DownHole%AnnCirculateMud)\n" ] } ], "source": [ "pattern=\"\"\"\t\tcall json%get(p,'@@@',pval)\n", - "\t\tcall json%get(pval,data%Configuration%BopStack%@@@)\"\"\"\n", + "\t\tcall json%get(pval,data%Equipments%DownHole%@@@)\"\"\"\n", "\n", "input = open(\"Text1.txt\")\n", "lines = input.readlines()\n", "for line in lines:\n", - "\tname = line.split(\"::\")[-1].strip()\n", + "\tparts = line.split(\"::\")\n", + "\tif len(parts)!=2:\n", + "\t\tcontinue\n", + "\tname = parts[1].split(' ')[1].strip()\n", "\tnewline = pattern.replace(\"@@@\",name)\n", "\tprint(newline)\n" ] @@ -967,22 +952,15 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{\"ComponentType\":0,\n", - "\"NumberOfJoint\":0,\n", - "\"LengthPerJoint\":0,\n", - "\"NominalOd\":0,\n", - "\"NominalId\":0,\n", - "\"WeightPerLength\":0,\n", - "\"ComponentLength\":0,\n", - "\"NominalToolJointOd\":0,\n", - "\"Grade\":0,\n", + "{\"AnnDrillMud\":0,\n", + "\"AnnCirculateMud\":0,\n", "}\n" ] } @@ -998,46 +976,47 @@ " output += f\"\\\"{name}\\\":0,\\n\" \n", " # name = line.split(\"%\")[-1][:-1]\n", " # print(name)\n", - "print(output+\"}\")\n" + "print(output+\"}\")" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "call json%add(p,\"Depth\",data%EquipmentControl%DrillingWatch%Depth)\n", - "call json%add(p,\"BitPosition\",data%EquipmentControl%DrillingWatch%BitPosition)\n", - "call json%add(p,\"HookLoad\",data%EquipmentControl%DrillingWatch%HookLoad)\n", - "call json%add(p,\"WeightOnBit\",data%EquipmentControl%DrillingWatch%WeightOnBit)\n", - "call json%add(p,\"RPM\",data%EquipmentControl%DrillingWatch%RPM)\n", - "call json%add(p,\"ROP\",data%EquipmentControl%DrillingWatch%ROP)\n", - "call json%add(p,\"Torque\",data%EquipmentControl%DrillingWatch%Torque)\n", - "call json%add(p,\"PumpPressure\",data%EquipmentControl%DrillingWatch%PumpPressure)\n", - "call json%add(p,\"SPM1\",data%EquipmentControl%DrillingWatch%SPM1)\n", - "call json%add(p,\"SPM2\",data%EquipmentControl%DrillingWatch%SPM2)\n", - "call json%add(p,\"CasingPressure\",data%EquipmentControl%DrillingWatch%CasingPressure)\n", - "call json%add(p,\"PercentFlow\",data%EquipmentControl%DrillingWatch%PercentFlow)\n", - "call json%add(p,\"PitGainLose\",data%EquipmentControl%DrillingWatch%PitGainLose)\n", - "call json%add(p,\"PitVolume\",data%EquipmentControl%DrillingWatch%PitVolume)\n", - "call json%add(p,\"KillMudVolume\",data%EquipmentControl%DrillingWatch%KillMudVolume)\n", - "call json%add(p,\"TripTankVolume\",data%EquipmentControl%DrillingWatch%TripTankVolume)\n", - "call json%add(p,\"MudWeightIn\",data%EquipmentControl%DrillingWatch%MudWeightIn)\n", - "call json%add(p,\"FillVolume\",data%EquipmentControl%DrillingWatch%FillVolume)\n", - "call json%add(p,\"MudWeightOut\",data%EquipmentControl%DrillingWatch%MudWeightOut)\n" + "call json%add(p,\"AnnalusFluidsCount\",data%Equipments%DownHole%AnnalusFluidsCount)\n", + "call json%add(p,\"StringFluidsCount\",data%Equipments%DownHole%StringFluidsCount)\n", + "call json%add(p,\"AnnalusFluids(:)\",data%Equipments%DownHole%AnnalusFluids(:))\n", + "call json%add(p,\"StringFluids(:)\",data%Equipments%DownHole%StringFluids(:))\n", + "call json%add(p,\"\",data%Equipments%DownHole%)\n", + "call json%add(p,\"StringCount\",data%Equipments%DownHole%StringCount)\n", + "call json%add(p,\"String(:)\",data%Equipments%DownHole%String(:))\n", + "call json%add(p,\"\",data%Equipments%DownHole%)\n", + "call json%add(p,\"BopElements(:)\",data%Equipments%DownHole%BopElements(:))\n", + "call json%add(p,\"\",data%Equipments%DownHole%)\n", + "call json%add(p,\"DrillPipePressure\",data%Equipments%DownHole%DrillPipePressure)\n", + "call json%add(p,\"CasingPressure\",data%Equipments%DownHole%CasingPressure)\n", + "call json%add(p,\"ShoePressure\",data%Equipments%DownHole%ShoePressure)\n", + "call json%add(p,\"BottomHolePressure\",data%Equipments%DownHole%BottomHolePressure)\n", + "call json%add(p,\"FormationPressure\",data%Equipments%DownHole%FormationPressure)\n", + "call json%add(p,\"InfluxRate\",data%Equipments%DownHole%InfluxRate)\n", + "call json%add(p,\"KickVolume\",data%Equipments%DownHole%KickVolume)\n", + "call json%add(p,\"SecondKickVolume\",data%Equipments%DownHole%SecondKickVolume)\n", + "call json%add(p,\"PermeabilityExposedHeight\",data%Equipments%DownHole%PermeabilityExposedHeight)\n" ] } ], "source": [ - "precode = \"\"\"call json%add(p,\"\",data%EquipmentControl%DrillingWatch%\"\"\"\n", + "precode = \"\"\"call json%add(p,\"\",data%Equipments%DownHole%\"\"\"\n", "input = open(\"Text1.txt\")\n", "lines = input.readlines()\n", "for line in lines:\n", " name = line.split(\"::\")[-1].strip()\n", + " name = name.split(' ')[0]\n", " icoute = precode.index(\"\\\"\")+1\n", " # name = line.split(\"%\")[-1][:-1]\n", " # print(name)\n", diff --git a/redisContent.json b/redisContent.json new file mode 100644 index 0000000..0cd216b --- /dev/null +++ b/redisContent.json @@ -0,0 +1,1045 @@ +{ + "Configuration": { + "StringConfiguration": { + "StringConfigurationItems": [], + "BitDefenition": { + "BitCodeHundreds": 0, + "BitCodeOnes": 0, + "BitCodeTens": 0, + "BitLength": 0.0E+0, + "BitNozzleNo": 0, + "BitNozzleSize": 0.0E+0, + "BitSize": 0.0E+0, + "BitType": 0, + "BitWeightPerLength": 0.0E+0, + "FloatValve": false + } + }, + "Formations": [], + "Reservoir": { + "AutoMigrationRate": 0.0E+0, + "FluidGradient": 0.0E+0, + "FluidType": 0, + "FluidViscosity": 0.0E+0, + "FormationNo": 0, + "FormationPermeability": 0.0E+0, + "FormationTop": 0.0E+0, + "GeothermalGradient": 0.0E+0, + "InactiveInflux": false, + "IsAutoMigrationRateSelected": false, + "MakeKickSinglePacket": false, + "PressureGradient": 0.0E+0 + }, + "Shoe": { + "Breakdown": 0.0E+0, + "FormationNo": 0, + "FracturePropagation": 0.0E+0, + "InactiveFracture": false, + "LeakOff": 0.0E+0, + "ShoeDepth": 0.0E+0 + }, + "Accumulator": { + "AccumulatorMinimumOperatingPressure": 0.0E+0, + "AccumulatorSystemSize": 0.0E+0, + "AirPlungerPumpOutput": 0.0E+0, + "ElectricPumpOutput": 0.0E+0, + "NumberOfBottels": 0, + "OilTankVolume": 0.0E+0, + "PrechargePressure": 0.0E+0, + "StartPressure": 0.0E+0, + "StartPressure2": 0.0E+0, + "StopPressure": 0.0E+0, + "StopPressure2": 0.0E+0 + }, + "BopStack": { + "AboveAnnularHeight": 0.1E+2, + "AnnularPreventerClose": 0.0E+0, + "AnnularPreventerHeight": 0.10199999999999999E+2, + "AnnularPreventerOpen": 0.0E+0, + "AnnularStringDrag": 0.0E+0, + "BlindRamClose": 0.0E+0, + "BlindRamHeight": 0.16239999999999998E+2, + "BlindRamOpen": 0.0E+0, + "ChokeClose": 0.0E+0, + "ChokeLineId": 0.0E+0, + "ChokeLineLength": 0.0E+0, + "ChokeOpen": 0.0E+0, + "GroundLevel": 0.3E+2, + "KillClose": 0.15E+1, + "KillHeight": 0.18800000000000001E+2, + "KillOpen": 0.15E+1, + "LowerRamClose": 0.0E+0, + "LowerRamHeight": 0.21350000000000001E+2, + "LowerRamOpen": 0.0E+0, + "RamStringDrag": 0.0E+0, + "UpperRamClose": 0.0E+0, + "UpperRamHeight": 0.14632E+2, + "UpperRamOpen": 0.0E+0 + }, + "Hoisting": { + "DrillingLineBreakingLoadAbrasiveness": 0.0E+0, + "DriveTypeAbrasiveness": 0, + "KellyWeightAbrasiveness": 0.0E+0, + "NumberOfLineAbrasiveness": 0, + "TopDriveWeightAbrasiveness": 0.0E+0, + "TravelingBlockWeightAbrasiveness": 0.0E+0 + }, + "Power": { + "CementPump": 0.0E+0, + "Drawworks": 0.0E+0, + "GeneratorPowerRating": 0.0E+0, + "MudPump1": 0.0E+0, + "MudPump2": 0.0E+0, + "NumberOfgenerators": 0, + "RotaryTable": 0.0E+0, + "TopDrive": 0.0E+0 + }, + "Pumps": { + "MudPump1LinerDiameter": 0.0E+0, + "MudPump1Stroke": 0.0E+0, + "MudPump1MechanicalEfficiency": 0.0E+0, + "MudPump1VolumetricEfficiency": 0.0E+0, + "MudPump1Output": 0.0E+0, + "MudPump1OutputBblStroke": 0.0E+0, + "MudPump1Maximum": 0.0E+0, + "MudPump1ReliefValvePressure": 0.0E+0, + "MudPump2LinerDiameter": 0.0E+0, + "MudPump2Stroke": 0.0E+0, + "MudPump2MechanicalEfficiency": 0.0E+0, + "MudPump2VolumetricEfficiency": 0.0E+0, + "MudPump2Output": 0.0E+0, + "MudPump2OutputBblStroke": 0.0E+0, + "MudPump2Maximum": 0.0E+0, + "MudPump2ReliefValvePressure": 0.0E+0, + "CementPumpLinerDiameter": 0.0E+0, + "CementPumpStroke": 0.0E+0, + "CementPumpMechanicalEfficiency": 0.0E+0, + "CementPumpVolumetricEfficiency": 0.0E+0, + "CementPumpOutput": 0.0E+0, + "CementPumpOutputBblStroke": 0.0E+0, + "CementPumpMaximum": 0.0E+0, + "CementPumpReliefValvePressure": 0.0E+0, + "MudPump1ReliefValveIsSet": false, + "MudPump2ReliefValveIsSet": false, + "CementPumpReliefValveIsSet": false, + "ManualPumpPower": false, + "Valve1": false, + "Valve2": false, + "Valve3": false, + "Valve4": false, + "Valve5": false + }, + "RigSize": { + "RigType": 0, + "CrownHeight": 0.0E+0, + "MonkeyBoandHeight": 0.0E+0, + "RigFloorHeight": 0.0E+0 + }, + "CasingLinerChoke": { + "CasingDepth": 0.0E+0, + "CasingId": 0.0E+0, + "CasingOd": 0.0E+0, + "CasingWeight": 0.0E+0, + "CasingCollapsePressure": 0.0E+0, + "CasingTensileStrength": 0.0E+0, + "LinerTopDepth": 0.0E+0, + "LinerLength": 0.0E+0, + "LinerId": 0.0E+0, + "LinerOd": 0.0E+0, + "LinerWeight": 0.0E+0, + "LinerCollapsePressure": 0.0E+0, + "LinerTensileStrength": 0.0E+0, + "OpenHoleId": 0.0E+0, + "OpenHoleLength": 0.0E+0 + }, + "Path": { + "Items": [], + "DataPoints": [] + }, + "Mud": { + "ActiveMudType": 0, + "ActiveRheologyModel": 0, + "ActiveMudVolume": 0.0E+0, + "ActiveMudVolumeGal": 0.0E+0, + "ActiveDensity": 0.0E+0, + "ActivePlasticViscosity": 0.0E+0, + "ActiveYieldPoint": 0.0E+0, + "ActiveThetaThreeHundred": 0.0E+0, + "ActiveThetaSixHundred": 0.0E+0, + "ReserveMudType": 0, + "ReserveMudVolume": 0.0E+0, + "ReserveMudVolumeGal": 0.0E+0, + "ReserveDensity": 0.0E+0, + "ReservePlasticViscosity": 0.0E+0, + "ReserveYieldPoint": 0.0E+0, + "ReserveThetaThreeHundred": 0.0E+0, + "ReserveThetaSixHundred": 0.0E+0, + "ActiveTotalTankCapacity": 0.0E+0, + "ActiveTotalTankCapacityGal": 0.0E+0, + "ActiveSettledContents": 0.0E+0, + "ActiveSettledContentsGal": 0.0E+0, + "ActiveTotalContents": 0.0E+0, + "ActiveTotalContentsGal": 0.0E+0, + "ActiveAutoDensity": false, + "InitialTripTankMudVolume": 0.0E+0, + "InitialTripTankMudVolumeGal": 0.0E+0, + "PedalFlowMeter": 0.0E+0 + } + }, + "Warnings": { + "PumpWithKellyDisconnected": false, + "PumpWithTopdriveDisconnected": false, + "Pump1PopOffValveBlown": false, + "Pump1Failure": false, + "Pump2PopOffValveBlown": false, + "Pump2Failure": false, + "Pump3PopOffValveBlown": false, + "Pump3Failure": false, + "DrawworksGearsAbuse": false, + "RotaryGearsAbuse": false, + "HoistLineBreak": false, + "PartedDrillString": false, + "ActiveTankOverflow": false, + "ActiveTankUnderVolume": false, + "TripTankOverflow": false, + "DrillPipeTwistOff": false, + "DrillPipeParted": false, + "TripWithSlipsSet": false, + "Blowout": false, + "UndergroundBlowout": false, + "MaximumWellDepthExceeded": false, + "CrownCollision": false, + "FloorCollision": false, + "TopdriveRotaryTableConfilict": false + }, + "Problems": { + "BitProblems": { + "JetWashout": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "PlugJets": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "JetWashoutCount": 0, + "PlugJetsCount": 0 + }, + "BopProblems": { + "AnnularWash": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AnnularFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AnnularLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "UpperRamWash": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "UpperRamFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "UpperRamLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "MiddleRamWash": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "MiddleRamFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "MiddleRamLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "LowerRamWash": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "LowerRamFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "LowerRamLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AccumulatorPumpFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AccumulatorPumpLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AccumulatorSystemFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AccumulatorSystemLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } + }, + "ChokeProblems": { + "HydraulicChoke1Plugged": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "HydraulicChoke1Fail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "HydraulicChoke1Washout": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "HydraulicChoke2Plugged": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "HydraulicChoke2Fail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "HydraulicChoke2Washout": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke1Plugged": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke1Fail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke1Washout": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke2Plugged": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke2Fail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke2Washout": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ChokePanelAirFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } + }, + "DrillStemsProblems": { + "StringDragIncrease": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StringTorqueIncrease": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StringTorqueFluctuation": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StringDragIncreaseTime": 0.0E+0, + "StringTorqueIncreaseTime": 0.0E+0 + }, + "GaugesProblems": { + "WeightIndicator": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "RotaryRpm": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "RotaryTorque": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StandPipePressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "CasingPressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Pump1Strokes": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Pump2Strokes": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ReturnLineTemperature": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "TripTank": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "PitGainLoss": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "MudTankVolume": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ReturnMudFlow": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "TorqueLimit": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "PowerLimit": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AccumulatorPressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManifoldPressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AnnularPressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "RigAirPressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StandPipe1": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StandPipe2": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "DrillPipePressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ChokePosition": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "CasingPressure2": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } + }, + "HoistingProblems": { + "MotorFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ClutchEngage": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ClutchDisengage": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } + }, + "KickProblems": { + "Kick": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "FluidType": 0, + "FlowRate": 0, + "OverBalancePressure": 0, + "IsAutoMigrationRateSelected": false, + "AutoMigrationRate": 0.0E+0 + }, + "Configuration": { + "LostCirculation": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "FlowRate": 0.0E+0 + }, + "MudTreatmentProblems": { + "Degasser": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ShaleShaker": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Desander": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Desilter": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } + }, + "OtherProblems": { + "RigAlarm": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "RigWaterSupply": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "RigAir": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Gen1": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Gen2": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Gen3": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Gen4": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Scr1": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Scr2": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Scr3": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Scr4": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } + }, + "PumpProblems": { + "Pump1PowerFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Pump1BlowPopOffValve": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Pump2PowerFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Pump2BlowPopOffValve": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "CementPumpPowerFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "CementPumpBlowPopOffValve": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } + }, + "RotaryProblems": { + "MotorFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "OverideTorqueLimit": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } + } + }, + "Equipments": { + "BopControl": { + "AnnularRegulatorSetControl": 0.0E+0, + "AirMasterValve": 0.0E+0, + "ByePassValve": 0.0E+0, + "AnnularValve": 0.0E+0, + "UpperRamsValve": 0.0E+0, + "MiddleRamsValve": 0.0E+0, + "KillLineValve": 0.0E+0, + "ChokeLineValve": 0.0E+0, + "LowerRamsValve": 0.0E+0, + "ManifoldPressureGauge": 0.0E+0, + "AirSupplyPressureGauge": 0.0E+0, + "AccumulatorPressureGauge": 0.0E+0, + "AnnularPressureGauge": 0.0E+0, + "AnnularOpenLED": 0, + "AnnularCloseLED": 0, + "UpperRamsOpenLED": 0, + "UpperRamsCloseLED": 0, + "MiddleRamsOpenLED": 0, + "MiddleRamsCloseLED": 0, + "KillLineOpenLED": 0, + "KillLineCloseLED": 0, + "ChokeLineOpenLED": 0, + "ChokeLineCloseLED": 0, + "LowerRamsOpenLED": 0, + "LowerRamsCloseLED": 0, + "AnnularStatus": 0.0E+0, + "UpperRamsStatus": 0.0E+0, + "MiddleRamsStatus": 0.0E+0, + "LowerRamsStatus": 0.0E+0 + }, + "ChokeControl": { + "ChokePanelPumpSelectorSwitch": 0, + "ChokePanelStrokeResetSwitch": false, + "ChokeSelectorSwitch": false, + "ChokeRateControlKnob": 0.0E+0, + "ChokeControlLever": 0.0E+0, + "ChokePanelRigAirSwitch": false, + "EnableAutoChoke": false, + "StandPipePressure": 0.0E+0, + "CasingPressure": 0.0E+0, + "ChokePosition": 0.0E+0, + "ChokePanelSPMCounter": 0.0E+0, + "ChokePanelTotalStrokeCounter": 0.0E+0, + "Choke1LED": 0, + "Choke2LED": 0 + }, + "ChokeManifold": { + "ChokeManifoldValve1": false, + "ChokeManifoldValve2": false, + "LeftManualChoke": 0.0E+0, + "ChokeManifoldValve4": false, + "ChokeManifoldValve5": false, + "RightManualChoke": 0.0E+0, + "ChokeManifoldValve7": false, + "ChokeManifoldValve8": false, + "ChokeManifoldValve9": false, + "ChokeManifoldValve10": false, + "ChokeManifoldValve11": false, + "ChokeManifoldValve12": false, + "ChokeManifoldValve13": false, + "HydraulicChock1": 0, + "HydraulicChock2": 0, + "HyChock1OnProblem": false, + "HyChock2OnProblem": false, + "LeftManChokeOnProblem": false, + "RightManChokeOnProblem": false + }, + "DataDisplay": { + "TripAlarmLow": 0.0E+0, + "TripAlarmHigh": 0.0E+0, + "RetFlowAlarmLow": 0.0E+0, + "RetFlowAlarmHigh": 0.0E+0, + "PitAlarmLow": 0.0E+0, + "PitAlarmHigh": 0.0E+0, + "PortWeightOnBit": 0.0E+0, + "PortHookLoad": 0.0E+0, + "PortCasingPressure": 0.0E+0, + "PortPumpPressure": 0.0E+0, + "TripTankSetAlarmLow": 0.0E+0, + "TripTankSetAlarmHigh": 0.0E+0, + "TripTankSetAlarmSwitch": 0, + "TripTankPowerSwitch": false, + "TripTankPumpSwitch": false, + "TripTankHornSwitch": false, + "AcidGasDetectionHornSwitch": false, + "TotalStrokeCounterResetSwitch": false, + "DrillingTrippingSelectorSwitch": false, + "MVTSetAlarmLowKnob": 0.0E+0, + "MVTSetAlarmHighKnob": 0.0E+0, + "MVTSetAlarmSwitch": 0, + "MudTank1Switch": false, + "MudTank2Switch": false, + "MudTank3Switch": false, + "MudTank4Switch": false, + "MVTFineKnob": 0.0E+0, + "MVTCoarseKnob": 0.0E+0, + "MVTHornSwitch": false, + "MVTDeviationTripSelectionSwitch": false, + "MVTPowerSwitch": false, + "MFFIResetTotalStrokes": false, + "MFFIResetFillCounter": false, + "MFFIPumpSelectorSwitch": 0, + "MFFIFillSPMSelectorSwitch": false, + "MFFISetAlarmLowKnob": 0.0E+0, + "MFFISetAlarmHighKnob": 0.0E+0, + "MFFISetAlarmSwitch": 0, + "MFFIPowerSwitch": false, + "MFFIHornSwitch": false, + "ResetWob": false, + "Clutch": false, + "WOBPointer": 0.0E+0, + "HookLoadPointer": 0.0E+0, + "TripTankGauge": 0.0E+0, + "TripTankAlarmLED": 0, + "TripTankPumpLED": 0, + "StandPipePressureGauge": 0.0E+0, + "CasingPressureGauge": 0.0E+0, + "MP1SPMGauge": 0.0E+0, + "MP2SPMGauge": 0.0E+0, + "ReturnLineTempGauge": 0.0E+0, + "RotaryTorqueGauge": 0.0E+0, + "RotaryRPMGauge": 0.0E+0, + "AcidGasDetectionLED": 0, + "TotalStrokeCounter": 0.0E+0, + "PitGainLossGauge": 0.0E+0, + "MudTanksVolumeGauge": 0.0E+0, + "MVTAlarmLED": 0, + "ReturnMudFlowGauge": 0.0E+0, + "FillStrokeCounter": 0.0E+0, + "MFFITotalStrokeCounter": 0.0E+0, + "MFFIAlarmLED": 0, + "MFFIPumpLED": 0, + "TotalWellDepth": 0.0E+0, + "BitDepth": 0.0E+0, + "HookLoad": 0.0E+0, + "StandPipePressure": 0.0E+0, + "CasingPressure": 0.0E+0, + "MP1SPM": 0.0E+0, + "MP2SPM": 0.0E+0, + "RTTorque": 0.0E+0, + "RTRPM": 0.0E+0, + "WOP": 0.0E+0, + "ROP": 0.0E+0, + "MudWeightIn": 0.0E+0, + "MudWeightOut": 0.0E+0, + "Buzzer1": false, + "Buzzer2": false, + "Buzzer3": false, + "Buzzer4": false + }, + "Drilling": { + "AssignmentSwitch": 0, + "EmergencySwitch": false, + "RTTorqueLimitKnob": 0.0E+0, + "MP1CPSwitchI": 0, + "MP1CPSwitchT": 0, + "MP1CPSwitch": 0, + "MP1ThrottleUpdate": false, + "MP1Throttle": -0.1E+1, + "MP2SwitchI": 0, + "MP2SwitchT": false, + "MP2Switch": false, + "MP2ThrottleUpdate": false, + "MP2Throttle": -0.1E+1, + "DWSwitch": 0, + "DWThrottle": 0.0E+0, + "RTSwitch": 0, + "RTThrottle": 0.0E+0, + "DWBreak": 0.0E+0, + "PreviousDWBreak": 0.0E+0, + "ForceBreak": false, + "DWAcceleretor": 0.0E+0, + "DWTransmisionLever": 0.0E+0, + "DWPowerLever": 0.0E+0, + "TongLever": 0.0E+0, + "RTTransmissionLever": 0.0E+0, + "DWClutchLever": 0.0E+0, + "EddyBreakLever": 0.0E+0, + "AutoDW": false, + "GEN1": false, + "GEN2": false, + "GEN3": false, + "GEN4": false, + "Permission_OpenKellyCock": false, + "OpenKellyCock": false, + "Permission_CloseKellyCock": false, + "CloseKellyCock": false, + "Permission_OpenSafetyValve": false, + "OpenSafetyValve": false, + "Permission_CloseSafetyValve": false, + "CloseSafetyValve": false, + "Permission_IRSafetyValve": false, + "IRSafetyValve": false, + "Permission_IRIBop": false, + "IRIBop": false, + "LatchPipe": false, + "UnlatchPipe": false, + "Swing": false, + "FillMouseHole": false, + "Slips": false, + "BrakeLeverCoefficient": 0.0E+0, + "HideDrillingBrake": false, + "ParkingBrakeBtn": false, + "ParkingBrakeLed": false, + "GEN1LED": 0, + "GEN2LED": 0, + "GEN3LED": 0, + "GEN4LED": 0, + "SCR1LED": 0, + "SCR2LED": 0, + "SCR3LED": 0, + "SCR4LED": 0, + "MP1BLWR": 0, + "MP2BLWR": 0, + "DWBLWR": 0, + "RTBLWR": 0, + "PWRLIM": 0, + "PWRLIMMTR": 0.0E+0, + "RTTorqueLimitGauge": 0.0E+0, + "AutoDWLED": 0, + "GEN1BTNLED": 0, + "GEN2BTNLED": 0, + "GEN3BTNLED": 0, + "GEN4BTNLED": 0, + "OpenKellyCockLed": 0, + "CloseKellyCockLed": 0, + "OpenSafetyValveLed": 0, + "CloseSafetyValveLed": 0, + "IRSafetyValveLed": 0, + "IRIBopLed": 0, + "LatchPipeLED": 0, + "UnlatchPipeLED": 0, + "SwingLed": 0, + "FillMouseHoleLed": 0 + }, + "Hook": { + "HookHeight_S": 0.0E+0, + "HookHeight": 0.0E+0 + }, + "StandPipeManifold": { + "StandPipeManifoldValve1": false, + "StandPipeManifoldValve2": false, + "StandPipeManifoldValve3": false, + "StandPipeManifoldValve4": false, + "StandPipeManifoldValve5": false, + "StandPipeManifoldValve6": false, + "StandPipeManifoldValve7": false, + "StandPipeManifoldValve8": false, + "StandPipeManifoldValve9": false, + "StandPipeManifoldValve10": false, + "StandPipeManifoldValve11": false, + "StandPipeManifoldValve12": false, + "StandPipeManifoldValve13": false, + "StandPipeManifoldValve14": false, + "StandPipeManifoldValve15": false, + "StandPipeGauge1": 0.0E+0, + "StandPipeGauge2": 0.0E+0 + }, + "DrillingWatch": { + "Depth": 0.0E+0, + "BitPosition": 0.0E+0, + "HookLoad": 0.0E+0, + "WeightOnBit": 0.0E+0, + "RPM": 0.0E+0, + "ROP": 0.0E+0, + "Torque": 0.0E+0, + "PumpPressure": 0.0E+0, + "SPM1": 0.0E+0, + "SPM2": 0.0E+0, + "CasingPressure": 0.0E+0, + "PercentFlow": 0.0E+0, + "PitGainLose": 0.0E+0, + "PitVolume": 0.0E+0, + "KillMudVolume": 0.0E+0, + "TripTankVolume": 0.0E+0, + "MudWeightIn": 0.0E+0, + "FillVolume": 0.0E+0, + "MudWeightOut": 0.0E+0 + }, + "Tank": [] + } +} + diff --git a/test.json b/test.json index 3df0ef5..7df7012 100644 --- a/test.json +++ b/test.json @@ -1,28 +1,31 @@ { + "status": 0, + "speed": 0, + "endstep": 0, "Configuration": { "StringConfiguration": { "StringConfigurationItems": [ { - "ComponentType": 1, - "NumberOfJoint": 0, - "LengthPerJoint": 0, - "NominalOd": 0, - "NominalId": 0, - "WeightPerLength": 0, - "ComponentLength": 0.15E+1, - "NominalToolJointOd": 0, - "Grade": "A" + "ComponentLength": 0.88931816251424378E-322, + "ComponentType": 0, + "Grade": "A", + "LengthPerJoint": 0.0E+0, + "NominalId": 0.0E+0, + "NominalOd": 0.0E+0, + "NominalToolJointOd": 0.0E+0, + "NumberOfJoint": 0.0E+0, + "WeightPerLength": 0.0E+0 }, { - "ComponentType": 2, - "NumberOfJoint": 0, - "LengthPerJoint": 0, - "NominalOd": 0, - "NominalId": 0, - "WeightPerLength": 0, - "ComponentLength": 0.26000000000000001E+1, - "NominalToolJointOd": 0, - "Grade": "B" + "ComponentLength": 0.0E+0, + "ComponentType": 0, + "Grade": "B", + "LengthPerJoint": 0.0E+0, + "NominalId": 0.0E+0, + "NominalOd": 0.0E+0, + "NominalToolJointOd": 0.63240402667679558E-321, + "NumberOfJoint": 0.0E+0, + "WeightPerLength": 0.0E+0 } ], "BitDefenition": { @@ -38,28 +41,28 @@ "FloatValve": false } }, - "Fromations": [ + "Formations": [ { - "Top": 0, - "Thickness": 0, - "Drillablity": 0, - "Abrasiveness": 0, - "ThresholdWeight": 0, - "PorePressureGradient": 0 + "Abrasiveness": 0.21312660155733048E-263, + "Drillablity": 0.6320758923451116E-66, + "PorePressureGradient": 0.28008646127460173E-84, + "Thickness": 0.65823145377002607E+181, + "ThresholdWeight": 0.19550125239880232E+209, + "Top": 0.0E+0 }, { - "Top": 0, - "Thickness": 0, - "Drillablity": 0, - "Abrasiveness": 0, - "ThresholdWeight": 0, - "PorePressureGradient": 0 + "Abrasiveness": 0.43520275400635665E+252, + "Drillablity": 0.9083672029223863E+224, + "PorePressureGradient": 0.81573800331711587E-42, + "Thickness": 0.51434297357626681E+171, + "ThresholdWeight": 0.1490043928945281E+196, + "Top": 0.1E+4 } ], "Reservoir": { "AutoMigrationRate": 0.0E+0, - "FluidGradient": 0.0E+0, - "FluidType": 0, + "FluidGradient": 0.49406564584124654E-323, + "FluidType": 1073741952, "FluidViscosity": 0.0E+0, "FormationNo": 0, "FormationPermeability": 0.0E+0, @@ -79,50 +82,50 @@ "ShoeDepth": 0.0E+0 }, "Accumulator": { - "AccumulatorMinimumOperatingPressure": 0.0E+0, + "AccumulatorMinimumOperatingPressure": 0.49406564584124654E-323, "AccumulatorSystemSize": 0.0E+0, "AirPlungerPumpOutput": 0.0E+0, "ElectricPumpOutput": 0.0E+0, - "NumberOfBottels": 0, - "OilTankVolume": 0.0E+0, - "PrechargePressure": 0.0E+0, + "NumberOfBottels": 1, + "OilTankVolume": 0.98813129168249309E-323, + "PrechargePressure": 0.35572726500569751E-321, "StartPressure": 0.0E+0, "StartPressure2": 0.0E+0, "StopPressure": 0.0E+0, "StopPressure2": 0.0E+0 }, "BopStack": { - "AboveAnnularHeight": 0.1E+2, + "AboveAnnularHeight": 0.0E+0, "AnnularPreventerClose": 0.0E+0, - "AnnularPreventerHeight": 0.10199999999999999E+2, + "AnnularPreventerHeight": 0.0E+0, "AnnularPreventerOpen": 0.0E+0, "AnnularStringDrag": 0.0E+0, "BlindRamClose": 0.0E+0, - "BlindRamHeight": 0.16239999999999998E+2, + "BlindRamHeight": 0.23715151000379834E-321, "BlindRamOpen": 0.0E+0, "ChokeClose": 0.0E+0, "ChokeLineId": 0.0E+0, "ChokeLineLength": 0.0E+0, - "ChokeOpen": 0.0E+0, - "GroundLevel": 0.3E+2, - "KillClose": 0.15E+1, - "KillHeight": 0.18800000000000001E+2, - "KillOpen": 0.15E+1, - "LowerRamClose": 0.0E+0, - "LowerRamHeight": 0.21350000000000001E+2, - "LowerRamOpen": 0.0E+0, + "ChokeOpen": 0.49406564584124654E-323, + "GroundLevel": 0.0E+0, + "KillClose": 0.49406564584124654E-323, + "KillHeight": 0.0E+0, + "KillOpen": 0.53049901345204898E-314, + "LowerRamClose": 0.23715151000379834E-321, + "LowerRamHeight": 0.11419335319803565E-315, + "LowerRamOpen": 0.98813129168249309E-323, "RamStringDrag": 0.0E+0, "UpperRamClose": 0.0E+0, - "UpperRamHeight": 0.14632E+2, + "UpperRamHeight": 0.98813129168249309E-323, "UpperRamOpen": 0.0E+0 }, "Hoisting": { - "DrillingLineBreakingLoadAbrasiveness": 0.0E+0, - "DriveTypeAbrasiveness": 0, - "KellyWeightAbrasiveness": 0.0E+0, - "NumberOfLineAbrasiveness": 0, - "TopDriveWeightAbrasiveness": 0.0E+0, - "TravelingBlockWeightAbrasiveness": 0.0E+0 + "DrillingLineBreakingLoad": 0.0E+0, + "DriveType": 0, + "KellyWeight": 0.0E+0, + "NumberOfLine": 0, + "TopDriveWeight": 0.0E+0, + "TravelingBlockWeight": 0.0E+0 }, "Power": { "CementPump": 0.0E+0, @@ -138,15 +141,15 @@ "MudPump1LinerDiameter": 0.0E+0, "MudPump1Stroke": 0.0E+0, "MudPump1MechanicalEfficiency": 0.0E+0, - "MudPump1VolumetricEfficiency": 0.0E+0, - "MudPump1Output": 0.0E+0, - "MudPump1OutputBblStroke": 0.0E+0, - "MudPump1Maximum": 0.0E+0, - "MudPump1ReliefValvePressure": 0.0E+0, - "MudPump2LinerDiameter": 0.0E+0, - "MudPump2Stroke": 0.0E+0, - "MudPump2MechanicalEfficiency": 0.0E+0, - "MudPump2VolumetricEfficiency": 0.0E+0, + "MudPump1VolumetricEfficiency": 0.1E+2, + "MudPump1Output": 0.10199999999999999E+2, + "MudPump1OutputBblStroke": 0.14632E+2, + "MudPump1Maximum": 0.21350000000000001E+2, + "MudPump1ReliefValvePressure": 0.16239999999999998E+2, + "MudPump2LinerDiameter": 0.18800000000000001E+2, + "MudPump2Stroke": 0.15E+1, + "MudPump2MechanicalEfficiency": 0.15E+1, + "MudPump2VolumetricEfficiency": 0.3E+2, "MudPump2Output": 0.0E+0, "MudPump2OutputBblStroke": 0.0E+0, "MudPump2Maximum": 0.0E+0, @@ -196,31 +199,21 @@ "Items": [ { "HoleType": 0, - "Angle": 0, - "Length": 0, - "FinalAngle": 0, - "TotalLength": 0, - "MeasuredDepth": 0, - "TotalVerticalDepth": 0 - }, - { - "HoleType": 0, - "Angle": 0, - "Length": 0, - "FinalAngle": 0, - "TotalLength": 0, - "MeasuredDepth": 0, - "TotalVerticalDepth": 0 - } - ], - "DataPoints": [ - { - "X": 0, - "Y": 0 + "Angle": 0.0E+0, + "Length": 0.1E+4, + "FinalAngle": 0.81573800331703431E-42, + "TotalLength": 0.25384625402140253E+266, + "MeasuredDepth": 0.85260404050988764E+248, + "TotalVerticalDepth": 0.13849770568415003E+220 }, { - "X": 0, - "Y": 0 + "HoleType": 926036234, + "Angle": 0.73530327575511794E+224, + "Length": 0.2E+4, + "FinalAngle": 0.78365824094029884E+200, + "TotalLength": 0.38606650640394845E-85, + "MeasuredDepth": 0.10912776606995678E+276, + "TotalVerticalDepth": 0.57356744358002641E+170 } ] }, @@ -246,267 +239,706 @@ "ActiveTotalTankCapacityGal": 0.0E+0, "ActiveSettledContents": 0.0E+0, "ActiveSettledContentsGal": 0.0E+0, - "ActiveTotalContents": 0.0E+0, - "ActiveTotalContentsGal": 0.0E+0, + "ActiveTotalContents": 0.98813129168249309E-323, + "ActiveTotalContentsGal": 0.11419398560206232E-315, "ActiveAutoDensity": false, "InitialTripTankMudVolume": 0.0E+0, - "InitialTripTankMudVolumeGal": 0.0E+0, - "PedalFlowMeter": 0.0E+0 + "InitialTripTankMudVolumeGal": 0.53049901345204898E-314, + "PedalFlowMeter": 0.49406564584124654E-323 } }, - "Configuration": { - "StringConfiguration": { - "StringConfigurationItems": [ - { - "ComponentType": 1, - "NumberOfJoint": 0, - "LengthPerJoint": 0, - "NominalOd": 0, - "NominalId": 0, - "WeightPerLength": 0, - "ComponentLength": 0.15E+1, - "NominalToolJointOd": 0, - "Grade": "A" - }, - { - "ComponentType": 2, - "NumberOfJoint": 0, - "LengthPerJoint": 0, - "NominalOd": 0, - "NominalId": 0, - "WeightPerLength": 0, - "ComponentLength": 0.26000000000000001E+1, - "NominalToolJointOd": 0, - "Grade": "B" - } - ], - "BitDefenition": { - "BitCodeHundreds": 0, - "BitCodeOnes": 0, - "BitCodeTens": 0, - "BitLength": 0.0E+0, - "BitNozzleNo": 0, - "BitNozzleSize": 0.0E+0, - "BitSize": 0.0E+0, - "BitType": 0, - "BitWeightPerLength": 0.0E+0, - "FloatValve": false + "Problems": { + "BitProblems": { + "JetWashout": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.53049901345204898E-314, + "DueValue": 0.49406564584124654E-323 + }, + "PlugJets": { + "ProblemType": 2, + "StatusType": 0, + "Value": 0.11419398560206232E-315, + "DueValue": 0.27667676167109806E-321 + }, + "JetWashoutCount": 0, + "PlugJetsCount": 0 + }, + "BopProblems": { + "AnnularWash": { + "ProblemType": 2, + "StatusType": 0, + "Value": 0.27667676167109806E-321, + "DueValue": 0.49406564584124654E-323 + }, + "AnnularFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AnnularLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "UpperRamWash": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "UpperRamFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "UpperRamLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "MiddleRamWash": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "MiddleRamFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "MiddleRamLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "LowerRamWash": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "LowerRamFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "LowerRamLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AccumulatorPumpFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AccumulatorPumpLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AccumulatorSystemFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AccumulatorSystemLeak": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 } }, - "Fromations": [ - { - "Top": 0, - "Thickness": 0, - "Drillablity": 0, - "Abrasiveness": 0, - "ThresholdWeight": 0, - "PorePressureGradient": 0 + "ChokeProblems": { + "HydraulicChoke1Plugged": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 }, - { - "Top": 0, - "Thickness": 0, - "Drillablity": 0, - "Abrasiveness": 0, - "ThresholdWeight": 0, - "PorePressureGradient": 0 + "HydraulicChoke1Fail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "HydraulicChoke1Washout": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "HydraulicChoke2Plugged": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "HydraulicChoke2Fail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "HydraulicChoke2Washout": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke1Plugged": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke1Fail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke1Washout": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke2Plugged": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke2Fail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke2Washout": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ChokePanelAirFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManualChoke1PluggedPercent": 0, + "HydraulicChoke2PluggedPercent": 0, + "HydraulicChoke1PluggedPercent": 0, + "ManualChoke2PluggedPercent": 0 + }, + "DrillStemsProblems": { + "StringDragIncrease": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StringTorqueIncrease": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StringTorqueFluctuation": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StringDragIncreaseTime": 0.0E+0, + "StringTorqueIncreaseTime": 0.0E+0 + }, + "GaugesProblems": { + "WeightIndicator": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "RotaryRpm": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "RotaryTorque": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StandPipePressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "CasingPressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Pump1Strokes": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Pump2Strokes": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ReturnLineTemperature": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "TripTank": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "PitGainLoss": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "MudTankVolume": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ReturnMudFlow": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "TorqueLimit": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "PowerLimit": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AccumulatorPressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ManifoldPressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "AnnularPressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "RigAirPressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StandPipe1": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "StandPipe2": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "DrillPipePressure": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ChokePosition": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "CasingPressure2": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 } - ], - "Reservoir": { - "AutoMigrationRate": 0.0E+0, - "FluidGradient": 0.0E+0, + }, + "HoistingProblems": { + "MotorFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ClutchEngage": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ClutchDisengage": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } + }, + "KickProblems": { + "Kick": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, "FluidType": 0, - "FluidViscosity": 0.0E+0, - "FormationNo": 0, - "FormationPermeability": 0.0E+0, - "FormationTop": 0.0E+0, - "GeothermalGradient": 0.0E+0, - "InactiveInflux": false, + "FlowRate": 0, + "OverBalancePressure": 0, "IsAutoMigrationRateSelected": false, - "MakeKickSinglePacket": false, - "PressureGradient": 0.0E+0 + "AutoMigrationRate": 0.0E+0 }, - "Shoe": { - "Breakdown": 0.0E+0, - "FormationNo": 0, - "FracturePropagation": 0.0E+0, - "InactiveFracture": false, - "LeakOff": 0.0E+0, - "ShoeDepth": 0.0E+0 + "LostProblems": { + "LostCirculation": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "FlowRate": 0.0E+0 }, - "Accumulator": { - "AccumulatorMinimumOperatingPressure": 0.0E+0, - "AccumulatorSystemSize": 0.0E+0, - "AirPlungerPumpOutput": 0.0E+0, - "ElectricPumpOutput": 0.0E+0, - "NumberOfBottels": 0, - "OilTankVolume": 0.0E+0, - "PrechargePressure": 0.0E+0, - "StartPressure": 0.0E+0, - "StartPressure2": 0.0E+0, - "StopPressure": 0.0E+0, - "StopPressure2": 0.0E+0 + "MudTreatmentProblems": { + "Degasser": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "ShaleShaker": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Desander": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Desilter": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } }, - "BopStack": { - "AboveAnnularHeight": 0.1E+2, - "AnnularPreventerClose": 0.0E+0, - "AnnularPreventerHeight": 0.10199999999999999E+2, - "AnnularPreventerOpen": 0.0E+0, - "AnnularStringDrag": 0.0E+0, - "BlindRamClose": 0.0E+0, - "BlindRamHeight": 0.16239999999999998E+2, - "BlindRamOpen": 0.0E+0, - "ChokeClose": 0.0E+0, - "ChokeLineId": 0.0E+0, - "ChokeLineLength": 0.0E+0, - "ChokeOpen": 0.0E+0, - "GroundLevel": 0.3E+2, - "KillClose": 0.15E+1, - "KillHeight": 0.18800000000000001E+2, - "KillOpen": 0.15E+1, - "LowerRamClose": 0.0E+0, - "LowerRamHeight": 0.21350000000000001E+2, - "LowerRamOpen": 0.0E+0, - "RamStringDrag": 0.0E+0, - "UpperRamClose": 0.0E+0, - "UpperRamHeight": 0.14632E+2, - "UpperRamOpen": 0.0E+0 + "OtherProblems": { + "RigAlarm": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "RigWaterSupply": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "RigAir": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Gen1": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Gen2": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Gen3": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Gen4": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Scr1": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Scr2": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Scr3": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Scr4": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } }, - "Hoisting": { - "DrillingLineBreakingLoadAbrasiveness": 0.0E+0, - "DriveTypeAbrasiveness": 0, - "KellyWeightAbrasiveness": 0.0E+0, - "NumberOfLineAbrasiveness": 0, - "TopDriveWeightAbrasiveness": 0.0E+0, - "TravelingBlockWeightAbrasiveness": 0.0E+0 + "PumpProblems": { + "Pump1PowerFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Pump1BlowPopOffValve": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Pump2PowerFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "Pump2BlowPopOffValve": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "CementPumpPowerFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "CementPumpBlowPopOffValve": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } }, - "Power": { - "CementPump": 0.0E+0, - "Drawworks": 0.0E+0, - "GeneratorPowerRating": 0.0E+0, - "MudPump1": 0.0E+0, - "MudPump2": 0.0E+0, - "NumberOfgenerators": 0, - "RotaryTable": 0.0E+0, - "TopDrive": 0.0E+0 + "RotaryProblems": { + "MotorFail": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + }, + "OverideTorqueLimit": { + "ProblemType": 0, + "StatusType": 0, + "Value": 0.0E+0, + "DueValue": 0.0E+0 + } + } + }, + "Equipments": { + "BopControl": { + "ManifoldPressureGauge": 0.0E+0, + "AirSupplyPressureGauge": 0.0E+0, + "AccumulatorPressureGauge": 0.0E+0, + "AnnularPressureGauge": 0.0E+0, + "AnnularOpenLED": 0, + "AnnularCloseLED": 0, + "UpperRamsOpenLED": 0, + "UpperRamsCloseLED": 0, + "MiddleRamsOpenLED": 0, + "MiddleRamsCloseLED": 0, + "KillLineOpenLED": 0, + "KillLineCloseLED": 0, + "ChokeLineOpenLED": 0, + "ChokeLineCloseLED": 0, + "LowerRamsOpenLED": 0, + "LowerRamsCloseLED": 0, + "AnnularStatus": 0.0E+0, + "UpperRamsStatus": 0.0E+0, + "MiddleRamsStatus": 0.0E+0, + "LowerRamsStatus": 0.0E+0 }, - "Pumps": { - "MudPump1LinerDiameter": 0.0E+0, - "MudPump1Stroke": 0.0E+0, - "MudPump1MechanicalEfficiency": 0.0E+0, - "MudPump1VolumetricEfficiency": 0.0E+0, - "MudPump1Output": 0.0E+0, - "MudPump1OutputBblStroke": 0.0E+0, - "MudPump1Maximum": 0.0E+0, - "MudPump1ReliefValvePressure": 0.0E+0, - "MudPump2LinerDiameter": 0.0E+0, - "MudPump2Stroke": 0.0E+0, - "MudPump2MechanicalEfficiency": 0.0E+0, - "MudPump2VolumetricEfficiency": 0.0E+0, - "MudPump2Output": 0.0E+0, - "MudPump2OutputBblStroke": 0.0E+0, - "MudPump2Maximum": 0.0E+0, - "MudPump2ReliefValvePressure": 0.0E+0, - "CementPumpLinerDiameter": 0.0E+0, - "CementPumpStroke": 0.0E+0, - "CementPumpMechanicalEfficiency": 0.0E+0, - "CementPumpVolumetricEfficiency": 0.0E+0, - "CementPumpOutput": 0.0E+0, - "CementPumpOutputBblStroke": 0.0E+0, - "CementPumpMaximum": 0.0E+0, - "CementPumpReliefValvePressure": 0.0E+0, - "MudPump1ReliefValveIsSet": false, - "MudPump2ReliefValveIsSet": false, - "CementPumpReliefValveIsSet": false, - "ManualPumpPower": false, - "Valve1": false, - "Valve2": false, - "Valve3": false, - "Valve4": false, - "Valve5": false + "ChokeControl": { + "StandPipePressure": 0.0E+0, + "CasingPressure": 0.0E+0, + "ChokePosition": 0.0E+0, + "ChokePanelSPMCounter": 0.0E+0, + "ChokePanelTotalStrokeCounter": 0.0E+0, + "Choke1LED": 0, + "Choke2LED": 0 }, - "RigSize": { - "RigType": 0, - "CrownHeight": 0.0E+0, - "MonkeyBoandHeight": 0.0E+0, - "RigFloorHeight": 0.0E+0 + "ChokeManifold": { + "HydraulicChock1": 0, + "HydraulicChock2": 0, + "HyChock1OnProblem": false, + "HyChock2OnProblem": false, + "LeftManChokeOnProblem": false, + "RightManChokeOnProblem": false }, - "CasingLinerChoke": { - "CasingDepth": 0.0E+0, - "CasingId": 0.0E+0, - "CasingOd": 0.0E+0, - "CasingWeight": 0.0E+0, - "CasingCollapsePressure": 0.0E+0, - "CasingTensileStrength": 0.0E+0, - "LinerTopDepth": 0.0E+0, - "LinerLength": 0.0E+0, - "LinerId": 0.0E+0, - "LinerOd": 0.0E+0, - "LinerWeight": 0.0E+0, - "LinerCollapsePressure": 0.0E+0, - "LinerTensileStrength": 0.0E+0, - "OpenHoleId": 0.0E+0, - "OpenHoleLength": 0.0E+0 + "DataDisplay": { + "WOBPointer": 0.0E+0, + "HookLoadPointer": 0.0E+0, + "TripTankGauge": 0.0E+0, + "TripTankAlarmLED": 0, + "TripTankPumpLED": 0, + "StandPipePressureGauge": 0.0E+0, + "CasingPressureGauge": 0.0E+0, + "MP1SPMGauge": 0.0E+0, + "MP2SPMGauge": 0.0E+0, + "ReturnLineTempGauge": 0.0E+0, + "RotaryTorqueGauge": 0.0E+0, + "RotaryRPMGauge": 0.0E+0, + "AcidGasDetectionLED": 0, + "TotalStrokeCounter": 0.0E+0, + "PitGainLossGauge": 0.0E+0, + "MudTanksVolumeGauge": 0.0E+0, + "MVTAlarmLED": 0, + "ReturnMudFlowGauge": 0.0E+0, + "FillStrokeCounter": 0.0E+0, + "MFFITotalStrokeCounter": 0.0E+0, + "MFFIAlarmLED": 0, + "MFFIPumpLED": 0, + "TotalWellDepth": 0.0E+0, + "BitDepth": 0.0E+0, + "HookLoad": 0.0E+0, + "StandPipePressure": 0.0E+0, + "CasingPressure": 0.0E+0, + "MP1SPM": 0.0E+0, + "MP2SPM": 0.0E+0, + "RTTorque": 0.0E+0, + "RTRPM": 0.0E+0, + "WOP": 0.0E+0, + "ROP": 0.0E+0, + "MudWeightIn": 0.0E+0, + "MudWeightOut": 0.0E+0, + "Buzzer1": false, + "Buzzer2": false, + "Buzzer3": false, + "Buzzer4": false }, - "Path": { - "Items": [ - { - "HoleType": 0, - "Angle": 0, - "Length": 0, - "FinalAngle": 0, - "TotalLength": 0, - "MeasuredDepth": 0, - "TotalVerticalDepth": 0 - }, - { - "HoleType": 0, - "Angle": 0, - "Length": 0, - "FinalAngle": 0, - "TotalLength": 0, - "MeasuredDepth": 0, - "TotalVerticalDepth": 0 - } - ], - "DataPoints": [ - { - "X": 0, - "Y": 0 - }, - { - "X": 0, - "Y": 0 - } - ] + "Drilling": { + "ParkingBrakeLed": false, + "GEN1LED": 0, + "GEN2LED": 0, + "GEN3LED": 0, + "GEN4LED": 0, + "SCR1LED": 0, + "SCR2LED": 0, + "SCR3LED": 0, + "SCR4LED": 0, + "MP1BLWR": 0, + "MP2BLWR": 0, + "DWBLWR": 0, + "RTBLWR": 0, + "PWRLIM": 0, + "PWRLIMMTR": 0.0E+0, + "RTTorqueLimitGauge": 0.0E+0, + "AutoDWLED": 0, + "GEN1BTNLED": 0, + "GEN2BTNLED": 0, + "GEN3BTNLED": 0, + "GEN4BTNLED": 0, + "OpenKellyCockLed": 0, + "CloseKellyCockLed": 0, + "OpenSafetyValveLed": 0, + "CloseSafetyValveLed": 0, + "IRSafetyValveLed": 0, + "IRIBopLed": 0, + "LatchPipeLED": 0, + "UnlatchPipeLED": 0, + "SwingLed": 0, + "FillMouseHoleLed": 0 }, - "Mud": { - "ActiveMudType": 0, - "ActiveRheologyModel": 0, - "ActiveMudVolume": 0.0E+0, - "ActiveMudVolumeGal": 0.0E+0, - "ActiveDensity": 0.0E+0, - "ActivePlasticViscosity": 0.0E+0, - "ActiveYieldPoint": 0.0E+0, - "ActiveThetaThreeHundred": 0.0E+0, - "ActiveThetaSixHundred": 0.0E+0, - "ReserveMudType": 0, - "ReserveMudVolume": 0.0E+0, - "ReserveMudVolumeGal": 0.0E+0, - "ReserveDensity": 0.0E+0, - "ReservePlasticViscosity": 0.0E+0, - "ReserveYieldPoint": 0.0E+0, - "ReserveThetaThreeHundred": 0.0E+0, - "ReserveThetaSixHundred": 0.0E+0, - "ActiveTotalTankCapacity": 0.0E+0, - "ActiveTotalTankCapacityGal": 0.0E+0, - "ActiveSettledContents": 0.0E+0, - "ActiveSettledContentsGal": 0.0E+0, - "ActiveTotalContents": 0.0E+0, - "ActiveTotalContentsGal": 0.0E+0, - "ActiveAutoDensity": false, - "InitialTripTankMudVolume": 0.0E+0, - "InitialTripTankMudVolumeGal": 0.0E+0, - "PedalFlowMeter": 0.0E+0 + "Hook": { + "HookHeight_S": 0.0E+0, + "HookHeight": 0.0E+0 + }, + "StandPipeManifold": { + "StandPipeGauge1": 0.0E+0, + "StandPipeGauge2": 0.0E+0 + }, + "DrillingWatch": { + "Depth": 0.0E+0, + "BitPosition": 0.0E+0, + "HookLoad": 0.0E+0, + "WeightOnBit": 0.0E+0, + "RPM": 0.0E+0, + "ROP": 0.0E+0, + "Torque": 0.0E+0, + "PumpPressure": 0.0E+0, + "SPM1": 0.0E+0, + "SPM2": 0.0E+0, + "CasingPressure": 0.0E+0, + "PercentFlow": 0.0E+0, + "PitGainLose": 0.0E+0, + "PitVolume": 0.0E+0, + "KillMudVolume": 0.0E+0, + "TripTankVolume": 0.0E+0, + "MudWeightIn": 0.0E+0, + "FillVolume": 0.0E+0, + "MudWeightOut": 0.0E+0 } } } diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..b50bd89 --- /dev/null +++ b/todo.txt @@ -0,0 +1 @@ +/mnt/c/Projects/VSIM/SimulationCore2/CSharp/BasicInputs/Geology/CShoeVariables.f90 diff --git a/write_vars b/write_vars new file mode 100644 index 0000000..e1befa1 Binary files /dev/null and b/write_vars differ