From: ageay Date: Mon, 2 Aug 2010 05:44:07 +0000 (+0000) Subject: Gauss point and Gauss Point on element node RW. X-Git-Tag: V5_1_main_FINAL~71 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2efdf9dde9cda8f13d1dbd69e10d49e8f3557867;p=tools%2Fmedcoupling.git Gauss point and Gauss Point on element node RW. --- diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index be1aa373f..e9a8cf654 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -23,6 +23,7 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingGaussLocalization.hxx" extern "C" { @@ -113,6 +114,8 @@ double MEDLoader::_EPS_FOR_NODE_COMP=1.e-12; int MEDLoader::_COMP_FOR_CELL=0; +int MEDLoader::_TOO_LONG_STR=0; + using namespace ParaMEDMEM; namespace MEDLoaderNS @@ -136,16 +139,17 @@ namespace MEDLoaderNS int _val; }; - std::string buildStringFromFortran(const char *expr, int lgth); std::vector getMeshNamesFid(med_idt fid); - void readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName, std::list& field, - int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField, double& time); + void readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName, + int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField, + std::list& field, + double& time, std::vector& infos); std::vector getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector& fams); std::vector getIdsFromGroups(const char *fileName, const char *meshName, const std::vector& grps); med_int getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception); void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entite_maillage& whichEntity); int readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector& possibilities); - void readUMeshDataInMedFile(med_idt fid, med_int meshId, double *&coords, int& nCoords, int& spaceDim, std::list& conn); + void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list& conn); int buildMEDSubConnectivityOfOneType(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, INTERP_KERNEL::NormalizedCellType type, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& connIndexRk24MEDFile, std::vector& fam4MEDFile); @@ -155,7 +159,8 @@ namespace MEDLoaderNS DataArrayInt* &conn, DataArrayInt* &connIndex, const std::vector& familiesToKeep); - ParaMEDMEM::DataArrayDouble *buildArrayFromRawData(const std::list& fieldPerType); + ParaMEDMEM::DataArrayDouble *buildArrayFromRawData(const std::list& fieldPerType, + const std::vector& infos); int buildMEDSubConnectivityOfOneTypesPolyg(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, std::vector& conn4MEDFile, std::vector& connIndex4MEDFile, std::vector& fam4MEDFile); int buildMEDSubConnectivityOfOneTypesPolyh(const DataArrayInt *conn, const DataArrayInt *connIndex, const DataArrayInt *families, std::vector& conn4MEDFile, @@ -170,16 +175,15 @@ namespace MEDLoaderNS void appendNodeProfileField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds); void appendCellProfileField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIds); void prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIds, std::list& split); + void fillGaussDataOnField(const char *fileName, const std::list& data, MEDCouplingFieldDouble *f); void writeUMeshDirectly(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh, const DataArrayInt *families, bool forceFromScratch); void writeUMeshesDirectly(const char *fileName, const char *meshName, const std::vector& meshes, bool forceFromScratch); void writeFieldAndMeshDirectly(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch); void writeFieldTryingToFitExistingMesh(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f); } -const char WHITE_SPACES[]=" \n"; - /*! - * This method set the epsilon value used for node comparison when trying to buid a profile for a field on node/cell on an already written mesh. + * This method sets the epsilon value used for node comparison when trying to buid a profile for a field on node/cell on an already written mesh. */ void MEDLoader::setEpsilonForNodeComp(double val) { @@ -187,13 +191,22 @@ void MEDLoader::setEpsilonForNodeComp(double val) } /*! - * This method set the policy comparison when trying to fit the already written mesh on a field. The semantic of the policy is specified in MEDCouplingUMesh::zipConnectivityTraducer. + * This method sets the policy comparison when trying to fit the already written mesh on a field. The semantic of the policy is specified in MEDCouplingUMesh::zipConnectivityTraducer. */ void MEDLoader::setCompPolicyForCell(int val) { _COMP_FOR_CELL=val; } +/*! + * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file. + * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown. + */ +void MEDLoader::setTooLongStrPolicy(int val) +{ + _TOO_LONG_STR=val; +} + /*! * @param lgth is the size of fam tab. For classical types conn is size of 'lgth'*number_of_nodes_in_type. * @param index is optionnal only for polys. Set it to 0 if it is not the case. @@ -224,10 +237,13 @@ void MEDLoader::MEDConnOfOneElemType::releaseArray() delete [] _global; } -MEDLoader::MEDFieldDoublePerCellType::MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple, const int *cellIdPerType):_ntuple(ntuple),_ncomp(ncomp),_values(values),_type(type) +MEDLoader::MEDFieldDoublePerCellType::MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple, + const int *cellIdPerType, const char *locName):_ntuple(ntuple),_ncomp(ncomp),_values(values),_type(type) { if(cellIdPerType) _cell_id_per_type.insert(_cell_id_per_type.end(),cellIdPerType,cellIdPerType+ntuple); + if(locName) + _loc_name=locName; } void MEDLoader::MEDFieldDoublePerCellType::releaseArray() @@ -235,21 +251,6 @@ void MEDLoader::MEDFieldDoublePerCellType::releaseArray() delete [] _values; } - -std::string MEDLoaderNS::buildStringFromFortran(const char *expr, int lgth) -{ - std::string ret(expr,lgth); - std::string whiteSpaces(WHITE_SPACES); - std::size_t lgthReal=strlen(ret.c_str()); - std::string ret2=ret.substr(0,lgthReal); - std::size_t found=ret2.find_last_not_of(whiteSpaces); - if (found!=std::string::npos) - ret2.erase(found+1); - else - ret2.clear();//ret is all whitespace - return ret2; -} - std::vector MEDLoaderNS::getMeshNamesFid(med_idt fid) { med_maillage type_maillage; @@ -261,12 +262,38 @@ std::vector MEDLoaderNS::getMeshNamesFid(med_idt fid) for(int i=0;i& data, MEDCouplingFieldDouble *f) +{ + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + char locName[MED_TAILLE_NOM+1]; + int nloc=MEDnGauss(fid); + med_geometrie_element typeGeo; + for(std::list::const_iterator iter=data.begin();iter!=data.end();iter++) + { + const std::string& loc=(*iter).getLocName(); + int idLoc=1; + int nbOfGaussPt=-1; + for(;idLoc<=nloc;idLoc++) + { + MEDgaussInfo(fid,idLoc,locName,&typeGeo,&nbOfGaussPt); + if(loc==locName) + break; + } + int dim=(int)INTERP_KERNEL::CellModel::getCellModel((*iter).getType()).getDimension(); + int nbPtPerCell=(int)INTERP_KERNEL::CellModel::getCellModel((*iter).getType()).getNumberOfNodes(); + std::vector refcoo(nbPtPerCell*dim),gscoo(nbOfGaussPt*dim),w(nbOfGaussPt); + MEDgaussLire(fid,(med_float *)&refcoo[0],(med_float *)&gscoo[0],(med_float *)&w[0],MED_FULL_INTERLACE,(char *)(*iter).getLocName().c_str()); + f->setGaussLocalizationOnType((*iter).getType(),refcoo,gscoo,w); + } + MEDfermer(fid); +} + std::vector MEDLoader::GetMeshNames(const char *fileName) { med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); @@ -291,7 +318,7 @@ std::vector MEDLoader::GetMeshFamilyNames(const char *fileName, con char *attdes=new char[MED_TAILLE_DESC*natt+1]; char *gro=new char[MED_TAILLE_LNOM*ngro+1]; MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro); - std::string cur=MEDLoaderNS::buildStringFromFortran(nomfam,sizeof(nomfam)); + std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam)); ret[i]=cur; delete [] attdes; delete [] gro; @@ -320,7 +347,7 @@ std::vector MEDLoader::GetMeshGroupsNames(const char *fileName, con MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro); for(int j=0;j MEDLoader::GetCellFieldNamesOnMesh(const char *fileName char *comp=new char[ncomp*MED_TAILLE_PNOM+1]; char *unit=new char[ncomp*MED_TAILLE_PNOM+1]; MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp); - std::string curFieldName=MEDLoaderNS::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1); + std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1); delete [] comp; delete [] unit; bool found=false; @@ -367,7 +394,7 @@ std::vector MEDLoader::GetCellFieldNamesOnMesh(const char *fileName if(nbPdt>0) { MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa); - std::string curMeshName=MEDLoaderNS::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); + std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); if(curMeshName==meshName) { found=true; @@ -404,7 +431,7 @@ std::vector MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName char *comp=new char[ncomp*MED_TAILLE_PNOM+1]; char *unit=new char[ncomp*MED_TAILLE_PNOM+1]; MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp); - std::string curFieldName=MEDLoaderNS::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1); + std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1); delete [] comp; delete [] unit; bool found=false; @@ -412,7 +439,7 @@ std::vector MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName if(nbPdt>0) { MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa); - std::string curMeshName=MEDLoaderNS::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); + std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1); if(curMeshName==meshName) { found=true; @@ -462,7 +489,7 @@ std::vector< std::pair > MEDLoader::GetCellFieldIterations(const char * char *comp=new char[ncomp*MED_TAILLE_PNOM+1]; char *unit=new char[ncomp*MED_TAILLE_PNOM+1]; MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp); - std::string curFieldName=MEDLoaderNS::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1); + std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1); delete [] comp; delete [] unit; if(curFieldName==fieldName) @@ -513,7 +540,7 @@ std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char * char *comp=new char[ncomp*MED_TAILLE_PNOM+1]; char *unit=new char[ncomp*MED_TAILLE_PNOM+1]; MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp); - std::string curFieldName=MEDLoaderNS::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1); + std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1); delete [] comp; delete [] unit; if(curFieldName==fieldName) @@ -537,8 +564,10 @@ std::vector< std::pair > MEDLoader::GetNodeFieldIterations(const char * return ret; } -void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName, std::list& field, - int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField, double& time) +void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName, + int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField, + std::list& field, + double& time, std::vector& infos) { time=0.; med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); @@ -557,14 +586,23 @@ void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char tabEnt[ON_NODES]=MED_NOEUD; tabType[ON_NODES]=typmainoeud; tabTypeLgth[ON_NODES]=1; + tabEnt[ON_GAUSS_PT]=MED_MAILLE; + tabType[ON_GAUSS_PT]=typmai; + tabTypeLgth[ON_GAUSS_PT]=MED_NBR_GEOMETRIE_MAILLE+2; + tabEnt[ON_GAUSS_NE]=MED_MAILLE; + tabType[ON_GAUSS_NE]=typmai; + tabTypeLgth[ON_GAUSS_NE]=MED_NBR_GEOMETRIE_MAILLE+2; // for(int i=0;i MEDLoaderNS::getIdsFromFamilies(const char *fileName, const cha char *attdes=new char[MED_TAILLE_DESC*natt+1]; char *gro=new char[MED_TAILLE_LNOM*ngro+1]; MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro); - std::string cur=buildStringFromFortran(nomfam,sizeof(nomfam)); + std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam)); if(std::find(fams.begin(),fams.end(),cur)!=fams.end()) ret.push_back(numfam); delete [] attdes; @@ -657,10 +706,10 @@ std::vector MEDLoaderNS::getIdsFromGroups(const char *fileName, const char char *attdes=new char[MED_TAILLE_DESC*natt+1]; char *gro=new char[MED_TAILLE_LNOM*ngro+1]; MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro); - std::string cur=buildStringFromFortran(nomfam,sizeof(nomfam)); + std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam)); for(int j=0;j& conn) +void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list& conn) { char nommaa[MED_TAILLE_NOM+1]; char maillage_description[MED_TAILLE_DESC+1]; - char comp[3*MED_TAILLE_PNOM+1]; - char unit[3*MED_TAILLE_PNOM+1]; med_maillage type_maillage; med_int Mdim; MEDmaaInfo(fid,meshId,nommaa,&Mdim,&type_maillage,maillage_description); - spaceDim=(int)Mdim; - nCoords=MEDnEntMaa(fid,nommaa,MED_COOR,MED_NOEUD,(med_geometrie_element)0,(med_connectivite)0); - coords=new double[nCoords*spaceDim]; + int spaceDim=(int)Mdim; + int nCoords=MEDnEntMaa(fid,nommaa,MED_COOR,MED_NOEUD,(med_geometrie_element)0,(med_connectivite)0); + coords=DataArrayDouble::New(); + coords->alloc(nCoords,spaceDim); + double *coordsPtr=coords->getPointer(); med_repere repere; - MEDcoordLire(fid,nommaa,Mdim,coords,MED_FULL_INTERLACE,MED_ALL,NULL,0,&repere,comp,unit); + char *comp=MEDLoaderBase::buildEmptyString(Mdim*MED_TAILLE_PNOM); + char *unit=MEDLoaderBase::buildEmptyString(Mdim*MED_TAILLE_PNOM); + MEDcoordLire(fid,nommaa,Mdim,coordsPtr,MED_FULL_INTERLACE,MED_ALL,NULL,0,&repere,comp,unit); + for(int i=0;isetInfoOnComponent(i,info.c_str()); + } + delete [] comp; + delete [] unit; med_booleen inoele, inuele; for(int i=0;i& fieldPerType) +ParaMEDMEM::DataArrayDouble *MEDLoaderNS::buildArrayFromRawData(const std::list& fieldPerType, + const std::vector& infos) { ParaMEDMEM::DataArrayDouble *ret=ParaMEDMEM::DataArrayDouble::New(); int totalNbOfTuple=std::accumulate(fieldPerType.begin(),fieldPerType.end(),0,FieldPerTypeAccumulator()); @@ -924,6 +984,8 @@ ParaMEDMEM::DataArrayDouble *MEDLoaderNS::buildArrayFromRawData(const std::list< double *ptr=new double[nbOfComp*totalNbOfTuple]; ret->useArray(ptr,true,ParaMEDMEM::CPP_DEALLOC,totalNbOfTuple,nbOfComp); std::for_each(fieldPerType.begin(),fieldPerType.end(),FieldPerTypeCopier(ptr)); + for(int i=0;isetInfoOnComponent(i,infos[i].c_str()); return ret; } @@ -1193,11 +1255,11 @@ MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); std::string trueMeshName; med_int mid=getIdFromMeshName(fid,meshName,trueMeshName); - double *coords; + DataArrayDouble *coords=0; int nCoords; int spaceDim; std::list conn; - readUMeshDataInMedFile(fid,mid,coords,nCoords,spaceDim,conn); + readUMeshDataInMedFile(fid,mid,coords,conn); meshDimExtract=MEDLoaderNS::calculateHighestMeshDim(conn); meshDimExtract=meshDimExtract+meshDimRelToMax; MEDLoaderNS::keepSpecifiedMeshDim(conn,meshDimExtract); @@ -1208,10 +1270,8 @@ MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const ret->setName(trueMeshName.c_str()); ret->setMeshDimension(meshDimExtract); // - DataArrayDouble *coordsArr=DataArrayDouble::New(); - coordsArr->useArray(coords,true,ParaMEDMEM::CPP_DEALLOC,nCoords,spaceDim); - ret->setCoords(coordsArr); - coordsArr->decrRef(); + ret->setCoords(coords); + coords->decrRef(); // DataArrayInt *connArr,*connIndexArr; tradMEDFileCoreFrmt2MEDCouplingUMesh(conn,connArr,connIndexArr,ids); @@ -1230,15 +1290,16 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char { std::list fieldPerCellType; double time; - readFieldDoubleDataInMedFile(fileName,meshName,fieldName,fieldPerCellType,iteration,order,typeOfOutField,time); + std::vector infos; + readFieldDoubleDataInMedFile(fileName,meshName,fieldName,iteration,order,typeOfOutField,fieldPerCellType,time,infos); std::vector familiesToKeep; std::vector typesToKeep; - if(typeOfOutField==ON_CELLS) + if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE) for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) typesToKeep.push_back((*iter).getType()); unsigned meshDim; ParaMEDMEM::MEDCouplingUMesh *mesh=readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim); - if(typeOfOutField==ON_CELLS) + if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE) MEDLoaderNS::keepSpecifiedMeshDim(fieldPerCellType,meshDim); //for profiles for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) @@ -1259,9 +1320,13 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char ret->setTime(time,iteration,order); ret->setMesh(mesh); mesh->decrRef(); - ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType); + ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType,infos); ret->setArray(arr); arr->decrRef(); + // + if(typeOfOutField==ON_GAUSS_PT) + fillGaussDataOnField(fileName,fieldPerCellType,ret); + // releaseMEDFileCoreFrmt(fieldPerCellType); return ret; } @@ -1318,8 +1383,12 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDouble(ParaMEDMEM::TypeO return ReadFieldDoubleCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order); case ON_NODES: return ReadFieldDoubleNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order); + case ON_GAUSS_PT: + return ReadFieldDoubleGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order); + case ON_GAUSS_NE: + return ReadFieldDoubleGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order); default: - throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !"); + throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !"); } } @@ -1333,6 +1402,16 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleNode(const char *f return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_NODES); } +ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) +{ + return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_PT); +} + +ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) +{ + return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_NE); +} + void MEDLoaderNS::writeUMeshDirectly(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh, const DataArrayInt *families, bool forceFromScratch) { med_idt fid=MEDouvrir((char *)fileName,forceFromScratch?MED_CREATION:MED_LECTURE_ECRITURE); @@ -1344,10 +1423,11 @@ void MEDLoaderNS::writeUMeshDirectly(const char *fileName, ParaMEDMEM::MEDCoupli } char *maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); char *desc=MEDLoaderBase::buildEmptyString(MED_TAILLE_DESC); - strcpy(maa,meshName.c_str()); - strcpy(desc,meshName.c_str()); - MEDmaaCr(fid,maa,mesh->getSpaceDimension(),MED_NON_STRUCTURE,desc); - MEDdimEspaceCr(fid,maa,mesh->getSpaceDimension()); + MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_TAILLE_NOM,maa,MEDLoader::_TOO_LONG_STR); + MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_TAILLE_DESC,desc,MEDLoader::_TOO_LONG_STR); + const int spaceDim=mesh->getSpaceDimension(); + MEDmaaCr(fid,maa,spaceDim,MED_NON_STRUCTURE,desc); + MEDdimEspaceCr(fid,maa,spaceDim); std::set allTypes(mesh->getAllTypes()); DataArrayInt *conn=mesh->getNodalConnectivity(); DataArrayInt *connIndex=mesh->getNodalConnectivityIndex(); @@ -1384,15 +1464,19 @@ void MEDLoaderNS::writeUMeshDirectly(const char *fileName, ParaMEDMEM::MEDCoupli } MEDfamCr(fid,maa,familyName,0,0,0,0,0,0,0); DataArrayDouble *arr=mesh->getCoords(); - char comp[2*MED_TAILLE_PNOM+1]; - char unit[2*MED_TAILLE_PNOM+1]; - std::fill(comp,comp+2*MED_TAILLE_PNOM,' '); - comp[2*MED_TAILLE_PNOM]='\0'; - char *work=comp; - for(int i=0;igetSpaceDimension();i++,work+=3) - *work='X'+i; - std::fill(unit,unit+2*MED_TAILLE_PNOM+1,'\0'); + char *comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); + char *unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM); + for(int i=0;igetInfoOnComponent(i); + std::string c,u; + MEDLoaderBase::splitIntoNameAndUnit(info,c,u); + MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + } MEDcoordEcr(fid,maa,mesh->getSpaceDimension(),arr->getPointer(),MED_FULL_INTERLACE,mesh->getNumberOfNodes(),MED_CART,comp,unit); + delete [] comp; + delete [] unit; delete [] maa; delete [] desc; MEDfermer(fid); @@ -1406,7 +1490,7 @@ void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const char *meshNam { std::string meshNameCpp(meshName); char *maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - strcpy(maa,meshName); + MEDLoaderBase::safeStrCpy(meshName,MED_TAILLE_NOM,maa,MEDLoader::_TOO_LONG_STR); if(meshName=="") throw INTERP_KERNEL::Exception("writeUMeshesDirectly : Invalid meshName : Must be different from \"\" !"); //MEDnumEcr(fid,maa,num,nele,_type_ent,typ_geo); @@ -1440,10 +1524,10 @@ void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const char *meshNam int ngro=gidsOfFamilies[fid].size(); char *groName=MEDLoaderBase::buildEmptyString(MED_TAILLE_LNOM*ngro); for(int i=0;igetName()); + MEDLoaderBase::safeStrCpy(meshes[gidsOfFamilies[fid][i]]->getName(),MED_TAILLE_LNOM-1,groName+i*MED_TAILLE_LNOM,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_LNOM-1 to avoid to write '\0' on next compo std::ostringstream oss; oss << "Family_" << *it; char *famName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - strcpy(famName,oss.str().c_str()); + MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,famName,MEDLoader::_TOO_LONG_STR); MEDfamCr(fid2,maa,famName,*it,0,0,0,0,groName,ngro); delete [] famName; delete [] groName; @@ -1475,7 +1559,6 @@ void MEDLoaderNS::appendNodeProfileField(const char *fileName, ParaMEDMEM::MEDCo */ void MEDLoaderNS::appendCellProfileField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIdsPerType) { - //not implemented yet. med_int numdt,numo; med_float dt; int nbComp=f->getNumberOfComponents(); @@ -1487,10 +1570,10 @@ void MEDLoaderNS::appendCellProfileField(const char *fileName, ParaMEDMEM::MEDCo for(std::list::const_iterator iter=split.begin();iter!=split.end();iter++) { char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - strcpy(nommaa,f->getMesh()->getName()); + MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_TAILLE_NOM,nommaa,MEDLoader::_TOO_LONG_STR); char *profileName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++; - strcpy(profileName,oss.str().c_str()); + MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,profileName,MEDLoader::_TOO_LONG_STR); const std::vector& ids=(*iter).getCellIdPerType(); int *profile=new int [ids.size()]; std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus(),1)); @@ -1515,8 +1598,15 @@ med_idt MEDLoaderNS::appendFieldSimpleAtt(const char *fileName, ParaMEDMEM::MEDC int nbComp=f->getNumberOfComponents(); char *comp=MEDLoaderBase::buildEmptyString(nbComp*MED_TAILLE_PNOM); char *unit=MEDLoaderBase::buildEmptyString(nbComp*MED_TAILLE_PNOM); + for(int i=0;igetArray()->getInfoOnComponent(i); + std::string c,u; + MEDLoaderBase::splitIntoNameAndUnit(info,c,u); + MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR); + MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR); + } MEDchampCr(fid,(char *)f->getName(),MED_FLOAT64,comp,unit,nbComp); - ParaMEDMEM::TypeOfTimeDiscretization td=f->getTimeDiscretization(); if(td==ParaMEDMEM::NO_TIME) { @@ -1541,6 +1631,8 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, ParaMEDMEM::MEDCoupl int nbComp=f->getNumberOfComponents(); med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); const double *pt=f->getArray()->getConstPointer(); + char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_TAILLE_NOM,nommaa,MEDLoader::_TOO_LONG_STR); switch(f->getTypeOfField()) { case ParaMEDMEM::ON_CELLS: @@ -1549,12 +1641,9 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, ParaMEDMEM::MEDCoupl prepareCellFieldDoubleForWriting(f,0,split); for(std::list::const_iterator iter=split.begin();iter!=split.end();iter++) { - char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - strcpy(nommaa,f->getMesh()->getName()); MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,(*iter).getNbOfTuple(), (char *)MED_NOGAUSS,MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_MAILLE, typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo); - delete [] nommaa; pt+=(*iter).getNbOfTuple()*nbComp; } break; @@ -1562,16 +1651,54 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, ParaMEDMEM::MEDCoupl case ParaMEDMEM::ON_NODES: { int nbOfTuples=f->getArray()->getNumberOfTuples(); - char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); - strcpy(nommaa,f->getMesh()->getName()); MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfTuples,(char *)MED_NOGAUSS, MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_NOEUD,MED_NONE,numdt,(char *)"",dt,numo); - delete [] nommaa; + break; + } + case ParaMEDMEM::ON_GAUSS_PT: + { + std::list split; + prepareCellFieldDoubleForWriting(f,0,split); + int idGp=0; + for(std::list::const_iterator iter=split.begin();iter!=split.end();iter++) + { + char *nomGauss=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + std::ostringstream oss; oss << "GP_" << f->getName() << idGp++; + MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,nomGauss,MEDLoader::_TOO_LONG_STR); + int id=f->getGaussLocalizationIdOfOneType((*iter).getType()); + const MEDCouplingGaussLocalization& gl=f->getGaussLocalization(id); + MEDgaussEcr(fid,typmai3[(int)(*iter).getType()],(med_float*)&gl.getRefCoords()[0],MED_FULL_INTERLACE,gl.getNumberOfGaussPt(), + (med_float*)&gl.getGaussCoords()[0], + (med_float*)&gl.getWeights()[0],nomGauss); + int nbOfValues=gl.getNumberOfGaussPt()*f->getMesh()->getNumberOfCellsWithType((*iter).getType()); + MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfValues, + nomGauss,MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_MAILLE, + typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo); + pt+=nbOfValues*nbComp; + delete [] nomGauss; + } + break; + } + case ParaMEDMEM::ON_GAUSS_NE: + { + std::list split; + prepareCellFieldDoubleForWriting(f,0,split); + int idGp=0; + for(std::list::const_iterator iter=split.begin();iter!=split.end();iter++) + { + int nbPtPerCell=(int)INTERP_KERNEL::CellModel::getCellModel((*iter).getType()).getNumberOfNodes(); + int nbOfValues=nbPtPerCell*f->getMesh()->getNumberOfCellsWithType((*iter).getType()); + MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfValues, + (char *)MED_GAUSS_ELNO,MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_MAILLE, + typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo); + pt+=nbOfValues*nbComp; + } break; } default: throw INTERP_KERNEL::Exception("Not managed this type of FIELD !"); } + delete [] nommaa; MEDfermer(fid); } @@ -1598,10 +1725,10 @@ void MEDLoaderNS::prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCoupling curType=(INTERP_KERNEL::NormalizedCellType)conn[*pt]; const int *pt2=std::find_if(pt+1,connI+nbOfCells,ConnReaderML(conn,(int)curType)); if(!cellIdsPerType) - split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,0)); + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,0,0)); else { - split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,wCellIdsPT)); + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,wCellIdsPT,0)); wCellIdsPT+=std::distance(pt,pt2); } pt=pt2; diff --git a/src/MEDLoader/MEDLoader.hxx b/src/MEDLoader/MEDLoader.hxx index 83dc10ecb..6b7dafd44 100644 --- a/src/MEDLoader/MEDLoader.hxx +++ b/src/MEDLoader/MEDLoader.hxx @@ -63,24 +63,27 @@ class MEDLOADER_EXPORT MEDLoader class MEDFieldDoublePerCellType { public: - MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple, const int *cellIdPerType); + MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple, const int *cellIdPerType, const char *locName); INTERP_KERNEL::NormalizedCellType getType() const { return _type; } int getNbComp() const { return _ncomp; } int getNbOfTuple() const { return _ntuple; } int getNbOfValues() const { return _ncomp*_ntuple; } double *getArray() const { return _values; } + const std::string& getLocName() const { return _loc_name; } const std::vector& getCellIdPerType() const { return _cell_id_per_type; } void releaseArray(); private: int _ntuple; int _ncomp; double *_values; + std::string _loc_name; std::vector _cell_id_per_type; INTERP_KERNEL::NormalizedCellType _type; }; // static void setEpsilonForNodeComp(double val); static void setCompPolicyForCell(int val); + static void setTooLongStrPolicy(int val); static std::vector GetMeshNames(const char *fileName); static std::vector GetMeshGroupsNames(const char *fileName, const char *meshName); static std::vector GetMeshFamilyNames(const char *fileName, const char *meshName); @@ -97,6 +100,8 @@ class MEDLOADER_EXPORT MEDLoader static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDouble(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); + static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order); static void WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch); static void WriteUMeshes(const char *fileName, const char *meshName, const std::vector& meshes, bool writeFromScratch); static void WriteField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch); @@ -106,6 +111,7 @@ class MEDLOADER_EXPORT MEDLoader public: static double _EPS_FOR_NODE_COMP; static int _COMP_FOR_CELL; + static int _TOO_LONG_STR; }; #endif diff --git a/src/MEDLoader/MEDLoaderBase.cxx b/src/MEDLoader/MEDLoaderBase.cxx index 173ca502a..69b679eab 100644 --- a/src/MEDLoader/MEDLoaderBase.cxx +++ b/src/MEDLoader/MEDLoaderBase.cxx @@ -20,7 +20,12 @@ #include "MEDLoaderBase.hxx" #include "InterpKernelException.hxx" +#include #include +#include +#include + +const char MEDLoaderBase::WHITE_SPACES[]=" \n"; int MEDLoaderBase::getStatusOfFile(const char *fileName) { @@ -67,3 +72,122 @@ char *MEDLoaderBase::buildEmptyString(int lgth) ret[lgth]='\0'; return ret; } + +std::string MEDLoaderBase::buildUnionUnit(const char *name, const char *unit) +{ + std::string ret(name); + if(unit[0]=='\0') + return ret; + ret+=" ("; + ret+=unit; + ret+=")"; + return ret; +} + +void MEDLoaderBase::splitIntoNameAndUnit(const std::string& s, std::string& name, std::string& unit) +{ + std::string::size_type f1=s.find_first_of('('); + std::string::size_type f2=s.find_last_of(')'); + if(f1!=std::string::npos && f2!=std::string::npos) + { + if(f1maxLgth) + { + if(behaviour==0 || behaviour>1) + { + std::ostringstream oss; oss << "A string : \"" << src << "\" has been detected to be too long for MED File ( > " << maxLgth << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + else if(behaviour==1) + { + std::string s=zipString(src,maxLgth); + std::cerr << "A string : \"" << src << "\" has been detected to be too long for MED File ( > " << maxLgth << ") : "; + std::cerr << "zipping to : " << s << "\n"; + strcpy(dest,s.c_str()); + return ; + } + } + strcpy(dest,src); +} + +std::string MEDLoaderBase::buildStringFromFortran(const char *expr, int lgth) +{ + std::string ret(expr,lgth); + std::string whiteSpaces(WHITE_SPACES); + std::size_t lgthReal=strlen(ret.c_str()); + std::string ret2=ret.substr(0,lgthReal); + std::size_t found=ret2.find_last_not_of(whiteSpaces); + if (found!=std::string::npos) + ret2.erase(found+1); + else + ret2.clear();//ret is all whitespace + return ret2; +} + +/*! + * This method given the target size to respect 'sizeToRespect' tries to reduce size of 'src' string. + * This method uses several soft methods to do its job. But if it fails a simple cut of string will be performed. + */ +std::string MEDLoaderBase::zipString(const char *src, int sizeToRespect) +{ + std::string s(src); + strip(s); + if(s.length()<=sizeToRespect) + return s; + s=src; + zipEqualConsChar(s,3); + if(s.length()<=sizeToRespect) + return s; + s=src; + zipEqualConsChar(s,2); + if(s.length()<=sizeToRespect) + return s; + s=src; + return s.substr(0,sizeToRespect); +} + +/*! + * This method see if there is in 's' more than 'minConsSmChar' consecutive same character. + * If yes, the group will be zipped using only one character for this group. + * If no such group is found, s remains unchanged. + */ +void MEDLoaderBase::zipEqualConsChar(std::string& s, int minConsSmChar) +{ + for(std::string::iterator it=s.begin();it!=s.end();it++) + { + char tmp=*it; + int sz=1; + for(std::string::iterator it2=it+1;it2!=s.end() && *it2==tmp;it2++) + sz++; + if(sz>=minConsSmChar) + s.erase(it+1,it+sz); + } +} + diff --git a/src/MEDLoader/MEDLoaderBase.hxx b/src/MEDLoader/MEDLoaderBase.hxx index 1520a3ae2..896b65059 100644 --- a/src/MEDLoader/MEDLoaderBase.hxx +++ b/src/MEDLoader/MEDLoaderBase.hxx @@ -20,17 +20,29 @@ #ifndef __MEDLOADERBASE_HXX__ #define __MEDLOADERBASE_HXX__ +#include "InterpKernelException.hxx" + +#include + class MEDLoaderBase { public: static int getStatusOfFile(const char *fileName); static char *buildEmptyString(int lgth); + static std::string buildUnionUnit(const char *name, const char *unit); + static void splitIntoNameAndUnit(const std::string& s, std::string& name, std::string& unit); + static void strip(std::string& s); + static void safeStrCpy(const char *src, int maxLgth, char *dest, int behaviour) throw(INTERP_KERNEL::Exception); + static std::string buildStringFromFortran(const char *expr, int lgth); + static void zipEqualConsChar(std::string& s, int minConsSmChar); + static std::string zipString(const char *src, int sizeToRespect); public: static const int EXIST_RW=0; static const int NOT_EXIST=1; static const int EXIST_RDONLY=2; static const int EXIST_WRONLY=3; static const int DIR_LOCKED=4; + static const char WHITE_SPACES[]; }; #endif diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx index 341e52cee..170b36063 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.cxx +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -19,6 +19,7 @@ #include "MEDLoaderTest.hxx" #include "MEDLoader.hxx" +#include "MEDLoaderBase.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingMemArray.hxx" @@ -366,6 +367,35 @@ void MEDLoaderTest::testFieldProfilRW1() mesh2->decrRef(); } +void MEDLoaderTest::testFieldGaussRW1() +{ + const char fileName[]="file13.med"; + MEDCouplingFieldDouble *f1=buildVecFieldOnGauss_1(); + MEDLoader::WriteField(fileName,f1,true); + MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldDouble(ON_GAUSS_PT,fileName,f1->getMesh()->getName(),0,f1->getName(),1,5); + CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); + f2->decrRef(); + f1->decrRef(); +} + +void MEDLoaderTest::testFieldGaussNERW1() +{ + const char fileName[]="file14.med"; + MEDCouplingFieldDouble *f1=buildVecFieldOnGaussNE_1(); + MEDLoader::WriteField(fileName,f1,true); + MEDCouplingFieldDouble *f2=MEDLoader::ReadFieldDouble(ON_GAUSS_NE,fileName,f1->getMesh()->getName(),0,f1->getName(),1,5); + CPPUNIT_ASSERT(f1->isEqual(f2,1e-12,1e-12)); + f2->decrRef(); + f1->decrRef(); +} + +void MEDLoaderTest::testLittleStrings1() +{ + std::string s("azeeeerrrtty"); + MEDLoaderBase::zipEqualConsChar(s,3); + CPPUNIT_ASSERT(s=="azertty"); +} + MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1() { double coords[6]={ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 }; @@ -381,6 +411,7 @@ MEDCouplingUMesh *MEDLoaderTest::build1DMesh_1() mesh->finishInsertingCells(); DataArrayDouble *myCoords=DataArrayDouble::New(); myCoords->alloc(6,1); + myCoords->setInfoOnComponent(0,"tototototototot (m*m*m*m*m*m*m*m)"); std::copy(coords,coords+6,myCoords->getPointer()); mesh->setCoords(myCoords); myCoords->decrRef(); @@ -425,6 +456,32 @@ MEDCouplingUMesh *MEDLoaderTest::build2DMesh_1() targetMesh->finishInsertingCells(); DataArrayDouble *myCoords=DataArrayDouble::New(); myCoords->alloc(12,2); + myCoords->setInfoOnComponent(0,"tototototototot (m)"); + myCoords->setInfoOnComponent(1,"energie (kW)"); + std::copy(targetCoords,targetCoords+24,myCoords->getPointer()); + targetMesh->setCoords(myCoords); + myCoords->decrRef(); + return targetMesh; +} + +MEDCouplingUMesh *MEDLoaderTest::build2DMesh_2() +{ + double targetCoords[24]={-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 }; + int targetConn[24]={1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4}; + MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New(); + targetMesh->setMeshDimension(2); + targetMesh->allocateCells(5); + targetMesh->setName("2DMesh_2"); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+3); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI6,6,targetConn+6); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+12); + targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+16); + targetMesh->finishInsertingCells(); + DataArrayDouble *myCoords=DataArrayDouble::New(); + myCoords->alloc(12,2); + myCoords->setInfoOnComponent(0,"toto (m)"); + myCoords->setInfoOnComponent(1,"energie (kW)"); std::copy(targetCoords,targetCoords+24,myCoords->getPointer()); targetMesh->setCoords(myCoords); myCoords->decrRef(); @@ -448,6 +505,8 @@ MEDCouplingUMesh *MEDLoaderTest::build3DSurfMesh_1() targetMesh->finishInsertingCells(); DataArrayDouble *myCoords=DataArrayDouble::New(); myCoords->alloc(12,3); + myCoords->setInfoOnComponent(0,"toto (m)"); + myCoords->setInfoOnComponent(2,"ff (km)");//component 1 is not set for test std::copy(targetCoords,targetCoords+36,myCoords->getPointer()); targetMesh->setCoords(myCoords); myCoords->decrRef(); @@ -514,6 +573,9 @@ MEDCouplingUMesh *MEDLoaderTest::build3DMesh_1() ret->finishInsertingCells(); DataArrayDouble *myCoords=DataArrayDouble::New(); myCoords->alloc(60,3); + myCoords->setInfoOnComponent(0,"titi (m)"); + myCoords->setInfoOnComponent(1,"density power (MW/m^3)"); + myCoords->setInfoOnComponent(2,"t (kW)"); std::copy(coords,coords+180,myCoords->getPointer()); ret->setCoords(myCoords); myCoords->decrRef(); @@ -529,6 +591,9 @@ MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnCells_1() f1->setMesh(mesh); DataArrayDouble *array=DataArrayDouble::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(); double *tmp=array->getPointer(); @@ -550,6 +615,9 @@ MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnNodes_1() DataArrayDouble *array=DataArrayDouble::New(); array->alloc(nbOfNodes,3); f1->setArray(array); + array->setInfoOnComponent(0,"power (MW/m^3)"); + array->setInfoOnComponent(1,"density (g/cm^3)"); + array->setInfoOnComponent(2,"temperature (K)"); array->decrRef(); double *tmp=array->getPointer(); const double arr1[36]={ @@ -562,3 +630,65 @@ MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnNodes_1() mesh->decrRef(); return f1; } + +MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGauss_1() +{ + const double _a=0.446948490915965; + const double _b=0.091576213509771; + const double _p1=0.11169079483905; + const double _p2=0.0549758718227661; + const double refCoo1[6]={ 0.,0., 1.,0., 0.,1. }; + const double gsCoo1[12]={ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b, + 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 }; + const double wg1[6]={ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 }; + std::vector _refCoo1(refCoo1,refCoo1+6); + std::vector _gsCoo1(gsCoo1,gsCoo1+12); + std::vector _wg1(wg1,wg1+6); + MEDCouplingUMesh *m=build2DMesh_2(); + MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_PT,ONE_TIME); + f->setTime(3.14,1,5); + f->setMesh(m); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1); + const double refCoo2[12]={-1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 }; + std::vector _refCoo2(refCoo2,refCoo2+12); + _gsCoo1.resize(6); _wg1.resize(3); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI6,_refCoo2,_gsCoo1,_wg1); + const double refCoo3[8]={ 0.,0., 1.,0., 1.,1., 0.,1. }; + std::vector _refCoo3(refCoo3,refCoo3+8); + _gsCoo1.resize(4); _wg1.resize(2); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo3,_gsCoo1,_wg1); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(19,2); + double *ptr=array->getPointer(); + for(int i=0;i<19*2;i++) + ptr[i]=(double)(i+7); + f->setArray(array); + f->setName("MyFirstFieldOnGaussPoint"); + array->setInfoOnComponent(0,"power (MW/m^3)"); + array->setInfoOnComponent(1,"density"); + array->decrRef(); + f->checkCoherency(); + m->decrRef(); + return f; +} + +MEDCouplingFieldDouble *MEDLoaderTest::buildVecFieldOnGaussNE_1() +{ + MEDCouplingUMesh *m=build2DMesh_2(); + MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_GAUSS_NE,ONE_TIME); + f->setTime(3.14,1,5); + f->setMesh(m); + DataArrayDouble *array=DataArrayDouble::New(); + array->alloc(20,2); + double *ptr=array->getPointer(); + for(int i=0;i<20*2;i++) + ptr[i]=(double)(i+8); + f->setArray(array); + array->setInfoOnComponent(0,"power (W)"); + array->setInfoOnComponent(1,"temperature"); + f->setName("MyFieldOnGaussNE"); + array->decrRef(); + f->checkCoherency(); + m->decrRef(); + return f; +} diff --git a/src/MEDLoader/Test/MEDLoaderTest.hxx b/src/MEDLoader/Test/MEDLoaderTest.hxx index 7ecfdd82d..11cc57d2b 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.hxx +++ b/src/MEDLoader/Test/MEDLoaderTest.hxx @@ -40,6 +40,9 @@ namespace ParaMEDMEM CPPUNIT_TEST( testFieldRW3 ); CPPUNIT_TEST( testMultiMeshRW1 ); CPPUNIT_TEST( testFieldProfilRW1 ); + CPPUNIT_TEST( testFieldGaussRW1 ); + CPPUNIT_TEST( testFieldGaussNERW1 ); + CPPUNIT_TEST( testLittleStrings1 ); CPPUNIT_TEST_SUITE_END(); public: void testMesh1DRW(); @@ -52,14 +55,20 @@ namespace ParaMEDMEM void testFieldRW3(); void testMultiMeshRW1(); void testFieldProfilRW1(); + void testFieldGaussRW1(); + void testFieldGaussNERW1(); + void testLittleStrings1(); private: MEDCouplingUMesh *build1DMesh_1(); MEDCouplingUMesh *build2DCurveMesh_1(); MEDCouplingUMesh *build2DMesh_1(); + MEDCouplingUMesh *build2DMesh_2(); MEDCouplingUMesh *build3DSurfMesh_1(); MEDCouplingUMesh *build3DMesh_1(); MEDCouplingFieldDouble *buildVecFieldOnCells_1(); MEDCouplingFieldDouble *buildVecFieldOnNodes_1(); + MEDCouplingFieldDouble *buildVecFieldOnGauss_1(); + MEDCouplingFieldDouble *buildVecFieldOnGaussNE_1(); }; }