Skip to content

Commit

Permalink
fix: config rework (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krande authored Sep 4, 2024
1 parent f5ad492 commit 62980ac
Show file tree
Hide file tree
Showing 40 changed files with 549 additions and 217 deletions.
1 change: 1 addition & 0 deletions conda/environment.core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ dependencies:
- meshio
- websockets
- plotly
- kaleido-core 0.1.0
- python-kaleido
- calculix
2 changes: 2 additions & 0 deletions src/ada/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from ada.api.user import User
from ada.api.walls import Wall
from ada.base.units import Units
from ada.config import configure_logger
from ada.core.utils import Counter
from ada.fem import FEM
from ada.geom.placement import Direction
Expand All @@ -47,6 +48,7 @@
# A set of convenience name generators for plates and beams
PL_N = Counter(start=1, prefix="PL")
BM_N = Counter(start=1, prefix="BM")
configure_logger()


def from_ifc(ifc_file: os.PathLike | ifcopenshell.file, units=Units.M, name="Ada") -> Assembly:
Expand Down
10 changes: 6 additions & 4 deletions src/ada/api/beams/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np

from ada.config import Settings, logger
from ada.config import Config, logger
from ada.core.vector_utils import is_between_endpoints, is_parallel, vector_length
from ada.fem.elements import HingeProp
from ada.geom.placement import Direction
Expand All @@ -14,6 +14,8 @@
from ada import Beam, Node
from ada.api.connections import JointBase

_config = Config()


class BeamConnectionProps:
def __init__(self, beam: Beam):
Expand All @@ -23,7 +25,7 @@ def __init__(self, beam: Beam):
self._connected_end2 = None
self._hinge_prop = None

def calc_con_points(self, point_tol=Settings.point_tol):
def calc_con_points(self, point_tol=_config.general_point_tol):
from ada.core.vector_utils import sort_points_by_dist

a = self._beam.n1.p
Expand Down Expand Up @@ -191,12 +193,12 @@ def is_equivalent(beam, other_beam: Beam) -> bool:

def is_weak_axis_stiffened(beam: Beam, other_beam: Beam) -> bool:
"""Assumes rotation local z-vector (up) is weak axis"""
return np.abs(np.dot(beam.up, other_beam.xvec)) < Settings.point_tol and beam is not other_beam
return np.abs(np.dot(beam.up, other_beam.xvec)) < _config.general_point_tol and beam is not other_beam


def is_strong_axis_stiffened(beam: Beam, other_beam: Beam) -> bool:
"""Assumes rotation local y-vector is strong axis"""
return np.abs(np.dot(beam.yvec, other_beam.xvec)) < Settings.point_tol and beam is not other_beam
return np.abs(np.dot(beam.yvec, other_beam.xvec)) < _config.general_point_tol and beam is not other_beam


def get_justification(beam: Beam) -> Justification:
Expand Down
20 changes: 11 additions & 9 deletions src/ada/api/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ada.api.plates.base_pl import Plate
from ada.api.transforms import Rotation
from ada.base.units import Units
from ada.config import Settings, logger
from ada.config import Config, logger
from ada.core.utils import Counter, roundoff
from ada.core.vector_utils import (
is_null_vector,
Expand All @@ -41,6 +41,8 @@
"Sections",
]

_config = Config()


class BaseCollections:
"""The Base class for all collections"""
Expand Down Expand Up @@ -132,7 +134,7 @@ def modify_beam(bm: Beam, new_nodes) -> Beam:
n1, n2 = new_nodes

n1_2_n2_vector = unit_vector(n2.p - n1.p)
beam_vector = bm.xvec.round(decimals=Settings.precision)
beam_vector = bm.xvec.round(decimals=_config.general_precision)

if is_parallel(n1_2_n2_vector, bm.xvec) and not is_null_vector(n1_2_n2_vector, bm.xvec):
n1, n2 = n2, n1
Expand Down Expand Up @@ -201,7 +203,7 @@ def remove(self, beam: Beam) -> None:
self._idmap = {n.guid: n for n in self._beams}
self._nmap = {n.name: n for n in self._beams}

def get_beams_within_volume(self, vol_, margins=Settings.point_tol) -> Iterable[Beam]:
def get_beams_within_volume(self, vol_, margins=_config.general_point_tol) -> Iterable[Beam]:
"""
:param vol_: List or tuple of tuples [(xmin, xmax), (ymin, ymax), (zmin, zmax)]
:param margins: Add margins to the volume box (equal in all directions). Input is in meters. Can be negative.
Expand Down Expand Up @@ -403,7 +405,7 @@ def get_from_name(self, name: str):
logger.error(f'No Joint with the name "{name}" found within this connection object')
return result

def add(self, joint: JointBase, point_tol=Settings.point_tol):
def add(self, joint: JointBase, point_tol=_config.general_point_tol):
if joint.name is None:
raise Exception("Name is not allowed to be None.")

Expand All @@ -428,7 +430,7 @@ def remove(self, joint: JointBase):
if joint.centre in self._nmap.keys():
self._nmap.pop(joint.centre)

def find(self, out_of_plane_tol=0.1, joint_func=None, point_tol=Settings.point_tol):
def find(self, out_of_plane_tol=0.1, joint_func=None, point_tol=_config.general_point_tol):
"""
Find all connections between beams in all parts using a simple clash check.
Expand Down Expand Up @@ -942,7 +944,7 @@ def nodes(self) -> list[Node]:
return self._nodes

def get_by_volume(
self, p=None, vol_box=None, vol_cyl=None, tol=Settings.point_tol, single_member=False
self, p=None, vol_box=None, vol_cyl=None, tol=_config.general_point_tol, single_member=False
) -> list[Node] | Node:
"""
Expand Down Expand Up @@ -1014,7 +1016,7 @@ def eval_p_in_cyl(no):

return result

def add(self, node: Node, point_tol: float = Settings.point_tol, allow_coincident: bool = False) -> Node:
def add(self, node: Node, point_tol: float = _config.general_point_tol, allow_coincident: bool = False) -> Node:
"""Insert node into sorted list"""

def insert_node(n, i):
Expand Down Expand Up @@ -1059,7 +1061,7 @@ def remove_standalones(self) -> None:
"""Remove nodes that are without any usage references"""
self.remove(filter(lambda x: not x.has_refs, self._nodes))

def merge_coincident(self, tol: float = Settings.point_tol) -> None:
def merge_coincident(self, tol: float = _config.general_point_tol) -> None:
"""
Merge nodes which are within the standard default of Nodes.get_by_volume. Nodes merged into the node connected
to most elements.
Expand All @@ -1082,7 +1084,7 @@ def replace_duplicate_nodes(duplicates: Iterable[Node], new_node: Node):

self._sort()

def rounding_node_points(self, precision: int = Settings.precision) -> None:
def rounding_node_points(self, precision: int = _config.general_precision) -> None:
"""Rounds all nodes to set precision"""
for node in self.nodes:
node.p_roundoff(precision=precision)
Expand Down
7 changes: 4 additions & 3 deletions src/ada/api/curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ada.api.nodes import Node
from ada.api.transforms import Placement
from ada.config import Config
from ada.core.curve_utils import (
build_polycurve,
calc_2darc_start_end_from_lines_radius,
Expand All @@ -25,6 +26,8 @@
from ada import Beam
from ada.geom.curves import ArcLine, IndexedPolyCurve, Line

_config = Config()


class CurveRevolve:
def __init__(
Expand Down Expand Up @@ -155,11 +158,9 @@ def _from_2d_points(self, points2d: list[np.ndarray[float, float]]) -> list[Poin
return local_2_global_points(points2d, place.origin, place.xdir, place.zdir)

def _points_to_segments(self, local_points2d, tol=1e-3):
from ada.config import Settings

debug_name = self._parent.name if self._parent is not None else "PolyCurveDebugging"

seg_list2d = build_polycurve(local_points2d, tol, Settings.debug, debug_name)
seg_list2d = build_polycurve(local_points2d, tol, _config.general_debug, debug_name)
seg_list3d = []
# Convert from local to global coordinates
for i, seg in enumerate(seg_list2d):
Expand Down
9 changes: 5 additions & 4 deletions src/ada/api/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np

from ada.base.units import Units
from ada.config import Settings, logger
from ada.config import Config, logger
from ada.core.vector_utils import vector_length
from ada.geom.points import Point

Expand All @@ -15,6 +15,7 @@
from ada.fem import Bc, Csys, Elem

numeric = Union[int, float, np.number]
_config = Config()


class Node:
Expand Down Expand Up @@ -66,7 +67,7 @@ def bc(self, value: Bc):
def r(self) -> float:
return self._r

def p_roundoff(self, scale_factor: Union[int, float] = 1, precision: int = Settings.precision) -> None:
def p_roundoff(self, scale_factor: Union[int, float] = 1, precision: int = _config.general_precision) -> None:
from ada.core.utils import roundoff

self.p = np.array([roundoff(scale_factor * x, precision=precision) for x in self.p])
Expand Down Expand Up @@ -161,7 +162,7 @@ def __repr__(self):
return f"Node([{self.x}, {self.y}, {self.z}], {self.id})"


def get_singular_node_by_volume(nodes: Nodes, p: np.ndarray, tol=Settings.point_tol) -> Node:
def get_singular_node_by_volume(nodes: Nodes, p: np.ndarray, tol=_config.general_point_tol) -> Node:
"""Returns existing node within the volume, or creates and returns a new Node at the point"""
nds = nodes.get_by_volume(p, tol=tol)
if len(nds) > 0:
Expand All @@ -179,7 +180,7 @@ def sort_nodes_by_distance(point: Union[Node, np.ndarray], nodes: list[Node]) ->
return sorted(nodes, key=lambda x: vector_length(x.p - point))


def replace_nodes_by_tol(nodes, decimals=0, tol=Settings.point_tol):
def replace_nodes_by_tol(nodes, decimals=0, tol=_config.general_point_tol):
def rounding(vec, decimals_):
return np.around(vec, decimals=decimals_)

Expand Down
9 changes: 5 additions & 4 deletions src/ada/api/piping/base_piping.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from ada.api.nodes import Node
from ada.base.physical_objects import BackendGeom
from ada.base.units import Units
from ada.config import Settings as _Settings
from ada.config import logger
from ada.config import Config, logger
from ada.core.exceptions import VectorNormalizeError
from ada.core.utils import Counter, roundoff
from ada.core.vector_utils import angle_between, calc_zvec, unit_vector, vector_length
Expand All @@ -23,6 +22,8 @@
if TYPE_CHECKING:
from ada import Material, Section

_config = Config()


class Pipe(BackendGeom):
def __init__(
Expand Down Expand Up @@ -344,7 +345,7 @@ def build_pipe_segments(pipe: Pipe) -> list[PipeSegStraight | PipeSegElbow]:
props = dict(section=pipe.section, material=pipe.material, parent=pipe, units=pipe.units)
angle_tol = 1e-1

len_tol = _Settings.point_tol if pipe.units == Units.M else _Settings.point_tol * 1000
len_tol = _config.general_point_tol if pipe.units == Units.M else _config.general_point_tol * 1000

pipe_segments = []
if len(segments) == 1:
Expand Down Expand Up @@ -426,7 +427,7 @@ def build_pipe_segments_alt(pipe: Pipe) -> list[PipeSegStraight | PipeSegElbow]:
seg_names = Counter(prefix=pipe.name + "_")
props = dict(section=pipe.section, material=pipe.material, parent=pipe, units=pipe.units)
angle_tol = 1e-1
len_tol = _Settings.point_tol if pipe.units == Units.M else _Settings.point_tol * 1000
len_tol = _config.general_point_tol if pipe.units == Units.M else _config.general_point_tol * 1000
segments = segments3d_from_points3d(pipe.points, radius=pipe.pipe_bend_radius, angle_tol=angle_tol, len_tol=len_tol)
pipe_segments = []
for segment in segments:
Expand Down
5 changes: 3 additions & 2 deletions src/ada/api/plates/base_pl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ada.api.nodes import Node
from ada.base.physical_objects import BackendGeom
from ada.base.units import Units
from ada.config import Settings
from ada.config import Config
from ada.geom import Geometry
from ada.geom.placement import Direction
from ada.geom.points import Point
Expand All @@ -21,6 +21,7 @@
from ada import Placement

_NTYPE = Union[int, float]
_config = Config()


class Plate(BackendGeom):
Expand Down Expand Up @@ -176,7 +177,7 @@ def units(self, value):
value = Units.from_str(value)
if self._units != value:
scale_factor = Units.get_scale_factor(self._units, value)
tol = Settings.mmtol if value == "mm" else Settings.mtol
tol = _config.general_mmtol if value == "mm" else _config.general_mtol
self._t *= scale_factor
self.poly.scale(scale_factor, tol)
for pen in self.booleans:
Expand Down
11 changes: 5 additions & 6 deletions src/ada/api/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ada.materials import Material
from ada.materials.utils import get_material

from ..config import Config
from ..geom import Geometry
from ..geom.placement import Axis2Placement3D, Direction
from ..geom.points import Point
Expand All @@ -26,6 +27,8 @@

from ada.cadit.ifc.store import IfcStore

_config = Config()


class Shape(BackendGeom):
IFC_CLASSES = ShapeTypes
Expand Down Expand Up @@ -346,10 +349,8 @@ def units(self, value):
if isinstance(value, str):
value = Units.from_str(value)
if value != self._units:
from ada.config import Settings

scale_factor = Units.get_scale_factor(self._units, value)
tol = Settings.mmtol if value == "mm" else Settings.mtol
tol = _config.general_mmtol if value == "mm" else _config.general_mtol
self.poly.scale(scale_factor, tol)
self._extrude_depth = self._extrude_depth * scale_factor
self._units = value
Expand Down Expand Up @@ -418,10 +419,8 @@ def units(self, value):
if isinstance(value, str):
value = Units.from_str(value)
if value != self._units:
from ada.config import Settings

scale_factor = Units.get_scale_factor(self._units, value)
tol = Settings.mmtol if value == "mm" else Settings.mtol
tol = _config.general_mmtol if value == "mm" else _config.general_mtol
self.poly.scale(scale_factor, tol)

@property
Expand Down
Loading

0 comments on commit 62980ac

Please sign in to comment.