NumOpt 0.0.2__tar.gz → 0.0.3__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.
- numopt-0.0.3/NumOpt/FSI/__init__.py +0 -0
- numopt-0.0.3/NumOpt/FSI/tools.py +33 -0
- numopt-0.0.3/NumOpt/__init__.py +4 -0
- numopt-0.0.3/NumOpt/cprint.py +9 -0
- numopt-0.0.3/NumOpt/nx/__init__.py +0 -0
- numopt-0.0.3/NumOpt/nx/tools.py +89 -0
- {numopt-0.0.2 → numopt-0.0.3}/NumOpt/opti.py +1 -9
- {numopt-0.0.2 → numopt-0.0.3}/NumOpt.egg-info/PKG-INFO +1 -1
- {numopt-0.0.2 → numopt-0.0.3}/NumOpt.egg-info/SOURCES.txt +6 -1
- {numopt-0.0.2 → numopt-0.0.3}/PKG-INFO +1 -1
- numopt-0.0.2/NumOpt/__init__.py +0 -3
- {numopt-0.0.2 → numopt-0.0.3}/LICENSE.txt +0 -0
- {numopt-0.0.2 → numopt-0.0.3}/NumOpt.egg-info/dependency_links.txt +0 -0
- {numopt-0.0.2 → numopt-0.0.3}/NumOpt.egg-info/requires.txt +0 -0
- {numopt-0.0.2 → numopt-0.0.3}/NumOpt.egg-info/top_level.txt +0 -0
- {numopt-0.0.2 → numopt-0.0.3}/README.md +0 -0
- {numopt-0.0.2 → numopt-0.0.3}/pyproject.toml +0 -0
- {numopt-0.0.2 → numopt-0.0.3}/setup.cfg +0 -0
- {numopt-0.0.2 → numopt-0.0.3}/setup.py +0 -0
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from ..cprint import cprint_green
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def deal_name(nasfile, outfile, simplify=True):
|
|
7
|
+
def sub_func(match):
|
|
8
|
+
old_str: list = match.group().split("\n")
|
|
9
|
+
pshell_name = match.group("name")
|
|
10
|
+
if simplify:
|
|
11
|
+
pshell_name = pshell_name.split(":")[0]
|
|
12
|
+
pshell_id = match.group("id")
|
|
13
|
+
insert_str = f"$ANSA_NAME_COMMENT;{pshell_id};PSHELL;{pshell_name};"
|
|
14
|
+
old_str.insert(1, insert_str)
|
|
15
|
+
new_str = "\n".join(old_str)
|
|
16
|
+
return new_str
|
|
17
|
+
|
|
18
|
+
pattern = r"\$\*\s+Property:\s(?P<name>.*)\nPSHELL\s+(?P<id>\d+)\s+.*\n"
|
|
19
|
+
pattern = re.compile(pattern)
|
|
20
|
+
|
|
21
|
+
content = Path(nasfile).read_text()
|
|
22
|
+
new_content = re.sub(pattern, sub_func, content)
|
|
23
|
+
outfile = Path(outfile)
|
|
24
|
+
if not outfile.parent.exists():
|
|
25
|
+
outfile.parent.mkdir(exist_ok=True)
|
|
26
|
+
outfile.write_text(new_content)
|
|
27
|
+
cprint_green(f"new nastran file `{outfile.as_posix()}` is generated.")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
nasfile = "./bulk.dat"
|
|
33
|
+
deal_name(nasfile, "new_bulk.dat")
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from termcolor import cprint
|
|
2
|
+
from functools import partial
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
cprint_green = partial(cprint, color="green", attrs=["bold"])
|
|
6
|
+
cprint_magenta = partial(cprint, color="magenta", attrs=["bold"])
|
|
7
|
+
cprint_blue = partial(cprint, color="blue", attrs=["bold"])
|
|
8
|
+
cprint_red = partial(cprint, color="red", attrs=["bold"])
|
|
9
|
+
cprint_yellow = partial(cprint, color="yellow", attrs=["bold"])
|
|
File without changes
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import NXOpen
|
|
2
|
+
import NXOpen.Features
|
|
3
|
+
from NXOpen import ParasolidExporter
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def create_af(coords, session: NXOpen.Session):
|
|
11
|
+
part = session.Parts.Work
|
|
12
|
+
|
|
13
|
+
markid = session.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "create airfoil")
|
|
14
|
+
splineEX = part.Features.CreateStudioSplineBuilderEx(NXOpen.NXObject.Null)
|
|
15
|
+
for i in coords:
|
|
16
|
+
pt = NXOpen.Point3d(i[0] * 1000.0, i[1] * 1000.0, 0.0)
|
|
17
|
+
pt = part.Points.CreatePoint(pt)
|
|
18
|
+
gcons = splineEX.ConstraintManager.CreateGeometricConstraintData()
|
|
19
|
+
gcons.Point = pt
|
|
20
|
+
splineEX.ConstraintManager.Append(gcons)
|
|
21
|
+
spline = splineEX.Commit()
|
|
22
|
+
splineEX.Destroy()
|
|
23
|
+
session.UpdateManager.DoUpdate(markid)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def modify_af(coords, name, session: NXOpen.Session):
|
|
27
|
+
part = session.Parts.Work
|
|
28
|
+
|
|
29
|
+
markid = session.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "modify airfoil")
|
|
30
|
+
spline = part.Features.FindObject(name)
|
|
31
|
+
splineEX = part.Features.CreateStudioSplineBuilderEx(spline)
|
|
32
|
+
for i, vi in enumerate(coords):
|
|
33
|
+
gcons = splineEX.ConstraintManager.FindItem(i)
|
|
34
|
+
pt = gcons.Point
|
|
35
|
+
pt.SetCoordinates(NXOpen.Point3d(vi[0] * 1000.0, vi[1] * 1000.0, 0.0))
|
|
36
|
+
splineEX.Evaluate()
|
|
37
|
+
spline = splineEX.Commit()
|
|
38
|
+
splineEX.Destroy()
|
|
39
|
+
session.UpdateManager.DoUpdate(markid)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def modify_expr(expr_name: str, value: float, session: NXOpen.Session, unit: str = None, update: bool = False):
|
|
43
|
+
markid = session.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, f"modify {expr_name}")
|
|
44
|
+
part = session.Parts.Work
|
|
45
|
+
expr = part.Expressions.FindObject(expr_name)
|
|
46
|
+
unit = NXOpen.Unit.Null if unit is None else part.UnitCollection.FindObject(unit)
|
|
47
|
+
part.Expressions.EditExpressionWithUnits(expr, unit, f"{value:.6f}")
|
|
48
|
+
if update:
|
|
49
|
+
session.UpdateManager.DoUpdate(markid)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def export_solid(solid_name: list[str], outfile: str, session: NXOpen.Session):
|
|
53
|
+
markid = session.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "export parasoild")
|
|
54
|
+
|
|
55
|
+
part = session.Parts.Work
|
|
56
|
+
parasolidExporter: ParasolidExporter = session.DexManager.CreateParasolidExporter()
|
|
57
|
+
parasolidExporter.InputFile = part.FullPath
|
|
58
|
+
parasolidExporter.OutputFile = outfile
|
|
59
|
+
|
|
60
|
+
parasolidExporter.ExportSelectionBlock.SelectionScope = NXOpen.ObjectSelector.Scope.SelectedObjects
|
|
61
|
+
for i in solid_name:
|
|
62
|
+
solid = part.Bodies.FindObject(i)
|
|
63
|
+
parasolidExporter.ExportSelectionBlock.SelectionComp.Add(solid)
|
|
64
|
+
parasolidExporter.Commit()
|
|
65
|
+
session.UpdateManager.DoUpdate(markid)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def saveAs(outfile, session: NXOpen.Session, overwrite: False):
|
|
69
|
+
outfile = Path(outfile)
|
|
70
|
+
if overwrite:
|
|
71
|
+
if outfile.exists():
|
|
72
|
+
os.unlink(outfile)
|
|
73
|
+
else:
|
|
74
|
+
if outfile.exists():
|
|
75
|
+
raise (f"{outfile} has been existed.")
|
|
76
|
+
|
|
77
|
+
markid = session.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, f"save as")
|
|
78
|
+
part = session.Parts.Work
|
|
79
|
+
part.SaveAs(outfile.as_posix())
|
|
80
|
+
session.UpdateManager.DoUpdate(markid)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
with open("C:/Users/Zcaic/Desktop/hxy_ppt/coords.json", "r") as fin:
|
|
85
|
+
data = json.load(fin)
|
|
86
|
+
|
|
87
|
+
session = NXOpen.Session.GetSession()
|
|
88
|
+
# create_af(data["init_coords"],session=session)
|
|
89
|
+
modify_af(coords=data["init_coords"], name="SPLINE(1)", session=session)
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import aerosandbox.numpy as anp
|
|
2
2
|
import aerosandbox as asb
|
|
3
3
|
import casadi as cas
|
|
4
|
-
from termcolor import cprint
|
|
5
|
-
from functools import partial
|
|
6
4
|
from typing import Callable, Any, Dict
|
|
7
|
-
|
|
8
|
-
cprint_green = partial(cprint, color="green", attrs=["bold"])
|
|
9
|
-
cprint_magenta = partial(cprint, color="magenta", attrs=["bold"])
|
|
10
|
-
cprint_blue = partial(cprint, color="blue", attrs=["bold"])
|
|
11
|
-
cprint_red = partial(cprint, color="red", attrs=["bold"])
|
|
12
|
-
cprint_yellow = partial(cprint, color="yellow", attrs=["bold"])
|
|
13
|
-
|
|
5
|
+
from .cprint import cprint_yellow
|
|
14
6
|
|
|
15
7
|
# def trape(y, x):
|
|
16
8
|
# y = anp.array(y)
|
|
@@ -3,9 +3,14 @@ README.md
|
|
|
3
3
|
pyproject.toml
|
|
4
4
|
setup.py
|
|
5
5
|
NumOpt/__init__.py
|
|
6
|
+
NumOpt/cprint.py
|
|
6
7
|
NumOpt/opti.py
|
|
7
8
|
NumOpt.egg-info/PKG-INFO
|
|
8
9
|
NumOpt.egg-info/SOURCES.txt
|
|
9
10
|
NumOpt.egg-info/dependency_links.txt
|
|
10
11
|
NumOpt.egg-info/requires.txt
|
|
11
|
-
NumOpt.egg-info/top_level.txt
|
|
12
|
+
NumOpt.egg-info/top_level.txt
|
|
13
|
+
NumOpt/FSI/__init__.py
|
|
14
|
+
NumOpt/FSI/tools.py
|
|
15
|
+
NumOpt/nx/__init__.py
|
|
16
|
+
NumOpt/nx/tools.py
|
numopt-0.0.2/NumOpt/__init__.py
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|