8. The Conduit/Blueprint file formatΒΆ

Conduit is a library for intuitively describing hierarchical scientific data in C++/C, Fortran, and Python. It is used for coupling between packages in-core, serialization, and I/O tasks. The Conduit Node is the basic abstraction for describing data. The Node supports hierarchical construction.

Here is a simple example of using Conduit in Python.

import conduit

n = conduit.Node()
n["my"] = "data"
n["a/b/c"] = "d"
n["a"]["b"]["e"] = 64.0
print(n)

print("total bytes: %d" % n.total_strided_bytes())

Here is the output.

my: "data"
a: 
  b: 
    c: "d"
    e: 64.0

total bytes: 15

Blueprint is a set of higher-level conventions for describing meshes and fields defined on those meshes. The Conduit library can be used to describe in-memory arrays defining a mesh and fields conforming to the Blueprint data model and then writing them to disk. Blueprint can be used to check if a Conduit Node conforms to the Blueprint specification.

Here is a simple example writing a Blueprint uniform mesh in Python.

import conduit
import conduit.relay.io
import conduit.blueprint.mesh
import numpy

mesh = conduit.Node()

# Create the coordinate set.
mesh["coordsets/coords/type"] = "uniform"
mesh["coordsets/coords/dims/i"] = 3
mesh["coordsets/coords/dims/j"] = 3
mesh["coordsets/coords/origin/x"] = -10.0
mesh["coordsets/coords/origin/y"] = -10.0
mesh["coordsets/coords/spacing/dx"] = 10.0
mesh["coordsets/coords/spacing/dy"] = 10.0

# Add the topology.
mesh["topologies/topo/type"] = "uniform"
mesh["topologies/topo/coordset"] = "coords"

# Add a simple element-associated field.
mesh["fields/ele_example/association"] = "element"
mesh["fields/ele_example/topology"] = "topo"

edata = numpy.array([1, 2, 3, 4], dtype=numpy.float64)
mesh["fields/ele_example/values"] = edata

# Add a simple vertex-associated field.
mesh["fields/vert_example/association"] = "vertex"
mesh["fields/vert_example/topology"] = "topo"
vdata = numpy.array([1, 1, 1, 2, 2, 2, 3, 3, 3], dtype=numpy.float64)
mesh["fields/vert_example/values"] = vdata

# Verify that the mesh conforms to the specification.
verify_info = conduit.Node()
if not conduit.blueprint.mesh.verify(mesh, verify_info):
    print("Verify failed")
    print(verify_info)

print(mesh)

conduit.relay.io.blueprint.write_mesh(mesh, "blueprint_example", "json")

Here is the output.

coordsets: 
  coords: 
    type: "uniform"
    dims: 
      i: 3
      j: 3
    origin: 
      x: -10.0
      y: -10.0
    spacing: 
      dx: 10.0
      dy: 10.0
topologies: 
  topo: 
    type: "uniform"
    coordset: "coords"
fields: 
  ele_example: 
    association: "element"
    topology: "topo"
    values: [1.0, 2.0, 3.0, 4.0]
  vert_example: 
    association: "vertex"
    topology: "topo"
    values: [1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0]

PyRelay_io_blueprint_write_mesh

The complete documentation for Blueprint can be found here.