Skip to content

Commit

Permalink
Mass constraint for multiples.
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavbroz committed Nov 7, 2024
1 parent 214b0fb commit c648a28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
10 changes: 2 additions & 8 deletions phoebe/frontend/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
25 changes: 19 additions & 6 deletions phoebe/parameters/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit c648a28

Please sign in to comment.