Loading docs/Examples.rst +3 −1 Original line number Diff line number Diff line Loading @@ -7,4 +7,6 @@ This chapter present some examples of the uses of BasicTools for some common tas .. toctree:: :glob: Examples/* No newline at end of file Examples/WriteXdmf Examples/TwoInclusions Examples/PrePostDeepLearning No newline at end of file docs/Examples/WriteXdmf.py 0 → 100644 +33 −0 Original line number Diff line number Diff line from BasicTools.Containers import UnstructuredMesh from BasicTools.IO.XdmfWriter import WriteMeshToXdmf from BasicTools.Containers import UnstructuredMeshCreationTools as UMCT from scipy.spatial import Delaunay import numpy as np def create_mesh_example() -> UnstructuredMesh: """This function creates a dummy mesh using Delaunay triangulation. """ # Create a grid of points x, y = np.meshgrid(np.linspace(0,1,10), np.linspace(0,1,10)) points = np.stack([x.ravel(), y.ravel()], axis=1) # Generate the triangles with Delaunay tri = Delaunay(points) triangles = tri.simplices # Create a BasicTools UnstructuredMesh using the CreateMeshOfTriangles utility mesh = UMCT.CreateMeshOfTriangles(points, triangles) return mesh if __name__ == "__main__": # Create a simple mesh mesh = create_mesh_example() # Make six dummy nodal fields fields = np.random.randn(mesh.GetNumberOfNodes(), 6) # Dump the mesh and nodal fields into a XDMF file WriteMeshToXdmf(filename="WriteXdmf.xdmf", # path where the file will be stored baseMeshObject=mesh, # UnstructuredMesh object PointFields=[fields[:,i] for i in range(6)], # list of scalar fields PointFieldsNames=[f"field_{i}" for i in range(6)], # list of names for each scalar field ) No newline at end of file docs/Examples/WriteXdmf.rst 0 → 100644 +10 −0 Original line number Diff line number Diff line ************************** Dump mesh into a XDMF file ************************** This small example shows how to dump a mesh and fields into a XDMF file that can be read by ParaView. .. literalinclude:: WriteXdmf.py :language: python :emphasize-lines: 22-33 :linenos: No newline at end of file Loading
docs/Examples.rst +3 −1 Original line number Diff line number Diff line Loading @@ -7,4 +7,6 @@ This chapter present some examples of the uses of BasicTools for some common tas .. toctree:: :glob: Examples/* No newline at end of file Examples/WriteXdmf Examples/TwoInclusions Examples/PrePostDeepLearning No newline at end of file
docs/Examples/WriteXdmf.py 0 → 100644 +33 −0 Original line number Diff line number Diff line from BasicTools.Containers import UnstructuredMesh from BasicTools.IO.XdmfWriter import WriteMeshToXdmf from BasicTools.Containers import UnstructuredMeshCreationTools as UMCT from scipy.spatial import Delaunay import numpy as np def create_mesh_example() -> UnstructuredMesh: """This function creates a dummy mesh using Delaunay triangulation. """ # Create a grid of points x, y = np.meshgrid(np.linspace(0,1,10), np.linspace(0,1,10)) points = np.stack([x.ravel(), y.ravel()], axis=1) # Generate the triangles with Delaunay tri = Delaunay(points) triangles = tri.simplices # Create a BasicTools UnstructuredMesh using the CreateMeshOfTriangles utility mesh = UMCT.CreateMeshOfTriangles(points, triangles) return mesh if __name__ == "__main__": # Create a simple mesh mesh = create_mesh_example() # Make six dummy nodal fields fields = np.random.randn(mesh.GetNumberOfNodes(), 6) # Dump the mesh and nodal fields into a XDMF file WriteMeshToXdmf(filename="WriteXdmf.xdmf", # path where the file will be stored baseMeshObject=mesh, # UnstructuredMesh object PointFields=[fields[:,i] for i in range(6)], # list of scalar fields PointFieldsNames=[f"field_{i}" for i in range(6)], # list of names for each scalar field ) No newline at end of file
docs/Examples/WriteXdmf.rst 0 → 100644 +10 −0 Original line number Diff line number Diff line ************************** Dump mesh into a XDMF file ************************** This small example shows how to dump a mesh and fields into a XDMF file that can be read by ParaView. .. literalinclude:: WriteXdmf.py :language: python :emphasize-lines: 22-33 :linenos: No newline at end of file