Understanding fields: The core data structure
What is a field
A Field is a container that associates numerical data with entities (points, nodes, elements) in a discretized region. Think of it as a structured way to store values that vary across space, time, or other dimensions. Why fields matter: Fields make data self-describing. Instead of just having an array of numbers, you have data that knows what it represents, where it applies, and how it’s measured. Real-world analogy: Imagine a temperature sensor network. A simple array[20.5, 21.3, 19.8] is just numbers. A field adds context: “These are temperatures in Celsius, measured at sensor IDs 1, 5, and 9, located at specific coordinates in the room.”
Field components explained
Every field contains several interconnected pieces of information:Data: The raw values
The data in a field is a flat array of numerical values. This is the actual information you want to work with (temperatures, displacements, stresses, etc.).Unit: The measurement system
Every field has a unit that defines how values are measured. All values in a field share the same unit. Examples:- Displacement:
m(meters) - Temperature:
°CorK - Stress:
Pa(Pascals) - Time:
s(seconds)
Elementary data: Data per entity
Elementary data is the set of values associated with a single entity (one node, one element, one time step). Structure:- Scalar: 1 value per entity (e.g., temperature:
[21.5]) - Vector: 3 values per entity (e.g., displacement:
[2.5, -1.2, 0.8]) - Matrix/Tensor: 6 or 9 values per entity (e.g., stress tensor:
[σx, σy, σz, τxy, τyz, τxz])
Support: The region of definition
The support defines the region where the field’s data applies. It provides the context for understanding what the entities represent. Types of support:Location: Type of entities
The location specifies what kind of entities the data is associated with within the support. Common locations:Nodal: Data at mesh nodes (vertices)Elemental: Data at mesh elementsElementalNodal: Data at mesh elements, for each node of the element (e.g., stress)TimeFreq: Data at time steps or frequencies
Scoping: Which entities
The scoping defines which specific entities (by ID) have data in the field. It acts as an index into the support. Example: If a mesh has 1000 nodes but you only computed displacement for nodes 10, 25, 100, and 500, the scoping contains[10, 25, 100, 500].
Why scoping matters: It allows fields to store data for subsets of a model (e.g., only boundary nodes, only elements in a specific part).
In Python, a scoping is a dpf.Scoping object. You can create one independently of a field:
field.scoping, you are working with a Scoping object that is embedded in the field.
You can also create standalone Scoping objects to pass to operators or to group into a ScopingsContainer
(covered in the Collections section below).
Name: Optional identifier
The name is an optional text identifier you can assign to a field for documentation and debugging purposes. Example:"temperature_field", "stress_von_mises", "displacement_x"
Why names help: When working with multiple fields in a workflow, names make it easier to identify which field contains what data.
How these pieces work together
Here’s a concrete example: Displacement field for 3 nodes of a mesh:- Node ID 10: displacement =
[2.5, -1.2, 0.8]m - Node ID 25: displacement =
[3.1, -0.9, 1.2]m - Node ID 100: displacement =
[1.8, -1.5, 0.5]m
Understanding data array ordering
The data array in a field follows a specific ordering structure from coarse to fine. Understanding this ordering is critical for correctly interpreting and manipulating field data.Basic ordering: Entity, layer, component
For most fields, the data array is organized as:- Entity (outermost loop): Loop through each entity in the scoping
- Layer (middle loop, if applicable): Loop through shell layers for shell elements
- Component (innermost loop): Loop through components (X, Y, Z for vectors)
Shell layers property
Theshell_layers property defines which layers are present in shell element data. Shell elements have thickness, and results can be computed at different layers through the thickness.
Available shell layer values:
layerindependent: No layer information (solid elements, or layer-independent data like displacement)bottom: Data at bottom surface onlytop: Data at top surface onlytopbottom: Data at both bottom and top surfacesmid: Data at mid-surface onlytopbottommid: Data at bottom, top, and mid surfacesnonelayer: No shell layer data
ElementalNodal ordering: Entity, node, layer, component
ForElementalNodal location, an additional loop is added because data exists for each node within each element. The ordering becomes:
- Entity (outermost): Loop through each element in the scoping
- Node (second loop): Loop through nodes of that element based on its connectivity table
- Layer (third loop, if applicable): Loop through shell layers
- Component (innermost): Loop through components
Quick reference: Data ordering by location
Key takeaway: The data array is always flat (1D), but organized in nested loops. The
location and shell_layers properties tell you how to interpret the nesting structure.
Accessing field data
While understanding data array ordering is important, you rarely need to parse the flat array manually. DPF provides convenient methods to query specific values directly.Getting data for a single entity
Two methods let you access data for individual entities:get_entity_data(index): Get data by position in the scoping (0-based index)
get_entity_data_by_id(id): Get data by entity ID (the actual node/element ID)
- Use
get_entity_data(index)when looping through all entities sequentially - Use
get_entity_data_by_id(id)when you know the specific entity ID you want
Understanding index vs. ID
The index is the position in the scoping array (0-based). The ID is the actual entity identifier from the mesh (1-based, potentially non-sequential, such as the node ID or element ID).Return shape for entity data
The returned data is automatically shaped based on the number of components and layers: Scalar field (1 component, no layers):field.component_count and field.shell_layers.
Accessing specific components
You can extract specific components directly from the data array:Efficient data access for loops
Warning: Do NOT callget_entity_data() or get_entity_data_by_id() inside loops over many entities. Each call is a request to the DPF server, which becomes prohibitively slow with thousands of requests.
Inefficient (thousands of server requests):
Choosing the right approach
Server connection types:- Local server: DPF server runs on your machine.
field.dataaccesses memory directly (pointer), very fast. - Remote server: DPF server runs on another machine.
field.datatransfers the entire array over the network.
Example: Local server (direct memory access)
field.data returns a pointer to the DPF server’s memory. No data is copied, making it extremely fast regardless of field size.
Example: Remote server with manageable field size
get_entity_data() calls are local array operations. The context manager ensures proper cleanup.
Alternative (equivalent performance):
Example: Remote server with very large field (filter first)
- Time steps: Use time scoping to extract specific time sets before downloading
- Mesh regions: Extract named selections or element/node sets on the server
- Result types: Get only the components you need (e.g., only X displacement, not full vector)
Quick reference: Data access methods
Key takeaway: For local servers,
field.data is extremely efficient (direct memory access). For remote servers, consider field size: use as_local_field() or field.data for small-to-medium fields, but filter with operators first for very large fields to minimize network transfer.
Types of fields by data type
DPF provides different field types for different data:
All field types follow the same organizational pattern (data + unit + support + location + scoping).
Creating a field from scratch
Here’s how to create a simple scalar field representing temperature at 4 nodes:Accessing field data from a result file
When you extract results from a file, DPF automatically creates fields with all components properly set:[X1, Y1, Z1, X2, Y2, Z2, ...] for vector fields.
Understanding supports: Defining the domain
You’ve learned that every field has a support and a scoping. These two concepts work together to define where field data lives:- Support: The complete domain containing all possible entities (the full mesh, all time steps, etc.)
- Scoping: The specific entity IDs within that domain where this field has data
What is a support
A support is an object that defines the domain where field data is defined. It provides the complete region or space containing all possible entities (nodes, elements, time steps, etc.). Why supports matter: A field’s data array is just numbers. The support defines the domain (mesh geometry, time series, or cyclic pattern), while the scoping maps those numbers to specific entity IDs within that domain. Together, support and scoping tell you exactly where each value applies. Example flow: How values in a field’s data array map to a physical location for a nodal 3D vector field:- Position in data array (
field.data[6:9]): Values[2.5, -1.2, 0.8]at indices 6, 7, 8 (third set of 3D elementary data) - Entity ID via scoping (
field.scoping.ids[2]): Corresponding third position in the nodal scoping → Node ID 100 - Physical location via support (
field.support.nodes.coordinates_field.get_entity_data_by_id(100)): Node ID 100 → Coordinates[0.025, 0.010, 0.000]m
[2.5, -1.2, 0.8] m applies at the node located at position (0.025, 0.010, 0.000) m in 3D space.
MeshedRegion: The geometric support
A MeshedRegion is a support that represents the finite element mesh: the geometric domain where spatial field data is defined. What it contains:- Nodes: Vertex coordinates (X, Y, Z positions in space)
- Elements: Connectivity (which nodes form each element)
- Element types: Solid, shell, beam, etc.
- Unit system: Length units (m, mm, in, etc.)
- Other case-specific properties: Faces, assigned material, etc.
Accessing the mesh
Every DPF model provides access to its meshed region:Working with nodes
Nodes represent points in 3D space where results are computed:Working with elements
Elements connect nodes to form the mesh structure:When you use MeshedRegion
You’ll work with meshed regions when:- Extracting node coordinates for spatial analysis
- Filtering results by element type
- Creating custom scopings for mesh subsets
- Exporting mesh geometry
- Understanding element connectivity
TimeFreqSupport: The temporal/frequency support
A TimeFreqSupport is a support that represents time steps (transient analysis) or frequency sets (harmonic analysis) where results are available. What it contains:- Time or frequency values: The actual time instants (seconds) or frequencies (Hz)
- Set IDs: Integer identifiers for each time/frequency set
- Cumulative index: Index for accessing results sequentially
Accessing time/frequency information
Understanding set IDs vs. time values
Set ID (also called time step ID): Integer identifier (1, 2, 3, …) Time value: Actual time in seconds (0.01s, 0.02s, 0.03s, …)Accessing results at specific time steps
When you use TimeFreqSupport
You’ll work with time/frequency supports when:- Extracting results for specific time steps
- Iterating through all time steps in a transient analysis
- Finding which time steps are available
- Converting between set IDs and actual time values
- Working with harmonic analyses (frequencies instead of times)
CyclicSupport: For cyclic symmetry (brief mention)
A CyclicSupport is a specialized support for models with cyclic symmetry (e.g., turbine blades, gears). It defines the base sector and how it repeats around an axis. Note: CyclicSupport is specific to cyclic analysis workflows. It will be covered in detail in the dedicated Cyclic Analysis with DPF chapter. For now, just know it exists for symmetric structures.Key takeaways about supports
What supports do:- Define the domain where field data applies (spatial mesh, time/frequency, cyclic pattern)
- Provide context for interpreting field data
- Connect field values to physical locations, time instants, or frequencies
- MeshedRegion: Geometric domain (nodes, elements, coordinates)
- TimeFreqSupport: Temporal or frequency domain (time steps, frequencies)
- CyclicSupport: Cyclic symmetry domain (base sector + repetition pattern)
- A field usually has a support (field.support property)
- Access mesh:
model.metadata.meshed_region - Access time/freq:
model.metadata.time_freq_support
Collections
What is a collection
A collection is a container that groups multiple DPF objects of the same type and organizes them using labels. Collections let you work with multiple fields, meshes, or scopings at once, making it easier to process results across time steps, frequency sets, or other dimensions. Why collections matter: When working with transient analysis (multiple time steps) or processing results for different regions, collections automatically organize and label your data, making it easy to access specific results or process all of them in bulk. Real-world analogy: Think of a photo album. Instead of storing hundreds of individual photos loosely, you organize them by year, event, or person. Collections do the same for DPF data.What are labels
Labels are categories used to organize objects within a collection. Each object is associated with an integer ID for every label. A label space (like{"time": 3}) acts as a filter to identify specific objects.
Common labels: time (time step ID), frequency (frequency set ID), zone (fluid zone ID), stage (load stage ID).
Types of collections
What you can do with collections
Collections provide powerful capabilities:- Access by index or label: Get a specific field by position (
container[0]) or by label (container.get_field({"time": 5})) - Iterate: Loop through all objects in the collection
- Filter: Query for objects matching specific label criteria
- Bulk processing: Pass entire collections to operators to process all objects at once
- Custom organization: Create collections with your own label schemes
When you’ll use collections
You’ve already seen FieldsContainer in action: when you extract results from a file, DPF returns a FieldsContainer:Learn more
For detailed examples of creating and working with collections, see the DPF Collections tutorial in the PyDPF-Core documentation. The exercises section below will also guide you through practical examples.Exercises
Practice what you’ve learned with these hands-on exercises. Try solving each exercise before looking at the solution.Exercise 1: Create a field from scratch
Create a scalar field representing pressure measurements at 5 specific nodes in a mesh. The field should contain:- Node IDs:
[10, 25, 42, 100, 150] - Pressure values:
[101325.0, 102000.0, 99500.0, 103200.0, 98750.0](in Pascals) - Unit:
"Pa" - Location: Nodal
- Name:
"pressure_field"
Exercise 2: Create a ScopingsContainer from scratch
A mesh is made of three zones, each assigned to a different material. Create aScopingsContainer
labeled on "material" that groups the element IDs belonging to each zone:
- Material 1 (steel): elements
[1, 2, 3, 10, 11, 12] - Material 2 (aluminum): elements
[4, 5, 6, 13, 14, 15] - Material 3 (composite): elements
[7, 8, 9, 16, 17, 18]
Exercise 3: Explore the ScopingsContainer from Exercise 2
Using theScopingsContainer you created in Exercise 2, complete each of the following tasks:
- Iterate over all scopings and print the element IDs in each one.
- Retrieve only the scoping for material 2 and print its element IDs and location.
- Print the label space (the label-value dictionary) of the first and second scopings.
- Count the total number of elements across all materials.
Exercise 4: Build a shell mesh and attach it to an ElementalNodal field (Advanced)
Advanced and Optional This exercise combines two concepts from this chapter: MeshedRegion (from the Supports section) and ElementalNodal fields (from the Fields section). It is intended for you if you want to go deeper. You can safely skip it and come back later. DPF needs a mesh to know how many nodes belong to each element, which is essential for correctly storing and retrieving ElementalNodal data (data defined at every node of every element). In this two-part exercise, you will first build a minimal shell mesh from scratch, then use it as the support for an ElementalNodal stress field.Part A: Create a single-element shell mesh
Build aMeshedRegion with 4 corner nodes and one quad shell element (ID 50). Place the 4 nodes at the
corners of a 1 m × 1 m square in the XY plane.
Hint: mesh.nodes.add_node(id, [x, y, z]) adds a node by ID and coordinates.
mesh.elements.add_shell_element(id, connectivity) adds a shell element by ID and a list of
0-based node indices (not IDs) in the mesh’s node list.
Performance note: building large meshes
add_node and add_shell_element (and their siblings add_solid_element, add_beam_element)
call the DPF server once per node or element. For meshes with thousands of entities this becomes
very slow because each call crosses the client-to-server boundary.
For performance-critical code, the correct approach is to build the underlying PropertyField
objects (coordinates, connectivity, element types) in NumPy arrays first and then push them to
the server in a single call via mesh.set_coordinates_field() and mesh.set_property_field().
This pattern is how DPF itself stores mesh data internally.
A complete working example of this approach is available in the official PyDPF-Core tutorial:
Create a mesh from scratch.
That tutorial builds a full 3D solid mesh with hundreds of elements entirely through
vectorised PropertyField assignments.
Part B: Create an ElementalNodal stress field on the mesh
Using the mesh from Part A, create a shell stress field representing three in-plane stress components (sigma_x, sigma_y, tau_xy) at both the top and bottom surfaces of the element. Specifications:- Location: ElementalNodal
- Shell layers: Top and bottom surfaces (
topbottom) - Components: 3 (sigma_x, sigma_y, tau_xy)
- Unit:
"Pa" - Name:
"shell_stress"
That is 4 nodes × 2 layers × 3 components = 24 values total for element 50.
After creating the field, use
get_entity_data(index=0) to retrieve and display the data for element 50.
Hint: For ElementalNodal fields, use field.append(data, entity_id) instead of field.data = [...].
append pushes values for one entity at a time and internally maintains a entity_data_offsets array — a
list of flat-array start indices, one per entity — so that get_entity_data can later slice out exactly
the right values for each element. field.data = [...] leaves the offsets empty, so get_entity_data
cannot know how many values belong to each entity and returns only a single data point.
Performance note: building ElementalNodal fields with many elements
Callingappend in a loop (one call per element) crosses the Python-to-server boundary for
every element. For large meshes, the vectorized approach is significantly faster: set
field.data with the full flat array in one shot, then set field.entity_data_offsets with the
cumulative start indices:
entity_data_offsets[i] is the flat-array index
where entity i’s data begins. For uniform elements (same node count), the values are
evenly spaced: [0, 24, 48, 72, ...].
Going further
Now that you understand how to work with Fields and Collections, explore these advanced topics:- Collections in depth: Check out the DPF Collections tutorial for examples of creating custom FieldsContainers, ScopingsContainers, and MeshesContainers
- PropertyField and StringField: Learn about other field types in the PyDPF-Core API documentation
- Working with meshes: Explore mesh manipulation in the Mesh tutorial