1 // Copyright (C) 2007-2015 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 "MEDFileUtilities.hxx"
22 #include "MEDLoader.hxx"
23 #include "MEDLoaderBase.hxx"
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 ParaMEDMEM;
34 std::size_t MEDFileJointCorrespondence::getHeapMemorySizeWithoutChildren() const
36 return sizeof(MEDCouplingAutoRefCountObjectPtr<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 MEDsubdomainCorrespondenceWr(fid, localMeshName.c_str(), jointName.c_str(),
138 _correspondence->getNbOfElems()/2,
139 _correspondence->getConstPointer());
143 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::deepCpy() const
179 MEDCouplingAutoRefCountObjectPtr<MEDFileJointCorrespondence> ret=new MEDFileJointCorrespondence(*this);
183 MEDFileJointCorrespondence *MEDFileJointCorrespondence::shallowCpy() const
185 MEDCouplingAutoRefCountObjectPtr<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(MEDCouplingAutoRefCountObjectPtr<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 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 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 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> correspondence=DataArrayInt::New();
279 correspondence->alloc(num_entity*2, 1);
280 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< MEDCouplingAutoRefCountObjectPtr<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::deepCpy() const
381 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJointCorrespondence> > correspondences(_correspondences.size());
383 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJointCorrespondence> >::const_iterator it=_correspondences.begin();it!=_correspondences.end();it++,i++)
384 if((const MEDFileJointCorrespondence *)*it)
385 correspondences[i]=(*it)->deepCpy();
386 MEDCouplingAutoRefCountObjectPtr<MEDFileJointOneStep> ret= new MEDFileJointOneStep;
387 ret->_correspondences=correspondences;
391 MEDFileJointOneStep *MEDFileJointOneStep::shallowCpy() const
393 MEDCouplingAutoRefCountObjectPtr<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< MEDCouplingAutoRefCountObjectPtr<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(MEDCouplingAutoRefCountObjectPtr<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 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);
498 * Writes \a this joint into a MED file specified by its name.
499 * \param [in] fileName - the MED file name.
500 * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
501 * - 2 - erase; an existing file is removed.
502 * - 1 - append; same data should not be present in an existing file.
503 * - 0 - overwrite; same data present in an existing file is overwritten.
504 * \throw If the mesh name is not set.
505 * \throw If \a mode == 1 and the same data is present in an existing file.
507 void MEDFileJoint::write(const std::string& fileName, int mode) const
509 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
510 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
511 std::ostringstream oss; oss << "MEDFileJoint : error on attempt to write in file : \"" << fileName << "\"";
512 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str());
516 void MEDFileJoint::write(med_idt fid) const
518 // if ( _loc_mesh_name.empty() )
519 // throw INTERP_KERNEL::Exception("MEDFileJoint::write : name of a local mesh not defined!");
520 MEDsubdomainJointCr(fid,getLocalMeshName().c_str(),getJointName().c_str(),getDescription().c_str(),getDomainNumber(),getRemoteMeshName().c_str());
521 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++) {
522 (*it)->writeLL(fid, getLocalMeshName(),getJointName());
526 void MEDFileJoint::pushStep(MEDFileJointOneStep* step)
529 throw INTERP_KERNEL::Exception("MEDFileJoint::pushStep : invalid input pointer ! should be different from 0 !");
530 _joint.push_back(step);
534 int MEDFileJoint::getNumberOfSteps() const
536 return _joint.size();
539 /** Return a borrowed reference (caller is not responsible) */
540 MEDFileJointOneStep *MEDFileJoint::getStepAtPos(int i) const
542 if(i<0 || i>=(int)_joint.size())
544 std::ostringstream oss; oss << "MEDFileJoint::getStepAtPos : invalid step id given in parameter ! Should be in [0;" << _joint.size() << ") !";
545 throw INTERP_KERNEL::Exception(oss.str().c_str());
547 const MEDFileJointOneStep* ret = _joint[i];
548 return const_cast<MEDFileJointOneStep *>( ret );
552 * Checks if \a this and another Joint are equal.
553 * \param [in] other - the Joint to compare with.
554 * \return bool - \c true if the Joints are equal, \c false, else.
556 bool MEDFileJoint::isEqual(const MEDFileJoint *other) const
558 if(_loc_mesh_name!=other->_loc_mesh_name)
560 if(_joint_name!=other->_joint_name)
562 if(_desc_name!=other->_desc_name)
564 if(_rem_mesh_name!=other->_rem_mesh_name)
566 if(_domain_number!=other->_domain_number)
568 std::vector<int> found( getNumberOfSteps(), false );
569 for(int i=0; i<getNumberOfSteps(); i++)
572 for(j=0; j<getNumberOfSteps(); j++)
575 getStepAtPos(i)->isEqual(other->getStepAtPos(j)))
581 if ( j == getNumberOfSteps() )
587 MEDFileJoint *MEDFileJoint::deepCpy() const
589 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJointOneStep> > joint(_joint.size());
591 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++,i++)
592 if((const MEDFileJointOneStep *)*it)
593 joint[i]=(*it)->deepCpy();
594 MEDCouplingAutoRefCountObjectPtr<MEDFileJoint> ret=MEDFileJoint::New();
599 MEDFileJoint *MEDFileJoint::shallowCpy() const
601 MEDCouplingAutoRefCountObjectPtr<MEDFileJoint> ret=new MEDFileJoint(*this);
605 bool MEDFileJoint::changeJointNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
607 for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
609 if((*it).first==_joint_name)
611 _joint_name=(*it).second;
619 * Returns a string describing \a this mesh. This description includes the correspondence and
620 * the number correspondence.
621 * \return std::string - the joint information string.
623 std::string MEDFileJoint::simpleRepr() const
625 std::ostringstream oss;
626 oss << "(*************************************)\n(* JOINT INFORMATION: *)\n(*************************************)\n";
627 oss << "- Local Mesh name : <<" << getLocalMeshName() << ">>\n";
628 oss << "- Remote Mesh name : <<" << getRemoteMeshName() << ">>\n";
629 oss << "- Description : <<" << getDescription() << ">>\n";
630 oss << "- Joint name : <<" << getJointName() << ">>\n";
631 oss << "- Domain number : " << getDomainNumber() << "\n";
632 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJointOneStep> >::const_iterator it=_joint.begin();it!=_joint.end();it++)
634 oss << (*it)->simpleRepr();
639 MEDFileJoints *MEDFileJoints::New()
641 return new MEDFileJoints;
644 MEDFileJoints *MEDFileJoints::New(const std::string& fileName, const std::string& meshName)
646 MEDFileUtilities::CheckFileForRead(fileName);
647 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(), MED_ACC_RDONLY);
648 return new MEDFileJoints( fid, meshName );
651 MEDFileJoints *MEDFileJoints::New(med_idt fid, const std::string& meshName)
653 return new MEDFileJoints( fid, meshName );
656 void MEDFileJoints::write(med_idt fid) const
658 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
664 void MEDFileJoints::write(const std::string& fileName, int mode) const
666 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
667 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
668 std::ostringstream oss; oss << "MEDFileJoints : error on attempt to write in file : \"" << fileName << "\"";
669 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str());
673 std::string MEDFileJoints::getMeshName() const
675 for ( size_t i = 0; i <= _joints.size(); ++i )
676 if ( (const MEDFileJoint*) _joints[i] )
677 return _joints[i]->getLocalMeshName();
682 int MEDFileJoints::getNumberOfJoints() const
684 return _joints.size();
687 /** Return a borrowed reference (caller is not responsible) */
688 MEDFileJoint *MEDFileJoints::getJointAtPos(int i) const
690 if(i<0 || i>=(int)_joints.size())
692 std::ostringstream oss; oss << "MEDFileJoints::getJointAtPos : invalid joint id given in parameter ! Should be in [0;" << _joints.size() << ") !";
693 throw INTERP_KERNEL::Exception(oss.str().c_str());
695 const MEDFileJoint* ret = _joints[i];
696 return const_cast<MEDFileJoint *>( ret );
700 /** Return a borrowed reference (caller is not responsible) */
701 MEDFileJoint *MEDFileJoints::getJointWithName(const std::string& jname) const
703 std::vector<std::string> js=getJointsNames();
704 std::vector<std::string>::iterator it=std::find(js.begin(),js.end(),jname);
707 std::ostringstream oss; oss << "MEDFileJoints::getJointWithName : Joint \"" << jname << "\" does not exist in this ! Existing are : ";
708 std::copy(js.begin(),js.end(),std::ostream_iterator<std::string>(oss," "));
709 throw INTERP_KERNEL::Exception(oss.str().c_str());
711 return getJointAtPos((int)std::distance(js.begin(),it));
714 std::vector<std::string> MEDFileJoints::getJointsNames() const
716 std::vector<std::string> ret(_joints.size());
718 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++,i++)
720 const MEDFileJoint *f=(*it);
723 ret[i]=f->getJointName();
727 std::ostringstream oss; oss << "MEDFileJoints::getJointsNames : At rank #" << i << " joint is not defined !";
728 throw INTERP_KERNEL::Exception(oss.str().c_str());
734 bool MEDFileJoints::changeJointNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
737 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJoint> >::iterator it=_joints.begin();it!=_joints.end();it++)
739 MEDFileJoint *cur(*it);
741 ret=cur->changeJointNames(modifTab) || ret;
746 void MEDFileJoints::resize(int newSize)
748 _joints.resize(newSize);
751 void MEDFileJoints::pushJoint(MEDFileJoint *joint)
754 throw INTERP_KERNEL::Exception("MEDFileJoints::pushJoint() : invalid input pointer ! should be different from 0 !");
755 if ( !_joints.empty() &&
756 _joints[0]->getLocalMeshName() != joint->getLocalMeshName() )
757 throw INTERP_KERNEL::Exception("MEDFileJoints::pushJoint() : different names of local meshes ! should be equal !");
759 _joints.push_back(joint);
763 void MEDFileJoints::setJointAtPos(int i, MEDFileJoint *joint)
766 throw INTERP_KERNEL::Exception("MEDFileJoints::setJointAtPos : invalid input pointer ! should be different from 0 !");
767 if(i>=(int)_joints.size())
773 void MEDFileJoints::destroyJointAtPos(int i)
775 if(i<0 || i>=(int)_joints.size())
777 std::ostringstream oss; oss << "MEDFileJoints::destroyJointAtPos : Invalid given id in input (" << i << ") should be in [0," << _joints.size() << ") !";
778 throw INTERP_KERNEL::Exception(oss.str().c_str());
780 _joints.erase(_joints.begin()+i);
783 MEDFileJoints::MEDFileJoints()
787 MEDFileJoints::MEDFileJoints(med_idt fid, const std::string& meshName)
789 int num_joint=MEDnSubdomainJoint(fid, meshName.c_str() );
790 for(int i = 1; i <= num_joint; i++)
791 _joints.push_back(MEDFileJoint::New(fid,meshName,i));
794 MEDFileJoints *MEDFileJoints::deepCpy() const
796 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJoint> > joints(_joints.size());
798 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++,i++)
799 if((const MEDFileJoint *)*it)
800 joints[i]=(*it)->deepCpy();
801 MEDCouplingAutoRefCountObjectPtr<MEDFileJoints> ret=MEDFileJoints::New();
806 std::size_t MEDFileJoints::getHeapMemorySizeWithoutChildren() const
808 return _joints.capacity()*(sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileJoint>));
811 std::vector<const BigMemoryObject *> MEDFileJoints::getDirectChildrenWithNull() const
813 std::vector<const BigMemoryObject *> ret;
814 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
815 ret.push_back((const MEDFileJoint *)*it);
819 std::string MEDFileJoints::simpleRepr() const
821 std::ostringstream oss;
822 oss << "(*****************)\n(* MEDFileJoints *)\n(*****************)\n\n";
823 simpleReprWithoutHeader(oss);
827 void MEDFileJoints::simpleReprWithoutHeader(std::ostream& oss) const
829 int nbOfJoints=getNumberOfJoints();
830 oss << "There are " << nbOfJoints << " joints with the following names : \n";
831 std::vector<std::string> jns=getJointsNames();
832 for(int i=0;i<nbOfJoints;i++)
833 oss << " - #" << i << " \"" << jns[i] << "\"\n";
834 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileJoint> >::const_iterator it=_joints.begin();it!=_joints.end();it++)
836 oss << (*it)->simpleRepr();