1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D
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 "MEDFileJoint.hxx"
21 #include "MEDFileBasis.hxx"
22 #include "MEDLoader.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileSafeCaller.txx"
26 #include "CellModel.hxx"
27 #include "InterpKernelAutoPtr.hxx"
29 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
30 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
31 extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE];
33 using namespace MEDCoupling;
35 std::size_t MEDFileJointCorrespondence::getHeapMemorySizeWithoutChildren() const
37 return sizeof(MCAuto<DataArrayIdType>);
40 std::vector<const BigMemoryObject *> MEDFileJointCorrespondence::getDirectChildrenWithNull() const
42 return std::vector<const BigMemoryObject *>();
45 MEDFileJointCorrespondence::MEDFileJointCorrespondence():
47 _loc_geo_type( INTERP_KERNEL::NORM_ERROR ),
48 _rem_geo_type( INTERP_KERNEL::NORM_ERROR )
54 * \param [in] correspondence - correspondence.
55 * \param [in] is_nodal - is the correspondence of cells or nodes.
56 * \param [in] loc_geo_type - the local geometry type of correspondence.
57 * \param [in] rem_geo_type - the remote geometry type of correspondence.
59 MEDFileJointCorrespondence::MEDFileJointCorrespondence(DataArrayIdType* correspondence,
61 INTERP_KERNEL::NormalizedCellType loc_geo_type,
62 INTERP_KERNEL::NormalizedCellType rem_geo_type):
64 _loc_geo_type( loc_geo_type ),
65 _rem_geo_type( rem_geo_type )
67 MEDFileJointCorrespondence::setCorrespondence( correspondence );
70 MEDFileJointCorrespondence* MEDFileJointCorrespondence::New(DataArrayIdType* correspondence,
71 INTERP_KERNEL::NormalizedCellType loc_geo_type,
72 INTERP_KERNEL::NormalizedCellType rem_geo_type)
74 return new MEDFileJointCorrespondence(correspondence, /*isNodal=*/false, loc_geo_type, rem_geo_type );
78 * Returns a new MEDFileJointCorrespondence of nodes
80 MEDFileJointCorrespondence *MEDFileJointCorrespondence::New(DataArrayIdType* correspondence)
82 return new MEDFileJointCorrespondence(correspondence);
86 * Returns a new undefined MEDFileJointCorrespondence
89 MEDFileJointCorrespondence *MEDFileJointCorrespondence::New()
91 return new MEDFileJointCorrespondence();
95 * Writes \a this joint into a MED file specified by its name.
96 * \param [in] fileName - the MED file name.
97 * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
98 * - 2 - erase; an existing file is removed.
99 * - 1 - append; same data should not be present in an existing file.
100 * - 0 - overwrite; same data present in an existing file is overwritten.
101 * \param [in] order - order.
102 * \param [in] iteration - iteration.
103 * \throw If the mesh name is not set.
104 * \throw If \a mode == 1 and the same data is present in an existing file.
106 void MEDFileJointCorrespondence::write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const
108 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
109 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
111 std::ostringstream oss; oss << "MEDFileJointCorrespondence : error on attempt to write in file : \"" << fileName << "\"";
112 MEDFileUtilities::CheckMEDCode((int)fid,fid,oss.str());
114 if (( !_is_nodal ) &&
115 ( _loc_geo_type == INTERP_KERNEL::NORM_ERROR ||
116 _rem_geo_type == INTERP_KERNEL::NORM_ERROR ))
118 throw INTERP_KERNEL::Exception( "Geometric type not specified for a cell Joint" );
121 if ( (const DataArrayIdType *)_correspondence )
123 writeLL(fid, localMeshName, jointName, order, iteration);
127 throw INTERP_KERNEL::Exception("MEDFileJointCorrespondence::write : correspondence array not defined");
131 void MEDFileJointCorrespondence::writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const
135 MEDFILESAFECALLERWR0(MEDsubdomainCorrespondenceWr,(fid, localMeshName.c_str(), jointName.c_str(),
139 ToMedInt(_correspondence->getNbOfElems()/2),
140 ToMedIntArray(_correspondence)->getConstPointer()));
144 MEDFILESAFECALLERWR0(MEDsubdomainCorrespondenceWr,(fid, localMeshName.c_str(), jointName.c_str(),
146 MED_CELL, typmai3[ _loc_geo_type ],
147 MED_CELL, typmai3[ _rem_geo_type ],
148 ToMedInt(_correspondence->getNbOfElems()/2),
149 ToMedIntArray(_correspondence)->getConstPointer()));
153 void MEDFileJointCorrespondence::setCorrespondence(DataArrayIdType *corr)
155 _correspondence=corr;
161 * Checks if \a this and another mesh are equal.
162 * \param [in] other - the mesh to compare with.
163 * \return bool - \c true if the meshes are equal, \c false, else.
165 bool MEDFileJointCorrespondence::isEqual(const MEDFileJointCorrespondence *other) const
167 if(_is_nodal!=other->_is_nodal)
169 if(_loc_geo_type!=other->_loc_geo_type)
171 if(_rem_geo_type!=other->_rem_geo_type)
173 if(!_correspondence->isEqual(*other->_correspondence))
178 MEDFileJointCorrespondence *MEDFileJointCorrespondence::deepCopy() const
180 MCAuto<MEDFileJointCorrespondence> ret=new MEDFileJointCorrespondence(*this);
184 MEDFileJointCorrespondence *MEDFileJointCorrespondence::shallowCpy() const
186 MCAuto<MEDFileJointCorrespondence> ret=new MEDFileJointCorrespondence(*this);
191 * Returns a string describing \a this mesh. This description includes the correspondence and
192 * the number correspondence.
193 * \return std::string - the joint information string.
195 std::string MEDFileJointCorrespondence::simpleRepr() const
197 std::ostringstream oss;
198 oss << "(*************************************)\n(* JOINT_CORRESPOND INFORMATION: *)\n(*************************************)\n";
199 oss << "- entity type of the correspondence : " << ( getIsNodal() ? "NODE" : "CELL" ) << "\n";
200 oss << "- Local geometry type of the correspondence : " << INTERP_KERNEL::CellModel::GetCellModel( _loc_geo_type ).getRepr() << "\n";
201 oss << "- Remote geometry type of the correspondence : " << INTERP_KERNEL::CellModel::GetCellModel( _rem_geo_type ).getRepr() << "\n";
202 if ( (const DataArrayIdType *)_correspondence )
204 oss << "- Number entity of the correspondence : " << getCorrespondence()->getNumberOfTuples() << "\n";
206 const DataArrayIdType* tmp=getCorrespondence();
207 oss << "- Correspondence : <<";
208 for(const mcIdType *it=tmp->begin();it!=tmp->end();it++)
213 oss << "- Number entity of the correspondence : 0\n";
220 MEDFileJointOneStep::MEDFileJointOneStep():_order(-1),_iteration(-1)
224 std::size_t MEDFileJointOneStep::getHeapMemorySizeWithoutChildren() const
226 return _correspondences.capacity()*sizeof(MCAuto<DataArrayIdType>);
229 std::vector<const BigMemoryObject *> MEDFileJointOneStep::getDirectChildrenWithNull() const
231 return std::vector<const BigMemoryObject *>();
234 MEDFileJointOneStep *MEDFileJointOneStep::New(int dt, int it)
236 MEDFileJointOneStep* j = new MEDFileJointOneStep();
238 j->setIteration( it );
243 * Returns a new MEDFileJointOneStep.
244 * \param [in] fileName - the name of MED file to read.
245 * \param [in] mName - the name of the mesh to read.
246 * \param [in] jointName - the joint name.
247 * \param [in] num - the number of an iteration.
248 * \return MEDFileMesh * - a new instance of MEDFileJointOneStep.
249 * \throw If the file is not readable.
250 * \throw If there is no mesh with given attributes in the file.
252 MEDFileJointOneStep *MEDFileJointOneStep::New(const std::string& fileName, const std::string& mName, const std::string& jointName, int num)
254 MEDFileUtilities::CheckFileForRead(fileName);
255 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
256 return new MEDFileJointOneStep(fid, mName, jointName, num);
259 MEDFileJointOneStep* MEDFileJointOneStep::New(med_idt fid, const std::string& mName, const std::string& jointName, int num)
261 return new MEDFileJointOneStep( fid, mName, jointName, num);
264 MEDFileJointOneStep::MEDFileJointOneStep(med_idt fid, const std::string& mName, const std::string& jointName, int num)
266 med_int order, iteration, ncorrespondence;
267 MEDFILESAFECALLERRD0(MEDsubdomainComputingStepInfo,(fid, mName.c_str(), jointName.c_str(), num, &order, &iteration, &ncorrespondence));
268 MEDFileJointOneStep::setOrder(FromMedInt<int>(order));
269 MEDFileJointOneStep::setIteration(FromMedInt<int>(iteration));
270 for ( int cur_it = 1; cur_it <= ncorrespondence; ++cur_it )
273 med_entity_type loc_ent_type, rem_ent_type;
274 med_geometry_type loc_geo_type, rem_geo_type;
275 MEDFILESAFECALLERRD0(MEDsubdomainCorrespondenceSizeInfo,(fid, mName.c_str(), jointName.c_str(), order, iteration, cur_it,
276 &loc_ent_type, &loc_geo_type, &rem_ent_type, &rem_geo_type, &num_entity));
277 if ( num_entity > 0 )
279 MCAuto<DataArrayMedInt> correspondence=DataArrayMedInt::New();
280 correspondence->alloc(num_entity*2, 1);
281 MEDFILESAFECALLERRD0(MEDsubdomainCorrespondenceRd,(fid, mName.c_str(), jointName.c_str(), order, iteration, loc_ent_type,
282 loc_geo_type, rem_ent_type, rem_geo_type, correspondence->getPointer()));
283 MEDFileJointCorrespondence *cor=MEDFileJointCorrespondence::New();
284 cor->setIsNodal( loc_ent_type == MED_NODE );
285 cor->setLocalGeometryType ( convertGeometryType( loc_geo_type ));
286 cor->setRemoteGeometryType( convertGeometryType( rem_geo_type ));
287 cor->setCorrespondence( FromMedIntArray<mcIdType>(correspondence ));
288 _correspondences.push_back(cor);
294 * Writes \a this joint into a MED file specified by its name.
295 * \param [in] fileName - the MED file name.
296 * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
297 * - 2 - erase; an existing file is removed.
298 * - 1 - append; same data should not be present in an existing file.
299 * - 0 - overwrite; same data present in an existing file is overwritten.
300 * \throw If the mesh name is not set.
301 * \throw If \a mode == 1 and the same data is present in an existing file.
303 void MEDFileJointOneStep::write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName) const
305 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
306 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
307 std::ostringstream oss; oss << "MEDFileJointOneStep : error on attempt to write in file : \"" << fileName << "\"";
308 MEDFileUtilities::CheckMEDCode((int)fid,fid,oss.str());
309 if ( _correspondences.empty() )
310 throw INTERP_KERNEL::Exception("MEDFileJointOneStep::write : no correspondences defined !");
311 writeLL(fid, localMeshName, jointName);
314 void MEDFileJointOneStep::writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName) const
316 for(std::vector< MCAuto<MEDFileJointCorrespondence> >::const_iterator it=_correspondences.begin();it!=_correspondences.end();it++)
318 (*it)->writeLL(fid, localMeshName, jointName, getOrder(), getIteration());
322 void MEDFileJointOneStep::pushCorrespondence(MEDFileJointCorrespondence* correspondence)
325 throw INTERP_KERNEL::Exception("MEDFileJointCorrespondence::pushCorrespondence : invalid input pointer ! should be different from 0 !");
326 _correspondences.push_back(correspondence);
327 correspondence->incrRef();
330 int MEDFileJointOneStep::getNumberOfCorrespondences() const
332 return (int)_correspondences.size();
335 /** Return a borrowed reference (caller is not responsible) */
336 MEDFileJointCorrespondence *MEDFileJointOneStep::getCorrespondenceAtPos(int i) const
338 if(i<0 || i>=(int)_correspondences.size())
340 std::ostringstream oss; oss << "MEDFileJointOneStep::getCorrespondenceAtPos : invalid correspondence id given in parameter ! Should be in [0;" << _correspondences.size() << ") !";
341 throw INTERP_KERNEL::Exception(oss.str().c_str());
343 const MEDFileJointCorrespondence* ret = _correspondences[i];
344 return const_cast<MEDFileJointCorrespondence *>( ret );
348 * Checks if \a this and another Joint are equal.
349 * \param [in] other - the Joint to compare with.
350 * \return bool - \c true if the Joints are equal, \c false, else.
352 bool MEDFileJointOneStep::isEqual(const MEDFileJointOneStep *other) const
354 if(_order!=other->_order)
356 if(_iteration!=other->_iteration)
358 if ( getNumberOfCorrespondences() != other->getNumberOfCorrespondences() )
361 std::vector<bool> found( getNumberOfCorrespondences(), false );
362 for(int i=0; i<getNumberOfCorrespondences(); i++)
365 for(j=0; j<getNumberOfCorrespondences(); j++)
368 getCorrespondenceAtPos(i)->isEqual(other->getCorrespondenceAtPos(j)))
374 if ( j == getNumberOfCorrespondences() )
380 MEDFileJointOneStep *MEDFileJointOneStep::deepCopy() const
382 std::vector< MCAuto<MEDFileJointCorrespondence> > correspondences(_correspondences.size());
384 for(std::vector< MCAuto<MEDFileJointCorrespondence> >::const_iterator it=_correspondences.begin();it!=_correspondences.end();it++,i++)
385 if((const MEDFileJointCorrespondence *)*it)
386 correspondences[i]=(*it)->deepCopy();
387 MCAuto<MEDFileJointOneStep> ret= new MEDFileJointOneStep;
388 ret->_correspondences=correspondences;
392 MEDFileJointOneStep *MEDFileJointOneStep::shallowCpy() const
394 MCAuto<MEDFileJointOneStep> ret=new MEDFileJointOneStep(*this);
399 * Returns a string describing \a this Joint. This description includes the correspondence and
400 * the number of correspondences.
401 * \return std::string - the joint information string.
403 std::string MEDFileJointOneStep::simpleRepr() const
405 std::ostringstream oss;
406 oss << "(*************************************)\n(* JOINT_ONE_STEP INFORMATION: *)\n(*************************************)\n";
407 oss << "- Number of the correspondences : <<" << _correspondences.size() << ">>\n";
408 for(std::vector< MCAuto<MEDFileJointCorrespondence> >::const_iterator it=_correspondences.begin();it!=_correspondences.end();it++)
410 oss << (*it)->simpleRepr();
415 INTERP_KERNEL::NormalizedCellType MEDFileJointOneStep::convertGeometryType(med_geometry_type geotype)
417 INTERP_KERNEL::NormalizedCellType result=INTERP_KERNEL::NORM_ERROR;
418 for(int i=0; i<MED_N_CELL_FIXED_GEO; i++)
420 if (typmai[i]==geotype)
429 std::size_t MEDFileJoint::getHeapMemorySizeWithoutChildren() const
431 return _joint.capacity()*sizeof(MCAuto<MEDFileJointOneStep>);
434 std::vector<const BigMemoryObject *> MEDFileJoint::getDirectChildrenWithNull() const
436 return std::vector<const BigMemoryObject *>();
439 MEDFileJoint *MEDFileJoint::New()
441 return new MEDFileJoint();
444 MEDFileJoint *MEDFileJoint::New(const std::string& fileName, const std::string& mName, int curJoint)
446 MEDFileUtilities::CheckFileForRead(fileName);
447 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
448 return new MEDFileJoint(fid,mName,curJoint);
451 MEDFileJoint *MEDFileJoint::New(med_idt fid, const std::string& mName, int curJoint)
453 return new MEDFileJoint(fid,mName,curJoint);
456 MEDFileJoint *MEDFileJoint::New(const std::string& jointName, const std::string& locMeshName, const std::string& remoteMeshName, int remoteMeshNum)
458 MEDFileJoint* j = new MEDFileJoint();
459 j->setJointName( jointName );
460 j->setLocalMeshName( locMeshName );
461 j->setRemoteMeshName( remoteMeshName );
462 j->setDomainNumber( remoteMeshNum );
466 MEDFileJoint::MEDFileJoint()
471 * Returns a new MEDFileJoint holding the mesh data that has been read from a given MED
472 * file. The Joint to load is specified by mesh name and a Joint iteration.
473 * \param [in] fileName - the name of MED file to read.
474 * \param [in] mName - the name of the mesh to read.
475 * \param [in] curJoint - the iteration number of current joint.
476 * \return MEDFileJoint * - a new instance of MEDFileJoint.
477 * \throw If the file is not readable.
478 * \throw If there is no mesh with given attributes in the file.
480 MEDFileJoint::MEDFileJoint(med_idt fid, const std::string& mName, int curJoint)
482 INTERP_KERNEL::AutoPtr<char> joint_name=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
483 INTERP_KERNEL::AutoPtr<char> desc_name=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
484 INTERP_KERNEL::AutoPtr<char> rem_mesh_name=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
485 med_int domain_number=0, nstep=0, nocstpncorrespondence=0;
486 MEDFILESAFECALLERRD0(MEDsubdomainJointInfo,(fid,mName.c_str(), curJoint, joint_name, desc_name, &domain_number,rem_mesh_name,
487 &nstep, &nocstpncorrespondence));
488 setLocalMeshName(mName);
489 setRemoteMeshName(MEDLoaderBase::buildStringFromFortran(rem_mesh_name,MED_NAME_SIZE));
490 setDescription(MEDLoaderBase::buildStringFromFortran(desc_name,MED_COMMENT_SIZE));
491 setJointName(MEDLoaderBase::buildStringFromFortran(joint_name,MED_NAME_SIZE));
492 setDomainNumber(FromMedInt<int>(domain_number));
493 for(int cur_step=1; cur_step <= nstep; ++cur_step)
495 MEDFileJointOneStep *cor=MEDFileJointOneStep::New(fid, mName.c_str(), getJointName(), cur_step);
496 _joint.push_back(cor);
500 void MEDFileJoint::writeLL(med_idt fid) const
502 // if ( _loc_mesh_name.empty() )
503 // throw INTERP_KERNEL::Exception("MEDFileJoint::write : name of a local mesh not defined!");
504 MEDFILESAFECALLERWR0(MEDsubdomainJointCr,(fid,getLocalMeshName().c_str(),getJointName().c_str(),getDescription().c_str(),getDomainNumber(),getRemoteMeshName().c_str()));
505 for(std::vector< MCAuto<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++)
506 (*it)->writeLL(fid, getLocalMeshName(),getJointName());
509 void MEDFileJoint::pushStep(MEDFileJointOneStep* step)
512 throw INTERP_KERNEL::Exception("MEDFileJoint::pushStep : invalid input pointer ! should be different from 0 !");
513 _joint.push_back(step);
517 int MEDFileJoint::getNumberOfSteps() const
519 return (int)_joint.size();
522 /** Return a borrowed reference (caller is not responsible) */
523 MEDFileJointOneStep *MEDFileJoint::getStepAtPos(int i) const
525 if(i<0 || i>=(int)_joint.size())
527 std::ostringstream oss; oss << "MEDFileJoint::getStepAtPos : invalid step id given in parameter ! Should be in [0;" << _joint.size() << ") !";
528 throw INTERP_KERNEL::Exception(oss.str().c_str());
530 const MEDFileJointOneStep* ret = _joint[i];
531 return const_cast<MEDFileJointOneStep *>( ret );
535 * Checks if \a this and another Joint are equal.
536 * \param [in] other - the Joint to compare with.
537 * \return bool - \c true if the Joints are equal, \c false, else.
539 bool MEDFileJoint::isEqual(const MEDFileJoint *other) const
541 if(_loc_mesh_name!=other->_loc_mesh_name)
543 if(_joint_name!=other->_joint_name)
545 if(_desc_name!=other->_desc_name)
547 if(_rem_mesh_name!=other->_rem_mesh_name)
549 if(_domain_number!=other->_domain_number)
551 int nbTS(getNumberOfSteps());
552 if(nbTS!=other->getNumberOfSteps())
554 std::vector<bool> found(nbTS,false);
555 for(int i=0;i<nbTS;i++)
560 if(!found[j] && getStepAtPos(i)->isEqual(other->getStepAtPos(j)))
572 MEDFileJoint *MEDFileJoint::deepCopy() const
574 std::vector< MCAuto<MEDFileJointOneStep> > joint(_joint.size());
576 for(std::vector< MCAuto<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++,i++)
577 if((const MEDFileJointOneStep *)*it)
578 joint[i]=(*it)->deepCopy();
579 MCAuto<MEDFileJoint> ret=MEDFileJoint::New();
584 MEDFileJoint *MEDFileJoint::shallowCpy() const
586 MCAuto<MEDFileJoint> ret=new MEDFileJoint(*this);
590 bool MEDFileJoint::changeJointNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
592 for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
594 if((*it).first==_joint_name)
596 _joint_name=(*it).second;
604 * Returns a string describing \a this mesh. This description includes the correspondence and
605 * the number correspondence.
606 * \return std::string - the joint information string.
608 std::string MEDFileJoint::simpleRepr() const
610 std::ostringstream oss;
611 oss << "(*************************************)\n(* JOINT INFORMATION: *)\n(*************************************)\n";
612 oss << "- Local Mesh name : <<" << getLocalMeshName() << ">>\n";
613 oss << "- Remote Mesh name : <<" << getRemoteMeshName() << ">>\n";
614 oss << "- Description : <<" << getDescription() << ">>\n";
615 oss << "- Joint name : <<" << getJointName() << ">>\n";
616 oss << "- Domain number : " << getDomainNumber() << "\n";
617 for(std::vector< MCAuto<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++)
619 oss << (*it)->simpleRepr();
624 MEDFileJoints *MEDFileJoints::New()
626 return new MEDFileJoints;
629 MEDFileJoints *MEDFileJoints::New(const std::string& fileName, const std::string& meshName)
631 MEDFileUtilities::CheckFileForRead(fileName);
632 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
633 return new MEDFileJoints( fid, meshName );
636 MEDFileJoints *MEDFileJoints::New(med_idt fid, const std::string& meshName)
638 return new MEDFileJoints( fid, meshName );
641 void MEDFileJoints::writeLL(med_idt fid) const
643 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
647 std::string MEDFileJoints::getMeshName() const
649 for ( size_t i = 0; i <= _joints.size(); ++i )
650 if ( (const MEDFileJoint*) _joints[i] )
651 return _joints[i]->getLocalMeshName();
656 int MEDFileJoints::getNumberOfJoints() const
658 return (int)_joints.size();
661 /** Return a borrowed reference (caller is not responsible) */
662 MEDFileJoint *MEDFileJoints::getJointAtPos(int i) const
664 if(i<0 || i>=(int)_joints.size())
666 std::ostringstream oss; oss << "MEDFileJoints::getJointAtPos : invalid joint id given in parameter ! Should be in [0;" << _joints.size() << ") !";
667 throw INTERP_KERNEL::Exception(oss.str().c_str());
669 const MEDFileJoint* ret = _joints[i];
670 return const_cast<MEDFileJoint *>( ret );
674 /** Return a borrowed reference (caller is not responsible) */
675 MEDFileJoint *MEDFileJoints::getJointWithName(const std::string& jname) const
677 std::vector<std::string> js=getJointsNames();
678 std::vector<std::string>::iterator it=std::find(js.begin(),js.end(),jname);
681 std::ostringstream oss; oss << "MEDFileJoints::getJointWithName : Joint \"" << jname << "\" does not exist in this ! Existing are : ";
682 std::copy(js.begin(),js.end(),std::ostream_iterator<std::string>(oss," "));
683 throw INTERP_KERNEL::Exception(oss.str().c_str());
685 return getJointAtPos((int)std::distance(js.begin(),it));
688 std::vector<std::string> MEDFileJoints::getJointsNames() const
690 std::vector<std::string> ret(_joints.size());
692 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++,i++)
694 const MEDFileJoint *f=(*it);
697 ret[i]=f->getJointName();
701 std::ostringstream oss; oss << "MEDFileJoints::getJointsNames : At rank #" << i << " joint is not defined !";
702 throw INTERP_KERNEL::Exception(oss.str().c_str());
708 bool MEDFileJoints::changeJointNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
711 for(std::vector< MCAuto<MEDFileJoint> >::iterator it=_joints.begin();it!=_joints.end();it++)
713 MEDFileJoint *cur(*it);
715 ret=cur->changeJointNames(modifTab) || ret;
720 void MEDFileJoints::resize(int newSize)
722 _joints.resize(newSize);
725 void MEDFileJoints::pushJoint(MEDFileJoint *joint)
728 throw INTERP_KERNEL::Exception("MEDFileJoints::pushJoint() : invalid input pointer ! should be different from 0 !");
729 if ( !_joints.empty() &&
730 _joints[0]->getLocalMeshName() != joint->getLocalMeshName() )
731 throw INTERP_KERNEL::Exception("MEDFileJoints::pushJoint() : different names of local meshes ! should be equal !");
733 _joints.push_back(joint);
737 void MEDFileJoints::setJointAtPos(int i, MEDFileJoint *joint)
740 throw INTERP_KERNEL::Exception("MEDFileJoints::setJointAtPos : invalid input pointer ! should be different from 0 !");
741 if(i>=(int)_joints.size())
747 void MEDFileJoints::destroyJointAtPos(int i)
749 if(i<0 || i>=(int)_joints.size())
751 std::ostringstream oss; oss << "MEDFileJoints::destroyJointAtPos : Invalid given id in input (" << i << ") should be in [0," << _joints.size() << ") !";
752 throw INTERP_KERNEL::Exception(oss.str().c_str());
754 _joints.erase(_joints.begin()+i);
757 MEDFileJoints::MEDFileJoints()
761 MEDFileJoints::MEDFileJoints(med_idt fid, const std::string& meshName)
763 med_int num_joint=MEDnSubdomainJoint(fid, meshName.c_str() );
764 for(int i = 1; i <= num_joint; i++)
765 _joints.push_back(MEDFileJoint::New(fid,meshName,i));
768 MEDFileJoints *MEDFileJoints::deepCopy() const
770 std::vector< MCAuto<MEDFileJoint> > joints(_joints.size());
772 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++,i++)
773 if((const MEDFileJoint *)*it)
774 joints[i]=(*it)->deepCopy();
775 MCAuto<MEDFileJoints> ret=MEDFileJoints::New();
780 std::size_t MEDFileJoints::getHeapMemorySizeWithoutChildren() const
782 return _joints.capacity()*(sizeof(MCAuto<MEDFileJoint>));
785 std::vector<const BigMemoryObject *> MEDFileJoints::getDirectChildrenWithNull() const
787 std::vector<const BigMemoryObject *> ret;
788 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
789 ret.push_back((const MEDFileJoint *)*it);
793 std::string MEDFileJoints::simpleRepr() const
795 std::ostringstream oss;
796 oss << "(*****************)\n(* MEDFileJoints *)\n(*****************)\n\n";
797 simpleReprWithoutHeader(oss);
801 void MEDFileJoints::simpleReprWithoutHeader(std::ostream& oss) const
803 int nbOfJoints=getNumberOfJoints();
804 oss << "There are " << nbOfJoints << " joints with the following names : \n";
805 std::vector<std::string> jns=getJointsNames();
806 for(int i=0;i<nbOfJoints;i++)
807 oss << " - #" << i << " \"" << jns[i] << "\"\n";
808 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
810 oss << (*it)->simpleRepr();