Integrate Phast models with our versatile APIs for enhanced customization and efficiency.
typescript
import { VesselLeakCalculation, VesselStateCalculation } from "@dnv-plant/typescriptpws";
import { DischargeParameters, Leak, Material, MaterialComponent, State, Vessel } from "@dnv-plant/typescriptpws";
import { ResultCode, TimeVaryingOption, VesselShape } from "@dnv-plant/typescriptpws";
// Define the material contained by the vessel.
const material = new Material("METHANE", [new MaterialComponent("METHANE", 1.0)]);
// Define the initial state of the vessel.
const pressure = 2000000; // Pa
const temperature = 300; // K
const liquidFraction = 0.0;
const myState = new State(pressure, temperature, liquidFraction);
// Create a vessel state calculation using the material and state.
const vesselStateCalculation = new VesselStateCalculation();
vesselStateCalculation.material = material;
vesselStateCalculation.materialState = myState;
// Run the vessel state calculation.
vesselStateCalculation.run();
// Create a vessel entity and pass in the results from the VesselStateCalculation.
const vessel = new Vessel();
vessel.material = material;
vessel.state = myState;
vessel.vesselConditions = vesselStateCalculation.vesselConditions;
// Create a leak to use in the vessel leak calculation.
// The leak has a hole diameter of 50mm (0.05m). The hole height fraction is set to 0.0, which corresponds to the
// bottom of the vessel. The time-varying option is set to initial rate.
const leak = new Leak();
leak.holeDiameter = 0.05;
leak.holeHeightFraction = 0.0;
leak.timeVaryingOption = TimeVaryingOption.INITIAL_RATE;
// Create discharge parameters to use in the vessel leak calculation taking all the default values.
const dischargeParameters = new DischargeParameters();
// Create a vessel leak calculation using the vessel, leak, and discharge parameters.
const vesselLeakCalculation = new VesselLeakCalculation();
vesselLeakCalculation.vessel = vessel;
vesselLeakCalculation.leak = leak;
vesselLeakCalculation.dischargeParameters = dischargeParameters;
// Run the vessel leak calculation.
const resultCode = vesselLeakCalculation.run();
if (resultCode === ResultCode.SUCCESS) {
console.log('SUCCESS: vesselLeakCalculation');
} else {
console.log(FAILED vesselLeakCalculation with result code ${resultCode});
throw new Error(Vessel leak calculation failed with result code ${resultCode});
}
// Print any messages.
if (vesselLeakCalculation.messages.length > 0) {
console.log('Messages:');
vesselLeakCalculation.messages.forEach((message: string) => console.log(message));
}
``