How to set up a new item
A new node, object, marker, load or sensor. Short: write the definition, generate, write the
.cpp, build, test. The details of each part are in the documents linked here; this page says what
to do in which order.
0. First in Python
Try the model with the generic items and user functions: ObjectGenericODE2/ODE1 with user
functions for a body or a system, ObjectConnectorCoordinateVector for a constraint, a spring-damper
with a force user function for a connector, SensorUserFunction for a sensor. A C++ item is worth it
when that prototype works and is too slow.
1. How it works
An item is one ItemDefinition(...) in definitions/itemDefs<Kind>.py. The generators read it and
write everything that follows from it; the computation is hand-written C++.
written |
for item |
by |
|---|---|---|
the definition |
|
you |
C++ headers: parameters, the three classes |
|
generator |
registration in the object factory: |
|
generator |
the Python class |
|
generator |
the reference manual page, and the item in the index of its kind |
|
generator |
the MiniExample file and its entry in the list the test suite runs |
|
generator |
the computation, the output variables and the drawing ( |
|
you |
the checks before assembly, if the definition declares |
|
you |
a new |
|
you |
the reference value of the MiniExample |
|
you |
Never edit a generated file; a hand edit is overwritten by the next generation.
2. The definition
Copy the definition of the item that is most like yours, in the same file, and change it. The vocabulary is in definitions/README.md.
Header:
className,classType,objectType(objects), the parentscParentClass,mainParentClass,visuParentClass,pythonShortName.Parameters:
ItemParameter(type=..., destination=..., pythonName=..., defaultValue=..., description=...). A description that starts with a symbol in$...$puts the symbol into the table,(symbol: ...).Functions:
ItemFunctionDef('Name')for a function that overrides a base-class function - the declaration comes from the library;implementation=for a one-line body, otherwise the body is in your.cpp.ItemFunction(...)for a function new in this item. Each with adescriptionwhere it is not obvious.Types: what the item provides and needs -
ItemTypes,ItemRequestedTypes,ItemAccessFunctionTypes()(objects: the types are derived from the access functions the object provides;ownMarkers=for a super element or kinematic tree with markers of its own),requestedNodeTypes(node markers). They decide which items fit together;Assemble()checks them, and the page lists the fitting items from them.outputVariables:ItemOutputVariable(OVPosition, r"""$symbol$description""")for every output variable; the generator writesGetOutputVariableTypesfrom the list, you implementGetOutputVariable...for exactly these.overallDescription: one or two sentences, what it is and what for.detailedDescription: the equations - headings and contents by kind in definitions/README.md §The page of an item, the rules of the text in §Writing a description.miniExample: a short model that uses the item and setsexu.sys['testResult']; rules in §The mini example.optional:
createFunctions,examples(§The page of an item).
3. Generate
In venvExuP313:
python tools/regenerate.py --check # validates the definitions, generates, reports what changed
exudev generate --all-checks # the same with all checks
The validator fails on a function that overrides nothing, a wrong type, a description that breaks
the text rules. Then read the page, docs/generated/items/<Item>.md.
4. The C++
Copy the .cpp of the same item as in step 2 and rewrite its functions; the class declarations are
in the generated headers.
kind |
functions to implement |
|---|---|
body |
|
connector |
|
constraint |
|
node |
|
marker |
|
load |
|
sensor |
|
every item |
|
Checks of parameters and of the items it is attached to go into CheckPreAssembleConsistency, with
a message that names the parameter; errors raised from C++ follow
CODING_STYLE.md §10.
5. Build and test
exudev build --env venvExuP313
exudev test --env venvExuP313 # runs the MiniExample; add its value to runTestSuiteRefSol.py
A test model in python/TestModels/ for what the MiniExample does not cover
(WORKFLOW.md §What a test model looks like); then the four gates of
WORKFLOW.md.