.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/basic_usages/01_phlower_tensor_basic.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_basic_usages_01_phlower_tensor_basic.py: .. _first: phlower is a deep learning framework based on PyTorch Ignite especially for physical phenomenon such as fluid dynamics. Phlower Tensor Operation with physical dimension ---------------------------------------------------- Usually, physics values have physics dimensions. Phlower can consider it. .. GENERATED FROM PYTHON SOURCE LINES 15-20 Let's check what kind of items are treated as physics dimension There are many possible choices of base physical dimensions. Following to the SI standard, physical dimensions and corresponding dimension symbols are shown blelow. time (T), length (L), mass (M), electric current (I), absolute temperature (Θ), amount of substance (N) and luminous intensity (J). .. GENERATED FROM PYTHON SOURCE LINES 20-25 .. code-block:: Python from phlower.utils.enums import PhysicalDimensionSymbolType print(f"{[str(v) for v in PhysicalDimensionSymbolType]}") .. rst-class:: sphx-glr-script-out .. code-block:: none ['T (time)', 'L (length)', 'M (mass)', 'I (electric current)', 'Theta (thermodynamic temperature)', 'N (amount of substance)', 'J (luminous intensity)'] .. GENERATED FROM PYTHON SOURCE LINES 26-29 Create PhlowerTensor which is tensor object with physical dimension. There are several way to create PhlowerTensor, the most simple way is shown. PhlowerTensor is a wrapper of torch.Tensor. Call `print` to check values and dimensions. .. GENERATED FROM PYTHON SOURCE LINES 29-41 .. code-block:: Python import torch from phlower import phlower_tensor sample_velocity = torch.rand(3, 4) dimension = {"L": 1, "T": -1} physical_tensor = phlower_tensor(sample_velocity, dimension=dimension) print(physical_tensor) .. rst-class:: sphx-glr-script-out .. code-block:: none PhlowerTensor(tensor([[0.5930, 0.9181, 0.3024, 0.1561], [0.3931, 0.1443, 0.4743, 0.4951], [0.2109, 0.3396, 0.4547, 0.4577]]), Dimension: PhlowerDimensionTensor(T: -1, L: 1, M: 0, I: 0, Theta: 0, N: 0, J: 0)), is_time_series: False, is_voxel: False .. GENERATED FROM PYTHON SOURCE LINES 42-44 Let's calculate square of velocity. You can find that physical dimension is also converted to new dimension. .. GENERATED FROM PYTHON SOURCE LINES 44-49 .. code-block:: Python square_velocity = torch.pow(physical_tensor, 2) print(square_velocity) .. rst-class:: sphx-glr-script-out .. code-block:: none PhlowerTensor(tensor([[0.3517, 0.8430, 0.0915, 0.0244], [0.1545, 0.0208, 0.2250, 0.2451], [0.0445, 0.1154, 0.2067, 0.2095]]), Dimension: PhlowerDimensionTensor(T: -2, L: 2, M: 0, I: 0, Theta: 0, N: 0, J: 0)), is_time_series: False, is_voxel: False .. GENERATED FROM PYTHON SOURCE LINES 50-52 Create PhlowerTensor without physical dimension if you do not pass information of dimension to phlower_tensor. Raise error when it comes to calculate PhlowerTensor with a physical dimension and that without it. .. GENERATED FROM PYTHON SOURCE LINES 52-63 .. code-block:: Python try: one_physical_tensor = phlower_tensor( torch.rand(3, 4), dimension={"L": 1, "T": -1} ) another_physical_tensor = phlower_tensor(torch.rand(3, 4)) _ = another_physical_tensor + one_physical_tensor except Exception as ex: print(ex) .. rst-class:: sphx-glr-script-out .. code-block:: none Cannnot calcualte PhlowerTensor with physics dimension and PhlowerTensor without it. PhlowerTensor(tensor([[0.9274, 0.0046, 0.8813, 0.1245], [0.2910, 0.0990, 0.3051, 0.4022], [0.2909, 0.1427, 0.7736, 0.0870]]), Dimension: None), is_time_series: False, is_voxel: False .. GENERATED FROM PYTHON SOURCE LINES 64-65 Some calculation operations are not allowed when physics dimension value is not the same, .. GENERATED FROM PYTHON SOURCE LINES 65-78 .. code-block:: Python try: one_physical_tensor = phlower_tensor( torch.rand(3, 4), dimension={"L": 1, "T": -1} ) another_physical_tensor = phlower_tensor( torch.rand(3, 4), dimension={"L": 1} ) _ = another_physical_tensor + one_physical_tensor except Exception as ex: print(ex) .. rst-class:: sphx-glr-script-out .. code-block:: none Add operation for different physical dimensions is not allowed. .. GENERATED FROM PYTHON SOURCE LINES 79-80 Some calculation operations are allowed even when physics dimension value is not the same, .. GENERATED FROM PYTHON SOURCE LINES 80-88 .. code-block:: Python one_physical_tensor = phlower_tensor( torch.rand(3, 4), dimension={"L": 1, "T": -1} ) another_physical_tensor = phlower_tensor( torch.rand(3, 4), dimension={"Theta": 1} ) print(another_physical_tensor * one_physical_tensor) .. rst-class:: sphx-glr-script-out .. code-block:: none PhlowerTensor(tensor([[0.0413, 0.0274, 0.0443, 0.0082], [0.3190, 0.8052, 0.0263, 0.1277], [0.3950, 0.4767, 0.4303, 0.1497]]), Dimension: PhlowerDimensionTensor(T: -1, L: 1, M: 0, I: 0, Theta: 1, N: 0, J: 0)), is_time_series: False, is_voxel: False .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.018 seconds) .. _sphx_glr_download_tutorials_basic_usages_01_phlower_tensor_basic.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_phlower_tensor_basic.ipynb <01_phlower_tensor_basic.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_phlower_tensor_basic.py <01_phlower_tensor_basic.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01_phlower_tensor_basic.zip <01_phlower_tensor_basic.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_