Design evaluation#

You use the RootSystem class to create and evaluate designs. To access this class from the Optislang instance, you use the Project.root_system property:

from ansys.optislang.core import Optislang
from ansys.optislang.core.project_parametric import Design
from ansys.optislang.core import examples
from pathlib import Path

# open project with defined parameters
parametric_project = examples.get_files("calculator_with_params")[1][0]
osl = Optislang(project_path=parametric_project)

# do not modify original file
osl.application.save_as(Path.cwd() / "parametric_project.opf")

# get root system
root_system = osl.application.project.root_system


The Design evaluation use case aims for creating and evaluating designs on the project root level. It is intended to be used when optiSLang is is being used in other environments to manage a parametric workflow, expose input and output parameters (that is parameters and responses), and evaluate designs based on this parametric workflow. This use case does not cover the generation or monitoring of designs of optiSLang internal nested analysis systems, such as Sensitivity and Optimization systems. To support the Design evaluation use case, the optiSLang project must be prepared in a certain way:

  • Create the workflow and register parameters and responses at the root system level.

  • Connect the workflow to the root system using the Receive designs and Send back designs options.

For more information, see the Ten bar truss example and the optiSLang user documentation on generating workflows.

Create a design#

To create an instance of the Design class, you can obtain a design with reference values from the RootSystem class and either modify its parameters or specify design parameters from scratch.

Create a design from reference values#

If a design has all parameters specified in the project, you can use the get_reference_design() method to obtain the design’s reference values. You can then modify parameter values using methods in the Design class.

# ...

from ansys.optislang.core.project_parametric import DesignVariable

reference_design = root_system.get_reference_design()

# modify parameter value using ``name`` and ``value``
reference_design.set_parameter_by_name(name="a", value=12)

# instance of ``DesignVariable`` or ``Parameter`` can be used as well
a = DesignVariable(name="a", value=12)

Create a design from scratch#

You can create a design from scratch by directly creating an instance of the Design class. You do not have to provide parameters when initializing a new design.

# design created directly using Design() class
direct_design = Design(parameters={"a": 3, "b": 4})

# create empty design and add parameters afterward
empty_design = Design()
empty_design.set_parameter_by_name(name="a", value=3)
empty_design.set_parameter_by_name(name="c", value=4)

# Remove a parameter if desired

# Remove all parameters if desired

Verify design parameters#

To verify if the design contains all parameters defined in the project, you use the get_missing_parameters_names() method. To verify if the design contains parameters that are not defined in the project, you use the get_undefined_parameters_names() method. Running these verifications are not necessary though, because they always run internally while evaluating the design.

# ...

missing_parameters = root_system.get_missing_parameters(empty_design)
undefined_parameters = root_system.get_undefined_parameters(direct_design)

Evaluate the design#

To evaluate a design, you use the evaluate_design() method. This method returns the same Design instance with updated results.

# ...

# single design
result_design = root_system.evaluate_design(design=reference_design)


optiSLang retains only the last evaluated design at the project root system. If results of previous designs are required for later usage, you must store them locally. For example, you can store results as an instance of the Design class.

Finally, when you are done using this Optislang instance, use the dispose() method to close it: