Mixture Function Section
Applicability: Synapse (core versions 0315+)

Synapse enables you to quickly and easily place constraints on physical properties. For example, if we are designing a mixture that should have liquid densities close to those of water, we can quickly enter the following constraints:

Function Minimum Goal Maximum
f("Density, Liquid - f(T,X)", 293.15, 0) 950 1000 1050
f("Density, Liquid - f(T,X)", 353.15, 0) 925 975 1025

However, we must often enter more complicated constraints. For example, constraints on ratios of properties, dimensionless numbers (e.g., the Prantl number), or heat transfer coefficients.

The Function Section enables you to construct a constraint function of any complexity needed. The section contains a single field having one large code edit control.

Editing Function Code

Clicking the left mouse button on the code edit control activates the Code Edit dialog.

The function's code is run for every mixture candidate in a design or selection. For input, the function is given the candidate's name, components, and composition. These input arguments can be accessed by the standard functions shown in the code to the right.

// Variable declarations string candidate, comps[10]; double xwtpct[10]; int ncomps, err; // Initialize variables ncomps = XWtPercents(xwtpct); candidate = Mixture(); // Retrieve components Components(candidate, comps, err); if( err != 0 ) return FALSE;

For details on editing function code, see documentation for the Code Edit Dialog.

Field Commands Menu

Clicking the right mouse button within the field's code edit control activates the field's commands menu.

The menu's commands enable you to copy, cut and paste values to and from the data control. See Common Menu Commands for documentation on the commands commonly found on command menus.

Example: Entering a function to find an azeotrope

In this example we will create a function that will determine if a given mixture candidate forms a minimum boiling azeotrope at atmospheric pressure. Finding a chemical which forms a minimum boiling azeotrope with a given solvent is a useful way to lower the drying temperature of heat labile materials.

The graph below shows the bubble point and dew point curves for a candidate mixture containing 2-propanol + 2,3-dimethylpentane. The curves were estimated by a variety of technique.

The two red dots (they are very close to each other) correpsond to the properties at the composition of the candidate mixture, e.g., 40 wt% for this candidate. The four black dots correspond to the properties at two limiting compositions equal to -10 wt% and +10 wt%, e.g., 30 wt% and 50 wt% for this candidate.

If the mixture's bubble point at its given composition, e.g., 40 wt%, is less than the bubble points at both of its limit values, e.g., 30 wt% and 50 wt%, then we will conclude that the mixture forms a minimum boiling azeotrope.

  1. Open the MKS Mixture Design Examples document. Save a "working" copy of the document. (See documentation on Copying Documents for details.)
  2. Change to the Functions chapter and add a new entity either by pressing the large "+" sign on the toolbar or selecting the Add New Page command from the Edit menu. Synapse will add a new, blank page to the current document.
  3. Click the left mouse button in the Identifier pane and enter a name for the new function. (By convention, we specify the units of the returned value in parentheses after the function's name.)
  4. Click the left mouse button in the Function Section's large edit field. Synapse will activate the Code Edit dialog. (See the Code Edit Dialog for additional documentation.)
  5. Press the dialog's Default Args button. Several lines of code will be added that declares variables and assigns parameter values.
    // Default declarations string candidate; double xwtpct[20]; int ncomps; // Default assignments ncomps = XWtPercents(xwtpct); candidate = Mixture();
  6. Declare and initialize the following variables.
    // Variable declarations double tlow, tmid, thigh, x; string prop; int err; // Initialize variables prop = "VLE, Bubble Temperature - f(P,X)"; x = xwtpct[0];
  7. Check that the candidate's composition satifies some limiting constraints.
    // Check for composition restrictions if( xwtpct[0] < 11.0 ) return FALSE; if( xwtpct[1] < 11.0 ) return FALSE; if( ncomps != 2 ) return FALSE;
  8. Estimate the bubble point at the input composition.
    // Middle temperature tmid = XProp(candidate, prop, 0, 101325.0, xwtpct, err); if( err != 0 ) return FALSE;
  9. Adjust the composition so it is 10 wt% less than the input value and estimate the bubble point at this new composition.
    // Lower composition xwtpct[0] = xwtpct[0] - 10.0; xwtpct[1] = xwtpct[1] + 10.0; // Lower temperature tlow = XProp(candidate, prop, 0, 101325.0, xwtpct, err); if( err != 0 ) return FALSE;
  10. Adjust the composition so it is 10 wt% greater than the input value (by adding 20 wt% because we just subtracted 10 wt%) and estimate the bubble point at this new composition.
    // Higher composition xwtpct[0] = xwtpct[0] + 20.0; xwtpct[1] = xwtpct[1] - 20.0; // Higher temperature thigh = XProp(candidate, prop, 0, 101325.0, xwtpct, err); if( err != 0 ) return FALSE;
  11. Finally, check if the bubble point at the input compositon is less than the bubble points at both of the limiting compositions.
    // Check for minimum temperature if( tmid > thigh ) return FALSE; if( tmid > tlow ) return FALSE; // Initial composition SetResult(x); // Successful return TRUE;
  12. Press the dialog's Save button. Synapse will check the code for errors and, if none are found, then compile and save the code into the current document.

To test our new function, first make sure either the MKS Sample or MKS Core Knowledge Base is open.

  1. Select the Test Mixture Function command from the chapter's Commands menu.
  2. The application will activate the Test Mixture Function dialog.
    Knowledge Base Control: select either the MKS Sample or MKS Core Knowledge Base.
    Mixture Candidates Control: select the 1-butanol + n-octane mixture. Experimental data shows that this mixture forms an azeotrope at atomospheric pressure at a composition of 54.3 wt% 1-butanol.
    Default Compositions Control: select the default values of 'X: 40,60 wt %'.
    Calculate Button: press the dialog's Calculate button.

    The application will apply the current function's code to the selected mixture and composition and display the results in the dialog.

    Results Control: displays the value returned from executing the function's code. In this example, the value returned is the input x,1 composition which is within 10 wt% of the minimum boiling azeotropic composition.
    Comments Control: displays any comments generated by the function's code or the application.
Related Documentation
Topic Description
Getting Started using Synapse provides a quick tour of Synapse's capabilities including examples of chemical product design.
Designing Chemical Products a short video demonstrating how to use Synapse to design candidate chemicals that satisfy a set of physical property and molecular structure constraints.