From bf0178fecbc6b7197ca242d32839536aca9cc21f Mon Sep 17 00:00:00 2001 From: krande Date: Wed, 26 May 2021 09:39:32 +0200 Subject: [PATCH] Bugfixes and formatting Fixed error in COG calculation causing test_calc_cog to fail. specify length and angle tol in build_pipe() Freeze pythonocc-core and occt version --- environment.yml | 3 +- images/environment.yml | 3 +- src/ada/__init__.py | 67 ++++++++++------ src/ada/base/renderer.py | 17 ++-- src/ada/core/ifc_template.py | 4 +- src/ada/core/utils.py | 18 ++++- src/ada/fem/containers.py | 44 +++++----- src/ada/fem/io/__init__.py | 17 +--- src/ada/fem/io/utils.py | 9 +++ src/ada/param_models/basic_module.py | 14 ++-- tests/test_assembly.py | 22 ++--- tests/test_elem_pipes.py | 115 +++++++++++++++------------ tests/test_io_fem.py | 11 ++- tests/test_io_fem_sesam.py | 3 +- tests/test_param_models.py | 4 +- 15 files changed, 188 insertions(+), 163 deletions(-) diff --git a/environment.yml b/environment.yml index d1ea97254..65ba422b5 100644 --- a/environment.yml +++ b/environment.yml @@ -2,5 +2,6 @@ name: adaenv channels: - conda-forge dependencies: - - pythonocc-core + - pythonocc-core==7.5.1 + - occt==7.5.1 - ifcopenshell \ No newline at end of file diff --git a/images/environment.yml b/images/environment.yml index 7e8cd06d9..06d20e3f4 100644 --- a/images/environment.yml +++ b/images/environment.yml @@ -3,6 +3,7 @@ channels: - conda-forge dependencies: - python==3.8.8 - - pythonocc-core + - pythonocc-core==7.5.1 + - occt==7.5.1 - ifcopenshell - jupyter \ No newline at end of file diff --git a/src/ada/__init__.py b/src/ada/__init__.py index 2da0e6678..afcbca214 100644 --- a/src/ada/__init__.py +++ b/src/ada/__init__.py @@ -34,6 +34,8 @@ "Beam", "Plate", "Pipe", + "PipeSegStraight", + "PipeSegElbow", "Wall", "Penetration", "Section", @@ -2598,7 +2600,7 @@ def _build_pipe(self): :return: """ - from ada.core.utils import local_2_global_nodes, make_arc_segment + from ada.core.utils import make_arc_segment segs = [] for p1, p2 in zip(self.points[:-1], self.points[1:]): @@ -2612,18 +2614,23 @@ def _build_pipe(self): # Make elbows and adjust segments props = dict(section=self.section, material=self.material, parent=self, units=self.units) - + angle_tol = 1e-1 + len_tol = _Settings.point_tol if self.units == "m" else _Settings.point_tol * 1000 for i, (seg1, seg2) in enumerate(zip(segments[:-1], segments[1:])): p11, p12 = seg1 p21, p22 = seg2 vlen1 = vector_length(seg1[1].p - seg1[0].p) vlen2 = vector_length(seg2[1].p - seg2[0].p) - if vlen1 < _Settings.point_tol or vlen2 == _Settings.point_tol: - logging.error("Segment Length is zero. Skipping") + + if vlen1 < len_tol or vlen2 == len_tol: + logging.error(f'Segment Length is below point tolerance for unit "{self.units}". Skipping') continue - xvec1 = p12.p - p11.p - xvec2 = p22.p - p21.p - if angle_between(xvec1, xvec2) in (np.pi, 0): + xvec1 = unit_vector(p12.p - p11.p) + xvec2 = unit_vector(p22.p - p21.p) + a = angle_between(xvec1, xvec2) + res = True if abs(abs(a) - abs(np.pi)) < angle_tol or abs(abs(a) - 0.0) < angle_tol else False + + if res is True: self._segments.append(PipeSegStraight(next(seg_names), p11, p12, **props)) else: if p12 != p21: @@ -2644,26 +2651,34 @@ def _build_pipe(self): continue if i == 0 or len(self._segments) == 0: - self._segments.append(PipeSegStraight(next(seg_names), Node(seg1.p1), Node(seg1.p2), **props)) + self._segments.append( + PipeSegStraight( + next(seg_names), Node(seg1.p1, units=self.units), Node(seg1.p2, units=self.units), **props + ) + ) else: if len(self._segments) == 0: print("sd") continue pseg = self._segments[-1] - pseg.p2 = Node(seg1.p2) + pseg.p2 = Node(seg1.p2, units=self.units) self._segments.append( PipeSegElbow( next(seg_names) + "_Elbow", - Node(seg1.p1), - Node(p21.p), - Node(seg2.p2), + Node(seg1.p1, units=self.units), + Node(p21.p, units=self.units), + Node(seg2.p2, units=self.units), arc.radius, **props, arc_seg=arc, ) ) - self._segments.append(PipeSegStraight(next(seg_names), Node(seg2.p1), Node(seg2.p2), **props)) + self._segments.append( + PipeSegStraight( + next(seg_names), Node(seg2.p1, units=self.units), Node(seg2.p2, units=self.units), **props + ) + ) @property def segments(self): @@ -2710,8 +2725,8 @@ def pipe_bend_radius(self): wt = self.section.wt r = self.section.r d = r * 2 - w_tol = 0.125 - cor_tol = 0.003 + w_tol = 0.125 if self.units == "m" else 125 + cor_tol = 0.003 if self.units == "m" else 3 corr_t = (wt - (wt * w_tol)) - cor_tol d -= 2.0 * corr_t @@ -2745,14 +2760,15 @@ def units(self, value): self.n2.units = value self.section.units = value self.material.units = value + self._segments = [] for p in self.points: p.units = value self._build_pipe() self._units = value def _generate_ifc_pipe(self): - from ada.core.ifc_utils import create_ifclocalplacement, create_property_set from ada.core.constants import X, Z + from ada.core.ifc_utils import create_ifclocalplacement, create_property_set if self.parent is None: raise ValueError("Cannot build ifc element without parent") @@ -2882,12 +2898,12 @@ def ifc_elem(self): return self._ifc_elem def _to_ifc_elem(self): + from ada.core.constants import O, X, Z from ada.core.ifc_utils import ( # create_ifcrevolveareasolid, create_ifcaxis2placement, create_ifcpolyline, to_real, ) - from ada.core.constants import X, Y, Z, O if self.parent is None: raise ValueError("Parent cannot be None for IFC export") @@ -2999,7 +3015,7 @@ def xvec2(self): @property def geom(self): - from ada.core.utils import sweep_pipe, make_edges_and_fillet_from_3points + from ada.core.utils import make_edges_and_fillet_from_3points, sweep_pipe i = self.parent._segments.index(self) if i != 0: @@ -3033,7 +3049,7 @@ def ifc_elem(self): def _elbow_tesselated(self, f, schema, a, context): import ifcopenshell.geom - from ada.core.ifc_utils import create_ifcpolyline, to_real + shape = self.geom if shape is None: logging.error(f"Unable to create geometry for Branch {self.name}") @@ -3057,9 +3073,12 @@ def _elbow_tesselated(self, f, schema, a, context): return ifc_shape def _elbow_revolved_solid(self, f, context): - from ada.core.ifc_utils import create_ifcrevolveareasolid, create_ifcaxis2placement - from ada.core.utils import normal_to_points_in_plane, get_center_from_3_points_and_radius - from ada.core.constants import X, Y, Z, O + from ada.core.constants import O, X, Z + from ada.core.ifc_utils import create_ifcaxis2placement + from ada.core.utils import ( + get_center_from_3_points_and_radius, + normal_to_points_in_plane, + ) center, _, _, _ = get_center_from_3_points_and_radius(self.p1.p, self.p2.p, self.p3.p, self.bend_radius) @@ -3085,8 +3104,6 @@ def _elbow_revolved_solid(self, f, context): def _to_ifc_elem(self): from ada.core.ifc_utils import create_ifclocalplacement - from ada.core.utils import faceted_tol - from ada.core.constants import X, Y, Z, O if self.parent is None: raise ValueError("Parent cannot be None for IFC export") @@ -3107,7 +3124,7 @@ def _to_ifc_elem(self): ifc_elbow = self._elbow_revolved_solid(f, context) pfitting_placement = create_ifclocalplacement(f) - # pfitting = f.createIfcBuildingElementProxy( + pfitting = f.createIfcPipeFitting( create_guid(), owner_history, diff --git a/src/ada/base/renderer.py b/src/ada/base/renderer.py index 8840723da..5da26de22 100644 --- a/src/ada/base/renderer.py +++ b/src/ada/base/renderer.py @@ -311,7 +311,7 @@ def DisplayAdaPart(self, part): ) def DisplayObj(self, obj): - from ada import Beam, Part, Plate, Shape, Pipe + from ada import Beam, Part, Pipe, Plate, Shape if issubclass(type(obj), Part) is True: self.DisplayAdaPart(obj) @@ -690,14 +690,13 @@ def write_metadata_to_html(met_d): fem_data=", ".join([f"({x}: {y})" for x, y in fem_data.items()]) ) vol_cog_str = ", ".join([f"{x:.3f}" for x in selected_part.fem.nodes.vol_cog]) - res = selected_part.fem.elements.calc_cog() - cogx, cogy, cogz, tot_mass, tot_vol, sh_mass, bm_mass, no_mass = res - cog_str = ", ".join([f"{x:.3f}" for x in (cogx, cogy, cogz)]) - html_value += f"Vol: {tot_vol:.3f} COG: ({vol_cog_str})
" - html_value += f"Mass: {tot_mass:.1f} COG: ({cog_str})
" - html_value += f"Beam mass: {bm_mass:.1f}
" - html_value += f"Shell mass: {sh_mass:.1f}
" - html_value += f"Node mass: {no_mass:.1f}
" + cog = selected_part.fem.elements.calc_cog() + cog_str = ", ".join([f"{x:.3f}" for x in cog.p]) + html_value += f"Vol: {cog.tot_vol:.3f} COG: ({vol_cog_str})
" + html_value += f"Mass: {cog.tot_mass:.1f} COG: ({cog_str})
" + html_value += f"Beam mass: {cog.bm_mass:.1f}
" + html_value += f"Shell mass: {cog.sh_mass:.1f}
" + html_value += f"Node mass: {cog.no_mass:.1f}
" html_value += ( "

Note! Mass calculations are calculated based on
beam offsets " "(which is not shown in the viewer yet)." diff --git a/src/ada/core/ifc_template.py b/src/ada/core/ifc_template.py index 1c011af64..9e6b6e28d 100644 --- a/src/ada/core/ifc_template.py +++ b/src/ada/core/ifc_template.py @@ -4,7 +4,7 @@ import uuid from ifcopenshell import main -from ifcopenshell.file import file +from ifcopenshell.file import file as ifc_file from ifcopenshell.guid import compress # A quick way to setup an 'empty' IFC file, taken from: @@ -72,4 +72,4 @@ def _(): d.update(dict(_())) - return file.from_string(TEMPLATE % d) + return ifc_file.from_string(TEMPLATE % d) diff --git a/src/ada/core/utils.py b/src/ada/core/utils.py index 7930d01a3..0e33d1638 100644 --- a/src/ada/core/utils.py +++ b/src/ada/core/utils.py @@ -565,15 +565,27 @@ def intersect_line_circle(line, center, radius): def get_center_from_3_points_and_radius(p1, p2, p3, radius): - from ada.core.constants import X, Y, Z + """ + + :param p1: + :param p2: + :param p3: + :param radius: + :return: + """ + p1 = np.array(p1) + p2 = np.array(p2) + p3 = np.array(p3) + from ada.core.constants import X, Y + points = [p1, p2, p3] n = normal_to_points_in_plane(points) xv = p2 - p1 yv = calc_yvec(xv, n) if angle_between(xv, X) in (np.pi, 0) and angle_between(yv, Y) in (np.pi, 0): - locn = [p-p1 for p in points] + locn = [p - p1 for p in points] res_locn = calc_2darc_start_end_from_lines_radius(*locn, radius) - res_glob = [np.array([p[0], p[1], 0])+p1 for p in res_locn] + res_glob = [np.array([p[0], p[1], 0]) + p1 for p in res_locn] else: locn = global_2_local_nodes([xv, yv], p1, points) res_loc = calc_2darc_start_end_from_lines_radius(*locn, radius) diff --git a/src/ada/fem/containers.py b/src/ada/fem/containers.py index d808030b3..47e4a9e96 100644 --- a/src/ada/fem/containers.py +++ b/src/ada/fem/containers.py @@ -1,10 +1,21 @@ from bisect import bisect_left +from dataclasses import dataclass from itertools import chain, groupby from operator import attrgetter import numpy as np +@dataclass +class COG: + p: np.array + tot_mass: float + tot_vol: float + sh_mass: float + bm_mass: float + no_mass: float + + class FemElements: """ @@ -179,6 +190,7 @@ def calc_cog(self): nodes :return: cogx, cogy, cogz, tot_mass, tot_vol + :rtype: COG """ from itertools import chain @@ -207,12 +219,9 @@ def calc_sh_elem(el): area = poly_area(x, y) vol_ = t * area mass = vol_ * el.fem_sec.material.model.rho - mass_per_node = mass / len(el.nodes) + center = sum([e.p for e in el.nodes]) / len(el.nodes) - # Have not added offset to fem_section yet - # adjusted_nodes = [e.p+t*normal for e in el.nodes] - - return mass_per_node, [e for e in el.nodes], vol_ + return mass, center, vol_ def calc_bm_elem(el): """ @@ -225,9 +234,9 @@ def calc_bm_elem(el): elem_len = vector_length(nodes_[-1] - nodes_[0]) vol_ = el.fem_sec.section.properties.Ax * elem_len mass = vol_ * el.fem_sec.material.model.rho - mass_per_node = mass / 2 + center = sum([e.p for e in el.nodes]) / len(el.nodes) - return mass_per_node, [el.nodes[0], el.nodes[-1]], vol_ + return mass, center, vol_ def calc_mass_elem(el): """ @@ -238,36 +247,29 @@ def calc_mass_elem(el): if el.mass_props.type != "MASS": raise NotImplementedError(f'Mass type "{el.mass_props.type}" is not yet implemented') mass = el.mass_props.mass - nodes_ = el.nodes vol_ = 0.0 - return mass, nodes_, vol_ + return mass, el.nodes[0].p, vol_ sh = list(chain(map(calc_sh_elem, self.shell))) bm = list(chain(map(calc_bm_elem, self.beams))) ma = list(chain(map(calc_mass_elem, self.masses))) - mcogx = 0.0 - mcogy = 0.0 - mcogz = 0.0 + tot_mass = 0.0 tot_vol = 0.0 + mcog_ = np.array([0, 0, 0]).astype(float) sh_mass = sum([r[0] for r in sh]) bm_mass = sum([r[0] for r in bm]) no_mass = sum([r[0] for r in ma]) - for m, nodes, vol in sh + bm + ma: + for m, c, vol in sh + bm + ma: tot_vol += vol tot_mass += m - for n in nodes: - mcogx += m * n[0] - mcogy += m * n[1] - mcogz += m * n[2] + mcog_ += m * np.array(c).astype(float) - cogx = mcogx / tot_mass - cogy = mcogy / tot_mass - cogz = mcogz / tot_mass + cog_ = mcog_ / tot_mass - return cogx, cogy, cogz, tot_mass, tot_vol, sh_mass, bm_mass, no_mass + return COG(cog_, tot_mass, tot_vol, sh_mass, bm_mass, no_mass) @property def max_el_id(self): diff --git a/src/ada/fem/io/__init__.py b/src/ada/fem/io/__init__.py index 6b7b19375..9809234be 100644 --- a/src/ada/fem/io/__init__.py +++ b/src/ada/fem/io/__init__.py @@ -1,6 +1,7 @@ from functools import wraps from . import abaqus, calculix, code_aster, sesam, usfos +from .utils import interpret_fem fem_exports = dict( abaqus=abaqus.to_fem, calculix=calculix.to_fem, code_aster=code_aster.to_fem, sesam=sesam.to_fem, usfos=usfos.to_fem @@ -11,22 +12,6 @@ def femio(f): - """ - - TODO: Make this into a file-identifcation utility and allow for storing cached FEM representations in a HDF5 file. - - :param f: - :return: - """ - - def interpret_fem(fem_ref): - fem_type = None - if ".fem" in str(fem_ref).lower(): - fem_type = "sesam" - elif ".inp" in str(fem_ref).lower(): - fem_type = "abaqus" - return fem_type - @wraps(f) def convert_fem_wrapper(*args, **kwargs): from .io_meshio import meshio_read_fem, meshio_to_fem diff --git a/src/ada/fem/io/utils.py b/src/ada/fem/io/utils.py index 7701dc379..d37d04dcf 100644 --- a/src/ada/fem/io/utils.py +++ b/src/ada/fem/io/utils.py @@ -329,3 +329,12 @@ def run_linux(exe, run_command): def run_macOS(exe, run_command): raise NotImplementedError() + + +def interpret_fem(fem_ref): + fem_type = None + if ".fem" in str(fem_ref).lower(): + fem_type = "sesam" + elif ".inp" in str(fem_ref).lower(): + fem_type = "abaqus" + return fem_type diff --git a/src/ada/param_models/basic_module.py b/src/ada/param_models/basic_module.py index 19016b22b..3d3edf9e5 100644 --- a/src/ada/param_models/basic_module.py +++ b/src/ada/param_models/basic_module.py @@ -49,7 +49,7 @@ def __init__(self, name, plate, spacing=0.2, s_type="HP140x8", stringer_dir="X") def penetration_check(self): import numpy as np - from ada import PrimCyl + from ada import PipeSegStraight, PrimCyl a = self.get_assembly() cog = self.nodes.vol_cog @@ -57,11 +57,13 @@ def penetration_check(self): for p in a.get_all_subparts(): for pipe in p.pipes: for segment in pipe.segments: - p1, p2 = segment - v1 = (p1.p - cog) * normal - v2 = (p2.p - cog) * normal - if np.dot(v1, v2) < 0: - self.add_penetration(PrimCyl("my_pen", p1.p, p2.p, pipe.section.r + 0.1)) + if type(segment) is PipeSegStraight: + assert isinstance(segment, PipeSegStraight) + p1, p2 = segment.p1, segment.p2 + v1 = (p1.p - cog) * normal + v2 = (p2.p - cog) * normal + if np.dot(v1, v2) < 0: + self.add_penetration(PrimCyl("my_pen", p1.p, p2.p, pipe.section.r + 0.1)) class SimpleStru(Part): diff --git a/tests/test_assembly.py b/tests/test_assembly.py index 590a37aa9..c8511842a 100644 --- a/tests/test_assembly.py +++ b/tests/test_assembly.py @@ -6,20 +6,17 @@ class VisualizeTests(unittest.TestCase): def test_beams_viz(self): - def viz(a): - a._repr_html_() - bm1 = Beam("bm1", n1=[0, 0, 0], n2=[2, 0, 0], sec="IPE220", colour="red") bm2 = Beam("bm2", n1=[0, 0, 1], n2=[2, 0, 1], sec="HP220x10", colour="blue") bm3 = Beam("bm3", n1=[0, 0, 2], n2=[2, 0, 2], sec="BG800x400x20x40", colour="green") bm4 = Beam("bm4", n1=[0, 0, 3], n2=[2, 0, 3], sec="CIRC200", colour="green") bm5 = Beam("bm5", n1=[0, 0, 4], n2=[2, 0, 4], sec="TUB200x10", colour="green") - viz(bm1) - viz(bm2) - viz(bm3) - viz(bm4) - viz(bm5) + bm1._repr_html_() + bm2._repr_html_() + bm3._repr_html_() + bm4._repr_html_() + bm5._repr_html_() def test_viz(self): a = Assembly("my_test_assembly") @@ -39,19 +36,14 @@ def test_viz(self): a._repr_html_() def test_fem(self): - a = Assembly("MyAssembly") - p = Part("MyPart") - p.add_beam(Beam("Bm", (0, 0, 0), (1, 0, 0), "IPE300")) - a.add_part(p) + a = Assembly("MyAssembly") / (Part("MyPart") / Beam("Bm", (0, 0, 0), (1, 0, 0), "IPE300")) a.gmsh.mesh() a._repr_html_() a._renderer.toggle_mesh_visibility() def test_module(self): - a = Assembly("ParametricSite") - pm = SimpleStru("ParametricModel") - a.add_part(pm) + a = Assembly("ParametricSite") / SimpleStru("ParametricModel") a.gmsh.mesh() a._repr_html_() diff --git a/tests/test_elem_pipes.py b/tests/test_elem_pipes.py index c271f4565..318a06b5e 100644 --- a/tests/test_elem_pipes.py +++ b/tests/test_elem_pipes.py @@ -2,9 +2,9 @@ from ada import Assembly, Part, Pipe, Section from ada.config import Settings -import logging -logging.basicConfig(level=logging.DEBUG) +# import logging +# logging.basicConfig(level=logging.DEBUG) test_folder = Settings.test_dir / "pipes" z = 3.2 @@ -45,57 +45,66 @@ def test_pipe_bend(self): # a.to_stp(test_folder / "pipe_bend.stp") # a._repr_html_() - def test_ifc_elbow(self): - from ada.core.ifc_utils import create_ifcaxis2placement, create_ifclocalplacement, create_guid - from ada.core.utils import normal_to_points_in_plane, get_center_from_3_points_and_radius - from ada.core.constants import X, Y, Z, O - - p1 = (0, y0, z) - p2 = (5 + x0, y0, z) - p3 = (5 + x0, y0 + 5, z) - sec = Section("PSec", "PIPE", r=0.10, wt=5e-3) - pi1 = Pipe("pipe1", [p1, p2], sec) - pi2 = Pipe("pipe2", [p2, p3], sec) - a = Assembly("MyTest") / (Part("MyPart") / [pi1, pi2]) - f = a.ifc_file - - context = f.by_type("IfcGeometricRepresentationContext")[0] - owner_history = f.by_type("IfcOwnerHistory")[0] - schema = a.ifc_file.wrapped_data.schema - - center, _, _, _ = get_center_from_3_points_and_radius(p1, p2, p3, 0.193) - - opening_axis_placement = create_ifcaxis2placement(f, O, Z, X) - - profile = sec.ifc_profile - normal = normal_to_points_in_plane([p1, p2, p3]) - revolve_axis = center + normal - revolve_angle = 10 - - ifcorigin = f.createIfcCartesianPoint(p1) - ifcaxis1dir = f.createIfcAxis1Placement(ifcorigin, f.createIfcDirection(revolve_axis.astype(float).tolist())) - - ifc_shape = f.createIfcRevolvedAreaSolid(profile, opening_axis_placement, ifcaxis1dir, revolve_angle) - - curve = f.createIfcTrimmedCurve() - body = f.createIfcShapeRepresentation(context, "Body", "SweptSolid", [ifc_shape]) - axis = f.createIfcShapeRepresentation(context, "Axis", "Curve3D", [curve]) - prod_def_shp = f.createIfcProductDefinitionShape(None, None, (axis, body)) - - pfitting_placement = create_ifclocalplacement(f, O, Z, X) - - pfitting = f.createIfcBuildingElementProxy( - # pfitting = f.createIfcPipeFitting( - create_guid(), - owner_history, - "MyManuel Elbow", - "An awesome Elbow", - None, - pfitting_placement, - prod_def_shp, - None, - None, - ) + # def test_ifc_elbow(self): + # import numpy as np + # from ada.core.constants import O, X, Z + # from ada.core.ifc_utils import ( + # create_guid, + # create_ifcaxis2placement, + # create_ifclocalplacement, + # to_real, + # ) + # from ada.core.utils import ( + # get_center_from_3_points_and_radius, + # normal_to_points_in_plane, + # ) + # + # p1 = (0, y0, z) + # p2 = (5 + x0, y0, z) + # p3 = (5 + x0, y0 + 5, z) + # sec = Section("PSec", "PIPE", r=0.10, wt=5e-3) + # pi1 = Pipe("pipe1", [p1, p2], sec) + # pi2 = Pipe("pipe2", [p2, p3], sec) + # a = Assembly("MyTest") / (Part("MyPart") / [pi1, pi2]) + # f = a.ifc_file + # + # context = f.by_type("IfcGeometricRepresentationContext")[0] + # owner_history = f.by_type("IfcOwnerHistory")[0] + # + # center, _, _, _ = get_center_from_3_points_and_radius(p1, p2, p3, 0.193) + # + # opening_axis_placement = create_ifcaxis2placement(f, O, Z, X) + # + # profile = sec.ifc_profile + # normal = normal_to_points_in_plane([np.array(x) for x in [p1, p2, p3]]) + # revolve_axis = center + normal + # revolve_angle = 10 + # + # ifcorigin = f.createIfcCartesianPoint(to_real(p1)) + # ifcaxis1dir = f.createIfcAxis1Placement(ifcorigin, f.createIfcDirection(to_real(revolve_axis))) + # + # ifc_shape = f.createIfcRevolvedAreaSolid(profile, opening_axis_placement, ifcaxis1dir, revolve_angle) + # + # curve = f.createIfcTrimmedCurve() + # body = f.createIfcShapeRepresentation(context, "Body", "SweptSolid", [ifc_shape]) + # axis = f.createIfcShapeRepresentation(context, "Axis", "Curve3D", [curve]) + # prod_def_shp = f.createIfcProductDefinitionShape(None, None, (axis, body)) + # + # pfitting_placement = create_ifclocalplacement(f, O, Z, X) + # + # pfitting = f.createIfcBuildingElementProxy( + # # pfitting = f.createIfcPipeFitting( + # create_guid(), + # owner_history, + # "MyManuel Elbow", + # "An awesome Elbow", + # None, + # pfitting_placement, + # prod_def_shp, + # None, + # None, + # ) + # f.add(pfitting) if __name__ == "__main__": diff --git a/tests/test_io_fem.py b/tests/test_io_fem.py index c906817e1..efb689b02 100644 --- a/tests/test_io_fem.py +++ b/tests/test_io_fem.py @@ -11,14 +11,13 @@ def test_calc_cog(self): a = build_test_model() p = a.parts["ParametricModel"] cog = p.fem.elements.calc_cog() - tol = 0.01 - assert abs(roundoff(cog[0]) - 2.5) < tol - assert abs(roundoff(cog[1]) - 2.5) < tol - assert abs(roundoff(cog[2]) - 1.5) < tol - assert abs(roundoff(cog[3]) - 7854.90) < tol - assert abs(roundoff(cog[4]) - 1.001) < tol + assert abs(roundoff(cog.p[0]) - 2.5) < tol + assert abs(roundoff(cog.p[1]) - 2.5) < tol + assert abs(roundoff(cog.p[2]) - 1.5) < tol + assert abs(roundoff(cog.tot_mass) - 7854.90) < tol + assert abs(roundoff(cog.tot_vol) - 1.001) < tol if __name__ == "__main__": diff --git a/tests/test_io_fem_sesam.py b/tests/test_io_fem_sesam.py index e002cd014..54caaea74 100644 --- a/tests/test_io_fem_sesam.py +++ b/tests/test_io_fem_sesam.py @@ -10,8 +10,7 @@ def test_write_simple_stru(self): from ada.param_models.basic_module import SimpleStru a = Assembly("MyTest") - p = SimpleStru("SimpleStru") - a.add_part(p) + p = a.add_part(SimpleStru("SimpleStru")) p.gmsh.mesh() a.to_fem("MyTest", fem_format="sesam", overwrite=True) diff --git a/tests/test_param_models.py b/tests/test_param_models.py index ca7f273c8..ebec456b8 100644 --- a/tests/test_param_models.py +++ b/tests/test_param_models.py @@ -43,9 +43,7 @@ def test_to_fem(self): def test_add_piping(self): a = Assembly("ParametricSite") - - pm = SimpleStru("ParametricModel") - a.add_part(pm) + pm = a.add_part(SimpleStru("ParametricModel")) elev = pm.Params.h - 0.4 offset_Y = 0.4