1 // Copyright (C) 2007-2016 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 "MEDLoader.hxx"
22 #include "MEDLoaderBase.hxx"
23 #include "MEDFileSafeCaller.txx"
25 #include "CellModel.hxx"
26 #include "InterpKernelAutoPtr.hxx"
28 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
29 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
30 extern med_geometry_type typmai3[34];
32 using namespace MEDCoupling;
34 std::size_t MEDFileJointCorrespondence::getHeapMemorySizeWithoutChildren() const
36 return sizeof(MCAuto<DataArrayInt>);
39 std::vector<const BigMemoryObject *> MEDFileJointCorrespondence::getDirectChildrenWithNull() const
41 return std::vector<const BigMemoryObject *>();
44 MEDFileJointCorrespondence::MEDFileJointCorrespondence():
46 _loc_geo_type( INTERP_KERNEL::NORM_ERROR ),
47 _rem_geo_type( INTERP_KERNEL::NORM_ERROR )
53 * \param [in] correspondence - correspondence.
54 * \param [in] is_nodal - is the correspondence of cells or nodes.
55 * \param [in] loc_geo_type - the local geometry type of correspondence.
56 * \param [in] rem_geo_type - the remote geometry type of correspondence.
58 MEDFileJointCorrespondence::MEDFileJointCorrespondence(DataArrayInt* correspondence,
60 INTERP_KERNEL::NormalizedCellType loc_geo_type,
61 INTERP_KERNEL::NormalizedCellType rem_geo_type):
63 _loc_geo_type( loc_geo_type ),
64 _rem_geo_type( rem_geo_type )
66 MEDFileJointCorrespondence::setCorrespondence( correspondence );
69 MEDFileJointCorrespondence* MEDFileJointCorrespondence::New(DataArrayInt* correspondence,
70 INTERP_KERNEL::NormalizedCellType loc_geo_type,
71 INTERP_KERNEL::NormalizedCellType rem_geo_type)
73 return new MEDFileJointCorrespondence(correspondence, /*isNodal=*/false, loc_geo_type, rem_geo_type );
77 * Returns a new MEDFileJointCorrespondence of nodes
79 MEDFileJointCorrespondence *MEDFileJointCorrespondence::New(DataArrayInt* correspondence)
81 return new MEDFileJointCorrespondence(correspondence);
85 * Returns a new undefined MEDFileJointCorrespondence
88 MEDFileJointCorrespondence *MEDFileJointCorrespondence::New()
90 return new MEDFileJointCorrespondence();
94 * Writes \a this joint into a MED file specified by its name.
95 * \param [in] fileName - the MED file name.
96 * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
97 * - 2 - erase; an existing file is removed.
98 * - 1 - append; same data should not be present in an existing file.
99 * - 0 - overwrite; same data present in an existing file is overwritten.
100 * \param [in] order - order.
101 * \param [in] iteration - iteration.
102 * \throw If the mesh name is not set.
103 * \throw If \a mode == 1 and the same data is present in an existing file.
105 void MEDFileJointCorrespondence::write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const
107 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
108 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
110 std::ostringstream oss; oss << "MEDFileJointCorrespondence : error on attempt to write in file : \"" << fileName << "\"";
111 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str());
113 if (( !_is_nodal ) &&
114 ( _loc_geo_type == INTERP_KERNEL::NORM_ERROR ||
115 _rem_geo_type == INTERP_KERNEL::NORM_ERROR ))
117 throw INTERP_KERNEL::Exception( "Geometric type not specified for a cell Joint" );
120 if ( (const DataArrayInt *)_correspondence )
122 writeLL(fid, localMeshName, jointName, order, iteration);
126 throw INTERP_KERNEL::Exception("MEDFileJointCorrespondence::write : correspondence array not defined");
130 void MEDFileJointCorrespondence::writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const
134 MEDFILESAFECALLERWR0(MEDsubdomainCorrespondenceWr,(fid, localMeshName.c_str(), jointName.c_str(),
138 _correspondence->getNbOfElems()/2,
139 _correspondence->getConstPointer()));
143 MEDFILESAFECALLERWR0(MEDsubdomainCorrespondenceWr,(fid, localMeshName.c_str(), jointName.c_str(),
145 MED_CELL, typmai3[ _loc_geo_type ],
146 MED_CELL, typmai3[ _rem_geo_type ],
147 _correspondence->getNbOfElems()/2,
148 _correspondence->getConstPointer()));
152 void MEDFileJointCorrespondence::setCorrespondence(DataArrayInt *corr)
154 _correspondence=corr;
160 * Checks if \a this and another mesh are equal.
161 * \param [in] other - the mesh to compare with.
162 * \return bool - \c true if the meshes are equal, \c false, else.
164 bool MEDFileJointCorrespondence::isEqual(const MEDFileJointCorrespondence *other) const
166 if(_is_nodal!=other->_is_nodal)
168 if(_loc_geo_type!=other->_loc_geo_type)
170 if(_rem_geo_type!=other->_rem_geo_type)
172 if(!_correspondence->isEqual(*other->_correspondence))
177 MEDFileJointCorrespondence *MEDFileJointCorrespondence::deepCopy() const
179 MCAuto<MEDFileJointCorrespondence> ret=new MEDFileJointCorrespondence(*this);
183 MEDFileJointCorrespondence *MEDFileJointCorrespondence::shallowCpy() const
185 MCAuto<MEDFileJointCorrespondence> ret=new MEDFileJointCorrespondence(*this);
190 * Returns a string describing \a this mesh. This description includes the correspondence and
191 * the number correspondence.
192 * \return std::string - the joint information string.
194 std::string MEDFileJointCorrespondence::simpleRepr() const
196 std::ostringstream oss;
197 oss << "(*************************************)\n(* JOINT_CORRESPOND INFORMATION: *)\n(*************************************)\n";
198 oss << "- entity type of the correspondence : " << ( getIsNodal() ? "NODE" : "CELL" ) << "\n";
199 oss << "- Local geometry type of the correspondence : " << INTERP_KERNEL::CellModel::GetCellModel( _loc_geo_type ).getRepr() << "\n";
200 oss << "- Remote geometry type of the correspondence : " << INTERP_KERNEL::CellModel::GetCellModel( _rem_geo_type ).getRepr() << "\n";
201 if ( (const DataArrayInt *)_correspondence )
203 oss << "- Number entity of the correspondence : " << getCorrespondence()->getNumberOfTuples() << "\n";
205 const DataArrayInt* tmp=getCorrespondence();
206 oss << "- Correspondence : <<";
207 for(const int *it=tmp->begin();it!=tmp->end();it++)
212 oss << "- Number entity of the correspondence : 0\n";
219 MEDFileJointOneStep::MEDFileJointOneStep():_order(-1),_iteration(-1)
223 std::size_t MEDFileJointOneStep::getHeapMemorySizeWithoutChildren() const
225 return _correspondences.capacity()*sizeof(MCAuto<DataArrayInt>);
228 std::vector<const BigMemoryObject *> MEDFileJointOneStep::getDirectChildrenWithNull() const
230 return std::vector<const BigMemoryObject *>();
233 MEDFileJointOneStep *MEDFileJointOneStep::New(int dt, int it)
235 MEDFileJointOneStep* j = new MEDFileJointOneStep();
237 j->setIteration( it );
242 * Returns a new MEDFileJointOneStep.
243 * \param [in] fileName - the name of MED file to read.
244 * \param [in] mName - the name of the mesh to read.
245 * \param [in] jointName - the joint name.
246 * \param [in] num - the number of an iteration.
247 * \return MEDFileMesh * - a new instance of MEDFileJointOneStep.
248 * \throw If the file is not readable.
249 * \throw If there is no mesh with given attributes in the file.
251 MEDFileJointOneStep *MEDFileJointOneStep::New(const std::string& fileName, const std::string& mName, const std::string& jointName, int num)
253 MEDFileUtilities::CheckFileForRead(fileName);
254 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
255 return new MEDFileJointOneStep(fid, mName, jointName, num);
258 MEDFileJointOneStep* MEDFileJointOneStep::New(med_idt fid, const std::string& mName, const std::string& jointName, int num)
260 return new MEDFileJointOneStep( fid, mName, jointName, num);
263 MEDFileJointOneStep::MEDFileJointOneStep(med_idt fid, const std::string& mName, const std::string& jointName, int num)
265 int order, iteration, ncorrespondence;
266 MEDFILESAFECALLERRD0(MEDsubdomainComputingStepInfo,(fid, mName.c_str(), jointName.c_str(), num, &order, &iteration, &ncorrespondence));
267 MEDFileJointOneStep::setOrder(order);
268 MEDFileJointOneStep::setIteration(iteration);
269 for ( int cur_it = 1; cur_it <= ncorrespondence; ++cur_it )
272 med_entity_type loc_ent_type, rem_ent_type;
273 med_geometry_type loc_geo_type, rem_geo_type;
274 MEDFILESAFECALLERRD0(MEDsubdomainCorrespondenceSizeInfo,(fid, mName.c_str(), jointName.c_str(), order, iteration, cur_it,
275 &loc_ent_type, &loc_geo_type, &rem_ent_type, &rem_geo_type, &num_entity));
276 if ( num_entity > 0 )
278 MCAuto<DataArrayInt> correspondence=DataArrayInt::New();
279 correspondence->alloc(num_entity*2, 1);
280 MEDFILESAFECALLERRD0(MEDsubdomainCorrespondenceRd,(fid, mName.c_str(), jointName.c_str(), order, iteration, loc_ent_type,
281 loc_geo_type, rem_ent_type, rem_geo_type, correspondence->getPointer()));
282 MEDFileJointCorrespondence *cor=MEDFileJointCorrespondence::New();
283 cor->setIsNodal( loc_ent_type == MED_NODE );
284 cor->setLocalGeometryType ( convertGeometryType( loc_geo_type ));
285 cor->setRemoteGeometryType( convertGeometryType( rem_geo_type ));
286 cor->setCorrespondence( correspondence );
287 _correspondences.push_back(cor);
293 * Writes \a this joint into a MED file specified by its name.
294 * \param [in] fileName - the MED file name.
295 * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
296 * - 2 - erase; an existing file is removed.
297 * - 1 - append; same data should not be present in an existing file.
298 * - 0 - overwrite; same data present in an existing file is overwritten.
299 * \throw If the mesh name is not set.
300 * \throw If \a mode == 1 and the same data is present in an existing file.
302 void MEDFileJointOneStep::write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName) const
304 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
305 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
306 std::ostringstream oss; oss << "MEDFileJointOneStep : error on attempt to write in file : \"" << fileName << "\"";
307 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str());
308 if ( _correspondences.empty() )
309 throw INTERP_KERNEL::Exception("MEDFileJointOneStep::write : no correspondences defined !");
310 writeLL(fid, localMeshName, jointName);
313 void MEDFileJointOneStep::writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName) const
315 for(std::vector< MCAuto<MEDFileJointCorrespondence> >::const_iterator it=_correspondences.begin();it!=_correspondences.end();it++)
317 (*it)->writeLL(fid, localMeshName, jointName, getOrder(), getIteration());
321 void MEDFileJointOneStep::pushCorrespondence(MEDFileJointCorrespondence* correspondence)
324 throw INTERP_KERNEL::Exception("MEDFileJointCorrespondence::pushCorrespondence : invalid input pointer ! should be different from 0 !");
325 _correspondences.push_back(correspondence);
326 correspondence->incrRef();
329 int MEDFileJointOneStep::getNumberOfCorrespondences() const
331 return _correspondences.size();
334 /** Return a borrowed reference (caller is not responsible) */
335 MEDFileJointCorrespondence *MEDFileJointOneStep::getCorrespondenceAtPos(int i) const
337 if(i<0 || i>=(int)_correspondences.size())
339 std::ostringstream oss; oss << "MEDFileJointOneStep::getCorrespondenceAtPos : invalid correspondence id given in parameter ! Should be in [0;" << _correspondences.size() << ") !";
340 throw INTERP_KERNEL::Exception(oss.str().c_str());
342 const MEDFileJointCorrespondence* ret = _correspondences[i];
343 return const_cast<MEDFileJointCorrespondence *>( ret );
347 * Checks if \a this and another Joint are equal.
348 * \param [in] other - the Joint to compare with.
349 * \return bool - \c true if the Joints are equal, \c false, else.
351 bool MEDFileJointOneStep::isEqual(const MEDFileJointOneStep *other) const
353 if(_order!=other->_order)
355 if(_iteration!=other->_iteration)
357 if ( getNumberOfCorrespondences() != other->getNumberOfCorrespondences() )
360 std::vector<bool> found( getNumberOfCorrespondences(), false );
361 for(int i=0; i<getNumberOfCorrespondences(); i++)
364 for(j=0; j<getNumberOfCorrespondences(); j++)
367 getCorrespondenceAtPos(i)->isEqual(other->getCorrespondenceAtPos(j)))
373 if ( j == getNumberOfCorrespondences() )
379 MEDFileJointOneStep *MEDFileJointOneStep::deepCopy() const
381 std::vector< MCAuto<MEDFileJointCorrespondence> > correspondences(_correspondences.size());
383 for(std::vector< MCAuto<MEDFileJointCorrespondence> >::const_iterator it=_correspondences.begin();it!=_correspondences.end();it++,i++)
384 if((const MEDFileJointCorrespondence *)*it)
385 correspondences[i]=(*it)->deepCopy();
386 MCAuto<MEDFileJointOneStep> ret= new MEDFileJointOneStep;
387 ret->_correspondences=correspondences;
391 MEDFileJointOneStep *MEDFileJointOneStep::shallowCpy() const
393 MCAuto<MEDFileJointOneStep> ret=new MEDFileJointOneStep(*this);
398 * Returns a string describing \a this Joint. This description includes the correspondence and
399 * the number of correspondences.
400 * \return std::string - the joint information string.
402 std::string MEDFileJointOneStep::simpleRepr() const
404 std::ostringstream oss;
405 oss << "(*************************************)\n(* JOINT_ONE_STEP INFORMATION: *)\n(*************************************)\n";
406 oss << "- Number of the correspondences : <<" << _correspondences.size() << ">>\n";
407 for(std::vector< MCAuto<MEDFileJointCorrespondence> >::const_iterator it=_correspondences.begin();it!=_correspondences.end();it++)
409 oss << (*it)->simpleRepr();
414 INTERP_KERNEL::NormalizedCellType MEDFileJointOneStep::convertGeometryType(med_geometry_type geotype)
416 INTERP_KERNEL::NormalizedCellType result=INTERP_KERNEL::NORM_ERROR;
417 for(int i=0; i<MED_N_CELL_FIXED_GEO; i++)
419 if (typmai[i]==geotype)
428 std::size_t MEDFileJoint::getHeapMemorySizeWithoutChildren() const
430 return _joint.capacity()*sizeof(MCAuto<MEDFileJointOneStep>);
433 std::vector<const BigMemoryObject *> MEDFileJoint::getDirectChildrenWithNull() const
435 return std::vector<const BigMemoryObject *>();
438 MEDFileJoint *MEDFileJoint::New()
440 return new MEDFileJoint();
443 MEDFileJoint *MEDFileJoint::New(const std::string& fileName, const std::string& mName, int curJoint)
445 MEDFileUtilities::CheckFileForRead(fileName);
446 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
447 return new MEDFileJoint(fid,mName,curJoint);
450 MEDFileJoint *MEDFileJoint::New(med_idt fid, const std::string& mName, int curJoint)
452 return new MEDFileJoint(fid,mName,curJoint);
455 MEDFileJoint *MEDFileJoint::New(const std::string& jointName, const std::string& locMeshName, const std::string& remoteMeshName, int remoteMeshNum)
457 MEDFileJoint* j = new MEDFileJoint();
458 j->setJointName( jointName );
459 j->setLocalMeshName( locMeshName );
460 j->setRemoteMeshName( remoteMeshName );
461 j->setDomainNumber( remoteMeshNum );
465 MEDFileJoint::MEDFileJoint()
470 * Returns a new MEDFileJoint holding the mesh data that has been read from a given MED
471 * file. The Joint to load is specified by mesh name and a Joint iteration.
472 * \param [in] fileName - the name of MED file to read.
473 * \param [in] mName - the name of the mesh to read.
474 * \param [in] curJoint - the iteration number of current joint.
475 * \return MEDFileJoint * - a new instance of MEDFileJoint.
476 * \throw If the file is not readable.
477 * \throw If there is no mesh with given attributes in the file.
479 MEDFileJoint::MEDFileJoint(med_idt fid, const std::string& mName, int curJoint)
481 INTERP_KERNEL::AutoPtr<char> joint_name=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
482 INTERP_KERNEL::AutoPtr<char> desc_name=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
483 INTERP_KERNEL::AutoPtr<char> rem_mesh_name=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
484 int domain_number=0, nstep=0, nocstpncorrespondence=0;
485 MEDFILESAFECALLERRD0(MEDsubdomainJointInfo,(fid,mName.c_str(), curJoint, joint_name, desc_name, &domain_number,rem_mesh_name,
486 &nstep, &nocstpncorrespondence));
487 setLocalMeshName(mName);
488 setRemoteMeshName(MEDLoaderBase::buildStringFromFortran(rem_mesh_name,MED_NAME_SIZE));
489 setDescription(MEDLoaderBase::buildStringFromFortran(desc_name,MED_COMMENT_SIZE));
490 setJointName(MEDLoaderBase::buildStringFromFortran(joint_name,MED_NAME_SIZE));
491 setDomainNumber(domain_number);
492 for(int cur_step=1; cur_step <= nstep; ++cur_step)
494 MEDFileJointOneStep *cor=MEDFileJointOneStep::New(fid, mName.c_str(), getJointName(), cur_step);
495 _joint.push_back(cor);
499 void MEDFileJoint::writeLL(med_idt fid) const
501 // if ( _loc_mesh_name.empty() )
502 // throw INTERP_KERNEL::Exception("MEDFileJoint::write : name of a local mesh not defined!");
503 MEDFILESAFECALLERWR0(MEDsubdomainJointCr,(fid,getLocalMeshName().c_str(),getJointName().c_str(),getDescription().c_str(),getDomainNumber(),getRemoteMeshName().c_str()));
504 for(std::vector< MCAuto<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++)
505 (*it)->writeLL(fid, getLocalMeshName(),getJointName());
508 void MEDFileJoint::pushStep(MEDFileJointOneStep* step)
511 throw INTERP_KERNEL::Exception("MEDFileJoint::pushStep : invalid input pointer ! should be different from 0 !");
512 _joint.push_back(step);
516 int MEDFileJoint::getNumberOfSteps() const
518 return _joint.size();
521 /** Return a borrowed reference (caller is not responsible) */
522 MEDFileJointOneStep *MEDFileJoint::getStepAtPos(int i) const
524 if(i<0 || i>=(int)_joint.size())
526 std::ostringstream oss; oss << "MEDFileJoint::getStepAtPos : invalid step id given in parameter ! Should be in [0;" << _joint.size() << ") !";
527 throw INTERP_KERNEL::Exception(oss.str().c_str());
529 const MEDFileJointOneStep* ret = _joint[i];
530 return const_cast<MEDFileJointOneStep *>( ret );
534 * Checks if \a this and another Joint are equal.
535 * \param [in] other - the Joint to compare with.
536 * \return bool - \c true if the Joints are equal, \c false, else.
538 bool MEDFileJoint::isEqual(const MEDFileJoint *other) const
540 if(_loc_mesh_name!=other->_loc_mesh_name)
542 if(_joint_name!=other->_joint_name)
544 if(_desc_name!=other->_desc_name)
546 if(_rem_mesh_name!=other->_rem_mesh_name)
548 if(_domain_number!=other->_domain_number)
550 int nbTS(getNumberOfSteps());
551 if(nbTS!=other->getNumberOfSteps())
553 std::vector<bool> found(nbTS,false);
554 for(int i=0;i<nbTS;i++)
559 if(!found[j] && getStepAtPos(i)->isEqual(other->getStepAtPos(j)))
571 MEDFileJoint *MEDFileJoint::deepCopy() const
573 std::vector< MCAuto<MEDFileJointOneStep> > joint(_joint.size());
575 for(std::vector< MCAuto<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++,i++)
576 if((const MEDFileJointOneStep *)*it)
577 joint[i]=(*it)->deepCopy();
578 MCAuto<MEDFileJoint> ret=MEDFileJoint::New();
583 MEDFileJoint *MEDFileJoint::shallowCpy() const
585 MCAuto<MEDFileJoint> ret=new MEDFileJoint(*this);
589 bool MEDFileJoint::changeJointNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
591 for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
593 if((*it).first==_joint_name)
595 _joint_name=(*it).second;
603 * Returns a string describing \a this mesh. This description includes the correspondence and
604 * the number correspondence.
605 * \return std::string - the joint information string.
607 std::string MEDFileJoint::simpleRepr() const
609 std::ostringstream oss;
610 oss << "(*************************************)\n(* JOINT INFORMATION: *)\n(*************************************)\n";
611 oss << "- Local Mesh name : <<" << getLocalMeshName() << ">>\n";
612 oss << "- Remote Mesh name : <<" << getRemoteMeshName() << ">>\n";
613 oss << "- Description : <<" << getDescription() << ">>\n";
614 oss << "- Joint name : <<" << getJointName() << ">>\n";
615 oss << "- Domain number : " << getDomainNumber() << "\n";
616 for(std::vector< MCAuto<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++)
618 oss << (*it)->simpleRepr();
623 MEDFileJoints *MEDFileJoints::New()
625 return new MEDFileJoints;
628 MEDFileJoints *MEDFileJoints::New(const std::string& fileName, const std::string& meshName)
630 MEDFileUtilities::CheckFileForRead(fileName);
631 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
632 return new MEDFileJoints( fid, meshName );
635 MEDFileJoints *MEDFileJoints::New(med_idt fid, const std::string& meshName)
637 return new MEDFileJoints( fid, meshName );
640 void MEDFileJoints::writeLL(med_idt fid) const
642 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
646 std::string MEDFileJoints::getMeshName() const
648 for ( size_t i = 0; i <= _joints.size(); ++i )
649 if ( (const MEDFileJoint*) _joints[i] )
650 return _joints[i]->getLocalMeshName();
655 int MEDFileJoints::getNumberOfJoints() const
657 return _joints.size();
660 /** Return a borrowed reference (caller is not responsible) */
661 MEDFileJoint *MEDFileJoints::getJointAtPos(int i) const
663 if(i<0 || i>=(int)_joints.size())
665 std::ostringstream oss; oss << "MEDFileJoints::getJointAtPos : invalid joint id given in parameter ! Should be in [0;" << _joints.size() << ") !";
666 throw INTERP_KERNEL::Exception(oss.str().c_str());
668 const MEDFileJoint* ret = _joints[i];
669 return const_cast<MEDFileJoint *>( ret );
673 /** Return a borrowed reference (caller is not responsible) */
674 MEDFileJoint *MEDFileJoints::getJointWithName(const std::string& jname) const
676 std::vector<std::string> js=getJointsNames();
677 std::vector<std::string>::iterator it=std::find(js.begin(),js.end(),jname);
680 std::ostringstream oss; oss << "MEDFileJoints::getJointWithName : Joint \"" << jname << "\" does not exist in this ! Existing are : ";
681 std::copy(js.begin(),js.end(),std::ostream_iterator<std::string>(oss," "));
682 throw INTERP_KERNEL::Exception(oss.str().c_str());
684 return getJointAtPos((int)std::distance(js.begin(),it));
687 std::vector<std::string> MEDFileJoints::getJointsNames() const
689 std::vector<std::string> ret(_joints.size());
691 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++,i++)
693 const MEDFileJoint *f=(*it);
696 ret[i]=f->getJointName();
700 std::ostringstream oss; oss << "MEDFileJoints::getJointsNames : At rank #" << i << " joint is not defined !";
701 throw INTERP_KERNEL::Exception(oss.str().c_str());
707 bool MEDFileJoints::changeJointNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
710 for(std::vector< MCAuto<MEDFileJoint> >::iterator it=_joints.begin();it!=_joints.end();it++)
712 MEDFileJoint *cur(*it);
714 ret=cur->changeJointNames(modifTab) || ret;
719 void MEDFileJoints::resize(int newSize)
721 _joints.resize(newSize);
724 void MEDFileJoints::pushJoint(MEDFileJoint *joint)
727 throw INTERP_KERNEL::Exception("MEDFileJoints::pushJoint() : invalid input pointer ! should be different from 0 !");
728 if ( !_joints.empty() &&
729 _joints[0]->getLocalMeshName() != joint->getLocalMeshName() )
730 throw INTERP_KERNEL::Exception("MEDFileJoints::pushJoint() : different names of local meshes ! should be equal !");
732 _joints.push_back(joint);
736 void MEDFileJoints::setJointAtPos(int i, MEDFileJoint *joint)
739 throw INTERP_KERNEL::Exception("MEDFileJoints::setJointAtPos : invalid input pointer ! should be different from 0 !");
740 if(i>=(int)_joints.size())
746 void MEDFileJoints::destroyJointAtPos(int i)
748 if(i<0 || i>=(int)_joints.size())
750 std::ostringstream oss; oss << "MEDFileJoints::destroyJointAtPos : Invalid given id in input (" << i << ") should be in [0," << _joints.size() << ") !";
751 throw INTERP_KERNEL::Exception(oss.str().c_str());
753 _joints.erase(_joints.begin()+i);
756 MEDFileJoints::MEDFileJoints()
760 MEDFileJoints::MEDFileJoints(med_idt fid, const std::string& meshName)
762 int num_joint=MEDnSubdomainJoint(fid, meshName.c_str() );
763 for(int i = 1; i <= num_joint; i++)
764 _joints.push_back(MEDFileJoint::New(fid,meshName,i));
767 MEDFileJoints *MEDFileJoints::deepCopy() const
769 std::vector< MCAuto<MEDFileJoint> > joints(_joints.size());
771 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++,i++)
772 if((const MEDFileJoint *)*it)
773 joints[i]=(*it)->deepCopy();
774 MCAuto<MEDFileJoints> ret=MEDFileJoints::New();
779 std::size_t MEDFileJoints::getHeapMemorySizeWithoutChildren() const
781 return _joints.capacity()*(sizeof(MCAuto<MEDFileJoint>));
784 std::vector<const BigMemoryObject *> MEDFileJoints::getDirectChildrenWithNull() const
786 std::vector<const BigMemoryObject *> ret;
787 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
788 ret.push_back((const MEDFileJoint *)*it);
792 std::string MEDFileJoints::simpleRepr() const
794 std::ostringstream oss;
795 oss << "(*****************)\n(* MEDFileJoints *)\n(*****************)\n\n";
796 simpleReprWithoutHeader(oss);
800 void MEDFileJoints::simpleReprWithoutHeader(std::ostream& oss) const
802 int nbOfJoints=getNumberOfJoints();
803 oss << "There are " << nbOfJoints << " joints with the following names : \n";
804 std::vector<std::string> jns=getJointsNames();
805 for(int i=0;i<nbOfJoints;i++)
806 oss << " - #" << i << " \"" << jns[i] << "\"\n";
807 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
809 oss << (*it)->simpleRepr();