mtnlion.tools.comsol module

COMSOL Data Handling.

This module is designed to load 1D solution data from a Gu & Wang reference model from COMSOL as CSV files. The idea is that CSV files take a long time to load, so it is more efficient to convert the data to a binary (npz) format before processing.

COMSOL now saves it’s data as a 2D matrix, however it still only uses repeated x values when the boundary solves for different values on either side. In order to normalize the repeated bounds, all bounds are check to ensure they’ve got repeated x values, such that the y values are duplicated.

class mtnlion.tools.comsol.FenicsFunctions(data: Mapping[str, mtnlion.domain.Domain[str, numpy.ndarray]], function_space: dolfin.FunctionSpace)[source]

Bases: object

Handle the assignment of raw COMSOL data to FEniCS functions.

update(time)[source]

Update the FEniCS function values for the current time. Interpolates the data as required.

Parameters

time – Time at which to assign the function

mtnlion.tools.comsol.adimensionalize_comsol_data(comsol_data: mtnlion.deprecated_domain.ReferenceCell, mesh: numpy.ndarray) → Mapping[str, Mapping[str, numpy.ndarray]][source]

Separate a one dimensional (in time) set of cell data into three [0-1] domains.

Parameters
  • comsol_data – data to adimensionalize

  • mesh – destination mesh

mtnlion.tools.comsol.collect_parameters(params: Mapping[str, Mapping[str, float]]) → Tuple[Mapping[str, Mapping[str, float]], Mapping[str, float]][source]

Translate deprecated domains into current domain.

Parameters

params – parameters

mtnlion.tools.comsol.comsol_preprocessor(comsol_data: mtnlion.deprecated_domain.ReferenceCell, mesh: numpy.ndarray) → Dict[str, Dict[str, scipy.interpolate.interpolate.interp1d]][source]

Pre-process COMSOL data to make it more useful in simulations.

Parameters
  • comsol_data – Data to preprocess

  • mesh – New solution mesh (adimensionalized)

mtnlion.tools.comsol.fix_boundaries(mesh: numpy.ndarray, data: numpy.ndarray, boundaries: Union[float, List[int], numpy.ndarray]) → numpy.ndarray[source]

Adjust COMSOL’s interpretation of two-sided boundaries.

When COMSOL outputs data from the reference model there are two solutions at every internal boundary, which causes COMSOL to have repeated domain values; one for the right and one for the left of the boundary. If there is only one internal boundary on the variable mesh at a given time, then a duplicate is added.

Parameters
  • mesh – x data to use to correct the y data

  • data – in 2D, this would be the y data

  • boundaries – internal boundaries

Returns

normalized boundaries to be consistent

mtnlion.tools.comsol.format_data(raw_data: Mapping[str, numpy.ndarray], boundaries: Union[float, List[int]]) → Optional[Mapping[str, numpy.ndarray]][source]

Format COMSOL stacked 1D data into a 2D matrix.

Collect single-column 2D data from COMSOL CSV format and convert into 2D matrix for easy access, where the first dimension is time and the second is the solution in space. Each solution has it’s own entry in a dictionary where the key is the name of the variable. The time step size (time_integration) and mesh have their own keys.

Parameters
  • raw_data – COMSOL formatted CSV files

  • boundaries – internal boundary locations

Returns

convenient dictionary of non-stationary solutions

mtnlion.tools.comsol.format_name(name: str) → str[source]

Determine variable name from filename to be used in loader.collect_files.

Parameters

name – filename

Returns

variable name

mtnlion.tools.comsol.get_standardized(cell: mtnlion.deprecated_domain.ReferenceCell) → Optional[mtnlion.deprecated_engine.Mountain][source]

Convert COMSOL solutions to something more easily fed into FEniCS (remove repeated coordinates at boundaries).

Parameters

cell – reference cell to remove double boundary values from

Returns

Simplified solution cell

mtnlion.tools.comsol.interp_time(time: numpy.ndarray, adim_data: Mapping[str, Mapping[str, numpy.ndarray]]) → Dict[str, Dict[str, scipy.interpolate.interpolate.interp1d]][source]

Return one dimensional interpolation functions corresponding to a dictionary of dictionaries.

Parameters
  • time – Times at which the data is sampled

  • adim_data – Data to interpolate

mtnlion.tools.comsol.load(filename: str) → mtnlion.deprecated_engine.Mountain[source]

Load COMSOL reference cell from formatted npz file.

Parameters

filename – name of the npz file

Returns

ReferenceCell

mtnlion.tools.comsol.remove_dup_boundary(data: mtnlion.deprecated_domain.ReferenceCell, item: numpy.ndarray) → Optional[numpy.ndarray][source]

Remove points at boundaries where two values exist at the same coordinate, favor electrodes over separator.

Parameters
  • data – data in which to reference the mesh and separator indices from

  • item – item to apply change to

Returns

Array of points with interior boundaries removed