Skip to content

Poorly formulated constraint in MCAS model #1547

@andrewlee94

Description

@andrewlee94

Description

The MCAS property model has the following constraint formulation (line 1464):

def rule_mass_frac_phase_comp(b, p, j):
    return b.mass_frac_phase_comp[p, j] == b.flow_mass_phase_comp[p, j] / sum(
        b.flow_mass_phase_comp[p, j] for j in self.params.component_list
    )

This leads to a potential division by zero as flow goes to zero and thus would be better reformulated as:

def rule_mass_frac_phase_comp(b, p, j):
    return b.flow_mass_phase_comp[p, j] == b.mass_frac_phase_comp[p, j]  * sum(
        b.flow_mass_phase_comp[p, j] for j in self.params.component_list
    )

However, doing this results in issues with the scaling methods, primarily due to the transform_property_constraints function which assumes that all constraints are written in the form of property = function(). I suspect that this might have further reaching effects than just this.

Motivation

Generally, constraints should be formulated in ways to avoid potential singularities, such as avoiding divisions where possible (unless the denominator is a simple constant). Doing so helps avoid numerical issues during solving and will generally make models more robust (and often better scaled).

Possible Implementation

This issue effectively has two parts:

  1. Looking for poorly formulated constraints and rewriting them (relatively easy, especially with the diagnostics tools), and
  2. Updating the scaling routines to accommodate these changes (somewhat more effort, especially with the above mentioned transform_property_constraints function). However, given the current push to using the new Scaler classes this hopefully becomes much easier (or at least can be done at the same time).

Additional Context

No response

Metadata

Metadata

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions