pycalphad / pycalphad

CALPHAD tools for designing thermodynamic models, calculating phase diagrams and investigating phase equilibria.
https://pycalphad.org
Other
270 stars 105 forks source link

Plotting arbitrary isopleths #5

Open richardotis opened 9 years ago

richardotis commented 9 years ago

Users would have a plot() style interface for specifying arbitrary sections through composition space. This is not too conceptually difficult using the energy_surf routine and scipy's ConvexHull routine (though we may run into performance problems); the main trick is efficiently calculating intersections of hyperplanes with the convex hull. Routines exist for this but need to be investigated further.

richardotis commented 9 years ago

The lower_convex_hull routine in the geometry module is performant enough to take this task on now. There's probably a way to vectorize it so that it can accept an ndarray of conditions and return EquilibriumResult objects in the same shape. Another issue is making sure we have a reliable answer so we don't end up with answers dependent on the initial point density, since right now lower_convex_hull is mostly used for finding starting points.

richardotis commented 8 years ago

It looks like equilibrium could probably do this task now with some tweaking, so I'll put it on the roadmap for 0.4.

richardotis commented 7 years ago

@bocklund Confused why this issue is tagged. Are you saying that PR lets you plot isopleths (slices through composition space as a function of T)?

bocklund commented 7 years ago

Brain malfunction

bocklund commented 7 years ago

Although I think my changes could be progress towards handling this nicely if I can figure out how to concatenate all of the points together for n-phase regions. We could just do a Gibbs phase rule calculations to calculate p and loop over the indices search, plotting, and tielines from 2 to p phases. It would use all of the same logic I already have, but instead of plotting x[.., 0], y[..., 0], x[.., 1], y[..., 1] we just concatenate the last dimension and plot/construct tielines with those two arrays (just x, y).

richardotis commented 7 years ago

In principle it's a straightforward implementation if you are okay with just plotting the tie-line points at each temperature. The key is the math for projecting the high-dimensional tie-plane onto the isopleth compositional line.

richardotis commented 7 years ago

An attempt at the geometry: create a triangle where one vertex (A) is the origin of the isopleth line, the second vertex (B) is the tie-plane point of interest (in high-dimensional space), and the third vertex (C) is the unknown point along the isopleth line.

We know:

Solve for:

Solution:

Once AC is known, we can use the equation for this isopleth line to map point A to a point on the line.

bocklund commented 6 years ago

The key is the math for projecting the high-dimensional tie-plane onto the isopleth compositional line.

What does this mean? Are you talking about plotting the actual tielines themselves or the endpoints (ZPF lines)?

richardotis commented 6 years ago

ZPF lines.

bocklund commented 3 years ago

In principle it's a straightforward implementation if you are okay with just plotting the tie-line points at each temperature. The key is the math for projecting the high-dimensional tie-plane onto the isopleth compositional line.

An attempt at the geometry: create a triangle where one vertex (A) is the origin of the isopleth line, the second vertex (B) is the tie-plane point of interest (in high-dimensional space), and the third vertex (C) is the unknown point along the isopleth line.

We know:

* Length of side AB: we know coordinates of both A and B

* Angle ACB: must be 90 degrees, by construction

* Length of side BC: we can compute this from the [hyperplane distance formula](https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_plane)

Solve for:

* Length of side AC

Solution:

* First, solve for angle BAC: `arcsin(BC/AB)`

* Next, solve for length AC: `BC/tan(BAC)` = `BC/tan(arcsin(BC/AB))`

Once AC is known, we can use the equation for this isopleth line to map point A to a point on the line.

I think we've changed our thinking on this, but I wanted to document that here. The approach outlined here to compute the ZPF line by finding the intersection between an equilibrium hyperplane and the line of the isopleth won't work because the intersection of a hyperplane and the isopleth line doesn't correspond to a change in the set of phases --- a point on a zero phase fraction line.

The key is that, within the plane of the diagram, one needs to know when there is a change in the stable set of phases, and this by definition, marks a point on the diagram where one phase has zero phase amount (the phase that either appears or disappears). This applies to any mapped axis, e.g. temperature or composition or chemical potential, etc.

Using the fixed phase condition to follow the lines where a phase has zero amount is the most widely accepted way of doing this and it's now theoretically possible to do these calculations using the new minimizer from #329. Thus, the main outstanding issues for isopleth plotting are: