1. Introduction
In recent years, digitalization has become increasingly important in achieving decarbonization objectives within the energy sector, influenced by both climate policies and global energy strategies. The European Union (EU) highlights digitalization as an essential component to reach the climate neutrality targets set by the European Green Deal, aiming for net-zero emissions by 2050 [
1]. Digital technologies specifically aid in effectively managing energy distribution networks, which face increased complexity due to the variability of renewable energy sources (expected to contribute at least 45% of total energy generation in the EU).
According to the International Energy Agency (IEA), the implementation of digital technologies such as data analytics, Digital Twins, and Internet of Things (IoT) systems can significantly enhance energy infrastructure efficiency, reliability, and flexibility, potentially reducing operational costs by 15–20% by 2040 [
2]. In this context, the digitalization of energy distribution networks, whether electrical, thermal, or gas, becomes indispensable to reduce energy consumption [
3]. Smart energy networks, where gas, electricity, and thermal systems interact, will be a key technology in achieving decarbonization goals [
4]. Digital integration helps manage growing uncertainties due to rising energy demands and greater penetration of renewable sources, thus enabling the development of adaptive and resilient infrastructures [
5].
Recent research also emphasizes that the implementation of advanced digital solutions like Digital Twins (DT) can substantially improve forecasting, real-time operation, and decision-making processes in energy networks, ultimately contributing to system optimization and emission reduction [
6]. DT are dynamic virtual representations of real-world systems, combining real-time IoT sensor data with predictive and optimization models [
7]. In electrical energy networks, DTs have progressed from theoretical concepts to functioning tools. A UK pilot by Deakin et al. showed a 56% reduction in solar export curtailment via real-time voltage control, using DT frameworks to mitigate measurement uncertainty [
8]. More broadly, DT integration in utility operations offers continuous monitoring, early failure detection, and resource optimization, boosting operational efficiency, reducing costs, and enhancing resilience [
9]. In gas networks, the benefits of digitalization are emerging rapidly [
10]. Yun et al. demonstrated that DTs could be used to increase overall energy supply-chain efficiency and to reduce operating cost and emissions in gas industries [
11]. Gas Networks Ireland is developing a DT for distribution assets, finding scalable benefits such as unified telemetry, maintenance planning, and emergency-response modelling [
12]. Thus, DTs in energy networks, especially for electric and gas systems, are more than digital replicas: they form integrated cyber-physical tools enabling enhanced monitoring, predictive maintenance, operational optimization, and improved decision-making.
Fluid dynamic simulation of natural gas pipeline networks with alternate low-calorific value gas, such as hydrogen and biomethane, has been conducted extensively for both long-distance transmission networks and regional distribution networks. In studies conducted, the pipeline networks used are either a dummy network or data [
13,
14] closely resembling an actual network, or predefined network data as obtained from GIS (Geographic Information System) software [
15] or network operators already processed [
16]. While
pandapipes [
17] in version 0.8.2 offers static fluid network simulation with structured component/result tables and basic thermal modelling, and
SAInt [
18] provides integrated electricity-gas co-simulation with transient gas dynamics, both lack detailed spatial data integration and realistic end-user mapping. In contrast, the proposed framework establishes a fully integrated DT, incorporating GIS-based topology, elevation mapping, 3D CAD (Computer-Aided Design) modelling, real consumption data (PDR-level), and hourly dynamic simulations through
GasNetSim. This multi-environment approach enables higher spatial-temporal resolution, fluid composition flexibility, and realistic scenario modelling, bridging key limitations in both pandapipes and SAInt. Lu et al. in their studies [
19,
20] presented a coupled power and gas system model with hydrogen-enriched natural gas, offering insights into integrated energy systems and their interdependencies. The authors developed a gas network simulation tool called
GasNetSim that allows for simulation of gas flow through it, with particular emphasis on how varying hydrogen concentrations affect gas flow dynamics and pressure drops in the network. Unlike recent studies on hydrogen blending in Italian distribution networks that relied on commercial/proprietary simulation codes [
21], the present study uses the open-source GasNetSim, integrated in a GIS to CAD workflow, to perform hourly fluid-dynamic simulations with explicit representation of network topology and end-user mapping.
Previous literature has shown that numerous studies focus on the simulation of gas networks. The widespread presence of such networks in developed countries, especially when blended with hydrogen, supports the decarbonisation of domestic hot water and space heating systems, as well as industrial and tertiary uses [
22]. However, reliable simulations and proper network operation require the digitalisation of existing infrastructure. Several limitations in the current state of the art can be identified:
Predominant use of closed-source simulation tools.
Limited information on data acquisition from operational networks.
Absence of DT applied in real case studies.
Minimal involvement of distribution system operators (DSOs).
In our previous studies conducted, various components such as elevation mapping [
23], user aggregation [
24] and simulation studies [
25] for peak and off-peak conditions were tested for smaller network sub-sections to evaluate the individual functionalities and explore further developments. In addition, this work presents a comprehensive methodology, from data collection to results visualisation, for developing a DT of a gas distribution network. This initial study is part of a broader objective aimed at developing smart energy networks, which will eventually include full integration with the electricity grid. It should be noted that this is an early version of a stand-alone tool, which will become available once an adequate technology readiness level is reached. Nevertheless, the aim of this work is to present a framework based exclusively on open-source tools, as detailed in the methodology, enhancing reproducibility and accessibility. The case study concerns a low-digitalised network, which posed specific challenges. Nevertheless, it highlights the flexibility and applicability of the proposed approach. Detailed explanations are provided regarding data processing, enhancement strategies, and data flows between system components. Finally, the methodology is applied to a real-world case study, demonstrating the potential of digital tools for supporting gas network management by DSOs. The structure of the paper is as follows:
Section 2 presents an overview of methodology, with a focus on both the physical system and its digital counterpart.
Section 3 outlines the components of the DT, including data handling, simulation, and visualisation.
Section 4 applies the framework to the case study, while
Section 5 present conclusions and future prospects of this work.
2. Methodology
This section presents the workflow developed for the implementation and use of the DT of a gas distribution network. The methodology describes how, by integrating open-source tools, the workflow effectively encompasses the entire digital lifecycle of the system, starting from the acquisition and digital conversion of physical data, advancing through modelling and simulation phases, and culminating in visualization and advanced analysis. Ensuring transparency and reproducibility across all development stages, the described process provides a solid basis for innovative and optimized management of network infrastructure.
The general framework proposed in this study is illustrated in
Figure 1, where the input–output dependencies are clarified. However, the specific functionalities of the DT components will be detailed in the following sections. Precisely this framework comprises four main components (see
Figure 1). The first is the real world, which includes the physical system, the actual counterpart of the network. The second is the Digital World, which encompasses the DT and manages the data flows exchanged between the physical system and its digital replica. From the Physical Twin, i.e., the physical and real counterpart of the gas network, two main types of information are extracted: firstly, the infrastructural characteristics of the network, such as pipelines and valves, and secondly, user consumption data, collected through metering devices. Information about the actual network model is captured and digitized in an interoperable format (e.g., shapefile), forming the Digital Data Infrastructure needed to build the DT.
Consumption data, on the other hand, is transmitted, hourly basis, from the meters to the distributor’s computer systems, to be subsequently processed and harmonized using computational and scripting tools (Python version 3.8), to make it compatible with the network structure in the Digital World. In the GIS environment (QGIS version 3.40.2) [
26], the Digital Data Infrastructure is used for detailed digitization of the physical network. At this stage, user locations are aggregated to network nodes, elevation data are integrated by extracting elevations from digital elevation models (DEMs) [
27], and all nodes are systematically indexed. The entire network, enriched with topological and elevation information, is then exported in metric format (such as .shp or DXF) for subsequent processing in the 3D CAD environment. Within the 3D CAD environment, FreeCAD version 1.0 [
28], which is also open source, the network is first imported from the GIS. Second, it is further enriched, through the aggregation of gas injection points information and the numerical indexing of nodes and pipelines, with the generation of structured files describing all its geometric and functional characteristics. These data are then exported to files compatible with the GasNetSim version 0.1.0 simulation environment. At the end of the simulation, the results produced are re-imported into FreeCAD, where they can be accessed, visualized, and processed using the GUI (Graphical User Interface) and special reporting tools, thus enabling effective and detailed evaluation of the simulated parameters. In the GasNetSim simulation environment, a Python-based open-source code, the structured data produced in FreeCAD (pipeline, node, and user files) is imported, and hourly consumption profiles are aggregated to the specific user consumption points on the network. This operation makes it possible to set up a dynamic or static simulation, in which the variation in parameters (e.g., pressure, flow rate, Wobbe Index, gross calorific value, etc.) is calculated hour by hour over the entire network. The simulation results, available for each node and pipeline section, are subsequently exported and can be visualized for reference and analysis in the CAD environment. The results obtained from the what-if analyses serve to guide user interaction with the DT, thereby supporting improved management of the Physical Twin (i.e., the gas network). The functionality of this feedback mechanism is illustrated by the dashed line in
Figure 1. Unlike SCADA systems and other supervisory monitoring solutions, which are designed to report real-time measurements, the proposed workflow uses the available consumption data to simulate the behaviour of the entire network, including all nodes and segments where no direct measurements are available. In fact this integrated approach provides a realistic and clear representation of gas network behaviour, making possible the analysis of complex operational scenarios and the exploration of possible optimization and innovation strategies from a completely open-source perspective.
2.1. The Physical World
The physical world refers to the real environment in which the energy system operates. The system is identified as the Physical Twin, representing the tangible components of the DT of the gas distribution network. Specifically, it consists of all the infrastructure and devices present in the network and directly involved in the process of transporting and delivering gas to the end users. This component can be divided into two basic macro-blocks.
The first, so-called grid and components, includes the entire physical network with its constituent elements: pipelines, junctions, control valves, pressure reduction devices, gas injection points, as well as all other equipment that contributes to the functionality, safety and flexibility of the network. Each element is characterized by several physical and technical attributes assigned, for example, for the pipelines: diameter, material of construction, and pressure range. Collectively, these elements form the foundational infrastructure that supports the network’s functionality and safety.
The second block is the Delivery Point, known in Italian as “Punto di Riconsegna” (PDR) (
Figure 2), the end users and meters, which is the set of delivery points and metering devices installed by the utilities. In this project, the focus is particularly on smart meters, which are meters capable of recording and transmitting hourly data on gas consumption. These devices capture key parameters such as volume delivered, gas temperature and instantaneous flow rate, enabling a reconstruction of the consumption profiles of each user. The data acquired from the meters are needed for feeding the digital model and for the subsequent simulation and analysis phase.
Thus, the Physical Twin component clearly distinguishes between the infrastructure component of the network and the consumption measurement and monitoring system, providing the necessary basis for the construction of a realistic and functional DT.
2.2. The Digital World
The second block in
Figure 1 is the Digital World. This block comprises the coordinated set of systems, processes, and digital tools dedicated to the collection, aggregation, normalization, and analysis of data originating from the Physical Twin of the gas network. Central to the Digital World are IT solutions and data management procedures that include the acquisition control systems, in Italian “Sistemi di Acquisizione e Controllo” (SAC), or Meter Data Management System (MDMS), a real-time data acquisition and control system responsible for the detection and transmission of consumption data from smart meters. Complementary to this, scripting and data management tools, primarily developed in Python, facilitate the harmonization and standardization of datasets. GIS platforms such as QGIS further integrate this data by enriching it with spatial, elevation, and topological attributes.
This comprehensive environment also encompasses three-dimensional modelling via 3D CAD software (e.g., FreeCAD), allowing for accurate reconstruction and geometric modification of the network, as well as simulation and analysis algorithms implemented through dedicated codes such as GasNetSim.
The entire workflow concludes in the processing, consultation, and visualization of results, which can be carried out within the CAD environment or using advanced visualization tools. Through this integrated approach, the Digital World provides a dynamic and continually updatable DT capable of supporting all monitoring activities, simulating various scenarios, including the injection of low-carbon gases such as hydrogen or biomethane, and facilitating validation and optimization of the gas distribution network.
2.2.1. Digital Data Infrastructure
The Digital Data Infrastructure represents the organized and structured set of all digital data derived from the physical infrastructure of the gas network, which is the foundation for modelling, analysis, and management of the DT.
The data are stored and managed in shapefile format, a standard widely adopted in GIS environments, which ensures interoperability and accuracy in the spatial representation of information that is thus georeferenced.
This data infrastructure primarily includes the pipelines (pipes) in the network, for which basic properties such as length, diameter, construction material, initial and final points of laying, year and date of installation, and type of cover (e.g., buried under asphalt, sidewalk or green area) are recorded. To these are added additional technical attributes such as the pressure categorisation (low, medium A or medium B, according to the Italian classification [
29,
30]), which defines the operating conditions of each network section.
The Digital Data Infrastructure also includes the location and characteristics of all network users (the PDRs position), with their spatial and master data are also managed in shapefile format. In addition to the simple geographic location, information acquired at the time the gas supply contract is signed is stored for each user: the type of consumption (according to the classes defined by ARERA [
31,
32]), the number of weekly days of gas withdrawal (e.g., 5, 6 or 7 days), the type and size of the installed meter, and the type of signal used by the device to send control data. These details make it possible to characterize each user’s profile in an hourly manner and to supplement the digital model with information associated with consumption and flow simulation.
Finally, the Digital Data Infrastructure includes information about the different types of nodes in the network: junctions, withdrawal points (which may serve one or more users depending on spatial density), control stations for cathodic protection, and other strategic devices. For each type of node, geometric, functional and operational properties are specified, so as to ensure a complete description of the morphology and functionality of the network.
2.2.2. User Consumption Data
End-user consumption data, referred to as User Consumption Data, consists of the measurements recorded at the network delivery points corresponding to each end-user. These data are acquired from the meters installed at the users, which can be either traditional or smart meters, and represent the volume values of gas withdrawn, appropriately converted into standard cubic meters (Sm3) through the application of corrections related to locally detected pressure and temperature. Depending on the type of meter, data can be aggregated on a daily or hourly basis. Regardless of the frequency of recording, transmission to the SAC or MDMS via an automated communication channel, typically via integrated SIM (Subscriber Identity Module). Data is normally collected in CSV format and for each delivery point. Data includes: the time reference of the measurement, average flow rates, converted volumes and measured volumes related to each time interval considered. This information associated with the individual delivery point forms the basis of consumption accounting for billing purposes.
2.2.3. Data Processing Python
Within Digital World, in the context of processing the data collected from the metering systems, a sequence of data processing operations is implemented aimed at cleaning, normalizing and harmonizing the consumption series from the different PDRs of the gas network. The source data, originally downloaded from the SAC system (or MDMS), represents the consumption readings associated with the various PDR’s, recorded at different times and often characterized by heterogeneous formats due to both the different meter technologies and the operating modes adopted in the field systems.
The processing operations were carried out through the development of specific Python scripts. In a first step, the source files undergo a thorough cleaning procedure that includes the removal of blank rows, outliers or non-standard formatting, as well as the elimination of any records without operational relevance. Particular attention is paid to the restructuring of temporal information: when date and time data are provided separately, they are appropriately resampled to a single consistent timestamp. This step involves standardizing how dates are represented and resolving any discrepancies due to different source formats. Temporal normalization also includes automatic correction for the transition from daylight saving time to standard time, as well as realignment of all data to a single reference time zone, Coordinated Universal Time (UTC).
An additional step, crucial for the subsequent simulation phase, concerns the structural harmonization of the datasets with respect to the input specifications required by the GasNetSim environment. The entire processing workflow leads to the production of a single normalized and integrated timesheet, in which, for each hourly interval, the consumption values of each redelivery point are systematically reported. This final file, structured in CSV format according to GasNetSim specifications, represents the input dataset for the simulation environment and ensures a reliable, seamless and consistent transition of real data from the SAC to the computational digital model of the gas network. This procedure enables the structuring of a reliable, clean and synchronized consumption database, an indispensable element for any subsequent simulation, network performance evaluation and advanced flow analysis in the DT.
3. Digital Twin Framework of the Gas Network
This section provides a comprehensive overview of the DT architecture as applied to gas network modelling and simulation. The DT is realized through the integration of three main digital environments: the GIS platform (QGIS), the 3D CAD environment (FreeCAD), and the GasNetSim simulation module. The GIS environment serves as the initial digital hub, where physical infrastructure data is imported, harmonized, and systematically mapped to create a detailed digital representation of the network, including spatial and elevation attributes. This data is then exported to the CAD environment, where the network undergoes further structuring, geometric enhancement, and preparation for simulation. FreeCAD facilitates both the creation of simulation-ready datasets and the post-simulation visualization of results. Finally, the GasNetSim environment enables advanced hydraulic and gas quality simulations by leveraging these structured datasets, allowing for dynamic scenario analysis and output generation. The coordinated functioning of these components not only ensures the accurate digital replication of the physical system but also enables comprehensive network simulation, performance analysis, and visualization.
3.1. The GIS Environment
The GIS environment developed within the QGIS platform represents the first digital hub where data from the Digital Data Infrastructure converges and is synchronized. At this initial stage, information related to the physical network-collected and organized into shapefiles is imported and subjected to a series of processes designed to ensure its consistency, quality, and full integration into the digital context.
The GIS system is used as the Physical Twin’s digitalization environment: this is where detailed mapping of the actual infrastructure takes place, enabling a realistic and structured cartographic representation of the pipelines, nodes, utilities and main components of the distribution network. This digital space also enables the unique aggregation of delivery points and end users (PDRs and users), allowing each consumption or user to be uniquely associated with the relevant network nodes. A key aspect of this process is also the integration of elevation data from digital terrain models, which is assigned to each network node to support accurate three-dimensional simulations. In parallel, nodes are systematically indexed with unique identifiers to ensure reliable traceability and compatibility throughout subsequent modelling and analysis phases.
At the end of this process, the digitized and harmonized network is exported in metric-typically shapefile or DXF-ready format to be transferred and further processed in the 3D CAD modelling environment.
3.1.1. Automated User Aggregation to Network Nodes and Assignment of Node IDs
As part of the DT construction for the gas distribution network, it is not sufficient to represent the physical infrastructure alone: in fact, it is essential to uniquely associate each PDR with the network node to which it is connected. In parallel, it is necessary to give each node a permanent numerical identifier that ensures its traceability in all subsequent modelling and simulation phases.
This methodological step addresses a major operational criticality: while the gas network is precisely digitized through technical mapping and GIS tools, the location of PDRs is often determined through geocoding processes and, as a result, does not exactly coincide with the digitized geometric nodes. To overcome this discrepancy and enable the logical and automated aggregation of PDRs to the network, an algorithm was developed in the Python/QGIS environment that can associate each user with the nearest node based on the minimum geographic distance.
The adopted workflow first involves the identification of all nodes in the network, defined as the start and end vertices of each pipe segment. Each node thus identified is immediately assigned a unique and permanent ID, which is the stable reference for all subsequent operations on the digital network. Each geometric pipeline vertex is registered as a node and given its own ID.
In the second step, the distance to all identified nodes is determined for each PDR, and the user is assigned to the closest node according to the minimum distance criterion.
The end result of this procedure is the creation of a new information layer, in which all the pipelines in the network are represented, with four additional fields have been added:
The ID of each PDR connected to that specific portion of the network.
The ID of the network node to which the connection is made.
The unique and permanent ID of the start point (starting node) of each pipeline.
The unique and permanent ID of the end point (end node) of each pipeline.
If there are multiple PDRs associated with the same node, their codes are listed in the same field, as are the corresponding connection node identifiers.
This data structure makes it possible to explicitly maintain the link between utilities and the network and to have a permanent reference for each node, providing a solid, ready-made basis for the subsequent simulation, flow analysis and interoperability phases within the DT (
Figure 3).
3.1.2. Implementation of Node Elevation Mapping
In the process of building the DT of the gas distribution network, automatic entry of node elevations is a network enrichment step. In fact, the correct representation of the elevation of each node in the network is crucial for all subsequent analyses related to flow, pressure, and the identification of any critical operational issues, since elevation changes along the pipeline route directly affect pressure distribution and gas motion regimes. For this, an automated procedure has been implemented (
Figure 4) in the QGIS environment that allows each vertex of the network lines to be associated with its respective elevation, obtained from an official DEM such as the Copernicus DEM. The latter, made available as public data and freely downloadable in GeoTIFF format, is integrated into the working platform just as it is for the vector layers of the network, thus expanding the information base with external but easily accessible and unconstrained information for use.
The logic of this procedure is based on the interaction between the layers representing the physical network and the raster file representing the elevation. Through a dedicated Python script, the operator is asked to select the layers of interest; for each pipeline segment, the script extracts the vertex coordinates, performs the reference system transformation to ensure compatibility between vector data and DEM, and timely queries the raster to obtain the corresponding elevation. The data thus collected are used to generate a new 3D geometry, in which the elevation dimension (Z) is directly associated with the planimetric coordinates of each node. All the resulting information is then saved in a new 3-D shapefile, including the elevation dimensions assigned to each node in the network.
A central aspect of this approach is the ability to quickly transfer network elevation into digital models in an integrated manner, without resorting to data acquisition systems via external APIs or third-party services that may introduce time constraints, usage limitations, or potential operational criticality. The public DEM, due to its open nature and wide coverage, allows all the necessary elevation information for each point in the network mapping to be obtained directly and without excessive computational effort, thus ensuring both spatial consistency and speed of process.
From a modelling perspective, incorporating elevation data allows the transition from a two-dimensional to a three-dimensional network layout. While pipelines may not always follow the terrain exactly, linking each node to DEM elevations offers a robust and realistic approximation. This approach is especially important, as it introduces gravity effects into flow simulations, which is an essential factor in medium-pressure gas networks and urban areas with varying elevations.
It should be emphasized that the procedure described for automatic entry of elevation information at network nodes is necessary only in cases where the original data provided through shapefiles or other vector formats are devoid of the elevation information or report only planimetric coordinates (X, Y) without the Z dimension. If, on the other hand, the mapping of the network is already structured in three dimensions, i.e., it has altimetric elevations associated with each node or segment, for example, through 3D shapefiles or pre-existing digital models, the operation of integrating the altimetric data via DEM would be unnecessary and more approximate.
3.1.3. Exporting the Network in Metric Format
The last key operation performed within the GIS environment concerns the export of the network in metric format, typically shapefile (SHP) or DXF, in order to enable its subsequent import into the 3D CAD. This export marks the transition from the cartographic representation of the network, based on geographic coordinates (latitude and longitude), to a fully metric representation expressed in three-dimensional X, Y, and Z coordinates suitable for a CAD-type environment.
The process first involves defining the most suitable spatial reference system to ensure the metricity and accuracy of the exported network. Depending on the geographic location of the study area, the correct UTM (Universal Transverse Mercator) zone is selected; in the present case, the projection used is UTM zone 32N, which ensures accurate conversion of data to metric coordinates. This choice is critical to ensure that the network, once transferred into CAD software, maintains exact dimensional and spatial correspondence with physical reality and is immediately usable for modelling.
The layer to be exported is structured as a linear layer, consisting of line or polyline type geometries, where each element represents a pipeline section of the network. Within the attribute table, in addition to the geometric data, all the essential additional information processed in the previous steps is maintained: each start point and node of the line is identified by a permanent, unique ID, each node is associated with the elevations previously derived, and each section reports the length of the pipeline automatically calculated by the GIS in meters. In addition, the associations between the delivery points and their respective connection node IDs are maintained, allowing the topological and functional relationship between the utilities and the network itself to be preserved.
3.2. 3D CAD Environment
The 3D CAD environment used for modelling and visualization of the gas network is developed through the adoption of FreeCAD, an open-source software that is distinguished by its modular nature, full accessibility to the source code, and ease of customization with respect to specific design needs. FreeCAD was chosen to have a flexible platform, fully or largely developed in Python, that allows for deep integration with data streams and scripts already employed in previous GIS processing steps.
Within the FreeCAD environment, a variety of file formats can be imported, including .shp, DXF files, and other vector and three-dimensional formats. This broad compatibility facilitates the direct transition of data from the GIS environment and ensures full interoperability. FreeCAD, through its graphical interface, provides an immediate visualization of the three-dimensional network trend, offering tools typical of CAD software for the analysis and management of geometries in space.
A key feature of this environment is the integrated Python console, enabling execution of custom commands and saving scripts as macros (an automated script for performing repetitive tasks) for automating routine or complex tasks. For this project, dedicated Python macros were developed to process GIS data and prepare inputs for GasNetSim simulations, helping standardize modelling workflows, minimize manual errors, and ensure repeatability.
The FreeCAD environment serves both for pre-processing, creating and adapting simulation inputs from GIS exports, and for post-processing, enabling visualization and analysis of GasNetSim results. This dual role makes FreeCAD a central interface for the Digital Twin, allowing for comprehensive management over the entire DT workflow.
3.2.1. Network Import from QGIS
One of the key operations is to import the network previously processed in the GIS environment to the FreeCAD platform. To facilitate this step, a dedicated Python macro was developed that can be executed directly in the FreeCAD console or invoked as a command via the dedicated macro interface.
The workflow (
Figure 5) involves the use of a dedicated dialog box, designed to guide the user in selecting the shapefiles to be imported, choosing the attribute fields of interest, including the initial and final (Z) elevation fields, and defining parameters such as the default elevation and the scale factor to be applied to the coordinates. The import is designed to handle the reading and conversion of all relevant attributes associated with network segments, including any metadata or topological information, such as node IDs, elevations, and PDR identification codes, pipeline materials, and pipeline laying date.
During the procedure, each segment is read from the initial file, and its coordinates are converted considering the defined scale factor. Elevation values are assigned to the vertices based on user-selected fields or, failing that, a default elevation. The segments processed in this way are created as three-dimensional objects in the CAD scene, and all the main attributes chosen during import are added as properties to the objects, thus maintaining the full traceability and informative richness of the original data. The macro also includes automatic checks for abnormal elevation jumps, which could indicate errors in the digitization of the elevation data or issues in the source GIS data.
When completed, the network model is displayed in isometric projection, ready for the next stages of analysis and simulation. This automated and fully customizable process ensures a unified continuity between the GIS and 3D CAD environments, guaranteeing the preservation of all essential information—topological, geometric, and attributive—necessary for advanced modelling and scenario simulations of the gas network.
3.2.2. Aggregation of the Injection Point Property
A targeted command, in the form of a Python macro (Python version 3.12), has been implemented in the three-dimensional modelling environment developed in FreeCAD to identify, assign, and characterize the injection points of the network. This operation, although it could theoretically also be carried out in the GIS environment, is here performed directly in FreeCAD to provide the user with maximum flexibility in identifying feed nodes within the three-dimensional model.
The command allows users, via FreeCAD’s interface, to select one or more point objects representing network nodes in the 3D scene. When a node is chosen, the macro enriches it with properties—such as operating pressure, temperature, and node type, which is explicitly set as “injection.”. Additional attributes like gas quality and mixture composition may be added in future DT development stages.
This procedure ensures that each injection point is not only correctly identified and positioned within the 3D network space but also enriched with all the physical and operational information required for subsequent hydraulic simulations, or for generating inputs to other external computational environments. The definition and management of properties occur in a transparent and traceable manner, ensuring full consistency between the CAD model and engineering simulation needs, and allowing the user to easily configure different operation scenarios directly in the 3-D environment.
3.2.3. Numerical Indexing of the Network and Data Creation for Simulation
In the context of gas network modelling and simulation, a key step is the numerical indexing of the network and the generation of the data structures required for the simulation environment. This is accomplished by means of a dedicated Python script, also developed as a macro, which is responsible for extracting and formalizing all the essential elements of the network, translating them into two separate CSV files: one for nodes (“nodes”) and one for pipelines (“pipelines”). These serve as the direct input data to the GasNetSim simulation modules.
The process consists of several steps. First, the script analyses all the objects in the active FreeCAD document, identifying for each pipeline section the two extremes (initial and final nodes), the relevant spatial coordinates (x, y, z), and retrieving all relevant supplementary information, such as the unique IDs (already assigned in the GIS environment), any PDR’s associated with the nodes, and injection points along the network as applicable to the case study.
Next, all nodes are collected in a data structure that stores their metric coordinates, elevations, and a series of placeholder fields intended to be enhanced in subsequent steps, e.g., pressure, temperature, gas quality, and mixture composition. In parallel, each pipeline is defined as a “pipeline” object with a unique identifier (“pipeline_index”) and assigned start and end node IDs (“inlet_index” and “outlet_index”) based on its connected nodes. The diameter is recorded as a specific attribute and, if needed, converted to meters, while length is calculated from end node coordinates. All node and pipeline data are then exported to “sf_nodes.csv” and “sf_pipelines.csv” files, following a rigorous formatting scheme to ensure full compatibility with GasNetSim and proper use of separators and numerical formats.
Figure 6 provides a clear example of how the physical gas network is numerically indexed. On the left, the network graph displays uniquely numbered nodes and pipelines with sequential IDs. The table on the right links each pipeline to its corresponding start and end nodes, following the format used for simulation input files. For each pipeline, relevant technical parameters—such as length, diameter, and other key attributes are also included as previously described. This procedure yields a numerically indexed, geometric topological representation of the network, with nodes and pipelines uniquely identified and linked to all relevant physical and geometric attributes for simulation. This approach preserves full traceability between the physical network, its digital model, and simulation results, ensuring maximum consistency and reproducibility in the DT workflow.
3.3. GasNetSim Simulation Environment
The simulation environment chosen for gas network modelling within DT is GasNetSim, an open-source platform developed for both static and dynamic simulation of gas distribution networks. The choice of GasNetSim responds to the need for a computationally efficient yet flexible tool that can handle networks of any scale- from single-site tertiary or industrial facilities to entire city or regional networks-and operate quickly even in the presence of considerable topological complexity.
In the steady-state approach GasNetSim makes it possible to simulate the hydraulic and chemical behavior of the network by assuming equilibrium conditions at each instant of calculation. This allows the balance of pressures and flows for each node and pipeline to be solved quickly and with numerical rigor, even in large networks, avoiding the heavy computational burden that characterizes dynamic simulations or large-scale FEM analyses.
GasNetSim is also distinguished by its open-source architecture, developed in Python, which ensures high code transparency and allows advanced levels of customization and integration with other computational and modelling tools. The MPL 2.0 license also ensures maximum flexibility for the future, allowing the software to be adapted and enriched according to the specific needs of the DT project.
One of the most valuable aspects of GasNetSim is its ability to handle and simulate complex gas mixtures. In fact, the calculation engine is designed to analyse networks supplied not only by natural gas, but also by different gas mixtures, including hydrogen and biomethane. Of particular note is the ability to set up and simulate the presence of different percentages of each component of the mixture, evaluating the properties of each gas—such as density, higher heating value and all the parameters that determine gas quality—in a timely manner. This functionality enables the study of the effects of injecting different blends into existing infrastructure and the evaluation of decarbonization and energy transition scenarios on a real-world basis.
Thermodynamic analysis of gas mixtures is performed using the GREG-2008 equation of state, which allows calculation for each node of key parameters such as the WI (Wobbe index), specific density and calorific value of the mixture, returning a detailed snapshot of the properties of the gas distributed along the network.
GasNetSim is therefore configured as an ideal calculation engine for the DT, thanks to its modularity, high level of interoperability and the ability to directly import data from the modelling and pre-processing environments, integrating seamlessly into the overall simulation, analysis, and scenario planning workflow.
3.3.1. Simulation Input Data Files
The network files for nodes and pipelines, created in the 3D CAD environment, along with the aggregated hourly consumption profiles for each PDR, generated through Python processing of SAC or smart meter data, are directly imported into GasNetSim and serve as the core consumption data for individual network users, constituting the input data for GasNetSim simulations.
Gas network nodes file: the nodes file represents the fundamental information base for digital modelling of the gas distribution network. Each row in this file describes a single node in the network, which is a physical point at which the network changes geometry, function, or operational properties. Through the detailed description of each node, the file makes it possible to map both the physical and functional structure of the network, to associate key operating conditions; such as pressure, flow rate, temperature, gas composition [
33], with each node, to support the simulation and analysis of real network behaviors under different operating scenarios, and to directly connect real utilities through the PDR field, which integrates consumption data from metering systems.
Main columns:
node_index: Progressive and unique identifier of the node in the network.
pressure_pa: Gas pressure expressed in Pascal (to be valued at injection and/or metering points).
flow_sm3_per_s: Instantaneous gas flow rate at the node (standard cubic meters per second).
altitude_m: Altitude in meters (elevation above sea level).
temperature_k: Temperature in Kelvin (to be valued at injection points).
gas_composition: Percent composition of gas (only at injection nodes).
node_type: Type of node (injection or consumption).
PDR: Delivery Point Code (links the node to actual consumption profiles and allows congruence between model and measurement data).
Gas network pipeline file: the pipeline file describes the set of physical pipelines that connect the network nodes together, forming the topological mesh on which gas distribution is based. Each row of the file represents an individual pipeline, defining its extremes (through references to inlet and outlet nodes), main geometric characteristics (such as diameter and length). Thanks to this structure, the file allows us to rigorously reconstruct the network topology, to attribute fundamental physical properties to the pipelines.
Main columns:
pipeline_index: Progressive and unique identifier of the pipeline.
inlet_index: Identifier of the inlet node (coincides with the node_index of the nodes file).
outlet_index: Identifier of the outlet node.
diameter_m: Inner diameter of the pipeline (in meters).
length_m: Length of the pipeline (in meters).
friction_method: Method of calculating roughness or friction (can be used to distinguish different materials).
PDR Hourly Consumption Profiles File: This file contains hourly consumption profiles for each PDR, aggregated and obtained from measurement data from SAC and smart meter systems via the data processing pipeline. Each row in the file corresponds to an hour of the day, while each successive column represents a consumption profile referring to a specific PDR. Through direct association between the PDR code in the nodes file and in the headers of this file, it is possible to attribute each node in the network its actual consumption profile.
Main columns:
timestamp: Indicates the reference time (e.g., 00, 01, …, 23).
PDR_xxx: Columns for each PDR code, containing the consumption value for that hour (in Sm3/h or adopted format).
3.3.2. Definition of Simulation and Simulation Parameters
After defining and importing the input files related to the physical structure of the network (nodes and pipelines) and the aggregated hourly consumption profiles for each PDR, the methodology involves the timely definition of the simulation parameters and their transmission to the GasNetSim calculation environment. These parameters constitute the set of operating conditions and numerical assumptions that govern the performance of the network simulation, and they are configured directly through Python scripts, ensuring maximum flexibility and possibility of customization of operating conditions and properties of network components.
In particular, the simulation code allows setting the reference period to be simulated, the numerical parameters required for stability and convergence of the calculation algorithms, the minimum flow rate values allowed for the nodes (in order to avoid numerical instabilities due to zero or near-zero flow conditions), and the technical properties of the pipelines, such as the internal roughness of the materials, which directly affects the calculation of pressure drops. It is also possible to automatically load hourly consumption profiles filtered on the date of interest and associate each node with the corresponding demand profile by mapping between PDR code and node identifier. This step also involves the automatic generation of demand profiles for each node in the network, ensuring that each hour of the day is represented through a complete and consistent set of boundary conditions.
The simulation procedure (
Figure 7) is developed through an iterative cycle over all hours of the selected period, during which the network model is built for each hourly interval, the operating conditions (flow rates, pressures, gas parameters) are assigned, and the actual simulation is started using GasNetSim’s internal functions. In each cycle, flow parameters are assigned to the nodes, pipeline roughness is set according to the defined specifications, and the correct evaluation of the friction factor is managed, also as a function of Reynolds number, so that laminar or turbulent conditions are defined. At the end of each hourly simulation, the results are collected for each node (pressure, flow rate, gas composition, gross calorific value, WI, etc.) and for each pipeline (velocity, flow rate, Reynolds number), and then saved in output files with homogeneous and standardized formatting.
3.3.3. Exporting Simulation Results
At the end of the simulation, GasNetSim returns two output files summarizing the hourly network operation results at the nodes and on the pipelines, respectively. The first file contains, for each node in the network, the node identifier and a set of parameters describing the operating conditions resulting from the simulation for each hour considered. These include the pressure at the node, the volumetric flow expressed in Sm3, as well as values such as WI, Higher Heating Value (HHV), and Relative Density (SG), all calculated based on the composition and simulated operating conditions. The spatial coordinates of each node are also reported, functional for subsequent export and visualization within the CAD environment.
The second file, relating to the pipelines, documents the hydraulic and fluid dynamic behaviour of each pipeline section in a timely manner. In addition to the progressive pipeline identifier and references to the inlet and outlet nodes, the value of the flow velocity within the pipeline, the volumetric flow rate, the Reynolds number, an essential parameter for distinguishing between laminar, transient, or turbulent regimes, and the actual friction calculation method used for each pipeline, which may vary depending on the simulated operating conditions, are returned. Again, the information is ready to be reintegrated and visualized in the CAD/FreeCAD environment, enabling spatial analysis and detailed documentation of simulation results directly on the three-dimensional network representation.
3.4. Export of Results and Visualization in the 3D CAD Environment
After the simulation, the output files produced by GasNetSim are re-imported into the CAD environment (FreeCAD) or a dedicated visualization environment to enable detailed qualitative and quantitative analysis of the results obtained. For this purpose, a Python script executable via macro was developed to import the output files generated by the hourly simulation and produce a complete graphical representation of the network. The code automatically loads the files containing the simulated results both at the nodes and on the pipelines and, for each of the 24 h considered, builds a visualization of the network, assigning a specific colouring to each element depending on the selected technical parameter.
The user has the option of choosing which parameter to display from all those calculated during the simulation, such as volumetric flow, pressure, gross calorific value, WI, and other indicators of gas quality or operating status. Once the parameter of interest has been selected, the system generates an ordered sequence of 24 images, each corresponding to a specific time of day, allowing immediate and intuitive observation of the temporal and spatial trends of the selected variable over the entire network.
Colorimetric mapping is applied to nodes and pipelines to identify state variations, critical zones or transient phenomena that emerge clearly, facilitating the technical interpretation of results and comparison between different operating scenarios. The graphical interface generated by the macro also allows rapid scrolling through all the images in the sequence, ensuring a dynamic and complete reading of the evolution of the simulated parameters throughout the entire time span analysed.
4. Case Study Results and Analysis
The case study is applied to the gas distribution network located in Southern Italy and serves end-users for educational and research purposes. For privacy and commercial confidentiality reasons, detailed information regarding the precise location, the name of the site, and the network operator cannot be disclosed. This section describes the existing physical system, which forms the informational and structural basis for subsequent digital modelling.
The selection of this network was motivated both by its structural and operational complexity, characteristic of a large-scale educational and research infrastructure in the tertiary sector, and by the availability of high-quality comprehensive data, obtained through collaboration with the local distributor, also responsible for the network’s SAC.
A distinctive structural element of the network is its topological configuration: the network has two gas injection points located at the extremes, which feed the network itself; the topology includes a ring and two tree sections, all interconnected through a main pipeline that connects the different subnetworks. This configuration gives the system both management flexibility and operational robustness and is a valuable pilot site for implementing the DT methodology in a real-world context.
The network covers more than 3.63 km of pipelines, put together as a significant distribution network even in comparison with small- to medium-scale urban networks. Specifically, the maximum linear distance between the two most distant points (marked in orange in
Figure 8, corresponding to the injection sites) is 1.38 km. The material composition of the pipelines is dominated by spheroidal cast iron, with the presence of some steel sections. This heterogeneity is due to both the different periods of initial installation and the subsequent modernization and maintenance work.
A total of 15 active users were considered in the analysis and simulation. All of them belong to the ‘large-user’ category, being equipped with gas meters with a nominal capacity greater than G10. This allows the availability of hourly consumption data for each PDR, a feature that makes it possible to generate principally accurate and detailed demand profiles compared to typical residential networks, where the temporal resolution of the consumption data is generally daily.
From a morphological point of view, the area stretches over a gently inclined area, with small but still methodologically relevant elevation variations. For this reason, in the digitization of the network and the subsequent simulation, actual elevations were considered, supplemented by DEM data, in order to ensure physical consistency and the possibility of assessing the impact (albeit limited) of elevation on the hydraulic regime of the network.
The consumption profiles of the PDR analysed are consistent with a usage pattern typical of educational and research facilities, showing prevalent consumption during working hours on weekdays, and significantly reduced demand during evening, night and weekend hours. This temporal distribution is directly reflected in the structure of the hourly data acquired and used for the simulation.
Results of the Digital Twin Implementation
The representation of the gas distribution network was developed and processed within the open-source GIS environment QGIS, following the methodology in
Section 3.1. (
Figure 8) shows the reference cartography of the entire infrastructure, obtained by digitizing the information provided by the operator. Within the cartography, utility consumption points (PDRs) are highlighted in blue, while gas injection points are marked in orange.
As for the consumption data, they were subjected to a normalization process in line with the data processing described in the methodology
Section 2.2.3. The hourly consumption profile clearly represents a usage pattern typical of educational and research facilities, characterized by a concentration of gas demand during operational hours and minimal to zero consumption during off-hours. Generally, consumption peaks in the early morning when the heating system is activated, stabilizes throughout the working day with minor fluctuations, and significantly decreases after typical working hours.
Specifically,
Figure 9 illustrates the hourly consumption profile for one of the buildings served by the network on 1 February 2025. It shows that the peak consumption occurs precisely at 07:00, coinciding with the activation of the heating system, reaching approximately 20 standard cubic meters. Consumption subsequently stabilizes at an average of around 12 Sm
3/h during working hours, showing a slight increase near lunchtime. After 7:00 p.m., consumption sharply decreases, approaching zero during nighttime hours. The data thus processed undergoes post-processing as described in the methodology
Section 3.2.3. At this stage, we proceed with the automated aggregation of users to their respective network nodes and the assignment of a unique identifier (ID) to each node. This ID is maintained and used in all subsequent modelling steps and throughout the simulation. Subsequently, elevation data are assigned to the nodes through an automated process of assigning elevation values taken from the DEM, so as to ensure the correct three-dimensional representation of the network.
The next step is to export the network in metric format, ready for subsequent import into the CAD environment. Once all these procedures have been completed, the file is imported into FreeCAD, where a dedicated macro has been developed for reading and associating the elevations of the nodes, as well as all the attributes necessary for numerical simulation. The resulting model, displayed within the FreeCAD CAD environment, thus takes on a complete 3D representation of the network, as shown in
Figure 10.
After preparing and importing the network and consumption data within the simulation environment, hourly simulations of gas network operation were run using GasNetSim software (version 0.1.0).
For each of the consumption hours recorded, network operating parameters (pressures, gas quality, hourly demand profiles) were set and point values of pressure, flow rate, and key chemical and physical properties were calculated at each node and on each pipeline section for the entire network.
The numerical results produced by GasNetSim were exported and then reimported into the 3D CAD environment (FreeCAD) for advanced visualization. The specific post-processing macros enable graphical representation of the simulated parameters on the various sections of the network by means of colorimetric maps that facilitate technical and operational analysis of the system.
Figure 11 shows the results of the numerical simulation of the flow rate within the gas network, obtained by exporting from the FreeCAD environment for four moments representative of a typical winter operating day: 8:00 a.m., 1:00 p.m., 3:00 p.m., and 7:00 p.m. For each selected time, the colorimetric map allows visualization of the distribution of flow values along all pipelines in the network. The side graphic scale indicates the range of simulated values expressed in Sm
3/h, with a chromatic progression that starts from green for the minimum values, passes through blue as an intermediate (neutral) value and reaches red in the sections characterized by the highest flow values.
This representation makes it possible to analyse the temporal and spatial evolution of flow regimes throughout the day, highlighting the variations induced by the hourly consumption profile typical of large educational and research facilities. Increments and redistributions of flow rate are observed at different hours, testifying to the dynamism of the system and the ability of the DT to return in detail the operating conditions at each phase of the day.
Figure 12 shows the represents an export from the FreeCAD environment related to the flow regime in the gas network pipelines, obtained as the output of the hourly simulation. Colorimetric mapping allows immediate distinction between different operating conditions: sections in green indicate pipelines in a turbulent flow regime, where the gas flow rate and velocity result in highly mixed, nonlaminar behaviour; sections in orange identify sections in laminar regime, where the gas motion is orderly and the velocity lower.
Classification of flow regimes was performed automatically by GasNetSim through calculation of the Reynolds number for each pipeline section, according to the operating conditions derived from the simulation.
5. Conclusions and Future Prospects
The approach illustrated in this paper demonstrates how to build a DT of a gas distribution network starting from the data made available by the network operator and employing exclusively open-source tools and libraries (i.e., QGIS, FreeCAD, GasNetSim) for all phases of digitization, modelling and simulation.
The digital infrastructure outlined in this study facilitates a near real-time monitoring, analysis, and simulation of network operations at an hourly resolution, thereby presenting the efficacy of such tools for both operational management and strategic planning. In particular, the system has the capacity to facilitate predictive maintenance, for instance by identifying the most stressed pipeline segments, and to enable what-if scenario analysis under varying operating conditions.
The DT is configured as an extremely flexible solution, not only for the validation of current consumption and hydraulic performance, but also for the evaluation of future scenarios, for example, the introduction of alternative gases (hydrogen, biomethane blends, etc.) or the analysis of impacts resulting from structural and managerial changes in the network. This is of increasing importance in an energy transition context, where the integration of new sources and carriers requires advanced simulation and control tools.
One of the main critical issues that emerged concerns the availability and quality of input data; however, the methodology presented shows that, when such data are available (e.g., by taking advantage of metering systems already in use for billing), a detailed and functional digital model can be obtained. In this study, enabled by the presence of large educational and research facilities equipped with advanced gas meters (hourly acquisition), provided a resolution and accuracy not achievable with daily data, typical of residential networks.
The results obtained highlight how the full digitization of the network and the hourly simulation of flows and pressures allow an in-depth understanding of the real dynamics of the network itself, enabling advanced analyses for management and safety.
Possible developments for the future version include:
the development of more advanced methodologies for aggregation, validation and normalization of different input formats, with the goal of extending the approach to networks of different scale and complexity.
The implementation of integrated tools capable of automating data management, simulation and visualisation of results in real-time, while also enabling automated information flow from the physical twin to the digital twin.
The future integration of multi criteria decision making methods for supporting technical, economic and environmental assessments.
The extension of the DT for the dynamic management of networks incorporating gases of different composition, with a focus on the variation in WI and chemical and physical properties in the presence of hydrogen or biomethane injections.
The use of the DT as a platform for testing and validating decarbonization and energy optimization strategies, thus facilitating the transition to low environmental impact systems while maintaining high standards of safety and operational reliability.
In conclusion, the DT represents a strategic resource for the evolved management of gas networks, capable of enabling not only timely supervision and simulation, but also future scenario planning and integration of new technologies and energy carriers, in line with the challenges posed by the energy transition and decarbonization.