You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
4.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# -*- coding: utf-8 -*-
"""Общие настройки МКЭ-расчёта: пути, единицы, материал, уровни сетки, запуск внешних программ.
Единицы КЭ-модели: мм, Н, МПа, т (тонна), с -> плотность в т/мм³, частоты в Гц.
"""
import json
import os
import subprocess
import sys
import time
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if ROOT not in sys.path:
sys.path.insert(0, ROOT)
FC_BIN = os.path.join(ROOT, "tools", "freecad", "squashfs-root", "usr", "bin")
GMSH = os.path.join(FC_BIN, "gmsh")
CCX = os.path.join(FC_BIN, "ccx")
VENV_PY = os.path.join(ROOT, "tools", "venv", "bin", "python")
OUT = os.path.join(ROOT, "out", "fea")
REPORT_MD = os.path.join(ROOT, "report", "sections", "40_fea.md")
CALC_JSON = os.path.join(ROOT, "out", "calc", "valve_calc.json")
BOM_JSON = os.path.join(ROOT, "out", "cad", "bom.json")
# ------------------------------------------------------------------ материал корпуса (12Х18Н9ТЛ)
MAT = dict(
name="12Х18Н9ТЛ ГОСТ 977-88",
E=2.00e5, # МПа при 100 °C — ГОСТ 34233.1-2017, прил. В, табл. В.1 (аустенитные стали: 2,00 при 20 и 100 °C)
nu=0.3, # общепринятое значение (valve/norms.py: POISSON)
rho=7900.0, # кг/м³ (задано; out/cad/bom.json — RHO["12Х18Н9ТЛ"])
)
RHO_T_MM3 = MAT["rho"] * 1e-12 # кг/м³ -> т/мм³
# ------------------------------------------------------------------ сетки
# h_g — глобальный размер, h_f — размер у острых переходов/галтелей, curv — элементов на 2π кривизны.
# Уровни статической задачи: 0 — грубая, 1 — основная; 2 — добавляется автоматически, если сходимость
# между 0 и 1 хуже допуска (ограничение по ОЗУ: решатель ccx ITERATIVE CHOLESKY, ~3 ГДФ на узел).
MESH_LEVELS = [
dict(name="L0", h_g=11.0, h_f=3.4, curv=8, scl_n=4, grad=0.7),
dict(name="L1", h_g=8.0, h_f=2.2, curv=11, scl_n=6, grad=0.55),
dict(name="L2", h_g=8.0, h_f=1.7, curv=12, scl_n=9, grad=0.55), # только местное сгущение (ОЗУ)
]
MESH_MODAL = dict(name="MOD", h_g=12.0, h_f=5.0, curv=6, scl_n=0, grad=0.8)
MESH_MODAL0 = dict(name="MOD0", h_g=17.0, h_f=7.5, curv=5, scl_n=0, grad=0.9) # проверка сходимости частот
CONV_TOL = 0.05 # допуск сходимости линеаризованных напряжений (5 %)
OMP_THREADS = "8"
def log(*a):
print(time.strftime("%H:%M:%S"), *a, flush=True)
def ensure_dir(p):
os.makedirs(p, exist_ok=True)
return p
def run(cmd, cwd, logname, env_extra=None, timeout=7200):
"""Запуск внешней программы с записью stdout/stderr в лог; возвращает код и время."""
env = dict(os.environ)
env.update({"OMP_NUM_THREADS": OMP_THREADS, "LC_ALL": "C"})
if env_extra:
env.update(env_extra)
t0 = time.time()
with open(os.path.join(cwd, logname), "w") as f:
p = subprocess.run(cmd, cwd=cwd, stdout=f, stderr=subprocess.STDOUT, env=env, timeout=timeout)
return p.returncode, time.time() - t0
def dump_json(obj, path):
def conv(o):
try:
import numpy as np
if isinstance(o, np.integer):
return int(o)
if isinstance(o, np.floating):
return float(o)
if isinstance(o, np.ndarray):
return o.tolist()
except ImportError:
pass
raise TypeError(type(o))
with open(path, "w", encoding="utf-8") as f:
json.dump(obj, f, ensure_ascii=False, indent=1, default=conv)
def load_json(path):
with open(path, encoding="utf-8") as f:
return json.load(f)

Powered by TurnKey Linux.