Project#

You can access the Project() class from the Optislang() instance. This class provides methods for obtaining information about the loaded project and its content:

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

example = examples.get_files("calculator_with_params")[1][0]
osl = Optislang(project_path=example)
osl.save_copy(Path.cwd() / "project_content.opf")
project = osl.project

# print project info
print(project)
# obtain these information directly
name = project.get_name()
location = project.get_location()
status = project.get_status()

Project structure#

The optiSLang project can be represented by a rooted tree structure. This structure consists of nodes and the connections between these nodes. On the top level, there is one node designated as a project root system. It is represented by the RootSystem() instance. Each System() , such as the RootSystem() class or ParametricSystem() class, has a get_nodes() method that returns all its direct children nodes. This provides the ability to determine the entire project structure.

The code shows how to go through all nodes in the project and print information about them:

# ...


def print_node_info(node):
    name = node.get_name()
    type_ = node.get_type()
    status = node.get_status()
    print(name, type_, status)


def process_nodes(nodes):
    for node in nodes:
        print_node_info(node)
        if isinstance(node, System):
            process_nodes(node.get_nodes())


root_system = project.root_system
nodes = root_system.get_nodes()
process_nodes(nodes)

Parameters#

To obtain defined parameters of any parametric system, an instance of the ParameterManager() class can be used. This class contains the get_parameters(), method for returning tuple with detailed information for instances of the OptimizationParameter(), StochasticParameter(), MixedParameter(), and DepenedentParameter() classes.

The get_parameters_names() method returns a tuple with only the names of the parameters:

# ...

parameter_manager = root_system.parameter_manager
parameters = parameter_manager.get_parameters()
parameters_names = parameter_manager.get_parameters_names()

Criteria#

To obtain defined criteria of any parametric system, an instance of the CriteriaManager() class can be used. This class contains the get_criteria(), method for returning tuple with detailed information for instances of the ConstraintCriterion(), ObjectiveCriterion(), LimitStateCriterion(), and VariableCriterion() classes.

# ...

criteria_manager = root_system.criteria_manager
criteria = criteria_manager.get_criteria()
criteria_names = criteria_manager.get_criteria_names()

Responses#

To obtain defined responses of any parametric system, an instance of the ResponseManager() class can be used. This class contains the get_responses(), method for returning tuple with detailed information for instance of the Response() class.

# ...

response_manager = root_system.response_manager
responses = response_manager.get_responses()
responses_names = response_manager.get_responses_names()

When the Optislang() instance is no longer needed, stop the connection with optiSLang server by running:

osl.dispose()