model.variable()
Create, define, and remove variables.
Syntax
model.variable().create(<tag>);
model.variable(<tag>).set(<var>,<expr>);
model.variable(<tag>).set(<var>,<expr>,<descr>);
model.variable(<tag>).descr(<var>,<descr>);
model.variable(<tag>).remove(<var>);
model.variable(<tag>).clear();
model.variable(<tag>).model(<mtag>);
 
model.variable(<tag>).varnames();
model.variable(<tag>).get(<var>);
model.variable(<tag>).descr(<var>);
model.variable(<tag>).model();
model.variable(<tag>).scope();
model.variable(<tag>).loadFile(tempFile, ...);
model.variable(<tag>).saveFile(tempFile, ...);.
For variables on the component level, use model.component(<ctag>).variable().create(<tag>), and so on, instead of the syntax above for global variables.
Description
 model.variable(<tag>) returns a variable collection. Each variable collection can contain several variables, but only one selection.
 model.variable().create(<tag>) creates a variables node with tag <tag>.
model.variable(<tag>).set(<var>,<expr>) defines the variable <var> by the expression <expr>.
model.variable(<tag>).set(<var>,<expr>,<descr>) defines a variable and gives it a description.
model.variable(<tag>).descr(<var>,<descr>) defines a description for the variable <var>.
model.variable(<tag>).model(<mtag>) sets the model component node.
model.variable(<tag>).selection().named(<seltag>) assigns the variable node to the named selection <seltag>.
model.shape(<tag>).selection().set(...) defines a local selection that assigns the variable collection to geometric entities. Before assigning a selection, the variable’s model must be set using model.variable(<tag>).model(<mtag>). Only the global selection and selections on a geometry in the model can be used. For a complete list of methods available under selection(), see Selections.
model.variable(<tag>).remove(<var>) removes a variable from the variable collection. model.variable(<tag>).clear() removes all variables from the variable collection.
model.variable(<tag>).varnames() returns the names of all expressions as a string array.
model.variable(<tag>).get(<var>) returns the variable value as a string.
model.variable(<tag>).descr(<var>) returns the variable description as a string.
model.variable(<tag>).model() returns the model component node tag.
model.variable(<tag>).scope() returns the fully qualified scope name.
model.variable(<tag>).selection().named() returns the selection tag as a string.
model.variable(<tag>).selection().getType() returns domain information. For available methods, see model.selection().
For model.param().loadFile() and model.param().saveFile(), see The loadFile and saveFile Methods.
Examples
Define the expression e as x+1 in Domains 1 and 2 and as x-1 in Domain 3.
Code for Use with Java
Model model = ModelUtil.create("Model");
model.component().create("comp1");
model.component("comp1").geom().create("geom1",3);
model.component("comp1").geom("geom1").create("blk1", "Block");
model.component("comp1").geom("geom1").run();
model.component("comp1").variable().create("e1").set("e","x+1");
model.component("comp1").variable("e1").selection().geom("geom1",2);
model.component("comp1").variable("e1").selection().set(new int[]{1,2});
model.component("comp1").variable().create("e2").set("e","x-1");
model.component("comp1").variable("e2").selection().geom("geom1",2);
model.component("comp1").variable("e2").selection().set(3);
Code for Use with MATLAB
model = ModelUtil.create('Model');
model.component.create('comp1');
model.component.geom.create('geom1',3);
model.component.geom('geom1').create('blk1', 'Block');
model.component.geom('geom1').run;
model.component.variable.create('e1').set('e','x+1');
model.component.variable('e1').selection.geom('geom1',2);
model.component.variable('e1').selection.set([1,2]);
model.component.variable.create('e2').set('e','x-1');
model.component.variable('e2').model('mod1');
model.component.variable('e2').selection().geom('geom1',2);
model.component.variable('e2').selection().set(3);
See Also
model.selection()