MATLAB Interface
This page documents the MATLAB-compatible interface of HASEonGPU.
The MATLAB interface is mainly intended for compatibility with existing MATLAB or Octave workflows. If this is your first time using HASEonGPU, the Python Interface Guide is usually the better starting point.
For general setup and dependency information, see Getting Started.
Compilation
The MATLAB interface requires a compiled calcPhiASE binary, see Compilation.
Installation
No separate installation step is required.
Add calcPhiASE.m to your MATLAB path, or run your MATLAB script from a
location where the wrapper can be found.
Usage
Call calcPhiASE from a MATLAB script:
[phiASE, MSE, nRays] = calcPhiASE(
points,
trianglePointIndices,
betaCells,
betaVolume,
claddingCellTypes,
claddingNumber,
claddingAbsorption,
useReflections,
refractiveIndices,
reflectivities,
triangleNormalsX,
triangleNormalsY,
triangleNeighbors,
triangleSurfaces,
triangleCenterX,
triangleCenterY,
triangleNormalPoint,
forbiddenEdge,
minRaysPerSample,
maxRaysPerSample,
mseThreshold,
repetitions,
adaptiveSteps,
nTot,
thickness,
laserParameter,
crystal,
numberOfLevels,
backend,
parallelMode,
numDevices,
nPerNode
);
The returned values are represented as two-dimensional matrices, where rows correspond to point indices and columns correspond to slice indices.
Example
A complete MATLAB example using laser pumping and cladding is provided under:
example/matlab_example/laserPumpCladdingExample.m
Typical workflow:
Compile HASEonGPU if needed
Change into
example/matlab_example/Run
matlab laserPumpCladdingExampleInspect the generated
.vtkfiles with ParaView
Input Argument Description
The following section describes all arguments of the MATLAB call.
points
Element type:
floatValue range:
{0, ..., max(maxPointX, maxPointY)}Size:
2 * numberOfPointsDescription: Coordinates of the 2D mesh points. All x coordinates are followed by all y coordinates.
Structure:
[x_1, x_2, ... x_n, y_1, y_2, ... y_n]
trianglePointIndices
Element type:
intValue range:
{0, ..., numberOfPoints}Size:
3 * numberOfTrianglesDescription: Point indices defining the triangles of the mesh. Each triangle is described by three point indices.
Structure:
[triangle1_p1, triangle2_p1, ... triangleN_p1, triangle1_p2, triangle2_p2, ... triangleN_p2, triangle1_p3, triangle2_p3, ... triangleN_p3]
betaCells
Element type:
floatSize:
numberOfPointsDescription: Excited-state fraction \(\beta_i\) at the sample points.
betaVolume
Element type:
floatSize:
numberOfTriangles * (numberOfLevels - 1)Description: Prism-centered excited-state fraction \(\beta_j\) used by the ASE ray integration.
Prism values are ordered according to the prism ID:
prismID = triangleID + layer * numberOfTrianglesTherefore, all prism values of one layer are grouped together.
claddingCellTypes
Element type:
intSize:
numberOfTrianglesDescription: Cladding type index for each triangle.
claddingNumber
Type:
unsignedSize:
1Description: Selects which cladding to use.
claddingAbsorption
Type:
floatSize:
1Description: Absorption coefficient of the cladding.
useReflections
Type:
boolSize:
1Description: Enables or disables reflections at the top and bottom planes.
refractiveIndices
Element type:
floatSize:
4Description: Refractive indices of the active gain medium and its surrounding media.
Structure:
[bottomInside, bottomOutside, topInside, topOutside]
reflectivities
Element type:
floatValue range:
{0, ..., 1}Size:
2 * numberOfTrianglesDescription: Reflectivities of the prism planes. First the reflectivities of the bottom plane, then the reflectivities of the top plane, both ordered by triangle index.
triangleNormalsX
Element type:
floatSize:
3 * numberOfTrianglesDescription: x-components of the normal vectors for each triangle edge.
Structure:
[triangle0_edge0, triangle1_edge0, ..., triangleN_edge0, triangle0_edge1, triangle1_edge1, ..., triangleN_edge1, triangle0_edge2, triangle1_edge2, ..., triangleN_edge2]
triangleNormalsY
Element type:
floatSize:
3 * numberOfTrianglesDescription: y-components of the normal vectors for each triangle edge.
Structure:
[triangle0_edge0, triangle1_edge0, ..., triangleN_edge0, triangle0_edge1, triangle1_edge1, ..., triangleN_edge1, triangle0_edge2, triangle1_edge2, ..., triangleN_edge2]
triangleNeighbors
Element type:
intValue range:
{-1, 0, ..., numberOfTriangles - 1}Size:
3 * numberOfTrianglesDescription: Neighbor triangle indices for each triangle edge.
-1means that no neighboring triangle exists at that edge.
triangleSurfaces
Element type:
floatSize:
numberOfTrianglesDescription: Surface area of each triangle.
triangleCenterX
Element type:
floatSize:
numberOfTrianglesDescription: x-coordinates of the triangle center points.
triangleCenterY
Element type:
floatSize:
numberOfTrianglesDescription: y-coordinates of the triangle center points.
triangleNormalPoint
Element type:
unsignedValue range:
{0, ..., numberOfPoints}Size:
3 * numberOfTrianglesDescription: Point indices where the corresponding triangle normal vectors start. For each triangle, one point index is stored for each of its three edges.
forbiddenEdge
Element type:
intValue range:
{-1, 0, 1, 2}Size:
3 * numberOfTrianglesDescription: Edge indices of the adjacent triangles.
-1means there is no adjacent triangle at that edge.0,1and2denote the corresponding edge index in the adjacent triangle.
minRaysPerSample
Type:
unsignedSize:
1Description: Minimum number of Monte Carlo rays \(N\) used for adaptive sampling.
maxRaysPerSample
Type:
unsignedSize:
1Description: Maximum number of rays used for adaptive sampling.
mseThreshold
Type:
floatSize:
1Description: Sets the maximal MSE of the ASE value. If a sample point does not reach this threshold, the number of rays per sample point is increased up to
maxRaysPerSampleor resampled with repetitive sampling.
repetitions
Type:
unsignedSize:
1Description: Maximum number of repetitions if the MSE threshold is not reached.
adaptiveSteps
Type:
unsignedSize:
1Description: Number of adaptive steps. The range between minimum and maximum ray count is split into that many parts. Setting it to
1disables adaptive stepping and uses onlyminRaysPerSample.
nTot
Type:
floatSize:
1Description: Active-ion concentration \(N_{\mathrm{tot}}\) of the active gain medium.
thickness
Type:
floatSize:
1Description: Thickness \(\Delta z\) of one prism layer of the mesh.
laserParameter
Type:
structDescription: Structure containing the laser material spectra. It provides the absorption and emission spectrum values, \(\sigma_a(\lambda)\) and \(\sigma_e(\lambda)\), together with the corresponding wavelength values \(\lambda\).
Required fields:
l_absl_emss_abss_emsl_res
Field layouts:
l_absContainer type: vector. Element type:
double. Supported layout: flat. Wavelength values \(\lambda\) of the absorption spectrum innm. Accessed in MATLAB aslaserParameter.l_abs.l_emsContainer type: vector. Element type:
double. Supported layout: flat. Wavelength values \(\lambda\) of the emission spectrum innm. Accessed in MATLAB aslaserParameter.l_ems.s_absContainer type: vector. Element type:
double. Supported layout: flat. Absorption cross sections \(\sigma_a\) incm^2, corresponding tol_abs. Accessed in MATLAB aslaserParameter.s_abs.s_emsContainer type: vector. Element type:
double. Supported layout: flat. Emission cross sections \(\sigma_e\) incm^2, corresponding tol_ems. Accessed in MATLAB aslaserParameter.s_ems.l_resType: scalar. Element type:
double. Resolution used for linear interpolation of the spectrum. Accessed in MATLAB aslaserParameter.l_res.
crystal
Type:
structDescription: Structure containing the crystal parameters.
Required fields:
tfluo
Field layouts:
tfluoType: scalar. Element type:
double. Fluorescence lifetime \(\tau\) of the active medium in seconds. Accessed in MATLAB ascrystal.tfluo.
numberOfLevels
Type:
unsignedSize:
1Description: Total number of mesh levels in z-direction.
backend
Type:
strDescription: Selects the alpaka backend used for the simulation.
For details on available runtime backends and backend naming, see the runtime selection section of Backend Selection.
parallelMode
Type:
strAllowed values:
"single": threads distribute samples across GPUs/devices within one node"mpi": distributes samples across nodes
Description: Selects the parallelization mode.
numDevices
Type:
unsignedDescription: Number of devices used by one process - internally HASEonGPU uses min(numDevices,availableDevices).
In
singlemode, this usually corresponds to the requested number of computing devices - this can be gpus or cpu sockets depending on the alpaka backend - used on the local node.In
mpimode, this corresponds to the number of computing devices used per MPI process rank. Therefore, ifnPerNode = 1 (default), it corresponds to the number of devices used per node.
nPerNode
Type:
unsignedDescription: Number of MPI process ranks launched per node (default = 1).