pyfemtet.opt.interface package
Module contents
- class pyfemtet.opt.interface.AbstractFEMInterface[source]
Bases:
object- contact_to_optimizer(opt, global_data, ctx)[source]
- Parameters:
opt (AbstractOptimizer) –
global_data (GlobalOptimizationData) –
ctx (OptimizationDataPerFEM) –
- property object_pass_to_fun
The object pass to the first argument of user-defined objective functions.
- Returns:
self (AbstractFEMInterface)
- class pyfemtet.opt.interface.AbstractSurrogateModelInterfaceBase(history_path=None, train_history=None, _output_directions=None)[source]
Bases:
AbstractFEMInterface- Parameters:
- contact_to_optimizer(opt, global_data, ctx)[source]
- Parameters:
opt (AbstractOptimizer) –
global_data (GlobalOptimizationData) –
ctx (OptimizationDataPerFEM) –
- property object_pass_to_fun
The object pass to the first argument of user-defined objective functions.
- Returns:
self (AbstractFEMInterface)
- class pyfemtet.opt.interface.BoTorchInterface(history_path=None, train_history=None, _output_directions=None)[source]
Bases:
AbstractSurrogateModelInterfaceBase- Parameters:
- pyfemtet.opt.interface.BoTorchWithExcelSettingsInterface
alias of
_WithExcelSettingsInterface
- class pyfemtet.opt.interface.ExcelInterface(input_xlsm_path, input_sheet_name, output_xlsm_path=None, output_sheet_name=None, constraint_xlsm_path=None, constraint_sheet_name=None, procedure_xlsm_path=None, procedure_name=None, procedure_args=None, connect_method='new', procedure_timeout=None, setup_xlsm_path=None, setup_procedure_name=None, setup_procedure_args=None, teardown_xlsm_path=None, teardown_procedure_name=None, teardown_procedure_args=None, related_file_paths=None, visible=False, display_alerts=False, terminate_excel_when_quit=None, interactive=True, use_named_range=True, force_override_when_load=False)[source]
Bases:
COMInterfaceExcel を計算コアとして利用するためのクラス。
通常の有限要素法を Excel に 置き換えて使用することが可能です。
すでに Excel マクロと Femtet を 連携させた自動解析システムを 構築している場合、このクラスは それをラップします。これにより、 PyFemtet を用いた最適化を 行う際に便利な機能を提供します。
- Parameters:
input_xlsm_path (str or Path) – 設計変数の定義を含む Excel ファイルのパスを指定 します。
input_sheet_name (str) – 設計変数の定義を含むシートの名前を指定します。
output_xlsm_path (str or Path, optional) – 目的関数の定義を含む Excel ファイルのパスを指定 します。指定しない場合は
input_xlsm_pathと 同じと見做します。output_sheet_name (str, optional) – 目的関数の定義を含む含むシートの名前を指定します。 指定しない場合は
input_sheet_nameと同じと見 做します。procedure_xlsm_path (str, optional) – 最適化ループ中に呼ぶ Excel マクロ関数を 含む xlsm のパスです。 指定しない場合は
input_xlsm_pathと 同じと見做します。procedure_name (str, optional) – Excel マクロ関数名を指定します。指定しない場合は
FemtetMacro.FemtetMainと見做します。procedure_args (list or tuple, optional) – Excel マクロ関数に渡す引数をリストまたはタプルで 指定します。
connect_method (str, optional) – Excel との接続方法を指定します。 ‘auto’ または ‘new’ が利用可能です。デフォルトは ‘auto’ です。
procedure_timeout (float or None, optional) – Excel マクロ関数のタイムアウト時間を秒単位で指定 します。 None の場合はタイムアウトなしとなります。
setup_xlsm_path (str or Path, optional) – セットアップ時に呼ぶ関数を含む xlsm のパスです。 指定しない場合は
input_xlsm_pathと 同じと見做します。setup_procedure_name (str, optional) – セットアップ時に呼ぶマクロ関数名です。 指定しない場合、セットアップ時に何もしません。
setup_procedure_args (list or tuple, optional) – セットアップ時に呼ぶマクロ関数の引数です。
teardown_xlsm_path (str or Path, optional) – 終了時に呼ぶ関数を含む xlsm のパスです。 指定しない場合は
input_xlsm_pathと 同じと見做します。teardown_procedure_name (str, optional) – 終了時に呼ぶマクロ関数名です。 指定しない場合、終了時に何もしません。
teardown_procedure_args (list or tuple, optional) – 終了時に呼ぶマクロ関数の引数です。
visible (bool) – excel を可視化するかどうかです。 ただし、 True を指定した場合でもマクロの実行中は 不可視になります。 デフォルトは False です。
display_alerts (bool) – excel ダイアログを表示するかどうかです。 デバッグ目的の場合以外は True にしないでください。 デフォルトは False です。
terminate_excel_when_quit (bool) – 終了時に Excel を終了するかどうかです。 指定しない場合、 connect_method が ‘new’ の場合 True とふるまい ‘auto’ の場合 False と振舞います。
interactive (bool) – excel を対話モードにするかどうかです。 False にすると、 visible == True であっても 自動化プロセス中にユーザーが誤って Excel 本体を操作できないようにします。 デフォルトは True です。
constraint_xlsm_path (str) –
constraint_sheet_name (str) –
use_named_range (bool) –
force_override_when_load (bool) –
- input_xlsm_path
設計変数の定義を含む Excel ファイルのパス。
- Type:
Path
- output_xlsm_path
目的関数の定義を含む Excel ファイルのパス。
- Type:
Path
- terminate_excel_when_quit
プログラム終了時に Excel を終了するかどうか。 connect_method が ‘new’ の場合 True, ‘auto’ の場合 False。
- Type:
- excel
Excel の COM オブジェクト。
- Type:
CDispatch
- com_members = {'excel': 'Excel.Application'}
- excel: CDispatch
- load_constraints(opt, raise_if_no_keyword=False)[source]
- Parameters:
opt (AbstractOptimizer) –
- load_objectives(opt, raise_if_no_keyword=True)[source]
- Parameters:
opt (AbstractOptimizer) –
- load_variables(opt, raise_if_no_keyword=True)[source]
- Parameters:
opt (AbstractOptimizer) –
- Return type:
None
- property object_pass_to_fun
The object pass to the first argument of user-defined objective functions.
- Returns:
COM object of Microsoft Excel.
- Return type:
excel (CDispatch)
- property sh_constraint: CDispatch
- property sh_input: CDispatch
- property sh_output: CDispatch
- property wb_constraint: CDispatch
- property wb_input: CDispatch
- property wb_output: CDispatch
- property wb_procedure: CDispatch
- property wb_setup: CDispatch
- property wb_teardown: CDispatch
- class pyfemtet.opt.interface.FEMListInterface[source]
Bases:
AbstractFEMInterface- append(fem)[source]
- Parameters:
fem (AbstractFEMInterface) –
- contact_to_optimizer(opt, global_data, ctx)[source]
- Parameters:
opt (AbstractOptimizer) –
global_data (GlobalOptimizationData) –
ctx (OptimizationDataPerFEM) –
- property object_pass_to_fun
The object pass to the first argument of user-defined objective functions.
- Returns:
self (AbstractFEMInterface)
- remove(fem)[source]
- Parameters:
fem (AbstractFEMInterface) –
- class pyfemtet.opt.interface.FemtetInterface(femprj_path=None, model_name=None, connect_method='auto', save_pdt='all', strictly_pid_specify=True, allow_without_project=False, open_result_with_gui=True, always_open_copy=False, parametric_output_indexes_use_as_objective=None)[source]
Bases:
COMInterfaceControl Femtet from optimizer.
- Parameters:
femprj_path (str, optional) – The path to the project file. If not specified, get it from connected Femtet.
model_name (str, optional) – The name of the model. If not specified, get it from connected Femtet or the first model when Femtet open the project file.
connect_method (str, optional) – The connection method. Default is ‘auto’. Other valid values are ‘new’ or ‘existing’.
save_pdt (str, optional) – The type to save result file. Valid values are ‘all’, ‘none’ or ‘optimal’. Default is ‘all’.
strictly_pid_specify (bool, optional) – Whether to strictly specify the PID in Femtet connection. Default is True.
allow_without_project (bool, optional) – Whether to allow without a project. Default is False.
open_result_with_gui (bool, optional) – Whether to open the result with GUI. Default is True.
parametric_output_indexes_use_as_objective (dict[int, str or float], optional) –
A list of parametric output indexes and its direction to use as the objective function. If not specified, it will be None and no parametric outputs are used as objectives.
Note
Indexes start at 0, but the parametric analysis output settings in the Femtet dialog box indicate setting numbers starting at 1.
Warning
Setting this argument deletes the parametric analysis swept table set in the femprj file. If you do not want to delete the swept table, make a copy of the original file.
Warning
Even if you specify
strictly_pid_specify=Trueon the constructor, the connection behavior is likestrictly_pid_specify=Falsein parallel processing because of its large overhead. So you should close all Femtet processes before running FEMOpt.optimize() ifn_parallel>= 2.Tip
If you search for information about the method to connect python and Femtet, see
connect_femtet().- close(timeout=15, force=True)[source]
Destructor.
May not quit Femtet. If you want to quit certainly, Please use quit() method.
- com_members = {'Femtet': 'FemtetMacro.Femtet'}
- connect_femtet(connect_method='auto', pid=None)[source]
Connects to a Femtet process.
- Parameters:
Note
When connect_method is ‘new’, starts a new Femtet process and connects to it. pid will be ignored.
Note
When ‘existing’, connect to an existing Femtet process. However, if there are no Femtets to which it can connect (i.e. already connected to another Python or Excel process), it throws an exception.
Note
When set to ‘auto’, first tries ‘existing’, and if that fails, connects with ‘new’. If pid is specified and failed to connect, it will not try existing another Femtet process.
- current_prm_values: TrialInput
- load_objectives(*args, **kwargs)
- property object_pass_to_fun
The object pass to the first argument of user-defined objective functions.
- Returns:
COM object of Femtet.
- Return type:
Femtet (CDispatch)
- postprocess(*args, **kwargs)
- preprocess(*args, **kwargs)
- save_screenshot: Literal['result', 'model', 'none']
- solve(*args, **kwargs)
- update(*args, **kwargs)
- update_model(*args, **kwargs)
- update_parameter(*args, **kwargs)
- pyfemtet.opt.interface.FemtetWithExcelSettingsInterface
alias of
_WithExcelSettingsInterface
- class pyfemtet.opt.interface.FemtetWithNXInterface(prt_path, femprj_path=None, model_name=None, connect_method='auto', save_pdt='all', strictly_pid_specify=True, allow_without_project=False, open_result_with_gui=True, parametric_output_indexes_use_as_objective=None, always_open_copy=False, export_curves=None, export_surfaces=None, export_solids=None, export_flattened_assembly=None)[source]
Bases:
FemtetInterface,_NXInterfaceControl Femtet and NX.
Using this class, you can import CAD files created in NX through the Parasolid format into a Femtet project. It allows you to pass design variables to NX, update the model, and perform analysis using the updated model in Femtet.
- Parameters:
prt_path (str) – The path to .prt file containing the CAD data from which the import is made.
export_curves (bool or None, optional) – Defaults to None.
export_surfaces (bool or None, optional) – Defaults to None.
export_solids (bool or None, optional) – Defaults to None.
export_flattened_assembly (bool or None, optional) – Defaults to None.
femprj_path (str) –
model_name (str) –
connect_method (str) –
save_pdt (str) –
strictly_pid_specify (bool) –
allow_without_project (bool) –
open_result_with_gui (bool) –
parametric_output_indexes_use_as_objective (dict[int, str | float]) –
Notes
`export_*`arguments sets parasolid export setting of NX. If None, PyFemtet does not change the current setting of NX.It is recommended not to change these values from the settings used when exporting the Parasolid that was imported into Femtet.
- pyfemtet.opt.interface.FemtetWithNXWithExcelSettingsInterface
alias of
_WithExcelSettingsInterface
- class pyfemtet.opt.interface.FemtetWithSolidworksInterface(sldprt_path, femprj_path=None, model_name=None, connect_method='auto', save_pdt='all', strictly_pid_specify=True, allow_without_project=False, open_result_with_gui=True, parametric_output_indexes_use_as_objective=None, always_open_copy=False, close_solidworks_on_terminate=False, solidworks_visible=True)[source]
Bases:
FemtetInterface,SolidworksInterface,AbstractFEMInterfaceInterface class integrating Femtet and SolidWorks operations.
This class combines the capabilities of both Femtet and SolidWorks interfaces, allowing coordinated operation between simulation (Femtet) and CAD manipulation (SolidWorks).
- Parameters:
sldprt_path (str) – Path to the SolidWorks part file (.sldprt).
femprj_path (str, optional) – Path to the Femtet project file (.femprj). Defaults to None.
model_name (str, optional) – Name of the model in the project. Defaults to None.
connect_method (str, optional) – Connection method for Femtet. Defaults to “auto”.
save_pdt (str, optional) – Specifies which data to save. Defaults to “all”.
strictly_pid_specify (bool, optional) – Whether to strictly specify parameter IDs. Defaults to True.
allow_without_project (bool, optional) – If True, allows operation without a project file. Defaults to False.
open_result_with_gui (bool, optional) – If True, open results with GUI. Defaults to True.
parametric_output_indexes_use_as_objective (dict[int, str | float], optional) – Indexes for parametric output used as objectives. Defaults to None.
always_open_copy (bool, optional) – If True, always open a copy of the project. Defaults to False.
close_solidworks_on_terminate (bool, optional) – If True, SolidWorks will close when this object is destroyed. Defaults to False.
solidworks_visible (bool, optional) – If True, SolidWorks will be started in visible mode. Defaults to True.
- pyfemtet.opt.interface.FemtetWithSolidworksWithExcelSettingsInterface
alias of
_WithExcelSettingsInterface
- class pyfemtet.opt.interface.NoFEM[source]
Bases:
AbstractFEMInterface
- class pyfemtet.opt.interface.PoFBoTorchInterface(history_path, train_history=None, observation_noise=None, feasibility_noise=None, feasibility_cdf_threshold=0.5, _output_directions=None)[source]
Bases:
BoTorchInterface,AbstractSurrogateModelInterfaceBase- Parameters:
- pyfemtet.opt.interface.PoFBoTorchWithExcelSettingsInterface
alias of
_WithExcelSettingsInterface