The .ebg language
A model can be built in C++, with the expression builder, or written as text in the .ebg language and
read at run time. A .ebg file describes:
the geometry: shapes, composed with operations, as an object;
its regions and the materials they are made of, when the object is made of several;
labels, names for surfaces and parts of surfaces (a box’s face, a mesh’s face group);
the domains that solvers compute in, each with its subdomains (the regions it computes in) and its surface groups (the surfaces it gives a boundary condition), and the couplings between domains;
the properties of the materials, subdomains, surface groups and couplings: numbers, vectors, strings and flags, whose meaning is the program’s.
The language describes; it computes nothing. A program reads the model with the C++ API (see Reading models in C++), compiles its object into a tape, builds its domains for that tape, and turns the properties into tables of its own types that run on a GPU beside the geometry. The language checks what can be checked without knowing what the properties mean: that every name used is defined, that every value a shape is given is valid, and that a domain leaves no surface without a condition.
If the terms above are new, Regions, materials and domains explains regions, materials, domains and surface groups, with a picture of the cable below, and the Glossary defines each in a line.
A first model
A cable along z: a copper core in a plastic (PTFE) jacket, in a box of air with a flow across it. The
model is two files, as most models are. The geometry, cable/model.ebg:
ebg 0
# A cable along z, wholly inside a box of air with a cross-flow along x: a copper core inside a PTFE jacket, and a steel
# sensor in the flow downstream. The core stops short of the cable's ends, where it meets the air.
param length = 6
param r_core = 0.5
param r_out = 0.8
param strip = 0.5 # how far the core stops short of each end
param margin = 1 # the air beyond each end of the cable
conductor = cylinder((0, 0, strip - length / 2), (0, 0, length / 2 - strip), radius = r_core)
insulation = tube((0, 0, -length / 2), (0, 0, length / 2), inner_radius = r_core, outer_radius = r_out)
air_box = box((-3, -2, -length / 2 - margin), (5, 2, length / 2 + margin))
.label(xmin = "inlet", xmax = "outlet", ymin = "far", ymax = "far", zmin = "ends", zmax = "ends")
probe = sphere((3, 0, 0), radius = 0.3)
object overlay { # each region lies on top of the ones before it
region air = air_box material air
region jacket = insulation material PTFE
region core = conductor material copper
region sensor = probe material steel
}
Line by line:
ebg 0is the language’s version, on the first line of every file.A
paramis a value that can be changed from outside the file (-D length=8toebgstudio, or an override passed to the reader), so that one file describes a family of cables.conductor,insulationandair_boxare shapes, calls of the built-in shapes (Shapes). Arguments are given in order, or by name (radius = r_core)..label(...)names the box’s faces: itsxminface is the inlet, itsxmaxface the outlet. The names are what surface groups select later.objectis the model’s one shape. Here it is anoverlayof three regions, each a shape and a material: the jacket on top of the air, the core on top of the jacket.
What is computed on the geometry goes in a second file, cable/setup.ebg, which includes the first. It is
the file a program reads:
ebg 0
include("model.ebg")
param mu_air = 1.8e-5
material copper { conductivity = 5.8e7 }
material PTFE { permittivity = 2.1, density = 2200 }
material air { permittivity = 1.0, density = 1.2, viscosity = mu_air }
material steel { density = 7850 }
# Electrostatics: the field in the insulation and the air; the conductor is a boundary held at its potential, the
# sensor one at ground.
domain electrostatics {
subdomain insulation = jacket
subdomain gas = air
group conductor = interface(core, jacket), interface(core, air) { potential = 1000 }
group dielectric = interface(jacket, air) { surface_charge = 0 }
group ground = label("inlet"), label("outlet"), label("far"), interface(sensor, air) { potential = 0 }
group ends = remaining() { kind = "zero_flux" }
}
# Flow: air past the cable and the sensor.
domain cfd {
subdomain fluid = air
group inlet = label("inlet") { velocity = (2, 0, 0) }
group outlet = label("outlet") { pressure = 0 }
group walls = interface(air, jacket) { kind = "no_slip" }
group tips = interface(air, core) { kind = "no_slip" }
group sensor = interface(air, sensor) { kind = "no_slip" }
group slip = label("far"), label("ends") { kind = "slip" }
}
# Heat in the cable alone, cooled by the air around it: its solver needs the cable and the air, not the sensor.
domain conduction {
subdomain conductor = core { thermal_conductivity = 400 }
subdomain insulation = jacket { thermal_conductivity = 0.25 }
group cooled = remaining() { kind = "convective", h = 10 }
}
# Coupling: the electric body force acts on the gas; the cable surface carries charge into the flow.
couple body_force = volume(electrostatics.gas, cfd.fluid)
couple cable_surface = surface(electrostatics.dielectric, cfd.walls) { transfer = "charge" }
view { camera = (7, 5, 9), target = (1, 0, 0), color.copper = (0.8, 0.5, 0.2), color.air = (0.55, 0.7, 0.9) }
A
materialgives a material’s properties. The names (conductivity,viscosity) mean nothing to the language; they are what the program reads.A
domainis one computation. The electrostatic one computes in two subdomains, the jacket and the air; the core and the sensor are in neither, so they are excluded, and their surfaces are boundaries of the domain (the sensor’s grounded). Eachgroupis a surface group: a name, the surfaces it holds (selected by what they are: an interface between two regions, a label, orremaining(), every surface no other group holds), and its properties.The flow computes in the air alone; its walls are the jacket’s surface, and the core’s ends, where the core stops short of the jacket, are a group of their own,
tips, since the walls are coupled to a group of the other domain that holds the jacket alone. The sensor is a wall of its own,sensor.Conduction computes in the cable alone, a subdomain each for the core and the jacket, with properties of their own; every surface it touches is cooled. A solver of it can compile the cable on its own, without the sensor (see Reading models in C++).
A
couplejoins two domains, here through a subdomain each (the gas, which both compute in) and through a surface group each (the jacket’s surface).viewsays how a viewer opens the model; programs ignore it.
Language domains reads cable/setup.ebg in C++ (see Reading models in C++ for the
calls).
Writing a model is easiest with ebgstudio (see ebgstudio) open on it: its window reloads the model
whenever a file is saved, and ebgstudio check reports what is wrong, line by line. The tutorial,
Tutorial: a cooled block, builds a model that way, step by step, and is the place to start.
The pages of this section
Writing a model: values and params, shapes and operations, the object, regions and materials, labels, files, and how a larger model is organized.
Domains and couplings: subdomains, properties, surface groups and their selectors, when a domain is complete, and couplings.
Shapes and Operations: every built-in shape and operation, with a line to copy.
Reference: the grammar, every keyword, the view block, the limits, and the errors and warnings a reader reports.