return decaratedFunc
class MEDLoaderDataForTest:
+ @classmethod
def build1DMesh_1(cls):
coords=[ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 ]
conn=[ 0,1, 1,2, 2,3 , 3,4,5]
mesh.setCoords(myCoords);
return mesh;
+ @classmethod
def build2DCurveMesh_1(cls):
coords=[ 0.0,0.0, 0.3,0.3, 0.75,0.75, 1.0,1.0, 1.4,1.4, 1.3,1.3 ]
conn=[ 0,1, 1,2, 2,3 , 3,4,5]
mesh.setCoords(myCoords);
return mesh;
+ @classmethod
def build2DMesh_1(cls):
targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
-0.05,0.95, 0.2,1.2, 0.45,0.95]
targetMesh.setCoords(myCoords)
return targetMesh;
+ @classmethod
def build2DMesh_2(cls):
targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
-0.05,0.95, 0.2,1.2, 0.45,0.95]
return targetMesh;
#this mesh has several cells duplicated ! it is not beautiful but efficient to test file WR.
+ @classmethod
def build2DMesh_3(cls):
targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
-0.05,0.95, 0.2,1.2, 0.45,0.95]
targetMesh.setCoords(myCoords);
return targetMesh;
+ @classmethod
def build3DMesh_1(cls):
coords=[0.,0.,0., 1.,1.,0., 1.,1.25,0., 0.,1.,0., 1.,1.5,0., 2.,0.,0., 2.,1.,0., 1.,2.,0., 0.,2.,0., 3.,1.,0.,
3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
myCoords.setInfoOnComponent(2,"t [kW]");
ret.setCoords(myCoords);
return ret;
-
+
+ @classmethod
def build3DSurfMesh_1(cls):
targetCoords=[-0.3,-0.3,-0.3, 0.2,-0.3,-0.3, 0.7,-0.3,-0.3, -0.3,0.2,-0.3, 0.2,0.2,-0.3, 0.7,0.2,-0.3, -0.3,0.7,-0.3, 0.2,0.7,-0.3, 0.7,0.7,-0.3
,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3]
myCoords.setInfoOnComponent(2,"ff [km]");#component 1 is not set for test
targetMesh.setCoords(myCoords);
return targetMesh;
-
+
+ @classmethod
def build3DMesh_2(cls):
m3dsurfBase=MEDLoaderDataForTest.build3DSurfMesh_1();
numbers=[0,1,2,3,5]
ret=m3dsurf.buildExtrudedMesh(m1d,0);
return ret;
+ @classmethod
def buildMultiLevelMesh_1(cls):
coo=[10.,0.,10.,1.25,10.,2.5,10.,3.75,10.,5.,8.75,0.,8.75,1.25,8.75,2.5,8.75,3.75,8.75,5.,7.5,0.,7.5,1.25,7.5,2.5,7.5,3.75,7.5,5.,6.25,0.,6.25,1.25,6.25,2.5,6.25,3.75,6.25,5.,5.,0.,5.,1.25,5.,2.5,5.,3.75,5.,5.,3.75,0.,3.75,1.25,3.75,2.5,3.75,3.75,3.75,5.,2.5,0.,2.5,1.25,2.5,2.5,2.5,3.75,2.5,5.,1.25,0.,1.25,1.25,1.25,2.5,1.25,3.75,1.25,5.,0.,1.25,0.,2.5,0.,3.75,0.,5.,0.,0.,0.,5.,10.,5.,0.,10.,10.,10.,5.,5.,5.,5.,5.,10.,5.,10.,0.625,5.,1.25,5.,1.875,5.,2.5,5.,3.125,5.,3.75,5.,4.375,5.,5.,6.25,5.,7.5,5.,8.75,4.375,10.,3.75,10.,3.125,10.,2.5,10.,1.875,10.,1.25,10.,0.625,10.,0.,8.75,0.,7.5,0.,6.25,4.375,6.25,4.375,7.5,4.375,8.75,3.75,6.25,3.75,7.5,3.75,8.75,3.125,6.25,3.125,7.5,3.125,8.75,2.5,6.25,2.5,7.5,2.5,8.75,1.875,6.25,1.875,7.5,1.875,8.75,1.25,6.25,1.25,7.5,1.25,8.75,0.625,6.25,0.625,7.5,0.625,8.75,5.625,5.,6.25,5.,6.875,5.,7.5,5.,8.125,5.,8.75,5.,9.375,5.,10.,6.25,10.,7.5,10.,8.75,9.375,10.,8.75,10.,8.125,10.,7.5,10.,6.875,10.,6.25,10.,5.625,10.,5.,8.75,5.,7.5,5.,6.25,9.375,6.25,9.375,7.5,9.375,8.75,8.75,6.25,8.75,7.5,8.75,8.75,8.125,6.25,8.125,7.5,8.125,8.75,7.5,6.25,7.5,7.5,7.5,8.75,6.875,6.25,6.875,7.5,6.875,8.75,6.25,6.25,6.25,7.5,6.25,8.75,5.625,6.25,5.625,7.5,5.625,8.75]
coo2=DataArrayDouble.New()
famIdsPerGrp=[[5],[-11],[1],[-8],[4],[-10],[-12],[2],[-9],[-4],[-5],[-6],[-7],[-4,-5,-6,-7],[6],[-14],[7],[-19],[8],[-17],[9],[-20],[10],[-15],[11],[-18],[12],[-21],[13],[-16],[3],[-13],[-3,-2,-1],[-3],[-2],[-1],[-4,-5,-6,-7,-3,-2,-1],[3]]
return m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp
+ @classmethod
def buildMLMeshUnPolyze(cls,tester):
"""Level 0 (meshDim=3) - 2 TETRA4 + 3 PENTA6 + 2 POLYH
# POLYH #0 becomes 1 TETRA4
pass
mesh0.finishInsertingCells()
mesh0.setCoords(coords)
-
+
meshM1=MEDCouplingUMesh(meshName,2)
typeM1=[NORM_TRI3,NORM_TRI3, NORM_QUAD4,NORM_QUAD4,NORM_QUAD4, NORM_POLYGON,NORM_POLYGON,NORM_POLYGON,NORM_POLYGON]
connM1=[[0,1,2],[3,4,5], [6,7,8,9],[10,11,12,13],[14,15,16,17], [18,19,20,21,22],[23,24,25,26,27],[28,29,30],[31,32,33,34,35,36,37]]
da=DataArrayInt.New(mm.getNumberOfNodes()) ; da.iota(8) ; mm.setRenumFieldArr(1,da)
return mm
+ @classmethod
def buildVecFieldOnCells_1(cls):
mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
nbOfCells=mesh.getNumberOfCells();
array.setInfoOnComponent(1,"density [g/cm^3]");
array.setInfoOnComponent(2,"temperature [K]");
f1.setArray(array);
- tmp=array.getPointer();
f1.setTime(2.,0,1);
f1.checkConsistencyLight();
return f1;
+ @classmethod
+ def buildIntVecFieldOnCells_1(cls):
+ mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
+ nbOfCells=mesh.getNumberOfCells();
+ f1=MEDCouplingFieldInt.New(ON_CELLS,ONE_TIME);
+ f1.setName("IntVectorFieldOnCells");
+ f1.setMesh(mesh);
+ array=DataArrayInt([0,10,20,1,11,21,2,12,22,3,13,23,4,14,24,5,15,25],nbOfCells ,3)
+ array.setInfoOnComponent(0,"va1 [MW/m^3]");
+ array.setInfoOnComponent(1,"va2 [g/cm^3]");
+ array.setInfoOnComponent(2,"val3 [K]");
+ f1.setArray(array);
+ f1.setTime(2.,0,1);
+ f1.checkConsistencyLight();
+ return f1;
+
+ @classmethod
+ def buildFloatVecFieldOnCells_1(cls):
+ mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
+ nbOfCells=mesh.getNumberOfCells();
+ f1=MEDCouplingFieldFloat.New(ON_CELLS,ONE_TIME);
+ f1.setName("FloatVectorFieldOnCells");
+ f1.setMesh(mesh);
+ array=DataArrayFloat([0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.], nbOfCells, 3);
+ array.setInfoOnComponent(0,"power [MW/m^3]");
+ array.setInfoOnComponent(1,"density [g/cm^3]");
+ array.setInfoOnComponent(2,"temperature [K]");
+ f1.setArray(array);
+ f1.setTime(2.,0,1);
+ f1.checkConsistencyLight();
+ return f1;
+
+ @classmethod
def buildVecFieldOnNodes_1(cls):
mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
nbOfNodes=mesh.getNumberOfNodes();
f1.checkConsistencyLight();
return f1;
+ @classmethod
def buildVecFieldOnGauss_1(cls):
_a=0.446948490915965;
_b=0.091576213509771;
f.checkConsistencyLight();
return f;
+ @classmethod
def buildVecFieldOnGauss_2(cls):
_a=0.446948490915965;
_b=0.091576213509771;
return f;
# idem buildVecFieldOnGauss_2 except that different discretizations are sorted inside one type
+ @classmethod
def buildVecFieldOnGauss_2_Simpler(cls):
_a=0.446948490915965;
_b=0.091576213509771;
f.checkConsistencyLight();
return f;
+ @classmethod
def buildVecFieldOnGaussNE_1(cls):
m=MEDLoaderDataForTest.build2DMesh_2();
f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME);
f.checkConsistencyLight();
return f;
+ @classmethod
def buildACompleteMEDDataStructureWithFieldsOnCells_1(cls):
coo=DataArrayDouble([0,0,1,0,2,0,0,1,1,1,2,1,0,2,1,2,2,2],9,2)
m0=MEDCouplingUMesh("mesh",2)
data=MEDFileData() ; data.setMeshes(ms) ; data.setFields(fs)
return data
+ @classmethod
def buildAMEDFileDataWithGroupOnOneFamilyForSauv(self):
# Coordinates
coords = [0.,0., 0.,1., 1.,1., 1.,0.]
mfd.setMeshes(ms)
#
return mfd
-
- build1DMesh_1=classmethod(build1DMesh_1)
- build2DCurveMesh_1=classmethod(build2DCurveMesh_1)
- build2DMesh_1=classmethod(build2DMesh_1)
- build2DMesh_2=classmethod(build2DMesh_2)
- build2DMesh_3=classmethod(build2DMesh_3)
- build3DMesh_1=classmethod(build3DMesh_1)
- build3DSurfMesh_1=classmethod(build3DSurfMesh_1)
- build3DMesh_2=classmethod(build3DMesh_2)
- buildMLMeshUnPolyze=classmethod(buildMLMeshUnPolyze)
- buildMultiLevelMesh_1=classmethod(buildMultiLevelMesh_1)
- buildVecFieldOnCells_1=classmethod(buildVecFieldOnCells_1)
- buildVecFieldOnNodes_1=classmethod(buildVecFieldOnNodes_1)
- buildVecFieldOnGauss_1=classmethod(buildVecFieldOnGauss_1)
- buildVecFieldOnGauss_2=classmethod(buildVecFieldOnGauss_2)
- buildVecFieldOnGauss_2_Simpler=classmethod(buildVecFieldOnGauss_2_Simpler)
- buildVecFieldOnGaussNE_1=classmethod(buildVecFieldOnGaussNE_1)
- buildACompleteMEDDataStructureWithFieldsOnCells_1=classmethod(buildACompleteMEDDataStructureWithFieldsOnCells_1)
- buildAMEDFileDataWithGroupOnOneFamilyForSauv=classmethod(buildAMEDFileDataWithGroupOnOneFamilyForSauv)
+
pass
def TestWriteUMeshesRW1(tester):
WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
f2=ReadFieldCell(fileName,f1.getMesh().getName(),-1,f1.getName(),2,7);
tester.assertTrue(f2.isEqual(f1,1e-12,1e-12));
-
+
def GeneratePyfile19(tester):
fileName="Pyfile19.med";
fileName2="Pyfile20.med";
#include "MEDLoaderBase.hxx"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingFieldInt.hxx"
+#include "MEDCouplingFieldFloat.hxx"
#include "MEDCouplingMemArray.hxx"
#include "TestInterpKernelUtils.hxx" // getResourceFile()
static const double VAL1=12345.67890314;
static const double VAL2=-1111111111111.;
MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
+ MEDCouplingFieldInt *f1_int=buildIntVecFieldOnCells_1();
+ MEDCouplingFieldFloat *f1_fl=buildFloatVecFieldOnCells_1();
WriteField(fileName,f1,true);
f1->setTime(10.,8,9);
+ f1_int->setTime(10.,8,9);
+ f1_fl->setTime(10.,8,9);
double *tmp=f1->getArray()->getPointer();
tmp[0]=VAL1;
WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
f1->setTime(10.14,18,19);
tmp[0]=VAL2;
WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ // Write int and float fields:
+ WriteFieldUsingAlreadyWrittenMesh(fileName,f1_int);
+ WriteFieldUsingAlreadyWrittenMesh(fileName,f1_fl);
//retrieving time steps...
MEDCouplingFieldDouble *f2=dynamic_cast<MEDCouplingFieldDouble *>(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),8,9));
f1->setTime(10.,8,9);
CPPUNIT_ASSERT_THROW(ReadFieldCell(fileName,f1->getMesh()->getName().c_str(),0,f1->getName().c_str(),28,19),INTERP_KERNEL::Exception);
f2->decrRef();
f1->decrRef();
+ // Reading Int and Float fields:
+ MEDCouplingFieldInt *f2_int=dynamic_cast<MEDCouplingFieldInt *>(ReadFieldCell(fileName,f1_int->getMesh()->getName().c_str(),0,f1_int->getName().c_str(),8,9));
+ CPPUNIT_ASSERT(f1_int->isEqual(f2_int,1e-12,0)); // exact equality for int values
+ f2_int->decrRef();
+ MEDCouplingFieldFloat *f2_fl=dynamic_cast<MEDCouplingFieldFloat *>(ReadFieldCell(fileName,f1_fl->getMesh()->getName().c_str(),0,f1_fl->getName().c_str(),8,9));
+ CPPUNIT_ASSERT(f1_fl->isEqual(f2_fl,1e-12,1e-12));
+ f2_fl->decrRef();
//ON NODES
f1=buildVecFieldOnNodes_1();
const char fileName2[]="file9.med";
}
/*!
- * Multi field in a same file, but this field has several
+ * Multi field in a same file, but this field has several timesteps
*/
void MEDLoaderTest::testFieldRW3()
{
return f1;
}
+MEDCouplingFieldInt *MEDLoaderTest::buildIntVecFieldOnCells_1()
+{
+ MEDCouplingUMesh *mesh=build3DSurfMesh_1();
+ mcIdType nbOfCells=mesh->getNumberOfCells();
+ MEDCouplingFieldInt *f1=MEDCouplingFieldInt::New(ON_CELLS,ONE_TIME);
+ f1->setName("IntVectorFieldOnCells");
+ f1->setMesh(mesh);
+ DataArrayInt *array=DataArrayInt::New();
+ array->alloc(nbOfCells,3);
+ array->setInfoOnComponent(0,"val1 [MW/m^3]");
+ array->setInfoOnComponent(1,"va2 [g/cm^3]");
+ array->setInfoOnComponent(2,"val3 [K]");
+ f1->setArray(array);
+ array->decrRef();
+ mcIdType *tmp=array->getPointer();
+ const mcIdType arr1[18]={0,10,20,1,11,21,2,12,22,3,13,23,4,14,24,5,15,25};
+ std::copy(arr1,arr1+18,tmp);
+ f1->setTime(2.,0,1);
+ f1->checkConsistencyLight();
+ mesh->decrRef();
+ return f1;
+}
+
+MEDCouplingFieldFloat *MEDLoaderTest::buildFloatVecFieldOnCells_1()
+{
+ MEDCouplingUMesh *mesh=build3DSurfMesh_1();
+ mcIdType nbOfCells=mesh->getNumberOfCells();
+ MEDCouplingFieldFloat *f1=MEDCouplingFieldFloat::New(ON_CELLS,ONE_TIME);
+ f1->setName("FloatVectorFieldOnCells");
+ f1->setMesh(mesh);
+ DataArrayFloat *array=DataArrayFloat::New();
+ array->alloc(nbOfCells,3);
+ array->setInfoOnComponent(0,"power [MW/m^3]");
+ array->setInfoOnComponent(1,"density [g/cm^3]");
+ array->setInfoOnComponent(2,"temperature [K]");
+ f1->setArray(array);
+ array->decrRef();
+ float *tmp=array->getPointer();
+ const float arr1[18]={0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.};
+ std::copy(arr1,arr1+18,tmp);
+ f1->setTime(2.,0,1);
+ f1->checkConsistencyLight();
+ mesh->decrRef();
+ return f1;
+}
+
+
MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnNodes_1()
{
MEDCouplingUMesh *mesh=build3DSurfMesh_1();