OpenSite/Guides/Create a material

From BathAfrica Documentation
Revision as of 14:00, 29 October 2026 by BathAfrica (talk | contribs) (Add rewritten practical lesson with steps, code and expected results)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
OpenSite 0.0.1 · DevelopmentSource scope and availability


Create a user-defined practice material and read its properties through the document object interface.

Stable identifier
opensite.help.create-a-material

Prerequisites

A matching build with the material API. User-material operations use document.workspace; the catalog-provider registration capability is a separate concern.

Steps

Start with a new document

Use document.new to obtain a live document handle. In the desktop, the material extension exposes Add Material and Material Manager when available.

Enter the practice values

Use E = 210 GPa, ν = 0.28 and density = 7850 kg/m³. The helper takes SI values: elastic_pa=210e9, not 210. The values are educational inputs, not an approved standard grade.

Create and validate

Call material_create_user, retain the returned object ID, and call material_validate. Validation concerns the material record; it does not approve a design.

Read the object and check shear modulus

Resolve the object using doc.get_object(id). Read E in GPa and compare G with E / (2 × (1 + ν)); expected G is 82.03125 GPa.

Expected result

The created object exposes E = 210 GPa. The listed derived shear modulus is approximately 82.03125 GPa and the validation result is reported.

Limitations

No production catalog grade or design-standard compliance is claimed. Save the document separately if you want to retain the new material.

Complete example

import opensite

doc = opensite.execute("document.new", {})["document"]
values = {
    "name": "Practice steel", "family": "steel", "role": "structural_steel",
    "has_elastic": True, "elastic_pa": 210.0e9,
    "has_poisson": True, "poisson": 0.28,
    "has_mass_density": True, "mass_density": 7850.0,
    "has_thermal": True, "thermal_per_k": 1.2e-5,
}
created = opensite.material_create_user(doc, values)
material = doc.get_object(created["id"])
print("Name:", material.name)
print("Elastic modulus:", material.elastic_modulus.value_in("GPa"), "GPa")
print("Validation:", opensite.material_validate(doc, created["id"])["validation"])
row = next(m for m in opensite.material_list(doc) if m["id"] == created["id"])
expected_g = 210.0e9 / (2.0 * (1.0 + 0.28))
assert abs(row["shear_modulus_pa"] - expected_g) < 1.0
print("Derived shear modulus:", row["shear_modulus_pa"] / 1e9, "GPa")