Giter Club home page Giter Club logo

Comments (3)

eudoxos avatar eudoxos commented on May 29, 2024

Putting here just as an example for now. Should be integrated somewhere later.

import mupif as mp
import numpy as np
import meshio
import meshzoo
points,cells=meshzoo.cube_tetra(np.linspace(0.0, 1.0, 11), np.linspace(0.0, 1.0, 11), np.linspace(0.0, 1.0, 11))
mm=meshio.Mesh(points,{'tetra':cells})
    
h5path='12-hm.h5'
xdmfPath='12-hm.xdmf'
    
with mp.HeavyUnstructuredMesh(h5path='12-hm.h5',mode='overwrite') as mesh:
    mesh.fromMeshioMesh(mm,progress=True,chunk=1000)
    fieldP=mesh.makeHeavyField(unit='Pa',fieldID=mp.DataID.FID_Pressure,fieldType=mp.FieldType.FT_cellBased,valueType=mp.ValueType.Scalar)
    fieldUVW=mesh.makeHeavyField(unit='m/s',fieldID=mp.DataID.FID_Velocity,fieldType=mp.FieldType.FT_cellBased,valueType=mp.ValueType.Vector)
    fieldP.value[:]=np.linspace(0,1,len(cells))
    mesh.writeXDMF(xdmfPath,fields=[fieldP,fieldUVW]) # this is actually not necessary
    print(fieldP.evaluate((.1,.1,.1)))

# load mesh and fields from HDF5, also opens the storage
mesh,fields=mp.HeavyUnstructuredMesh.load(h5path)
print(fields[0].evaluate((.1,.1,.1)))

from mupif.

eudoxos avatar eudoxos commented on May 29, 2024

We are currently using our own convention of naming the HDF5 groups. This could be perhaps aligned with FEniCS conventions; pygimli.meshtoos.exportFenicsHdf5Mesh has a terse documentation on expected HDF5 group names; this should be compatible with Paraview and XDMF as it appears from this post

from mupif.

eudoxos avatar eudoxos commented on May 29, 2024

The code above was integrated into unittests in

class HeavyMesh_TestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.box=mp.demo.make_meshio_box_hexa(dim=(1,2,3),sz=.1)
cls.tmpdir=tempfile.TemporaryDirectory()
cls.tmp=cls.tmpdir.name
@classmethod
def tearDownClass(cls):
try: cls.tmpdir.cleanup()
except: pass # this would fail under Windows
def test_saveload(self):
cls=self.__class__
h5path=f'{cls.tmp}/01-mesh.h5'
xdmfPath=f'{cls.tmp}/01-mesh.xdmf'
evalAt=(.1,.1,.1)
with mp.HeavyUnstructuredMesh(h5path=h5path,mode='overwrite') as mesh:
mesh.fromMeshioMesh(cls.box)
fieldP=mesh.makeHeavyField(unit='Pa',fieldID=mp.DataID.FID_Pressure,fieldType=mp.FieldType.FT_cellBased,valueType=mp.ValueType.Scalar)
fieldUVW=mesh.makeHeavyField(unit='m/s',fieldID=mp.DataID.FID_Velocity,fieldType=mp.FieldType.FT_cellBased,valueType=mp.ValueType.Vector)
fieldP.value[:]=np.linspace(0,1,mesh.getNumberOfCells())
# mesh.writeXDMF(xdmfPath,fields=[fieldP,fieldUVW]) # this is actually not necessary
val0=fieldP.evaluate(evalAt)
# load mesh and fields from HDF5, also opens the storage
mesh,fields=mp.HeavyUnstructuredMesh.load(h5path)
val1=fields[0].evaluate((.1,.1,.1))
self.assertEqual(val0,val1)

from mupif.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.