pyfemtet.opt.interface package

モジュール内容

class pyfemtet.opt.interface.AbstractFEMInterface[ソース]

ベースクラス: object

close(*args, **kwargs)[ソース]
contact_to_optimizer(opt, global_data, ctx)[ソース]
パラメータ:
  • opt (AbstractOptimizer) –

  • global_data (GlobalOptimizationData) –

  • ctx (OptimizationDataPerFEM) –

current_prm_values: dict[str, Variable]
kwargs: dict = {}
load_constraints(opt)[ソース]
パラメータ:

opt (OptimizationDataPerFEM) –

load_objectives(opt)[ソース]
パラメータ:

opt (OptimizationDataPerFEM) –

load_variables(opt)[ソース]
パラメータ:

opt (OptimizationDataPerFEM) –

property object_pass_to_fun

ユーザー定義目的関数の第1引数に渡されるオブジェクト。

戻り値:

self (AbstractFEMInterface)

reopen()[ソース]
trial_postprocess()[ソース]
戻り値の型:

None

trial_postprocess_per_fidelity()[ソース]
戻り値の型:

None

trial_preprocess()[ソース]
戻り値の型:

None

trial_preprocess_per_fidelity()[ソース]
戻り値の型:

None

update()[ソース]
戻り値の型:

None

update_parameter(x)[ソース]
パラメータ:

x (dict[str, Variable]) –

戻り値の型:

None

class pyfemtet.opt.interface.AbstractSurrogateModelInterfaceBase(history_path=None, train_history=None, _output_directions=None)[ソース]

ベースクラス: AbstractFEMInterface

パラメータ:
  • history_path (str | None) –

  • train_history (History) –

  • _output_directions (Sequence[DIRECTION] | dict[str, DIRECTION] | dict[int, DIRECTION] | None) –

contact_to_optimizer(opt, global_data, ctx)[ソース]
パラメータ:
  • opt (AbstractOptimizer) –

  • global_data (GlobalOptimizationData) –

  • ctx (OptimizationDataPerFEM) –

current_obj_values: dict[str, float]
property object_pass_to_fun

ユーザー定義目的関数の第1引数に渡されるオブジェクト。

戻り値:

self (AbstractFEMInterface)

train_history: History
class pyfemtet.opt.interface.BoTorchInterface(history_path=None, train_history=None, _output_directions=None)[ソース]

ベースクラス: AbstractSurrogateModelInterfaceBase

パラメータ:
current_obj_std_values: dict[str, float]
update()[ソース]
戻り値の型:

None

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)[ソース]

ベースクラス: COMInterface

A 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) –

  • related_file_paths (list[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

input_sheet_name

Name of the sheet including the definition of design variables.

Type:

str

output_xlsm_path

Path to the Excel file containing the definition of the objective function.

Type:

Path

output_sheet_name

Name of the sheet containing the definition of the objective function.

Type:

str

procedure_name

Name of the Excel macro function to execute.

Type:

str

procedure_args

List または tuple の形式で Excel マクロ関数に渡す引数。

Type:

list or tuple

excel_connect_method

Connection method. 『new』 または 『auto』。

Type:

str

procedure_timeout

Excel マクロ関数の実行タイムアウト。Noneの場合は無制限。

Type:

float or None

terminate_excel_when_quit

Whether to close Excel upon program termination. True if connect_method is 『new』, False if 『auto』.

Type:

bool

excel

Excel の COM オブジェクト。

Type:

CDispatch

static add_femtet_macro_reference(wb)[ソース]
close()[ソース]
com_members = {'excel': 'Excel.Application'}
connect_excel(connect_method)[ソース]
constraint_from_excel(_, name)[ソース]
パラメータ:

name (str) –

constraint_sheet_name: str
constraint_xlsm_path: str
display_alerts: bool
excel: CDispatch
force_override_when_load: bool
input_sheet_name: str
input_xlsm_path: str
interactive: bool
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)

objective_from_excel(_, name)[ソース]
パラメータ:

name (str) –

open_femtet_ref_xla()[ソース]
output_sheet_name: str
output_xlsm_path: str
procedure_args: list
procedure_name: str
related_file_paths: list[str]
static remove_femtet_ref_xla(wb)[ソース]
setup_procedure_args: list
setup_procedure_name: str
setup_xlsm_path: str
property sh_constraint: CDispatch
property sh_input: CDispatch
property sh_output: CDispatch
teardown_procedure_args: list
teardown_procedure_name: str
teardown_xlsm_path: str
terminate_excel_when_quit: bool
update()[ソース]
戻り値の型:

None

update_parameter(x)[ソース]
パラメータ:

x (dict[str, Variable]) –

戻り値の型:

None

use_named_range: bool
visible: bool
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) –

