1 // Copyright (C) 2007-2023 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDPARTITIONER_Utils.hxx"
22 #include "MEDLoader.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileUtilities.hxx"
25 #include "CellModel.hxx"
26 #include "MEDCouplingUMesh.hxx"
27 #include "MEDCouplingFieldDouble.hxx"
28 #include "InterpKernelException.hxx"
30 #include "InterpKernelAutoPtr.hxx"
39 using namespace MEDPARTITIONER;
41 int MEDPARTITIONER::MyGlobals::_Verbose=0;
42 int MEDPARTITIONER::MyGlobals::_Is0verbose=0;
43 int MEDPARTITIONER::MyGlobals::_Rank=-1;
44 int MEDPARTITIONER::MyGlobals::_World_Size=-1;
45 int MEDPARTITIONER::MyGlobals::_Randomize=0;
46 int MEDPARTITIONER::MyGlobals::_Atomize=0;
47 int MEDPARTITIONER::MyGlobals::_Create_Boundary_Faces=0;
48 int MEDPARTITIONER::MyGlobals::_Create_Joints=0;
49 std::vector<std::string> MEDPARTITIONER::MyGlobals::_File_Names;
50 std::vector<std::string> MEDPARTITIONER::MyGlobals::_Mesh_Names;
51 std::vector<std::string> MEDPARTITIONER::MyGlobals::_Field_Descriptions;
52 std::vector<std::string> MEDPARTITIONER::MyGlobals::_General_Informations;
54 std::string MEDPARTITIONER::Trim(const std::string& s,const std::string& drop)
57 r.erase(r.find_last_not_of(drop)+1);
58 return r.erase(0,r.find_first_not_of(drop));
61 std::string MEDPARTITIONER::IntToStr(const int i)
63 std::ostringstream oss;
68 std::string MEDPARTITIONER::DoubleToStr(const double i)
70 std::ostringstream oss;
75 int MEDPARTITIONER::StrToInt(const std::string& s)
78 std::istringstream iss(s);
83 double MEDPARTITIONER::StrToDouble(const std::string& s)
86 std::istringstream iss(s);
91 bool MEDPARTITIONER::TestArg(const char *arg, const char *argExpected, std::string& argValue)
95 for (i=0; i<strlen(arg); i++)
99 if (arg[i]!=argExpected[i])
102 for (std::size_t j=i+1; j<strlen(arg); j++)
107 std::vector<int> MEDPARTITIONER::CreateRandomSize(const int size)
109 std::vector<int> res(size);
110 for (int i=0; i<size; i++)
112 //cvw TODO or not? srand( (unsigned)time( NULL ) );
113 srand( MyGlobals::_Randomize );
114 for (int i=0; i<size; i++)
125 * randomize a xadj and adjncy, renumbering vertices belong rand. Works only on one processor!!!!
127 void MEDPARTITIONER::RandomizeAdj(int* xadj, int* adjncy, std::vector<int>& ran, std::vector<int>& vx, std::vector<int>& va)
129 if (MyGlobals::_World_Size>1)
131 std::cerr << "MEDPARTITIONER::RandomizeAdj only works on one proc!" << std::endl;
134 std::size_t size=ran.size();
135 std::vector<int> invran(size);
136 for (unsigned int i=0; i<size; i++)
143 for (std::size_t i=0; i<size; i++)
147 int lgj=xadj[ir+1]-ii;
148 for (int j=0; j<lgj; j++)
150 va[jj]=invran[adjncy[ii]];
158 void MEDPARTITIONER::TestRandomize()
160 //int xadj[6]={0,2,5,9,12,13}; //for first debug only
161 //int adjncy[13]={1,4,0,2,4,1,3,4,2,4,4,3,4};
162 int xadj[6]={0,2,5,9,12,13};
163 int adjncy[13]={0,0,1,1,1,2,2,2,2,3,3,3,4};
165 std::vector<int> r=CreateRandomSize(size);
166 std::vector<int> vx,va;
167 RandomizeAdj(&xadj[0],&adjncy[0],r,vx,va);
170 std::string MEDPARTITIONER::ReprVectorOfString(const std::vector<std::string>& vec)
173 return std::string(" NONE\n");
174 std::ostringstream oss;
175 for (std::vector<std::string>::const_iterator i=vec.begin(); i!=vec.end(); ++i)
176 oss << " -> '" << *i << "'" << std::endl;
180 std::string MEDPARTITIONER::ReprVectorOfString(const std::vector<std::string>& vec, const std::string separator)
183 return std::string(" NONE\n");
184 std::ostringstream oss;
185 for (std::vector<std::string>::const_iterator i=vec.begin(); i!=vec.end(); ++i)
186 oss << separator << *i;
190 std::string MEDPARTITIONER::ReprMapOfStringInt(const std::map<std::string,mcIdType>& mymap)
193 return std::string(" NONE\n");
194 std::ostringstream oss;
195 for (std::map<std::string,mcIdType>::const_iterator i=mymap.begin(); i!=mymap.end(); ++i)
196 oss << " -> [" << (*i).first << "]=" << (*i).second << std::endl;
200 std::string MEDPARTITIONER::ReprMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap)
203 return std::string(" NONE\n");
204 std::ostringstream oss;
205 for (std::map< std::string,std::vector<std::string> >::const_iterator i=mymap.begin(); i!=mymap.end(); ++i)
206 oss << " -> [" << (*i).first << "]=" << std::endl << ReprVectorOfString((*i).second) << std::endl;
210 std::string MEDPARTITIONER::ReprFieldDescriptions(const std::vector<std::string>& vec, const std::string separator)
213 return std::string(" NONE\n");
214 std::ostringstream oss;
215 for (std::vector<std::string>::const_iterator i=vec.begin(); i!=vec.end(); ++i)
218 oss << ReprVectorOfString(DeserializeToVectorOfString(*i), separator) << std::endl;
224 * a string "hello" gives a string " 5/hello/"
225 * serialized_FromVectorOfString_string+SerializeFromString("toto") is
226 * equivalent to vector<string>.push_back("toto") on serialized_FromVectorOfString_string
228 std::string MEDPARTITIONER::SerializeFromString(const std::string& s)
230 std::ostringstream oss;
231 oss << std::setw(5) << s.size() << "/" << s << "/";
236 * a vector of string gives a string
238 std::string MEDPARTITIONER::SerializeFromVectorOfString(const std::vector<std::string>& vec)
240 std::ostringstream oss;
241 for (std::vector<std::string>::const_iterator i=vec.begin(); i!=vec.end(); ++i)
242 oss<< std::setw(5) << (*i).size() << "/" << *i << "/";
247 * a string gives a vector of string
249 std::vector<std::string> MEDPARTITIONER::DeserializeToVectorOfString(const std::string& str)
251 std::vector<std::string> res;
253 std::size_t posmax=str.size();
255 return res; //empty vector
257 while (pos < posmax-6) //setw(5)+" "
259 std::istringstream iss(str.substr(pos,5));
261 if ((str[pos+5]!='/') || (str[pos+6+length]!='/'))
263 std::cerr << "Error on string '" << str << "'" << std::endl;;
264 throw INTERP_KERNEL::Exception("Error on string");
266 res.push_back(str.substr(pos+6,length));
272 std::string MEDPARTITIONER::EraseTagSerialized(const std::string& fromStr, const std::string& tag)
274 std::vector<std::string> vec=DeserializeToVectorOfString(fromStr);
275 std::vector<std::string> res;
276 for (std::size_t i=0; i<vec.size(); i++)
278 if (vec[i].find(tag)==std::string::npos)
279 res.push_back(vec[i]);
281 return MEDPARTITIONER::SerializeFromVectorOfString(res);
285 * elements first and second of map give one elements in result vector of string
286 * converting formatted the int second as firsts characters ending at first slash
288 std::vector<std::string> MEDPARTITIONER::VectorizeFromMapOfStringInt(const std::map<std::string,mcIdType>& mymap)
290 std::vector<std::string> res;
291 for (std::map<std::string,mcIdType>::const_iterator i=mymap.begin(); i!=mymap.end(); ++i)
293 std::ostringstream oss;
294 oss << (*i).second << "/" << (*i).first;
295 res.push_back(oss.str());
301 * if existing identicals (first,second) in vector no problem, else Exception
303 std::map<std::string,mcIdType> MEDPARTITIONER::DevectorizeToMapOfStringInt(const std::vector<std::string>& vec)
305 std::map<std::string,mcIdType> res;
306 for (std::vector<std::string>::const_iterator i=vec.begin(); i!=vec.end(); ++i)
309 std::size_t posmax=(*i).size();
310 std::size_t found=(*i).find('/'); //first slash
311 if ((found==std::string::npos) || (found<1))
312 throw INTERP_KERNEL::Exception("Error aIntNumber/anyString is expected");
314 std::istringstream iss((*i).substr(pos,found));
316 std::string first=(*i).substr(pos+found+1,posmax-found);
317 std::map<std::string,mcIdType>::iterator it=res.find(first);
319 if ((*it).second!=second)
320 throw INTERP_KERNEL::Exception("Error not the same map value");
327 * elements first and second of map give one elements in result vector of string
328 * adding key map and length of second vector as first string in each serialized vector
329 * one serialized vector per key map
331 std::vector<std::string> MEDPARTITIONER::VectorizeFromMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap)
333 std::vector<std::string> res;
334 for (std::map< std::string,std::vector<std::string> >::const_iterator i=mymap.begin(); i!=mymap.end(); ++i)
336 std::vector<std::string> vs=(*i).second; //a vector of string;
337 std::ostringstream oss;
338 oss << "Keymap/" << (*i).first << "/" << (*i).second.size();
339 vs.insert(vs.begin(), oss.str());
340 res.push_back(SerializeFromVectorOfString(vs));
346 * if existing identicals keymap in vector no problem
347 * duplicates in second vector
349 std::map< std::string,std::vector<std::string> > MEDPARTITIONER::DevectorizeToMapOfStringVectorOfString(const std::vector<std::string>& vec)
351 std::map< std::string,std::vector<std::string> > res;
352 for (std::vector<std::string>::const_iterator i=vec.begin(); i!=vec.end(); ++i)
354 std::vector<std::string> vs=DeserializeToVectorOfString(*i);
356 std::string enTete=vs[0];
357 std::size_t posmax=enTete.size();
358 std::size_t foundKey=enTete.find("Keymap/");
359 std::size_t foundSizeVector=enTete.find_last_of('/');
360 if ((foundKey==std::string::npos) || (foundKey!=0) || ((foundKey+7)>=foundSizeVector))
361 throw INTERP_KERNEL::Exception("Error Keymap/anyString/aIntNumber is expected");
363 std::istringstream iss(enTete.substr(foundSizeVector+1,posmax-foundSizeVector));
365 std::string keymap=enTete.substr(foundKey+7,foundSizeVector-foundKey-7);
366 for (int ii=1; ii<=sizeVector; ii++)
367 res[keymap].push_back(vs[ii]); //add unconditionally,so merge duplicates in second vector
373 * shit for unique and unique_copy for the duplicate CONSECUTIVE elements
374 * I do not want to sort
376 std::vector<std::string> MEDPARTITIONER::SelectTagsInVectorOfString(const std::vector<std::string>& vec, const std::string tag)
378 std::vector<std::string> res;
381 for (std::vector<std::string>::const_iterator i=vec.begin(); i!=vec.end(); ++i)
383 if ((*i).find(tag)!=std::string::npos) res.push_back(*i);
391 std::vector<std::string> MEDPARTITIONER::DeleteDuplicatesInVectorOfString(const std::vector<std::string>& vec)
393 std::vector<std::string> res;
394 if (vec.size()==0) return res;
395 //shit for unique and unique_copy for the duplicate CONSECUTIVE elements
396 //I do not want to sort
397 for (std::vector<std::string>::const_iterator i=vec.begin(); i!=vec.end(); ++i)
400 for (std::vector<std::string>::const_iterator j=res.begin(); j!=res.end(); ++j)
402 if ((*i).compare(*j)==0)
408 if (!found) res.push_back(*i);
413 std::map< std::string,std::vector<std::string> > MEDPARTITIONER::DeleteDuplicatesInMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap)
415 std::map< std::string,std::vector<std::string> > res;
416 for (std::map< std::string,std::vector<std::string> >::const_iterator i=mymap.begin(); i!=mymap.end(); ++i)
417 res[(*i).first]=DeleteDuplicatesInVectorOfString((*i).second);
421 //void MEDPARTITIONER::sendRecvVectorOfString(const std::vector<string>& vec, const int source, const int target)
423 std::string MEDPARTITIONER::Cle1ToStr(const std::string& s, const int inew)
425 std::ostringstream oss;
426 oss << s << " " << inew;
430 void MEDPARTITIONER::Cle1ToData(const std::string& key, std::string& s, int& inew)
432 std::size_t posmax=key.size();
433 std::size_t found=key.find(' ');
434 if ((found==std::string::npos) || (found<1))
435 throw INTERP_KERNEL::Exception("Error 'aStringWithoutWhitespace aInt' is expected");
436 s=key.substr(0,found);
437 std::istringstream iss(key.substr(found,posmax-found));
441 std::string MEDPARTITIONER::Cle2ToStr(const std::string& s, const int inew, const int iold)
443 std::ostringstream oss;
444 oss << s << " " << inew << " " << iold;
448 void MEDPARTITIONER::Cle2ToData(const std::string& key, std::string& s, int& inew, int& iold)
450 std::size_t posmax=key.size();
451 std::size_t found=key.find(' ');
452 if ((found==std::string::npos) || (found<1))
453 throw INTERP_KERNEL::Exception("Error 'aStringWithoutWhitespace aInt aInt' is expected");
454 s=key.substr(0,found);
455 std::istringstream iss(key.substr(found,posmax-found));
459 std::string MEDPARTITIONER::ExtractFromDescription(const std::string& description,const std::string& tag)
461 std::size_t found=description.find(tag);
462 if ((found==std::string::npos) || (found<1))
464 std::cerr << "ERROR : not found '" << tag << "' in '"<< description << "'\n";
465 throw INTERP_KERNEL::Exception("Error ExtractFromDescription");
467 std::size_t beg=found;
469 if (description[found-1]!='/')
471 //find without '/'... and pray looking for first whitespace
472 //something like 'idomain=0 fileName=tmp.med meshName=...'
473 end=description.size();
475 std::string res=description.substr(beg,end-beg);
477 if (found==std::string::npos)
479 res=res.substr(0,found);
482 std::size_t lg=StrToInt(description.substr(found-6,found));
484 return description.substr(beg,lg-tag.length());
487 void MEDPARTITIONER::FieldDescriptionToData(const std::string& description,
488 int& idomain, std::string& fileName, std::string& meshName, std::string& fieldName, int& typeField, int& DT, int& IT)
490 idomain=StrToInt(ExtractFromDescription(description,"idomain="));
491 fileName=ExtractFromDescription(description,"fileName=");
492 meshName=ExtractFromDescription(description,"meshName=");
493 fieldName=ExtractFromDescription(description,"fieldName=");
494 typeField=StrToInt(ExtractFromDescription(description,"typeField="));
495 DT=StrToInt(ExtractFromDescription(description,"DT="));
496 IT=StrToInt(ExtractFromDescription(description,"IT="));
499 void MEDPARTITIONER::FieldShortDescriptionToData(const std::string& description,
500 std::string& fieldName, int& typeField, int& entity, int& DT, int& IT)
502 fieldName=ExtractFromDescription(description,"fieldName=");
503 typeField=StrToInt(ExtractFromDescription(description,"typeField="));
504 entity=StrToInt(ExtractFromDescription(description,"entity="));
505 DT=StrToInt(ExtractFromDescription(description,"DT="));
506 IT=StrToInt(ExtractFromDescription(description,"IT="));
509 MEDCoupling::DataArrayIdType *MEDPARTITIONER::CreateDataArrayIntFromVector(const std::vector<mcIdType>& v)
511 MEDCoupling::DataArrayIdType* p=MEDCoupling::DataArrayIdType::New();
512 p->alloc(v.size(),1);
513 std::copy(v.begin(),v.end(),p->getPointer());
517 MEDCoupling::DataArrayIdType *MEDPARTITIONER::CreateDataArrayIntFromVector(const std::vector<mcIdType>& v,const int nbComponents)
519 MEDCoupling::DataArrayIdType* p=MEDCoupling::DataArrayIdType::New();
520 if (v.size()%nbComponents!=0)
521 throw INTERP_KERNEL::Exception("Problem size modulo nbComponents != 0");
522 p->alloc(v.size()/nbComponents,nbComponents);
523 std::copy(v.begin(),v.end(),p->getPointer());
527 MEDCoupling::DataArrayDouble* MEDPARTITIONER::CreateDataArrayDoubleFromVector(const std::vector<double>& v)
529 MEDCoupling::DataArrayDouble* p=MEDCoupling::DataArrayDouble::New();
530 p->alloc(v.size(),1);
531 std::copy(v.begin(),v.end(),p->getPointer());
537 std::vector<std::string> MEDPARTITIONER::BrowseFieldDouble(const MEDCoupling::MEDCouplingFieldDouble* fd)
539 std::vector<std::string> res;
542 std::size_t nb=fd->getArray()->getNumberOfComponents();
543 res.push_back("nbComponents="); res.back()+=IntToStr((int)nb);
544 for (unsigned int i=0; i<nb; i++)
546 res.push_back("componentInfo");
547 res.back()+=IntToStr(i)+"="+fd->getArray()->getInfoOnComponent(i);
552 res.push_back("nbComponents=0"); //unknown
558 * quick almost human readable information on all fields in a .med file
560 std::vector<std::string> MEDPARTITIONER::BrowseAllFields(const std::string& myfile)
562 std::vector<std::string> res;
563 std::vector<std::string> meshNames=MEDCoupling::GetMeshNames(myfile);
565 for (std::size_t i=0; i<meshNames.size(); i++)
567 std::vector<std::string> fieldNames=
568 MEDCoupling::GetAllFieldNamesOnMesh(myfile,meshNames[i]);
569 for (std::size_t j = 0; j < fieldNames.size(); j++)
571 std::vector< MEDCoupling::TypeOfField > typeFields=
572 MEDCoupling::GetTypesOfField(myfile, meshNames[i], fieldNames[j]);
573 for (std::size_t k = 0; k < typeFields.size(); k++)
575 std::vector< std::pair< int, int > > its=
576 GetFieldIterations(typeFields[k], myfile, meshNames[i], fieldNames[j]);
577 if (MyGlobals::_Is0verbose>100)
578 std::cout<< "fieldName " << fieldNames[j] << " typeField " << typeFields[k] << " its.size() " << its.size() << std::endl;
579 for (std::size_t m = 0; m < its.size(); m++)
581 std::vector<std::string> resi;
582 resi.push_back("fileName="); resi.back()+=myfile;
583 resi.push_back("meshName="); resi.back()+=meshNames[i];
584 resi.push_back("fieldName="); resi.back()+=fieldNames[j];
585 resi.push_back("typeField="); resi.back()+=IntToStr((int)typeFields[k]);
586 resi.push_back("DT="); resi.back()+=IntToStr((int)its[m].first);
587 resi.push_back("IT="); resi.back()+=IntToStr((int)its[m].second);
588 res.push_back(SerializeFromVectorOfString(resi));
596 std::vector<std::string> MEDPARTITIONER::GetInfosOfField(const char *fileName, const char *meshName, const int idomain)
599 const med_geometry_type GEOMTYPE[lggeom]={ //MED_N_CELL_FIXED_GEO] = {
624 const char * const GEOMTYPENAME[lggeom]={
650 const int lgentity=3;
651 const med_entity_type ENTITYTYPE[lgentity]={ //MED_N_ENTITY_TYPES+2]={
652 //MED_UNDEF_ENTITY_TYPE,
654 //MED_DESCENDING_FACE,
655 //MED_DESCENDING_EDGE,
658 //MED_STRUCT_ELEMENT,
659 //MED_UNDEF_ENTITY_TYPE
662 const char * const ENTITYTYPENAME[lgentity]={ //MED_N_ENTITY_TYPES+2]={
663 //"MED_UNDEF_ENTITY_TYPE",
669 //"MED_STRUCT_ELEMENT",
670 //"MED_UNDEF_ENTITY_TYPE"
673 std::vector<std::string> res;
674 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
675 med_int nbFields=MEDnField(fid);
676 if (MyGlobals::_Verbose>20)
677 std::cout << "on filename " << fileName << " nbOfField " << nbFields << std::endl;
679 med_field_type typcha;
680 med_int numdt=0,numo=0;
682 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
683 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
686 for(int i=1; i<=nbFields; i++)
688 med_int ncomp=MEDfieldnComponent(fid,i);
689 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
690 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
691 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
693 MEDfieldInfo(fid,i,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
694 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
695 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
696 for (int k=1; k<=nbPdt; k++)
698 MEDfieldComputingStepInfo(fid,nomcha,k,&numdt,&numo,&dt);
699 if (MyGlobals::_Verbose>20)
700 std::cout<< "on filename " << fileName << " field " << i << " fieldName " << curFieldName << " meshName " << curMeshName <<
701 " typ " << typcha << " nbComponent " << ncomp << " nbPdt " << nbPdt << " noPdt " << k <<
702 " ndt " << numdt << " nor " << numo << " dt " << dt << std::endl;
703 for (int ie=0; ie<lgentity; ie++)
705 for (int j=0; j<lggeom; j++)
707 med_int profilesize=0,nbi=0;
708 med_entity_type enttype=ENTITYTYPE[ie];
709 //enttype=MED_NODE;enttype=MED_CELL;enttype=MED_NODE_ELEMENT;
710 char pflname[MED_NAME_SIZE+1]="";
711 char locname[MED_NAME_SIZE+1]="";
712 med_int nbofprofile=MEDfieldnProfile(fid,nomcha,numdt,numo,enttype,GEOMTYPE[j],pflname,locname);
714 if (enttype==MED_NODE)
716 med_geometry_type mygeomtype=MED_UNDEF_ENTITY_TYPE;
717 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,enttype,mygeomtype,profileit,
718 MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi);
721 if (MyGlobals::_Verbose>20)
722 std::cout << "on filename " << fileName << " entity " << enttype << " nbOfVal with " <<
723 nbofprofile << " profile(s) for geomType (AUCUN) nbOfVal " <<
724 nbOfVal << " profilName '" << pflname << "' profileSize " << profilesize << " nbPtGauss " << nbi << std::endl;
725 std::vector<std::string> resi;
726 resi.push_back("idomain="); resi.back()+=IntToStr(idomain);
727 resi.push_back("fileName="); resi.back()+=fileName;
728 resi.push_back("meshName="); resi.back()+=curMeshName;
729 resi.push_back("fieldName="); resi.back()+=curFieldName;
730 resi.push_back("typeField="); resi.back()+=IntToStr((int)MEDCoupling::ON_NODES);
731 resi.push_back("typeData="); resi.back()+=IntToStr((int)typcha); //6 for double?
732 resi.push_back("nbComponent="); resi.back()+=IntToStr((int)ncomp);
733 resi.push_back("DT="); resi.back()+=IntToStr((int)numdt);
734 resi.push_back("IT="); resi.back()+=IntToStr((int)numo);
735 resi.push_back("time="); resi.back()+=DoubleToStr(dt);
736 resi.push_back("entity="); resi.back()+=IntToStr((int)enttype);
737 resi.push_back("entityName="); resi.back()+=ENTITYTYPENAME[ie];
738 resi.push_back("nbOfVal="); resi.back()+=IntToStr((int)nbOfVal);
739 resi.push_back("profilName="); resi.back()+=pflname;
740 resi.push_back("profileSize="); resi.back()+=IntToStr((int)profilesize);
741 resi.push_back("nbPtGauss="); resi.back()+=IntToStr((int)nbi);
742 res.push_back(SerializeFromVectorOfString(resi));
744 break; //on nodes no need to scute all geomtype
748 med_geometry_type mygeomtype=GEOMTYPE[j];
749 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,enttype,mygeomtype,profileit,
750 MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi);
753 if (MyGlobals::_Verbose>20)
754 std::cout << "on filename " << fileName << " entity " << enttype << " nbOfVal with " <<
755 nbofprofile << " profile(s) for geomType " <<
756 GEOMTYPE[j] << " " << GEOMTYPENAME[j] << " nbOfVal " <<
757 nbOfVal << " profilName '" << pflname << "' profileSize " << profilesize << " nbPtGauss " << nbi << std::endl;
758 int typeField=-1; //unknown
759 if (enttype==MED_CELL)
760 typeField=MEDCoupling::ON_CELLS;
761 if (enttype==MED_NODE_ELEMENT)
762 typeField=MEDCoupling::ON_GAUSS_NE;
763 //if (enttype==??) typeField=ON_GAUSS_PT;
764 std::vector<std::string> resi;
765 resi.push_back("idomain="); resi.back()+=IntToStr(idomain);
766 resi.push_back("fileName="); resi.back()+=fileName;
767 resi.push_back("meshName="); resi.back()+=curMeshName;
768 resi.push_back("fieldName="); resi.back()+=curFieldName;
769 resi.push_back("typeField="); resi.back()+=IntToStr((int)typeField);
770 resi.push_back("typeData="); resi.back()+=IntToStr((int)typcha); //6 for double?
771 resi.push_back("nbComponent="); resi.back()+=IntToStr((int)ncomp);
772 resi.push_back("DT="); resi.back()+=IntToStr((int)numdt);
773 resi.push_back("IT="); resi.back()+=IntToStr((int)numo);
774 resi.push_back("time="); resi.back()+=DoubleToStr(dt);
775 resi.push_back("entity="); resi.back()+=IntToStr((int)enttype);
776 resi.push_back("entityName="); resi.back()+=ENTITYTYPENAME[ie];
777 resi.push_back("geomType="); resi.back()+=IntToStr((int)GEOMTYPE[j]);
778 resi.push_back("geomTypeName="); resi.back()+=GEOMTYPENAME[j];
779 resi.push_back("nbOfVal="); resi.back()+=IntToStr((int)nbOfVal);
780 resi.push_back("profilName="); resi.back()+=pflname;
781 resi.push_back("profileSize="); resi.back()+=IntToStr((int)profilesize);
782 resi.push_back("nbPtGauss="); resi.back()+=IntToStr((int)nbi);
785 std::cout << "WARNING : unknown typeField for entity type " << enttype << std::endl <<
786 SerializeFromVectorOfString(resi) << std::endl;
787 continue; //do not register push_back
789 res.push_back(SerializeFromVectorOfString(resi));
799 if (MyGlobals::_Verbose>10)
800 std::cout << "detected fields:\n" << ReprVectorOfString(res) << std::endl;
804 MEDCoupling::MCAuto< MEDCoupling::DataArrayInt32 > MEDPARTITIONER::FromIdTypeVec( const std::vector< mcIdType >& vec )
806 MEDCoupling::DataArrayInt32* array = MEDCoupling::DataArrayInt32::New();
807 array->alloc( vec.size(), 1 );
808 std::copy( vec.begin(), vec.end(), array->getPointer() );
814 * quick almost human readable information on all fields on a mesh in a .med file
816 std::vector<std::string> MEDPARTITIONER::BrowseAllFieldsOnMesh(const std::string& myfile, const std::string& mymesh, const int idomain)
818 std::vector<std::string> res=GetInfosOfField(myfile.c_str(),mymesh.c_str(),idomain);
823 * create empty MEDCouplingUMesh* dim 3
825 MEDCoupling::MEDCouplingUMesh* MEDPARTITIONER::CreateEmptyMEDCouplingUMesh()
827 MEDCoupling::MEDCouplingUMesh* umesh=MEDCoupling::MEDCouplingUMesh::New();
828 umesh->setMeshDimension(3);
829 umesh->allocateCells(0);
830 umesh->finishInsertingCells();
831 MEDCoupling::DataArrayDouble *myCoords=MEDCoupling::DataArrayDouble::New();
832 myCoords->alloc(0,3);
833 umesh->setCoords(myCoords);
834 umesh->setName("EMPTY");
836 umesh->checkConsistencyLight();
840 namespace MEDPARTITIONER
842 BBTreeOfDim::BBTreeOfDim( std::size_t dim,
852 _tree=new BBTree<3,mcIdType> (bbs,elems,level,nbelems,epsilon);
853 _PgetElementsAroundPoint = & BBTreeOfDim::_getElementsAroundPoint< 3 >;
854 _PgetIntersectingElems = & BBTreeOfDim::_getIntersectingElems< 3 >;
857 _tree=new BBTree<2,mcIdType> (bbs,elems,level,nbelems,epsilon);
858 _PgetElementsAroundPoint = & BBTreeOfDim::_getElementsAroundPoint< 2 >;
859 _PgetIntersectingElems = & BBTreeOfDim::_getIntersectingElems< 2 >;
862 _tree=new BBTree<1,mcIdType> (bbs,elems,level,nbelems,epsilon);
863 _PgetElementsAroundPoint = & BBTreeOfDim::_getElementsAroundPoint< 1 >;
864 _PgetIntersectingElems = & BBTreeOfDim::_getIntersectingElems< 1 >;
868 throw INTERP_KERNEL::Exception("BBTreeOfDim(): wrong space dimension");
872 BBTreeOfDim::~BBTreeOfDim()
874 delete (BBTree<3>*)_tree;
877 void BBTreeOfDim::getElementsAroundPoint( const double* coordsPtr,
878 std::vector<mcIdType>& elems ) const
880 BBTreeOfDim* me = (BBTreeOfDim*) this;
881 (me->*_PgetElementsAroundPoint) ( coordsPtr, elems );
883 void BBTreeOfDim::getIntersectingElems(const double* bb,
884 std::vector<mcIdType>& elems) const
886 BBTreeOfDim* me = (BBTreeOfDim*) this;
887 (me->*_PgetIntersectingElems) ( bb, elems );