Modify built-in product configurations#
SAF GLOW Engine provides built-in configurations for Ansys products like optiSLang, Fluent, and Mechanical. However, you may need to customize these configurations for specific use cases. This includes modifying command line arguments, extending support to additional product versions, or setting custom environment variables.
To customize built-in product configurations, you need to:
Create custom product configuration classes that inherit from the built-in ones
Create custom product instance manager classes that inherit from the built-in ones and that use your new configurations
Use the new custom managers in your solution steps
This section demonstrates this process using optiSLang as an example.
Create custom configurations that modify the built-in ones#
Look for the product configuration classes in the ansys.saf.product_configuration module for the product to modify.
For example:
from ansys.saf.product_configuration.optislang_wrapper import (
OptislangWrapperInstanceConfiguration,
OptislangWrapperInstanceVersionConfiguration,
)
Create a python file and put it inside a directory called product_instance_configs in the solution directory alongside the solution and ui directories. For example:
> tree .\src\ansys\solutions\my_solution\product_instance_configs
.
└── custom_optislang_config.py
In this file, you need to implement 2 classes:
A class that inherits from
OptislangWrapperInstanceVersionConfigurationand overrides only what is needed: command arguments, environment variables, etc.A class that inherits from
OptislangWrapperInstanceConfigurationand overrides theget_version_configurationmethod to return your custom version configuration class and set a newproduct_name. You can also modify the supported productversionsproperty.
from ansys.saf.product_configuration.interfaces import IProductInstanceVersionConfiguration
from ansys.saf.product_configuration.optislang_wrapper import (
OptislangWrapperInstanceConfiguration,
OptislangWrapperInstanceVersionConfiguration,
)
class CustomOptislangInstanceVersionConfiguration(OptislangWrapperInstanceVersionConfiguration):
@property
def environment(self) -> dict[str, str]:
return {**super().environment, "MY_CUSTOM_VARIABLE": "my-value"}
class CustomOptislangInstanceConfiguration(OptislangWrapperInstanceConfiguration):
@property
def product_name(self) -> str:
return "custom-optislang"
def get_version_configuration(self, version: str) -> IProductInstanceVersionConfiguration:
return CustomOptislangInstanceVersionConfiguration(version)
Warning
Product names must use only lowercase letters and hyphens, for safety. Uppercase letters in product names can cause failures in Product Instance Management Systems.
Create custom product managers that launch the new custom configurations#
Look for the product instance manager classes in the ansys.saf.product_manager module for the product to modify.
from ansys.saf.product_manager.optislang_wrapper import InternalOptislangManagerImpl, OslManager
Create a python file and put it inside the solution directory, alongside the step files. For example:
> tree .\src\ansys\solutions\my_solution\solution
.
├── definition.py
├── my_step.py
└── custom_optislang_manager.py
In this file, you need to implement 2 classes:
A class that inherits from
InternalOptislangManagerImpland overrides thePRODUCT_NAMEattribute to match the one that you set in the custom configuration class.A class that inherits from
OslManagerto point to the new internal manager.
from ansys.saf.product_manager.optislang_wrapper import InternalOptislangManagerImpl, OslManager
class InternalCustomOptislangManager(InternalOptislangManagerImpl):
PRODUCT_NAME = "custom-optislang"
class CustomOptislangManager(OslManager, instance_manager_impl_type=InternalCustomOptislangManager): ...
Use the new product instance manager in your solution#
from pathlib import Path
from ansys.saf.glow.solution import (
StepModel,
StepSpec,
create_instance,
instance,
long_running,
transaction,
)
from ansys.solutions.my_solution.solution.custom_optislang_manager import CustomOptislangManager
class OptislangCustomStep(StepModel):
@transaction(self=StepSpec())
@create_instance("osl_manager", CustomOptislangManager)
@long_running
def launch_instance(self, osl_manager: CustomOptislangManager) -> None:
osl_manager.initialize(version="252")
osl_manager.instance.start(
project_path=Path("path/to/project.opf"),
project_properties_file=Path("path/to/working_properties_file.json"),
input_files=[],
osl_version="252",
loglevel="INFO",
)
@transaction(self=StepSpec())
@instance("osl_manager")
def use_instance(self, osl_manager: CustomOptislangManager) -> None:
with osl_manager.instance.optislang_client() as osl:
project = osl.application.project
# do something with project
@transaction(self=StepSpec())
@instance("osl_manager")
def close_instance(self, osl_manager: CustomOptislangManager) -> None:
osl_manager.shutdown()