# Questions about matrix

**URL:** <https://pyfr.discourse.group/t/questions-about-matrix/908>\
**Category:** Development\
**Created:** [30 August 2023 23:51 UTC](https://pyfr.discourse.group/t/questions-about-matrix/908 "2023-08-30T23:51:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fei](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fei](https://pyfr.discourse.group/u/fei)\
**Post date:** [30 August 2023 23:51 UTC](https://pyfr.discourse.group/t/questions-about-matrix/908/1 "2023-08-30T23:51:03Z")

</div>

Hello, I have some questions.

What’s the meaning of the method “matrix”, “matrix\_slice”, “xchg\_matrix”? and where’s the definition of these methods?

Second, assuming the element u\_{i}, how to get the left and right interface value (u^{+}_{i-1/2} and u^{-}_ {i+1/2} ) of the current value?

And what’s the meaning of “nfacefpts”?

---

<div class="post-metadata">

**Author:** ![nnunn](https://avatars.discourse-cdn.com/v4/letter/n/c89c15/32.png) [@nnunn](https://pyfr.discourse.group/u/nnunn)\
**Post date:** [31 August 2023 19:49 UTC](https://pyfr.discourse.group/t/questions-about-matrix/908/2 "2023-08-31T19:49:37Z")

</div>

Hi @fei,

For all things matrix, start with pyfr/backends/base/types.py:

```auto
class Matrix(MatrixBase):
class MatrixSlice:
class XchgMatrix(Matrix):

```

Each device type derives specializations from these.

For nfacefpts, see [pyfr/shapes.py#L297](https://github.com/PyFR/PyFR/blob/98929401cd2d607da4058f13ecac3f4a6aeee60b/pyfr/shapes.py#L297)

---

<div class="post-metadata">

**Author:** ![nnunn](https://avatars.discourse-cdn.com/v4/letter/n/c89c15/32.png) [@nnunn](https://pyfr.discourse.group/u/nnunn)\
**Post date:** [1 September 2023 12:09 UTC](https://pyfr.discourse.group/t/questions-about-matrix/908/3 "2023-09-01T12:09:19Z")

</div>

After exploring those base classes, next step is to look at /pyfr/backends/\*/base.py to see how these get hooked up for each device type.

For example, in [pyfr/backends/cuda/base.py (Line 65)](https://github.com/PyFR/PyFR/blob/98929401cd2d607da4058f13ecac3f4a6aeee60b/pyfr/backends/cuda/base.py#L65)

```auto
# Register our data types and meta kernels
self.const_matrix_cls = types.CUDAConstMatrix
self.graph_cls = types.CUDAGraph
self.matrix_cls = types.CUDAMatrix
self.matrix_slice_cls = types.CUDAMatrixSlice
self.view_cls = types.CUDAView
self.xchg_matrix_cls = types.CUDAXchgMatrix
self.xchg_view_cls = types.CUDAXchgView
self.ordered_meta_kernel_cls = provider.CUDAOrderedMetaKernel
self.unordered_meta_kernel_cls = provider.CUDAUnorderedMetaKernel

```

So with regard to your question about “matrix”, “matrix\_slice”, “xchg\_matrix”,

**matrix** \_cls = types.CUDAMatrix  
**matrix\_slice** \_cls = types.CUDAMatrixSlice  
**xchg\_matrix** \_cls = types.CUDAXchgMatrix

Likewise for each device type:

for HIP: [pyfr/backends/hip/base.py (Line 61)](https://github.com/PyFR/PyFR/blob/98929401cd2d607da4058f13ecac3f4a6aeee60b/pyfr/backends/hip/base.py#L61)  
OpenMP: [pyfr/backends/openmp/base.py (Line 40)](https://github.com/PyFR/PyFR/blob/98929401cd2d607da4058f13ecac3f4a6aeee60b/pyfr/backends/openmp/base.py#L40)  
Metal: [pyfr/backends/metal/base.py (Line 33)](https://github.com/PyFR/PyFR/blob/98929401cd2d607da4058f13ecac3f4a6aeee60b/pyfr/backends/metal/base.py#L33)

Very neat architecture!

---

<div class="post-metadata">

**Author:** ![fei](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fei](https://pyfr.discourse.group/u/fei)\
**Post date:** [1 September 2023 15:26 UTC](https://pyfr.discourse.group/t/questions-about-matrix/908/4 "2023-09-01T15:26:48Z")

</div>

Yes, and what are these ‘matrix’ used for?

Also, the meaning of ‘nfacefpts’ is n faces of the element, is it right?
