pyfemtet.opt.interface package
モジュール内容
- class pyfemtet.opt.interface.AbstractFEMInterface[ソース]
ベースクラス:
object- contact_to_optimizer(opt, global_data, ctx)[ソース]
- パラメータ:
opt (AbstractOptimizer) –
global_data (GlobalOptimizationData) –
ctx (OptimizationDataPerFEM) –
- property object_pass_to_fun
ユーザー定義目的関数の第1引数に渡されるオブジェクト。
- 戻り値:
self (AbstractFEMInterface)
- class pyfemtet.opt.interface.AbstractSurrogateModelInterfaceBase(history_path=None, train_history=None, _output_directions=None)[ソース]
ベースクラス:
AbstractFEMInterface- パラメータ:
- contact_to_optimizer(opt, global_data, ctx)[ソース]
- パラメータ:
opt (AbstractOptimizer) –
global_data (GlobalOptimizationData) –
ctx (OptimizationDataPerFEM) –
- property object_pass_to_fun
ユーザー定義目的関数の第1引数に渡されるオブジェクト。
- 戻り値:
self (AbstractFEMInterface)
- class pyfemtet.opt.interface.BoTorchInterface(history_path=None, train_history=None, _output_directions=None)[ソース]
ベースクラス:
AbstractSurrogateModelInterfaceBase- パラメータ:
- pyfemtet.opt.interface.BoTorchWithExcelSettingsInterface
:py:class:`~pyfemtet.opt.interface._with_excel_settings.with_excel_settings._class_factory.<locals>._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)[ソース]
ベースクラス:
COMInterfaceA class for using Excel as the calculation core.
通常の FEM を Excel に置き換えて使用することが可能です。
すでに Excel マクロと FEMTET を連携させた自動解析システムを構築している場合、このクラスはそれをラップします。これにより、PyFemtet を用いた最適化を行う際に便利な機能を提供します。
- パラメータ:
input_xlsm_path (str or Path) – Specify the path of the Excel file including the definition of design variables.
input_sheet_name (str) – Specify the name of the sheet that includes the definition of design variables.
output_xlsm_path (str or Path, optional) – 目的関数の定義を含む Excel ファイルのパスを指定します。指定しない場合は
input_xlsm_pathと同じとみなします。output_sheet_name (str, optional) – 目的関数の定義を含むシートの名前を指定します。指定しない場合は
input_sheet_nameと同じと見なします。procedure_xlsm_path (str, optional) – The path of the xlsm file containing the Excel macro function called during the optimization loop. If not specified, it is assumed to be the same as
input_xlsm_path.procedure_name (str, optional) – Specify the Excel macro function name. If not specified, it defaults to
FemtetMacro.FemtetMain.procedure_args (list or tuple, optional) – Specify the arguments to pass to the Excel macro function as a list or tuple.
connect_method (str, optional) – Specify the connection method with Excel. 『auto』 or 『new』 are available. The default is 『auto』.
procedure_timeout (float or None, optional) – Specify the Excel macro function timeout in seconds. If None, there is no timeout.
setup_xlsm_path (str or Path, optional) – The path to the xlsm file containing the function called during setup. If not specified, it is considered the same as
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) – This is the name of the macro function called at the end. If not specified, nothing will be done at the end.
teardown_procedure_args (list or tuple, optional) – Arguments for the macro function called at the end.
visible (bool) – excel を可視化するかどうかです。ただし、True を指定した場合でもマクロの実行中は不可視になります。デフォルトは False です。
display_alerts (bool) – excel ダイアログを表示するかどうかです。デバッグ目的の場合以外は True にしないでください。デフォルトは False です。
terminate_excel_when_quit (bool) – Whether to quit Excel upon completion. If not specified, it behaves as True when connect_method is 『new』 and False when it is 『auto』.
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
Path of the Excel file including the definitions of design variables.
- Type:
Path
- output_xlsm_path
Path to the Excel file containing the definition of the objective function.
- Type:
Path
- terminate_excel_when_quit
Whether to close Excel upon program termination. True if connect_method is 『new』, False if 『auto』.
- Type:
- excel
Excel の COM オブジェクト。
- Type:
CDispatch
- com_members = {'excel': 'Excel.Application'}
- excel: CDispatch
- load_constraints(opt, raise_if_no_keyword=False)[ソース]
- パラメータ:
opt (AbstractOptimizer) –
- load_objectives(opt, raise_if_no_keyword=True)[ソース]
- パラメータ:
opt (AbstractOptimizer) –
- load_variables(opt, raise_if_no_keyword=True)[ソース]
- パラメータ:
opt (AbstractOptimizer) –
- 戻り値の型:
None
- property object_pass_to_fun
ユーザー定義目的関数の第1引数に渡されるオブジェクト。
- 戻り値:
Microsoft Excel の COM オブジェクト。
- 戻り値の型:
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[ソース]
ベースクラス:
AbstractFEMInterface- append(fem)[ソース]
- パラメータ:
fem (AbstractFEMInterface) –
- contact_to_optimizer(opt, global_data, ctx)[ソース]
- パラメータ:
opt (AbstractOptimizer) –
global_data (GlobalOptimizationData) –
ctx (OptimizationDataPerFEM) –
- property object_pass_to_fun
ユーザー定義目的関数の第1引数に渡されるオブジェクト。
- 戻り値:
self (AbstractFEMInterface)
- remove(fem)[ソース]
- パラメータ:
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)[ソース]
ベースクラス:
COMInterface最適化ツールから Femtet を制御します。
- パラメータ:
femprj_path (str, optional) – プロジェクトファイルへのパスです。指定されていない場合は、接続された Femtet から取得します。
model_name (str, optional) – モデルの名前です。指定されていない場合は、接続された Femtet から取得するか、Femtet がプロジェクトファイルを開いたときの最初のモデルを取得します。
connect_method (str, optional) – 接続方法です。デフォルトは 『auto』 です。他の有効な値は 『new』 または 『existing』 です。
save_pdt (str, optional) – 結果ファイルを保存する方法です。 『all』, 『optimal』 または 『none』 を指定できます。デフォルトは 『all』 です。
strictly_pid_specify (bool, optional) – Femtet 接続で PID を厳密に指定するかどうかです。デフォルトは True です。
allow_without_project (bool, optional) – プロジェクトなしでの実行を許可するかどうかです。デフォルトは False です。
open_result_with_gui (bool, optional) – 結果を GUI で開くかどうかです。デフォルトは True です。
parametric_output_indexes_use_as_objective (dict[int, str or float], optional) –
目的関数として使用するパラメトリック出力インデックスのリストとその方向です。指定されていない場合は None となり、パラメトリック出力は目的として使用されません。
注釈
インデックスは0から始まりますが、Femtet のパラメトリック解析ダイアログの結果出力設定タブには、1から始まる設定番号が表示されます。
警告
この引数を設定すると、femprj ファイルに設定されているパラメトリック解析スイープテーブルが削除されます。 スイープテーブルを削除したくない場合は、元のファイルをコピーしてください。
警告
コンストラクタで
strictly_pid_specify=Trueを指定しても、並列処理では接続の動作がstrictly_pid_specify=Falseのようになります。これは大きなオーバーヘッドによるものです。したがって、n_parallelが 2 以上の場合は、FEMOpt.optimize() を実行する前にすべての Femtet プロセスを閉じるべきです。Tip
Python と Femtet を接続する方法についての情報を探している場合は、
connect_femtet()を参照してください。- close(timeout=15, force=True)[ソース]
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)[ソース]
Femtet プロセスに接続します。
- パラメータ:
注釈
接続方法が 『new』 の場合、新しい Femtet プロセスを起動して接続します。pid は無視されます。
注釈
『existing』 の場合、既存の Femtet プロセスに接続します。ただし、接続できる Femtet がない場合(すなわち、他の Python または Excel プロセスにすでに接続されている場合)、例外をスローします。
注釈
『auto』 に設定されている場合、最初に 『existing』 を試み、失敗した場合は 『new』 で接続します。pid が指定されていて接続に失敗した場合、別の Femtet プロセスへの接続は試みません。
- current_prm_values: TrialInput
- load_objectives(*args, **kwargs)
- property object_pass_to_fun
ユーザー定義目的関数の第1引数に渡されるオブジェクト。
- 戻り値:
Femtet の COM オブジェクト.
- 戻り値の型:
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
:py:class:`~pyfemtet.opt.interface._with_excel_settings.with_excel_settings._class_factory.<locals>._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)[ソース]
ベースクラス:
FemtetInterface,_NXInterfaceFemtet と NX を制御します。
このクラスを使用すると、NX で作成された CAD ファイルを Parasolid 形式を介して Femtet プロジェクトにインポートできます。これにより、設計変数を NX に渡し、モデルを更新し、更新されたモデルを使用して Femtet で解析を実行することができます。
- パラメータ:
prt_path (str) – インポート元の CAD データを含む .prt ファイルへのパスです。
export_curves (bool or None, optional) – デフォルトは None です。
export_surfaces (bool or None, optional) – デフォルトは None です。
export_solids (bool or None, optional) – デフォルトは None です。
export_flattened_assembly (bool or None, optional) – デフォルトは 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]) –
メモ
`export_*`引数は NX の Parasolid エクスポート設定を設定します。None の場合、PyFemtet は NX の現在の設定を変更しません。Femtet にインポートされた Parasolid をエクスポートする際に使用された設定から、これらの値を変更しないことを推奨します。
- pyfemtet.opt.interface.FemtetWithNXWithExcelSettingsInterface
:py:class:`~pyfemtet.opt.interface._with_excel_settings.with_excel_settings._class_factory.<locals>._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)[ソース]
ベースクラス:
FemtetInterface,SolidworksInterface,AbstractFEMInterfaceFemtet と SolidWorks の操作を統合するインターフェースクラス。
このクラスは、Femtet と SolidWorks のインターフェースの機能を組み合わせており、シミュレーション(Femtet)と CAD 操作(SolidWorks)間の連携動作を可能にします。
- パラメータ:
sldprt_path (str) – SolidWorks 部品ファイル(.sldprt)へのパス。
femprj_path (str, optional) – Femtetプロジェクトファイル(.femprj)へのパス。デフォルトはNoneです。
model_name (str, optional) – プロジェクト内のモデル名。デフォルトは None です。
connect_method (str, optional) – 接続方法です。』new』 、 『existing』 、または 『auto』 を指定できます。デフォルトは 『auto』 です。
save_pdt (str, optional) – 保存するデータを指定します。デフォルトは「all」です。
strictly_pid_specify (bool, optional) – Femtet 接続で PID を厳密に指定するかどうかです。デフォルトは True です。
allow_without_project (bool, optional) – プロジェクトなしでの実行を許可するかどうかです。デフォルトは False です。
open_result_with_gui (bool, optional) – 結果を GUI で開くかどうかです。デフォルトは True です。
parametric_output_indexes_use_as_objective (dict[int, str | float], optional) – 目的関数として使用されるパラメトリック出力のインデックス。デフォルトは None です。
always_open_copy (bool, optional) – True の場合、常にプロジェクトのコピーを開きます。デフォルトは False です。
close_solidworks_on_terminate (bool, optional) – True の場合、このオブジェクトが破棄されると SolidWorks は終了します。デフォルトは False です。
solidworks_visible (bool, optional) – True の場合、SolidWorks は表示モードで起動されます。初期値は True です。
- pyfemtet.opt.interface.FemtetWithSolidworksWithExcelSettingsInterface
:py:class:`~pyfemtet.opt.interface._with_excel_settings.with_excel_settings._class_factory.<locals>._WithExcelSettingsInterface`の別名です。
- class pyfemtet.opt.interface.NoFEM[ソース]
ベースクラス:
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)[ソース]
ベースクラス:
BoTorchInterface,AbstractSurrogateModelInterfaceBase- パラメータ: