From c648a281f1eae45719f7cdc47db1fa13b8f52491 Mon Sep 17 00:00:00 2001 From: Miroslav Broz Date: Thu, 7 Nov 2024 14:53:54 +0100 Subject: [PATCH] Mass constraint for multiples. --- phoebe/frontend/bundle.py | 10 ++-------- phoebe/parameters/constraint.py | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/phoebe/frontend/bundle.py b/phoebe/frontend/bundle.py index 9b082e37b..d7a9164dc 100644 --- a/phoebe/frontend/bundle.py +++ b/phoebe/frontend/bundle.py @@ -2840,14 +2840,8 @@ def set_hierarchy(self, *args, **kwargs): solve_for=constraint_param.constrained_parameter.uniquetwig, constraint=constraint_param.constraint) else: - # NOTE: IN ORDER TO DEFAULT_TRIPLE() WORKS - sibling = self.hierarchy.get_sibling_of(component) - kind = self.hierarchy.get_kind_of(sibling) - if kind != 'star': - logger.warning('constraint mass not working for multiple systems') - else: - self.add_constraint(constraint.mass, component, - constraint=self._default_label('mass', context='constraint')) + self.add_constraint(constraint.mass, component, + constraint=self._default_label('mass', context='constraint')) logger.debug('re-creating comp_sma constraint for {}'.format(component)) diff --git a/phoebe/parameters/constraint.py b/phoebe/parameters/constraint.py index 077d05219..fb8216168 100644 --- a/phoebe/parameters/constraint.py +++ b/phoebe/parameters/constraint.py @@ -1553,14 +1553,27 @@ def mass(b, component, solve_for=None, **kwargs): component_ps = _get_system_ps(b, component) - sibling = hier.get_sibling_of(component) - sibling_ps = _get_system_ps(b, sibling) - parentorbit = hier.get_parent_of(component) parentorbit_ps = _get_system_ps(b, parentorbit) - mass = component_ps.get_parameter(qualifier='mass', **_skip_filter_checks) - mass_sibling = sibling_ps.get_parameter(qualifier='mass', **_skip_filter_checks) + m1 = component_ps.get_parameter(qualifier='mass', **_skip_filter_checks) + masses = [] + masses.append(m1) + + siblings = hier.get_stars_of_sibling_of(component) + siblings = siblings if isinstance(siblings, list) else [siblings] + + for i, sibling in enumerate(siblings): + sibling_ps = _get_system_ps(b, sibling) + m2 = sibling_ps.get_parameter(qualifier='mass', **_skip_filter_checks) + if i==0: + msum = m2 + else: + msum += m2 + masses.append(m2) + + mass = m1 + mass_sibling = msum # we need to find the constraint attached to the other component... but we # don't know who is constrained, or whether it belongs to the sibling or parent @@ -1619,7 +1632,7 @@ def mass(b, component, solve_for=None, **kwargs): else: raise NotImplementedError - return lhs, rhs, [mass, mass_sibling, period, sma, q], {'component': component} + return lhs, rhs, [period, sma, q] + masses, {'component': component} # ecosw_def = FloatParameter(qualifier='ecosw', value=0.0, default_unit=u.dimensionless_unscaled, limits=(-1.0,1.0), description='Eccentricity times cos of argument of periastron')