.. _cheat-sheet: Muscat Cheat Sheet ================== Mesh Import, Export and Creation -------------------------------- +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ | Description | Command | URL | +====================+===============================================================================================================+========================================================+ | Installation |.. code:: bash |:ref:`Doc` | | | | | | | mamba install muscat | | | | mamba install muscat-core | | | | mamba install muscat-extentions | | +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ | Help | https://muscat.readthedocs.io/ | | + +---------------------------------------------------------------------------------------------------------------+ + | | https://gitlab.com/drti/muscat | | + +---------------------------------------------------------------------------------------------------------------+ + | | https://github.com/conda-forge/muscat-split-feedstock/ | | | | | | +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ | From a script |.. code:: python | :py:mod:`API` | | | | | | import some | from Muscat.Simple import * | | | commonly used | | | | symbols | | | +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ | Create a mesh |.. admonition:: Imports | :py:mod:`API` | | | :collapsible: closed | | | | | | | | .. code:: python | | | | | | | | from Muscat.MeshTools.MeshCreationTools import ( | | | | CreateUniformMeshOfBars, | | | | CreateMeshOfTriangles, | | | | CreateSquare, | | | | CreateCube, | | | | CreateMeshOf, | | | | CreateMeshFromCellsDict, | | | | ) | | | | | | | |.. code:: python | | | | | | | | CreateUniformMeshOfBars(startPoint,stopPoint,nbPoints) | | | | CreateMeshOfTriangles(points, triangles) | | | | CreateSquare(dimension, origin, spacing, ofTriangles) | | | | CreateCube(dimension, origin, spacing, ofTetras) | | | | CreateMeshOf(points, connectivity, elementType) | | | | CreateMeshFromCellsDict(...) | | +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ | Linear |.. code:: python | :py:mod:`API` | | <-> | | | | Quadratic mesh | from Muscat.MeshTools.MeshCreationTools import * | | | | ToQuadraticMesh(mesh) | | | | QuadToLin(mesh) | | | | | | | | | | +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ | Read a |.. code:: python | :py:mod:`API` | | Mesh File | | | | | from Muscat.IO.UniversalReader import InitAllReaders | | | | from Muscat.IO.UniversalReader import ReadMesh | | | | InitAllReaders() | | | | ReadMesh("filename.ext") | | | | | | | |(a reader is selected using the extension) | | +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ | Read a |.. code:: python | :py:mod:`API` | | Mesh File | | | | Using MeshIO | from Muscat.Bridges.MeshIOBridge import InitAllReaders | | | | InitAllReaders() | | | | from Muscat.IO.UniversalReader import ReadMesh | | | | ReadMesh("filename.ext") | | | | | | | |(a reader is selected using the extension) | | +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ | Convert |.. code:: python | :py:mod:`API` | | to/from | | | | MeshIO format | from Muscat.Bridges.MeshIOBridge import MeshToMeshIO | | | | MeshToMeshIO(meshiodata) | | | | from Muscat.Bridges.MeshIOBridge import MeshIOToMesh | | | | MeshIOToMesh(muscatMesh) | | +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ | Convert |.. code:: python | :py:mod:`API` | | to/from | | | | vtk format | from Muscat.Bridges.vtkBridge import VtkToMesh | | | | VtkToMesh(vtkMesh) | | | | from Muscat.Bridges.vtkBridge import MeshToVtk | | | | MeshToVtk(muscatMesh) | | +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ | Export mesh |.. code:: python | :py:mod:`API` | | using Xdmf | | | | | from Muscat.IO.XdmfWriter import WriteMeshToXdmf | | | | WriteMeshToXdmf(filename="toto.xdmf", mesh,...) | | | | | | | |For Temporal data | | | | | | | |.. code:: python | | | | | | | | from Muscat.IO.XdmfWriter import XdmfWriter | | | | writer = XdmfWriter(filename="outputmesh.xdmf") | | | | writer.SetTemporal(True) | | | | writer.Open() | | | | for i in range(timesteps): | | | | writer.Write(mesh,...) | | | | writer.Close() | | +--------------------+---------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+ Mesh Manipulation ----------------- +---------------+----------------------------------------------------------------------+------------------------------------------------------------+ | Description | Command | URL | +===============+======================================================================+============================================================+ | Iteration over|.. code:: python | | | points | | | | | for i in range(mesh.GetNumberOfNodes()): | | | | point_i = mesh.nodes[i,:] | | +---------------+----------------------------------------------------------------------+------------------------------------------------------------+ | Iteration |.. code:: python | :py:mod:`API` | | using a | | | | NodeFilter | from Muscat.MeshContainers.Filters.FilterObjects import NodeFilter | | | | nf = NodeFilter(eTag="leading edge") | | | | for i in nf.GetNodesIndices(mesh) | | | | leading_edge_point_i = mesh.nodes(i,:) | | +---------------+----------------------------------------------------------------------+------------------------------------------------------------+ | Iteration over|.. code:: python | :ref:`Mesh` | | elements | | | | | for el_container in mesh.elements.values(): | | | | for i in range(el_container.GetNumberOfElements()) | | | | connectivity_e_i = elt_container.connectivity[i,:] | | +---------------+----------------------------------------------------------------------+------------------------------------------------------------+ | Iteration over|.. code:: python | :py:mod:`API` | | using an | | | | ElementFilter | from Muscat.MeshContainers.Filters.FilterObjects import ElementFilter| | | | ef = ElementFilter(dimensionality=1,tag="trailing edge") | | | | for selection in ef(mesh): | | | | conn=selection.elements.connectivity[selection.indices,:] | | +---------------+----------------------------------------------------------------------+------------------------------------------------------------+ | Remeshing |.. code:: python | | | | | | | | from Musca.MeshTools.Remesh import Remesh | | | | Remesh(mesh, metric,remesher_options={"hmax":0.1}) | | | | | | +---------------+----------------------------------------------------------------------+------------------------------------------------------------+ Field Manipulation ------------------ +---------------+-----------------------------------------------------------------------------+------------------------------------------------------------+ | Description | Command | URL | +===============+=============================================================================+============================================================+ | Creating a |.. code:: python | | | point/element | | | | field | mesh.nodeFields["temp"]= np.zeros(mesh.GetNumberOfNodes()) | | | | mesh.elemFields["rho"] = np.zeros(mesh. GetNumberOfElements()) | | | | | | | |* Fields are defined over all the points/elements | | +---------------+-----------------------------------------------------------------------------+------------------------------------------------------------+ |Integration |.. code:: python | | |into a scalar | | | | | from Muscat.FE.IntegrationTools import IntegrateField | :py:mod:`API` | | | nodeData = mesh.nodeFields["temp"] | | | | nodeField = FEField("temp",mesh,data=nodeData) | | | | int_temp = IntegrateField(nodeField) | | | | | | | | from Muscat.FE.FieldTools import ElemFieldsToFEField | | | | elemData = mesh.elemFields["rho"] | | | | rhoField = ElemFieldsToFEField(mesh, {"rho":elemData} ) | | | | mass = IntegrateField(rhoField, ElementFilter(eTag="bulk")) | | | | | | | | | | +---------------+-----------------------------------------------------------------------------+------------------------------------------------------------+ |Integration |.. admonition:: Imports | | |into a Vector | :collapsible: closed | | |(right hand | | | |side) | .. code:: python | | | | | | | | from Muscat.FE.SymWeakForm import GetField, GetTestField | | | | from Muscat.FE.Fields.FEField import FEField | | | | from Muscat.FE.Integration import IntegrateGeneral | | | | from Muscat.MeshContainers.Filters.FilterObjects import ElementFilter | :py:mod:`API` | | | | | | | | | | | | | | |.. code:: python | | | | | | | | weakForm = GetField("p",1,3)*GetTestField("t",1,3) | | | | mesh = ... #(create a mesh or read one from file) | | | | p = FEField("p", mesh=mesh) | | | | p.Allocate(1) | | | | testFields = [FEField("t", mesh=mesh)] | | | | | | | | _, F = IntegrateGeneral(mesh=mesh, | | | | wform=weakForm, | | | | constants={}, | | | | fields=[p], | | | | testFields=testFields, | | | | integrationRuleName="LagrangeP1Quadrature", | | | | elementFilter=ElementFilter(eTag="top_surface") ) | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------------+-----------------------------------------------------------------------------+------------------------------------------------------------+ |Integration |.. admonition:: Imports | | |into a Matrix | :collapsible: closed | | |(operator) | | | | | .. code:: python | | | | | | | | from Muscat.FE.SymWeakForm import GetField, GetTestField | | | | from Muscat.FE.Fields.FEField import FEField | | | | from Muscat.FE.Integration import IntegrateGeneral | | | | from Muscat.MeshContainers.Filters.FilterObjects import ElementFilter | :py:mod:`API` | | | | | | |.. code:: python | | | | | | | | weakForm = GetField("t",1,3)*GetTestField("t",1,3) | | | | mesh = ... #(create a mesh or read one from file) | | | | unknownFields = [FEField("t", mesh=mesh)] | | | | | | | | M, _ = IntegrateGeneral(mesh=mesh, | | | | wform=weakForm, | | | | constants={}, | | | | fields=[], | | | | unknownFields=unknownFields, | | | | integrationRuleName="LagrangeP1Quadrature", | | | | elementFilter=ElementFilter(dimensionality=3) ) | | | | | | | |* M is the scalar mass matrix of the mesh | | | | | | +---------------+-----------------------------------------------------------------------------+------------------------------------------------------------+