close(*args, **kwargs)[ソース]
contact_to_optimizer(opt, global_data, ctx)[ソース]
パラメータ:
  • opt (AbstractOptimizer) –

  • global_data (GlobalOptimizationData) –

  • ctx (OptimizationDataPerFEM) –

load_constraints(opt)[ソース]
パラメータ:

opt (OptimizationDataPerFEM) –

load_objectives(opt)[ソース]
パラメータ:

opt (OptimizationDataPerFEM) –

load_variables(opt)[ソース]
パラメータ:

opt (OptimizationDataPerFEM) –

property object_pass_to_fun

ユーザー定義目的関数の第1引数に渡されるオブジェクト。

戻り値:

self (AbstractFEMInterface)

pop(index)[ソース]
パラメータ:

index (int) –

戻り値の型:

AbstractFEMInterface

remove(fem)[ソース]
パラメータ:

fem (AbstractFEMInterface) –

reopen()[ソース]
trial_postprocess()[ソース]
戻り値の型:

None

trial_postprocess_per_fidelity()[ソース]
戻り値の型:

None

trial_preprocess()[ソース]
戻り値の型:

None

trial_preprocess_per_fidelity()[ソース]
戻り値の型:

None

update()[ソース]
update_parameter(x)[ソース]
パラメータ:

x (dict[str, Variable]) –

戻り値の型:

None

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 プロセスに接続します。

パラメータ:
  • connect_method (str, optional) – 接続方法です。 『new』 、 『existing』 、または 『auto』 を指定できます。デフォルトは 『auto』 です。

  • pid (int or None, optional) – 接続したい既存の Femtet プロセスのプロセス ID です。

注釈

接続方法が 『new』 の場合、新しい Femtet プロセスを起動して接続します。pid は無視されます。

注釈

『existing』 の場合、既存の Femtet プロセスに接続します。ただし、接続できる Femtet がない場合(すなわち、他の Python または Excel プロセスにすでに接続されている場合)、例外をスローします。

注釈

『auto』 に設定されている場合、最初に 『existing』 を試み、失敗した場合は 『new』 で接続します。pid が指定されていて接続に失敗した場合、別の Femtet プロセスへの接続は試みません。

current_prm_values: TrialInput
femtet_is_alive()[ソース]

接続された Femtet プロセスが存在するかどうかを返します。

戻り値の型:

bool

load_objectives(*args, **kwargs)
property object_pass_to_fun

ユーザー定義目的関数の第1引数に渡されるオブジェクト。

戻り値:

Femtet の COM オブジェクト.

戻り値の型:

Femtet (CDispatch)

open(femprj_path, model_name=None)[ソース]

接続された Femtet で特定の解析モデルを開きます。

パラメータ:
  • femprj_path (str) –

  • model_name (str | None) –

戻り値の型:

None

parametric_output_indexes_use_as_objective: dict[int, str | float]
postprocess(*args, **kwargs)
preprocess(*args, **kwargs)
quit(timeout=15, force=True)[ソース]

接続された Femtet を強制終了します。

reopen()[ソース]
save_screenshot: Literal['result', 'model', 'none']
solve(*args, **kwargs)
update(*args, **kwargs)
update_model(*args, **kwargs)
update_parameter(*args, **kwargs)
use_parametric_output_as_objective(number, direction='minimize')[ソース]

Femtetのパラメトリック解析の出力設定を目的関数として使用します。

パラメータ:
  • number (int) – Femtet のパラメトリック分析ダイアログにおける出力設定タブの行番号です。1 から始まります。

  • direction (str | float) – 最適化の方向です。変数の値は 『maximize』 、 『minimize』 、または浮動小数点値です。デフォルトは 『minimize』 です。

戻り値:

None

戻り値の型:

None

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, _NXInterface

Femtet と 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 をエクスポートする際に使用された設定から、これらの値を変更しないことを推奨します。

update_model()[ソース]
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, AbstractFEMInterface

Femtet と 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 です。

close(timeout=15, force=True)[ソース]

Destructor.

May not quit Femtet. If you want to quit certainly, Please use quit() method.

update_model()[ソース]

Update .sldprt

update_parameter(x, with_warning=False)[ソース]
パラメータ:

x (dict[str, Variable]) –

戻り値の型:

None

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

update()[ソース]
戻り値の型:

None

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

パラメータ:
calc_pof()[ソース]
update()[ソース]
戻り値の型:

None

pyfemtet.opt.interface.PoFBoTorchWithExcelSettingsInterface

:py:class:`~pyfemtet.opt.interface._with_excel_settings.with_excel_settings._class_factory.<locals>._WithExcelSettingsInterface`の別名です。