PyFemtet 0.3.8__tar.gz → 0.3.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/PKG-INFO +1 -1
- pyfemtet-0.3.10/pyfemtet/FemtetPJTSample/Sldworks_ex01/Sldworks_ex01.SLDPRT +0 -0
- pyfemtet-0.3.10/pyfemtet/FemtetPJTSample/Sldworks_ex01/Sldworks_ex01.femprj +0 -0
- pyfemtet-0.3.10/pyfemtet/FemtetPJTSample/Sldworks_ex01/Sldworks_ex01.py +99 -0
- pyfemtet-0.3.10/pyfemtet/__init__.py +1 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/opt/base.py +3 -2
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyproject.toml +1 -1
- pyfemtet-0.3.8/pyfemtet/__init__.py +0 -1
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/LICENSE +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/README.md +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.femprj +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.prt +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/FemtetPJTSample/NX_ex01/NX_ex01.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/FemtetPJTSample/gau_ex08_parametric.femprj +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/FemtetPJTSample/gau_ex08_parametric.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/FemtetPJTSample/her_ex40_parametric.femprj +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/FemtetPJTSample/her_ex40_parametric.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/FemtetPJTSample/wat_ex14_parallel_parametric.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/FemtetPJTSample/wat_ex14_parametric.femprj +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/FemtetPJTSample/wat_ex14_parametric.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/core.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/dispatch_extensions.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/logger.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/opt/_FemtetWithNX/update_model.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/opt/__init__.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/opt/interface.py +0 -0
- {pyfemtet-0.3.8 → pyfemtet-0.3.10}/pyfemtet/opt/monitor.py +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""外部 CAD ソフト Solidworks との連携
|
|
2
|
+
|
|
3
|
+
外部 CAD ソフト Solidworks で作成したパラメトリックモデルを
|
|
4
|
+
Femtet にインポートして最適化を行います。
|
|
5
|
+
|
|
6
|
+
事前準備として、以下の作業を行ってください。
|
|
7
|
+
- Sldworks_ex01.SLDPRT と Sldworks_ex01.femprj を同じフォルダに配置する
|
|
8
|
+
- C:\temp フォルダを作成する
|
|
9
|
+
※ 最適化の実行中に Solidworks から .x_t ファイルがエクスポートされます。
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
from pyfemtet.opt import FEMOpt, OptunaOptimizer
|
|
14
|
+
from pyfemtet.opt.interface import FemtetWithSolidworksInterface
|
|
15
|
+
from pyfemtet.core import ModelError
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
here, me = os.path.split(__file__)
|
|
19
|
+
os.chdir(here)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def disp(Femtet):
|
|
23
|
+
"""解析結果から Z 方向最大変位を取得します。
|
|
24
|
+
目的関数の第一引数は Femtet インスタンスである必要があります。
|
|
25
|
+
"""
|
|
26
|
+
_, _, ret = Femtet.Gogh.Galileo.GetMaxDisplacement_py()
|
|
27
|
+
|
|
28
|
+
# CAD 連携の場合、境界条件をトポロジーIDに基づいて割り当てているので、
|
|
29
|
+
# 意図しない箇所に境界条件が割り当てられることがあります。
|
|
30
|
+
# この問題では意図通りの割り当てができていれば最大変位は必ず負なので
|
|
31
|
+
# 答えが正の場合は境界条件割り当てに失敗しているとみなして
|
|
32
|
+
# ModelError を送出するようにします。
|
|
33
|
+
# 最適化ルーチン中に ModelError, MeshError, SolveError が送出された場合
|
|
34
|
+
# Optimizer はその試行を失敗とみなし、スキップして次の試行を行います。
|
|
35
|
+
if ret >= 0:
|
|
36
|
+
raise ModelError('境界条件の割り当てが間違えています。')
|
|
37
|
+
return ret
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def volume(Femtet):
|
|
41
|
+
"""解析結果からモデル体積を取得します。
|
|
42
|
+
目的関数の第一引数は Femtet インスタンスである必要があります。
|
|
43
|
+
"""
|
|
44
|
+
_, ret = Femtet.Gogh.CalcVolume_py([0])
|
|
45
|
+
return ret
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def C_minus_B(_, opt):
|
|
49
|
+
"""C 寸法と B 寸法の差を計算します。
|
|
50
|
+
|
|
51
|
+
拘束関数の第一引数は Femtet インスタンスである必要がありますが、
|
|
52
|
+
この例では使用していません。
|
|
53
|
+
|
|
54
|
+
ほかの例では設計変数にアクセスする際以下のスニペットを用いますが、
|
|
55
|
+
CAD 連携を行う場合、Femtet に設計変数が設定されていないためです。
|
|
56
|
+
A = Femtet.GetVariableValue('A')
|
|
57
|
+
|
|
58
|
+
pyfemtet.opt では目的関数・拘束関数の第二引数以降に任意の変数を設定できます。
|
|
59
|
+
この例では、第二引数に FEMOpt のメンバー変数 opt を取り、
|
|
60
|
+
そのメソッド get_parameter() を用いて設計変数を取得しています。
|
|
61
|
+
|
|
62
|
+
"""
|
|
63
|
+
A, B, C = opt.get_parameter('values')
|
|
64
|
+
return C - B
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == '__main__':
|
|
68
|
+
|
|
69
|
+
# Solidworks-Femtet 連携オブジェクトを用意
|
|
70
|
+
# ここで起動している Femtet と紐づけがされます。
|
|
71
|
+
fem = FemtetWithSolidworksInterface(
|
|
72
|
+
sldprt_path='Sldworks_ex01.SLDPRT',
|
|
73
|
+
femprj_path='Sldworks_ex01.femprj',
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
opt = OptunaOptimizer(
|
|
77
|
+
sampler_kwargs=dict(
|
|
78
|
+
n_startup_trials=5,
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# 最適化処理を行うオブジェクトに連携オブジェクトを紐づけ
|
|
83
|
+
femopt = FEMOpt(fem=fem, opt=opt)
|
|
84
|
+
|
|
85
|
+
# 設計変数の設定
|
|
86
|
+
femopt.add_parameter('A', 10, lower_bound=1, upper_bound=59)
|
|
87
|
+
femopt.add_parameter('B', 10, lower_bound=1, upper_bound=40)
|
|
88
|
+
femopt.add_parameter('C', 20, lower_bound=5, upper_bound=59)
|
|
89
|
+
|
|
90
|
+
# 拘束関数の設定
|
|
91
|
+
femopt.add_constraint(C_minus_B, 'C>B', lower_bound=1, args=femopt.opt)
|
|
92
|
+
|
|
93
|
+
# 目的関数の設定
|
|
94
|
+
femopt.add_objective(disp, name='変位', direction=0)
|
|
95
|
+
femopt.add_objective(volume, name='体積', direction='minimize')
|
|
96
|
+
|
|
97
|
+
# 最適化の実行
|
|
98
|
+
femopt.set_random_seed(42)
|
|
99
|
+
femopt.main(n_trials=20)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.10"
|
|
@@ -2,6 +2,7 @@ from abc import ABC, abstractmethod
|
|
|
2
2
|
from typing import List, Iterable
|
|
3
3
|
|
|
4
4
|
import os
|
|
5
|
+
import sys
|
|
5
6
|
import datetime
|
|
6
7
|
import inspect
|
|
7
8
|
import ast
|
|
@@ -842,7 +843,7 @@ class OptunaOptimizer(AbstractOptimizer):
|
|
|
842
843
|
try:
|
|
843
844
|
_, _y, c = self.f(x)
|
|
844
845
|
except (ModelError, MeshError, SolveError) as e:
|
|
845
|
-
logger.info(
|
|
846
|
+
logger.info(e)
|
|
846
847
|
logger.info('以下の変数で FEM 解析に失敗しました。')
|
|
847
848
|
print(self.get_parameter('dict'))
|
|
848
849
|
|
|
@@ -1330,7 +1331,7 @@ class FEMOpt:
|
|
|
1330
1331
|
# monitor 用 worker を起動
|
|
1331
1332
|
logger.info('Launching monitor server. This may take a few seconds.')
|
|
1332
1333
|
self.monitor_process_worker_name = datetime.datetime.now().strftime("Monitor-%Y%m%d-%H%M%S")
|
|
1333
|
-
cmd = f'dask worker {self.client.scheduler.address} --name {self.monitor_process_worker_name} --no-nanny'
|
|
1334
|
+
cmd = f'{sys.executable} -m dask worker {self.client.scheduler.address} --name {self.monitor_process_worker_name} --no-nanny'
|
|
1334
1335
|
current_n_workers = len(self.client.nthreads().keys())
|
|
1335
1336
|
Popen(cmd, shell=True) # , stdout=PIPE) --> cause stream error
|
|
1336
1337
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "pyfemtet"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.10" # ignored by versioning plugin
|
|
4
4
|
description = "Design parameter optimization using Femtet."
|
|
5
5
|
authors = ["kazuma.naito <kazuma.naito@murata.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.3.8"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|