From: ageay Date: Fri, 8 Oct 2010 08:02:30 +0000 (+0000) Subject: Profile on nodes management. X-Git-Tag: V5_1_5~27 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2247535d45f395de8f1ad0c233e96980a269d8b4;p=tools%2Fmedcoupling.git Profile on nodes management. --- diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index b8b61edc9..1b4b88e92 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -1416,6 +1416,7 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char MEDLoaderNS::keepSpecifiedMeshDim(fieldPerCellType,meshDim); //for profiles ParaMEDMEM::MEDCouplingUMesh *newMesh=0; + std::string mName(mesh->getName()); for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) { const std::vector& cellIds=(*iter).getCellIdPerType(); @@ -1424,10 +1425,31 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char std::vector ci(cellIds.size()); std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus(),-1)); ParaMEDMEM::MEDCouplingUMesh *mesh2; - if(newMesh) - mesh2=newMesh->keepSpecifiedCells((*iter).getType(),ci); - else - mesh2=mesh->keepSpecifiedCells((*iter).getType(),ci); + if(typeOfOutField==ON_CELLS) + { + if(newMesh) + mesh2=newMesh->keepSpecifiedCells((*iter).getType(),ci); + else + mesh2=mesh->keepSpecifiedCells((*iter).getType(),ci); + } + else if(typeOfOutField==ON_NODES) + { + DataArrayInt *da=0,*da2=0; + if(newMesh) + { + da=newMesh->getCellIdsFullyIncludedInNodeIds(&ci[0],&ci[ci.size()]); + mesh2=dynamic_cast(newMesh->buildPartAndReduceNodes(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems(),da2)); + } + else + { + da=mesh->getCellIdsFullyIncludedInNodeIds(&ci[0],&ci[ci.size()]); + mesh2=dynamic_cast(mesh->buildPartAndReduceNodes(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems(),da2)); + } + if(da) + da->decrRef(); + if(da2) + da2->decrRef(); + } if(newMesh) newMesh->decrRef(); newMesh=mesh2; @@ -1439,6 +1461,7 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char ret->setTime(time,iteration,order); if(newMesh) { + newMesh->setName(mName.c_str());//retrieving mesh name to avoid renaming due to mesh restriction in case of profile. ret->setMesh(newMesh); newMesh->decrRef(); } @@ -1818,11 +1841,25 @@ void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char */ void MEDLoaderNS::appendNodeProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds) { - //not implemented yet. med_int numdt,numo; med_float dt; - //int nbComp=f->getNumberOfComponents(); + char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_TAILLE_NOM,nommaa,MEDLoader::_TOO_LONG_STR); med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt); + int nbOfNodes=f->getMesh()->getNumberOfNodes(); + const double *pt=f->getArray()->getConstPointer(); + int *profile=new int[nbOfNodes]; + std::ostringstream oss; oss << "Pfln" << f->getName(); + char *profileName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM); + MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,profileName,MEDLoader::_TOO_LONG_STR); + std::transform(thisMeshNodeIds,thisMeshNodeIds+nbOfNodes,profile,std::bind2nd(std::plus(),1)); + MEDprofilEcr(fid,profile,nbOfNodes,profileName); + delete [] profile; + MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfNodes, + (char *)MED_NOGAUSS,MED_ALL,profileName,MED_COMPACT,MED_NOEUD, + MED_NONE,numdt,(char *)"",dt,numo); + delete [] profileName; + delete [] nommaa; MEDfermer(fid); } diff --git a/src/MEDLoader/Test/MEDLoaderTest.cxx b/src/MEDLoader/Test/MEDLoaderTest.cxx index 7c3451419..b5da3bfd5 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.cxx +++ b/src/MEDLoader/Test/MEDLoaderTest.cxx @@ -372,6 +372,50 @@ void MEDLoaderTest::testFieldProfilRW1() mesh2->decrRef(); } +void MEDLoaderTest::testFieldNodeProfilRW1() +{ + const char fileName[]="file19.med"; + const char fileName2[]="file20.med"; + MEDCouplingUMesh *m=build2DMesh_1(); + int nbOfNodes=m->getNumberOfNodes(); + MEDLoader::WriteUMesh(fileName,m,true); + MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME); + f1->setName("VFieldOnNodes"); + f1->setMesh(m); + DataArrayDouble *array=DataArrayDouble::New(); + const double arr1[24]={1.,101.,2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.}; + array->alloc(nbOfNodes,2); + std::copy(arr1,arr1+24,array->getPointer()); + f1->setArray(array); + array->setInfoOnComponent(0,"tyty (mm)"); + array->setInfoOnComponent(1,"uiop (MW)"); + array->decrRef(); + f1->setTime(3.14,2,7); + f1->checkCoherency(); + const int arr2[6]={2,4,5,3,6,7}; + MEDCouplingFieldDouble *f2=f1->buildSubPart(arr2,arr2+6); + ((MEDCouplingMesh *)f2->getMesh())->setName(f1->getMesh()->getName()); + MEDLoader::WriteField(fileName,f2,false);//<- false important for the test + // + MEDCouplingFieldDouble *f3=MEDLoader::ReadFieldNode(fileName,f2->getMesh()->getName(),0,f2->getName(),2,7); + f3->checkCoherency(); + CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12)); + f3->decrRef(); + // + const int arr3[6]={1,3,0,5,2,4}; + f2->renumberNodes(arr3); + MEDLoader::WriteUMesh(fileName2,m,true); + MEDLoader::WriteField(fileName2,f2,false);//<- false important for the test + f3=MEDLoader::ReadFieldNode(fileName,f2->getMesh()->getName(),0,f2->getName(),2,7); + f3->checkCoherency(); + //CPPUNIT_ASSERT(f3->isEqual(f2,1e-12,1e-12));//<- bug + f3->decrRef(); + f2->decrRef(); + // + f1->decrRef(); + m->decrRef(); +} + void MEDLoaderTest::testFieldGaussRW1() { const char fileName[]="file13.med"; @@ -589,7 +633,7 @@ MEDCouplingUMesh *MEDLoaderTest::build2DCurveMesh_1() MEDCouplingUMesh *MEDLoaderTest::build2DMesh_1() { - 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 }; + 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, -0.05,0.95, 0.2,1.2, 0.45,0.95 }; 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); diff --git a/src/MEDLoader/Test/MEDLoaderTest.hxx b/src/MEDLoader/Test/MEDLoaderTest.hxx index fce8a331b..2b508205a 100644 --- a/src/MEDLoader/Test/MEDLoaderTest.hxx +++ b/src/MEDLoader/Test/MEDLoaderTest.hxx @@ -40,6 +40,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testFieldRW3 ); CPPUNIT_TEST( testMultiMeshRW1 ); CPPUNIT_TEST( testFieldProfilRW1 ); + CPPUNIT_TEST( testFieldNodeProfilRW1 ); CPPUNIT_TEST( testFieldGaussRW1 ); CPPUNIT_TEST( testFieldGaussNERW1 ); CPPUNIT_TEST( testLittleStrings1 ); @@ -59,6 +60,7 @@ namespace ParaMEDMEM void testFieldRW3(); void testMultiMeshRW1(); void testFieldProfilRW1(); + void testFieldNodeProfilRW1(); void testFieldGaussRW1(); void testFieldGaussNERW1(); void testLittleStrings1();