Contour Lines¶
Contour lines connect points of equal value in a field, providing an intuitive way to visualize the shape and structure of a dataset. They are particularly useful in MICRESS simulations for analyzing interfaces between different phases or concentration gradients. In this section, we demonstrate how to generate contour plots using MicPy, focusing on phase fractions and element concentrations.
We begin with an example showing the distribution of graphite (A9) phase fraction. Then, we extend the concept to visualize the carbon concentration field, using contour levels to highlight different concentration thresholds.
Example 1: Contour Lines for Graphite Fraction¶
In this example, we visualize the fraction of graphite (A9) phase in a MICRESS simulation. The contour lines help identify regions where the phase fraction reaches a specific threshold, offering insight into the phase distribution.
Step 1: Import Required Libraries¶
We start by importing the necessary library for reading MICRESS binary files.
Step 2: Load the Phase Fraction Data¶
The frac2 file contains phase fraction data for the graphite (A9) phase in the simulation. We load the data using MicPy's bin.File interface.
Step 3: Extract the Final Time Step¶
We extract the phase fraction field at the 30th recorded time step to analyze the final phase distribution.
Step 4: Create the Initial Plot¶
We use the bin.plot() function to visualize the graphite fraction. The transparency (alpha=0.66) allows better visibility of the overlaid contour lines.
Step 5: Access Image Data¶
To overlay contour lines, we access the underlying image array from the plot.
Step 6: Add Contour Lines¶
We draw contour lines at a phase fraction level of 0.5, which helps highlight regions where the graphite phase reaches 50%.
Step 7: Annotate the Colorbar¶
A horizontal line is added to the colorbar to indicate the contour level.
The resulting plot provides an intuitive representation of graphite fraction distribution in the simulation and the location of the sharp interface.

Example 2: Contour Lines for Carbon Concentration¶
In this example, we analyze the carbon concentration field in a cast iron solidification simulation. Contour lines are used to highlight specific concentration levels, revealing spatial variations in composition.
Step 1: Import Required Libraries¶
We begin by importing the MicPy library for handling MICRESS binary files.
Step 2: Load the Concentration Data¶
We load the carbon concentration data from the conc1 file, which stores the simulation output for solute concentrations.
Step 3: Extract the Final Time Step¶
To analyze the 30th distribution of carbon concentration, we extract the data from the last time step.
Step 4: Create the Initial Plot¶
The concentration field is visualized using bin.plot(), with transparency set for better readability.
Step 5: Access Image Data¶
We retrieve the image array from the plot to overlay contour lines.
Step 6: Add Contour Lines¶
Contour lines are drawn at carbon concentration levels of 25%, 50%, and 75%. These levels highlight the concentration gradient within the material.
Step 7: Annotate the Colorbar¶
To improve readability, horizontal lines are added to the colorbar at the same contour levels.
The resulting plot visually separates regions with different carbon concentrations, making it easier to identify areas with specific composition levels.
