}
}
-//================================================================================
-/*!
- * \brief Creates SauvWriter
- */
-//================================================================================
+SauvWriter::SauvWriter():_cpy_grp_if_on_single_family(false)
+{
+}
SauvWriter* SauvWriter::New()
{
return std::vector<const BigMemoryObject *>();
}
+void SauvWriter::setCpyGrpIfOnASingleFamilyStatus(bool status)
+{
+ _cpy_grp_if_on_single_family=status;
+}
+
+bool SauvWriter::getCpyGrpIfOnASingleFamilyStatus() const
+{
+ return _cpy_grp_if_on_single_family;
+}
+
//================================================================================
/*!
* \brief Fills own DS by MEDFileData
if (k != famNames.size())
famSubMeshes.resize(k);
SubMesh* grpSubMesh = addSubMesh( groupName, famSubMeshes[0]->_dimRelExt );
- grpSubMesh->_subs.swap( famSubMeshes );
+ if(!_cpy_grp_if_on_single_family)
+ grpSubMesh->_subs.swap( famSubMeshes );
+ else
+ {
+ /* If a group sub mesh consists of only one family, the group is written as
+ * a copy of this family.
+ * A mesh composed of only one submesh may cause an issue with some Gibi operators.*/
+ if (famSubMeshes.size() == 1)
+ {
+ for(int i = 0; i < famSubMeshes[0]->cellIDsByTypeSize() ; i++)
+ {
+ grpSubMesh->_cellIDsByType[i] = famSubMeshes[0]->_cellIDsByType[i];
+ }
+ }
+ else
+ grpSubMesh->_subs.swap( famSubMeshes );
+ }
}
}
class SauvWriter : public ParaMEDMEM::RefCountObject
{
public:
- MEDLOADER_EXPORT static SauvWriter * New();
+ MEDLOADER_EXPORT static SauvWriter *New();
MEDLOADER_EXPORT void setMEDFileDS(const MEDFileData* medData, unsigned meshIndex = 0);
MEDLOADER_EXPORT void write(const char* fileName);
-
+ MEDLOADER_EXPORT void setCpyGrpIfOnASingleFamilyStatus(bool status);
+ MEDLOADER_EXPORT bool getCpyGrpIfOnASingleFamilyStatus() const;
private:
+ SauvWriter();
std::size_t getHeapMemorySizeWithoutChildren() const;
std::vector<const BigMemoryObject *> getDirectChildren() const;
/*!
std::vector<SauvUtilities::nameGIBItoMED> _longNames[ LN_NB ];
std::fstream* _sauvFile;
+ bool _cpy_grp_if_on_single_family;
};
}
static SauvWriter * New();
void setMEDFileDS(const MEDFileData* medData, unsigned meshIndex = 0) throw(INTERP_KERNEL::Exception);
void write(const char* fileName) throw(INTERP_KERNEL::Exception);
+ void setCpyGrpIfOnASingleFamilyStatus(bool status) throw(INTERP_KERNEL::Exception);
+ bool getCpyGrpIfOnASingleFamilyStatus() const throw(INTERP_KERNEL::Exception);
};
///////////////
#
data=MEDFileData() ; data.setMeshes(ms) ; data.setFields(fs)
return data
+
+ def buildAMEDFileDataWithGroupOnOneFamilyForSauv(self):
+ # Coordinates
+ coords = [0.,0., 0.,1., 1.,1., 1.,0.]
+ # lvl 0 connectivity
+ conn2D = [1,2,3,4]
+ # lvl -1 connectivity
+ conn1D = [0,1, 1,2, 2,3, 4,1]
+ # lvl 0 mesh
+ mesh2D=MEDCouplingUMesh.New()
+ mesh2D.setMeshDimension(2)
+ mesh2D.allocateCells(1)
+ mesh2D.insertNextCell(NORM_QUAD4,4,conn2D)
+ mesh2D.finishInsertingCells()
+ # lvl -1 mesh
+ mesh1D=MEDCouplingUMesh.New()
+ mesh1D.setMeshDimension(1)
+ mesh1D.allocateCells(4)
+ mesh1D.insertNextCell(NORM_SEG2,2,conn1D[0:2])
+ mesh1D.insertNextCell(NORM_SEG2,2,conn1D[2:4])
+ mesh1D.insertNextCell(NORM_SEG2,2,conn1D[4:6])
+ mesh1D.insertNextCell(NORM_SEG2,2,conn1D[6:8])
+ mesh1D.finishInsertingCells()
+ # assigning coordinates
+ meshCoords=DataArrayDouble.New()
+ meshCoords.setValues(coords, 4, 2)
+ mesh2D.setCoords(meshCoords)
+ mesh1D.setCoords(meshCoords)
+ # Creating a multi level mesh
+ mm = MEDFileUMesh.New()
+ mm.setMeshAtLevel(0, mesh2D)
+ mm.setMeshAtLevel(-1, mesh1D)
+ mm.setName("carre")
+ # Creating groups
+ # Creating a group with an element on level -1
+ grp0_LM1 = DataArrayInt.New([0])
+ grp0_LM1.setName("grp0_LM1")
+ # Creating a group with all elements on level -1
+ grp1_LM1 = DataArrayInt.New([0,1,2,3])
+ grp1_LM1.setName("grp1_LM1")
+ #
+ mm.setGroupsAtLevel(-1,[grp0_LM1,grp1_LM1])
+ #
+ ms=MEDFileMeshes.New()
+ ms.setMeshAtPos(0,mm)
+ mfd=MEDFileData.New()
+ mfd.setMeshes(ms)
+ #
+ return mfd
build1DMesh_1=classmethod(build1DMesh_1)
build2DCurveMesh_1=classmethod(build2DCurveMesh_1)
buildVecFieldOnGauss_2_Simpler=classmethod(buildVecFieldOnGauss_2_Simpler)
buildVecFieldOnGaussNE_1=classmethod(buildVecFieldOnGaussNE_1)
buildACompleteMEDDataStructureWithFieldsOnCells_1=classmethod(buildACompleteMEDDataStructureWithFieldsOnCells_1)
+ buildAMEDFileDataWithGroupOnOneFamilyForSauv=classmethod(buildAMEDFileDataWithGroupOnOneFamilyForSauv)
pass
self.assertTrue(m0.isEqual(mRead,1e-12))
pass
+ def testChangeGroupName(self):
+ """ This test is a non regression test on MEDFileUMesh.changeGroupName thanks to Alliance.
+ """
+ mfd=MEDLoaderDataForTest.buildAMEDFileDataWithGroupOnOneFamilyForSauv()
+ mesh = mfd.getMeshes().getMeshAtPos(0)
+ mesh.changeGroupName("grp0_LM1", "xonall1")
+ self.assertTrue("xonall1" in mesh.getGroupsNames())
+ pass
+
pass
unittest.main()
self.assertTrue( f2.isEqual( f, 1e-12, 1e-12 ))
del sr
os.remove( sauvFile )
+ pass
+ def testSauvWriterGroupWithOneFamily(self):
+ """
+ This test checks an option for sauv writing. It is requested here to copy a group from a family if a group is lying on a single family.
+ """
+ import re
+ mfd=MEDLoaderDataForTest.buildAMEDFileDataWithGroupOnOneFamilyForSauv()
+ sauvFile = "mesh.sauv"
+ sw=SauvWriter.New()
+ sw.setMEDFileDS(mfd)
+ self.assertTrue(not sw.getCpyGrpIfOnASingleFamilyStatus())
+ sw.setCpyGrpIfOnASingleFamilyStatus(True)
+ self.assertTrue(sw.getCpyGrpIfOnASingleFamilyStatus())
+ sw.write(sauvFile)
+
+ f = open(sauvFile)
+ # String pattern for the header of the sub meshes record ("PILE" number, number of named objects, number of objects)
+ pattern_pile= re.compile(r'\sPILE\sNUMERO\s+(?P<number>[0-9]+)NBRE\sOBJETS\sNOMMES\s+(?P<nbnamed>[0-9]+)NBRE\sOBJETS\s+(?P<nbobjects>[0-9]+)')
+ # String pattern for a sub mesh header (cell type, number of components and three numbers)
+ pattern_header=re.compile(r'\s+(?P<type>[0-9]+)\s+(?P<nbsubs>[0-9]+)\s+[0-9]+\s+[0-9]+\s+[0-9]+')
+
+ nbobjects=0
+ line = f.readline()
+ while(line):
+ match_pile = pattern_pile.match(line)
+ if match_pile:
+ number=int(match_pile.group("number"))
+ if number == 1:
+ nbnamed=int(match_pile.group("nbnamed"))
+ nbobjects=int(match_pile.group("nbobjects"))
+ break
+ pass
+ line=f.readline()
+ pass
+
+ # Skipping the objects names
+ f.readline()
+ # Skipping the objects ids
+ f.readline()
+ # Looking for each sub-mesh header
+ line = f.readline()
+ cur_object=0
+ while(line and cur_object < nbobjects):
+ match_header=pattern_header.match(line)
+ if match_header:
+ cell_type=int(match_header.group("type"))
+ nb_subs=int(match_header.group("nbsubs"))
+ # Looking for a compound object
+ if cell_type == 0:
+ # Testing if there is only one component
+ self.assertTrue(nb_subs > 1)
+ else:
+ f.readline()
+ f.readline()
+ cur_object = cur_object + 1
+ pass
+ pass
+ line=f.readline()
+ pass
+ os.remove(sauvFile)
pass
+
pass
unittest.main()