Visualization Without Solution Data: Grid Datasets
The section Results shows how to write code for various parts of the Results node in the model tree, including Datasets, Tables, and Plot Groups. These examples assume that you have solution data available from solving, for example, a heat transfer, CFD, or structural mechanics problem.
You can also create visualizations without having associated solution data by either using grid datasets or using low-level functionality only available through methods. You can, for example, write code for plotting points and triangles without any associated solution data. These techniques are useful when creating applications where customized plot functionality is needed. This section shows how to use grid datasets, and the next section shows how to use low-level functionality.
Plotting a Unit Sphere using a Grid Dataset
Grid datasets are available in the Model Builder and can be used in applications for the sole purpose of visualization without any associated solution data. The code below creates a visualization of a unit sphere as an isosurface with the z-coordinate as color data.
 
model.func().create("an1", "Analytic");
model.result().dataset().create("grid1", "Grid3D");
 
with(model.result().dataset("grid1"));
  set("source", "data");
  set("parmin1", -1);
  set("parmax1", +1);
  set("parmin2", -1);
  set("parmax2", +1);
  set("parmin3", -1);
  set("parmax3", +1);
  set("source", "function");
  set("function", "an1");
endwith();
 
model.result().create("pg1", "PlotGroup3D");
model.result("pg1").create("iso1", "Isosurface");
 
with(model.result("pg1").feature("iso1"));
  set("expr", "x^2+y^2+z^2-1");
  set("levelmethod", "levels");
  set("levels", 0.0);
endwith();
 
model.result("pg1").feature("iso1").create("col1", "Color");
with(model.result("pg1").feature("iso1").feature("col1"));
  set("expr", "z");
endwith();
 
model.result("pg1").run();
Comments
If there is no solution-based Dataset available, then the Grid3D dataset needs to have a Function as its Source. In the example above, a default Analytic function is created with tag an1. A default Analytic function corresponds to f(x) = x, and its only purpose is to give the grid dataset an evaluation context.
Note: The alternative is to solve a physics problem on a mesh and reference the corresponding solution dataset. The method of referencing an arbitrary Function makes it possible to create visualizations without solution data.
The source for the Grid3D dataset with tag grid1 is set to function, and finally, the function property of grid1 is set to an1.
The Grid3D dataset has options for max and min parameter bounds, shown in the example code above. An additional grid resolution option is not shown in this example. However, you can learn about its syntax by using Record Code from the Model Builder.