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<int> 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();
413 INTERP_KERNEL::NormalizedCellType MEDFileJointOneStep::convertGeometryType(med_geometry_type geotype)
415 INTERP_KERNEL::NormalizedCellType result=INTERP_KERNEL::NORM_ERROR;
416 for(int i=0; i<MED_N_CELL_FIXED_GEO; i++)
418 if (typmai[i]==geotype)
426 std::size_t MEDFileJoint::getHeapMemorySizeWithoutChildren() const
428 return _joint.capacity()*sizeof(MCAuto<MEDFileJointOneStep>);
431 std::vector<const BigMemoryObject *> MEDFileJoint::getDirectChildrenWithNull() const
433 return std::vector<const BigMemoryObject *>();
436 MEDFileJoint *MEDFileJoint::New()
438 return new MEDFileJoint();
441 MEDFileJoint *MEDFileJoint::New(const std::string& fileName, const std::string& mName, int curJoint)
443 MEDFileUtilities::CheckFileForRead(fileName);
444 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
445 return new MEDFileJoint(fid,mName,curJoint);
448 MEDFileJoint *MEDFileJoint::New(med_idt fid, const std::string& mName, int curJoint)
450 return new MEDFileJoint(fid,mName,curJoint);
453 MEDFileJoint *MEDFileJoint::New(const std::string& jointName, const std::string& locMeshName, const std::string& remoteMeshName, int remoteMeshNum)
455 MEDFileJoint* j = new MEDFileJoint();
456 j->setJointName( jointName );
457 j->setLocalMeshName( locMeshName );
458 j->setRemoteMeshName( remoteMeshName );
459 j->setDomainNumber( remoteMeshNum );
463 MEDFileJoint::MEDFileJoint()
468 * Returns a new MEDFileJoint holding the mesh data that has been read from a given MED
469 * file. The Joint to load is specified by mesh name and a Joint iteration.
470 * \param [in] fileName - the name of MED file to read.
471 * \param [in] mName - the name of the mesh to read.
472 * \param [in] curJoint - the iteration number of current joint.
473 * \return MEDFileJoint * - a new instance of MEDFileJoint.
474 * \throw If the file is not readable.
475 * \throw If there is no mesh with given attributes in the file.
477 MEDFileJoint::MEDFileJoint(med_idt fid, const std::string& mName, int curJoint)
479 INTERP_KERNEL::AutoPtr<char> joint_name=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
480 INTERP_KERNEL::AutoPtr<char> desc_name=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
481 INTERP_KERNEL::AutoPtr<char> rem_mesh_name=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
482 int domain_number=0, nstep=0, nocstpncorrespondence=0;
483 MEDFILESAFECALLERRD0(MEDsubdomainJointInfo,(fid,mName.c_str(), curJoint, joint_name, desc_name, &domain_number,rem_mesh_name,
484 &nstep, &nocstpncorrespondence));
485 setLocalMeshName(mName);
486 setRemoteMeshName(MEDLoaderBase::buildStringFromFortran(rem_mesh_name,MED_NAME_SIZE));
487 setDescription(MEDLoaderBase::buildStringFromFortran(desc_name,MED_COMMENT_SIZE));
488 setJointName(MEDLoaderBase::buildStringFromFortran(joint_name,MED_NAME_SIZE));
489 setDomainNumber(domain_number);
490 for(int cur_step=1; cur_step <= nstep; ++cur_step)
492 MEDFileJointOneStep *cor=MEDFileJointOneStep::New(fid, mName.c_str(), getJointName(), cur_step);
493 _joint.push_back(cor);
497 void MEDFileJoint::writeLL(med_idt fid) const
499 // if ( _loc_mesh_name.empty() )
500 // throw INTERP_KERNEL::Exception("MEDFileJoint::write : name of a local mesh not defined!");
501 MEDFILESAFECALLERWR0(MEDsubdomainJointCr,(fid,getLocalMeshName().c_str(),getJointName().c_str(),getDescription().c_str(),getDomainNumber(),getRemoteMeshName().c_str()));
502 for(std::vector< MCAuto<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++)
503 (*it)->writeLL(fid, getLocalMeshName(),getJointName());
506 void MEDFileJoint::pushStep(MEDFileJointOneStep* step)
509 throw INTERP_KERNEL::Exception("MEDFileJoint::pushStep : invalid input pointer ! should be different from 0 !");
510 _joint.push_back(step);
514 int MEDFileJoint::getNumberOfSteps() const
516 return _joint.size();
519 /** Return a borrowed reference (caller is not responsible) */
520 MEDFileJointOneStep *MEDFileJoint::getStepAtPos(int i) const
522 if(i<0 || i>=(int)_joint.size())
524 std::ostringstream oss; oss << "MEDFileJoint::getStepAtPos : invalid step id given in parameter ! Should be in [0;" << _joint.size() << ") !";
525 throw INTERP_KERNEL::Exception(oss.str().c_str());
527 const MEDFileJointOneStep* ret = _joint[i];
528 return const_cast<MEDFileJointOneStep *>( ret );
532 * Checks if \a this and another Joint are equal.
533 * \param [in] other - the Joint to compare with.
534 * \return bool - \c true if the Joints are equal, \c false, else.
536 bool MEDFileJoint::isEqual(const MEDFileJoint *other) const
538 if(_loc_mesh_name!=other->_loc_mesh_name)
540 if(_joint_name!=other->_joint_name)
542 if(_desc_name!=other->_desc_name)
544 if(_rem_mesh_name!=other->_rem_mesh_name)
546 if(_domain_number!=other->_domain_number)
548 std::vector<int> found( getNumberOfSteps(), false );
549 for(int i=0; i<getNumberOfSteps(); i++)
552 for(j=0; j<getNumberOfSteps(); j++)
555 getStepAtPos(i)->isEqual(other->getStepAtPos(j)))
561 if ( j == getNumberOfSteps() )
567 MEDFileJoint *MEDFileJoint::deepCopy() const
569 std::vector< MCAuto<MEDFileJointOneStep> > joint(_joint.size());
571 for(std::vector< MCAuto<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++,i++)
572 if((const MEDFileJointOneStep *)*it)
573 joint[i]=(*it)->deepCopy();
574 MCAuto<MEDFileJoint> ret=MEDFileJoint::New();
579 MEDFileJoint *MEDFileJoint::shallowCpy() const
581 MCAuto<MEDFileJoint> ret=new MEDFileJoint(*this);
585 bool MEDFileJoint::changeJointNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
587 for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
589 if((*it).first==_joint_name)
591 _joint_name=(*it).second;
599 * Returns a string describing \a this mesh. This description includes the correspondence and
600 * the number correspondence.
601 * \return std::string - the joint information string.
603 std::string MEDFileJoint::simpleRepr() const
605 std::ostringstream oss;
606 oss << "(*************************************)\n(* JOINT INFORMATION: *)\n(*************************************)\n";
607 oss << "- Local Mesh name : <<" << getLocalMeshName() << ">>\n";
608 oss << "- Remote Mesh name : <<" << getRemoteMeshName() << ">>\n";
609 oss << "- Description : <<" << getDescription() << ">>\n";
610 oss << "- Joint name : <<" << getJointName() << ">>\n";
611 oss << "- Domain number : " << getDomainNumber() << "\n";
612 for(std::vector< MCAuto<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++)
614 oss << (*it)->simpleRepr();
619 MEDFileJoints *MEDFileJoints::New()
621 return new MEDFileJoints;
624 MEDFileJoints *MEDFileJoints::New(const std::string& fileName, const std::string& meshName)
626 MEDFileUtilities::CheckFileForRead(fileName);
627 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
628 return new MEDFileJoints( fid, meshName );
631 MEDFileJoints *MEDFileJoints::New(med_idt fid, const std::string& meshName)
633 return new MEDFileJoints( fid, meshName );
636 void MEDFileJoints::writeLL(med_idt fid) const
638 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
642 std::string MEDFileJoints::getMeshName() const
644 for ( size_t i = 0; i <= _joints.size(); ++i )
645 if ( (const MEDFileJoint*) _joints[i] )
646 return _joints[i]->getLocalMeshName();
651 int MEDFileJoints::getNumberOfJoints() const
653 return _joints.size();
656 /** Return a borrowed reference (caller is not responsible) */
657 MEDFileJoint *MEDFileJoints::getJointAtPos(int i) const
659 if(i<0 || i>=(int)_joints.size())
661 std::ostringstream oss; oss << "MEDFileJoints::getJointAtPos : invalid joint id given in parameter ! Should be in [0;" << _joints.size() << ") !";
662 throw INTERP_KERNEL::Exception(oss.str().c_str());
664 const MEDFileJoint* ret = _joints[i];
665 return const_cast<MEDFileJoint *>( ret );
669 /** Return a borrowed reference (caller is not responsible) */
670 MEDFileJoint *MEDFileJoints::getJointWithName(const std::string& jname) const
672 std::vector<std::string> js=getJointsNames();
673 std::vector<std::string>::iterator it=std::find(js.begin(),js.end(),jname);
676 std::ostringstream oss; oss << "MEDFileJoints::getJointWithName : Joint \"" << jname << "\" does not exist in this ! Existing are : ";
677 std::copy(js.begin(),js.end(),std::ostream_iterator<std::string>(oss," "));
678 throw INTERP_KERNEL::Exception(oss.str().c_str());
680 return getJointAtPos((int)std::distance(js.begin(),it));
683 std::vector<std::string> MEDFileJoints::getJointsNames() const
685 std::vector<std::string> ret(_joints.size());
687 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++,i++)
689 const MEDFileJoint *f=(*it);
692 ret[i]=f->getJointName();
696 std::ostringstream oss; oss << "MEDFileJoints::getJointsNames : At rank #" << i << " joint is not defined !";
697 throw INTERP_KERNEL::Exception(oss.str().c_str());
703 bool MEDFileJoints::changeJointNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
706 for(std::vector< MCAuto<MEDFileJoint> >::iterator it=_joints.begin();it!=_joints.end();it++)
708 MEDFileJoint *cur(*it);
710 ret=cur->changeJointNames(modifTab) || ret;
715 void MEDFileJoints::resize(int newSize)
717 _joints.resize(newSize);
720 void MEDFileJoints::pushJoint(MEDFileJoint *joint)
723 throw INTERP_KERNEL::Exception("MEDFileJoints::pushJoint() : invalid input pointer ! should be different from 0 !");
724 if ( !_joints.empty() &&
725 _joints[0]->getLocalMeshName() != joint->getLocalMeshName() )
726 throw INTERP_KERNEL::Exception("MEDFileJoints::pushJoint() : different names of local meshes ! should be equal !");
728 _joints.push_back(joint);
732 void MEDFileJoints::setJointAtPos(int i, MEDFileJoint *joint)
735 throw INTERP_KERNEL::Exception("MEDFileJoints::setJointAtPos : invalid input pointer ! should be different from 0 !");
736 if(i>=(int)_joints.size())
742 void MEDFileJoints::destroyJointAtPos(int i)
744 if(i<0 || i>=(int)_joints.size())
746 std::ostringstream oss; oss << "MEDFileJoints::destroyJointAtPos : Invalid given id in input (" << i << ") should be in [0," << _joints.size() << ") !";
747 throw INTERP_KERNEL::Exception(oss.str().c_str());
749 _joints.erase(_joints.begin()+i);
752 MEDFileJoints::MEDFileJoints()
756 MEDFileJoints::MEDFileJoints(med_idt fid, const std::string& meshName)
758 int num_joint=MEDnSubdomainJoint(fid, meshName.c_str() );
759 for(int i = 1; i <= num_joint; i++)
760 _joints.push_back(MEDFileJoint::New(fid,meshName,i));
763 MEDFileJoints *MEDFileJoints::deepCopy() const
765 std::vector< MCAuto<MEDFileJoint> > joints(_joints.size());
767 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++,i++)
768 if((const MEDFileJoint *)*it)
769 joints[i]=(*it)->deepCopy();
770 MCAuto<MEDFileJoints> ret=MEDFileJoints::New();
775 std::size_t MEDFileJoints::getHeapMemorySizeWithoutChildren() const
777 return _joints.capacity()*(sizeof(MCAuto<MEDFileJoint>));
780 std::vector<const BigMemoryObject *> MEDFileJoints::getDirectChildrenWithNull() const
782 std::vector<const BigMemoryObject *> ret;
783 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
784 ret.push_back((const MEDFileJoint *)*it);
788 std::string MEDFileJoints::simpleRepr() const
790 std::ostringstream oss;
791 oss << "(*****************)\n(* MEDFileJoints *)\n(*****************)\n\n";
792 simpleReprWithoutHeader(oss);
796 void MEDFileJoints::simpleReprWithoutHeader(std::ostream& oss) const
798 int nbOfJoints=getNumberOfJoints();
799 oss << "There are " << nbOfJoints << " joints with the following names : \n";
800 std::vector<std::string> jns=getJointsNames();
801 for(int i=0;i<nbOfJoints;i++)
802 oss << " - #" << i << " \"" << jns[i] << "\"\n";
803 for(std::vector< MCAuto<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
805 oss << (*it)->simpleRepr();