MATLAB-Defined Uniaxial Material¤
Note
MatlabUniaxialMaterial is an OpenSeesMatlab extension. It is not a native
OpenSees material type and requires the OpenSeesMATLAB MEX module.
MatlabUniaxialMaterial lets a MATLAB function implement the stress, tangent,
and history evolution of an ordinary OpenSees UniaxialMaterial. Once created,
it can be assigned to zeroLength, truss, section, bearing, and other OpenSees
objects that accept a uniaxial material.
Create a material¤
Use the normal ops.uniaxialMaterial
command:
1 2 3 4 5 6 7 8 | |
The MATLAB wrapper recognizes MatlabUniaxialMaterial and routes it to the
internal MEX extensionMaterial dispatcher. Native material types such as
Elastic and Steel01 continue to use the upstream OpenSees material factory.
Callback contract¤
1 2 | |
The MEX calls MATLAB only for init and trial:
| Action | Purpose |
|---|---|
init |
Establish the initial stress, tangent, and MATLAB state |
trial |
Evaluate a candidate response from the last committed state |
response must contain finite scalar doubles:
1 2 | |
An optional viscous tangent can also be returned:
1 | |
A zero status accepts the callback evaluation. A nonzero value makes the
material evaluation fail.
The trial struct provides:
| Field | Meaning |
|---|---|
strain |
Current trial strain or element deformation |
strainRate |
Current trial strain rate |
committedStrain |
Strain at the last accepted step |
committedStrainRate |
Strain rate at the last accepted step |
committedStress |
Stress at the last accepted step |
committedTangent |
Tangent at the last accepted step |
materialTag |
OpenSees material tag |
callId |
MATLAB callback evaluation counter |
committedRevision |
Committed-state revision counter |
action |
init or trial |
Complete linear example¤
The following example creates a linear callback material, assigns it to a
zeroLength element, and solves one static load step. Notice that
initialState, committedState, and trialState always use the same fields.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
Keep one state schema¤
Use the same field names and compatible MATLAB types in all three states:
| State | Example fields |
|---|---|
initialState |
K, lastStrain, trialEvaluationCount |
committedState |
K, lastStrain, trialEvaluationCount |
trialState |
K, lastStrain, trialEvaluationCount |
This is especially important for revertToStart(): C++ restores the original
initialState supplied when the material was created. If the callback adds a
required field only during init, that field will be absent after a reset.
Define the complete state schema in initialState, then update values without
changing its structure.
State progression¤
Suppose the committed state is S0. Newton may evaluate several trial strains:
1 2 3 | |
Every candidate starts from S0; S1 must not be used to calculate S2.
After convergence, C++ executes:
1 | |
If the step fails, C++ discards the candidate and restores S0 without calling
MATLAB.
History-dependent callback rule¤
Always derive candidate history from committedState:
1 2 | |
Do not accumulate history in persistent or global variables during trial
evaluations. Newton's method may evaluate several candidates before accepting a
step. Only the state returned by the accepted trial is committed.
The C++ material follows the standard OpenSees trial/commit model:
1 2 3 4 5 | |
Commit, rollback, reset, and destruction do not enter MATLAB. This prevents script-cleanup re-entry and reduces callback overhead.
Use the material in a zero-length element¤
1 2 3 4 5 6 7 8 9 10 11 | |
For a cyclic pushover, define a unit reference load and control the node with
DisplacementControl:
1 2 3 4 5 6 7 | |
Passing the same value as the requested, minimum, and maximum increment prevents OpenSees from adaptively changing the prescribed cyclic path.
Query responses¤
MatlabUniaxialMaterial inherits UniaxialMaterial::setResponse and
UniaxialMaterial::getResponse. Standard element material queries therefore
work without a custom recorder implementation:
1 2 3 4 | |
These functions return the current trial response. Immediately after a
successful ops.analyze(1), trial and committed responses are identical. After
an analysis failure, OpenSees reverts the trial response to the preceding
committed response.
Performance¤
Crossing from C++ into MATLAB is much more expensive than evaluating a native OpenSees material. The implementation reduces this cost by:
- calling MATLAB only for
initandtrial; - caching repeated requests with the same strain, strain rate, and committed revision;
- performing commit and rollback entirely in C++.
For good performance, keep callbacks small, return scalar numeric response fields, avoid graphics or file access inside callbacks, and use only as many cyclic increments as needed to resolve the response.
Limitations¤
- MATLAB function handles and arbitrary MATLAB states cannot be serialized
through an OpenSees
Channel; distributed-process material transfer is not supported. - Do not call
ops.analyze, change the model, or replace the solution algorithm from inside a material callback. Handle failed steps in the outer MATLAB analysis loop. - The inherited
plasticStrainresponse is the OpenSees approximationstrain - stress/initialTangent; it is not a direct view of a callback state field. Store and post-process specialized history variables separately when their exact values are required.