const char MEDFileMesh::DFT_FAM_NAME[]="FAMILLE_ZERO";
-MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.),_univ_wr_status(true)
+MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.),_univ_wr_status(true),_axis_type(AX_CART)
{
}
std::vector<const BigMemoryObject *> MEDFileMesh::getDirectChildrenWithNull() const
{
- return std::vector<const BigMemoryObject *>();
+ std::vector<const BigMemoryObject *> ret(1);
+ ret[0]=(const MEDFileEquivalences *)_equiv;
+ return ret;
}
/*!
MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
int dt,it;
std::string dummy2;
- MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
+ ParaMEDMEM::MEDCouplingAxisType dummy3;
+ MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> ret;
switch(meshType)
{
case UNSTRUCTURED:
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
- ret->loadUMeshFromFile(fid,ms.front(),dt,it,mrs);
- ret->loadJointsFromFile(fid);
- return (MEDFileUMesh *)ret.retn();
+ ret=MEDFileUMesh::New();
+ break;
}
case CARTESIAN:
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
- ret->loadCMeshFromFile(fid,ms.front(),dt,it,mrs);
- ret->loadJointsFromFile(fid);
- return (MEDFileCMesh *)ret.retn();
+ ret=MEDFileCMesh::New();
+ break;
}
case CURVE_LINEAR:
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=MEDFileCurveLinearMesh::New();
- ret->loadCLMeshFromFile(fid,ms.front(),dt,it,mrs);
- ret->loadJointsFromFile(fid);
- return (MEDFileCurveLinearMesh *)ret.retn();
+ ret=MEDFileCurveLinearMesh::New();
+ break;
}
default:
{
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
+ ret->loadLLWithAdditionalItems(fid,ms.front(),dt,it,mrs);
+ return ret.retn();
}
/*!
MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
int dummy0,dummy1;
std::string dummy2;
- MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
+ ParaMEDMEM::MEDCouplingAxisType dummy3;
+ MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy3,dummy0,dummy1,dummy2);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> ret;
switch(meshType)
{
case UNSTRUCTURED:
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
- ret->loadUMeshFromFile(fid,mName,dt,it,mrs);
- ret->loadJointsFromFile(fid,joints);
- return (MEDFileUMesh *)ret.retn();
+ ret=MEDFileUMesh::New();
+ break;
}
case CARTESIAN:
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
- ret->loadCMeshFromFile(fid,mName,dt,it,mrs);
- ret->loadJointsFromFile(fid,joints);
- return (MEDFileCMesh *)ret.retn();
+ ret=MEDFileCMesh::New();
+ break;
}
case CURVE_LINEAR:
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=MEDFileCurveLinearMesh::New();
- ret->loadCLMeshFromFile(fid,mName,dt,it,mrs);
- ret->loadJointsFromFile(fid,joints);
- return (MEDFileCurveLinearMesh *)ret.retn();
+ ret=MEDFileCurveLinearMesh::New();
+ break;
}
default:
{
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
+ ret->loadLLWithAdditionalItems(fid,mName,dt,it,mrs);
+ return ret.retn();
}
/*!
if(_name.empty())
throw INTERP_KERNEL::Exception("MEDFileMesh : name is empty. MED file ask for a NON EMPTY name !");
writeLL(fid);
+ writeJoints(fid);
+ const MEDFileEquivalences *eqs(_equiv);
+ if(eqs)
+ eqs->write(fid);
}
/*!
return false;
if(!areFamsEqual(other,what))
return false;
+ if(!areEquivalencesEqual(other,what))
+ return false;
return true;
}
return ret;
}
+/*!
+ * Returns names of all families of \a this mesh but like they would be in file.
+ * This method is here only for MED file families gurus. If you are a kind user forget this method :-)
+ * This method is only useful for aggressive users that want to have in their file a same family lying both on cells and on nodes. This is not a good idea for lisibility !
+ * For your information internaly in memory such families are renamed to have a nicer API.
+ */
+std::vector<std::string> MEDFileMesh::getFamiliesNamesWithFilePointOfView() const
+{
+ std::vector<std::string> ret(getFamiliesNames());
+ MEDFileMeshL2::RenameFamiliesFromMemToFile(ret);
+ return ret;
+}
+
+std::string MEDFileMesh::GetMagicFamilyStr()
+{
+ return std::string(MEDFileMeshL2::ZE_SEP_FOR_FAMILY_KILLERS);
+}
+
/*!
* Changes a name of every family, included in one group only, to be same as the group name.
* \throw If there are families with equal names in \a this mesh.
std::vector<int> MEDFileMesh::getDistributionOfTypes(int meshDimRelToMax) const
{
- MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mLev(getGenMeshAtLevel(meshDimRelToMax));
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mLev(getMeshAtLevel(meshDimRelToMax));
return mLev->getDistributionOfTypes();
}
+void MEDFileMesh::loadLLWithAdditionalItems(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+{
+ loadLL(fid,mName,dt,it,mrs);
+ loadJointsFromFile(fid);
+ loadEquivalences(fid);
+}
+
void MEDFileMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp)
{
famArr->applyLin(offset>0?1:-1,offset,0);
int dt,it;
ParaMEDMEM::MEDCouplingMeshType meshType;
std::string dummy2;
- MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
+ ParaMEDMEM::MEDCouplingAxisType dummy3;
+ MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2);
return new MEDFileUMesh(fid,ms.front(),dt,it,mrs);
}
MEDFileMesh *MEDFileUMesh::shallowCpy() const
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=new MEDFileUMesh(*this);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(new MEDFileUMesh(*this));
return ret.retn();
}
MEDFileMesh *MEDFileUMesh::deepCpy() const
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=new MEDFileUMesh(*this);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(new MEDFileUMesh(*this));
+ ret->deepCpyEquivalences(*this);
if((const DataArrayDouble*)_coords)
ret->_coords=_coords->deepCpy();
if((const DataArrayInt*)_fam_coords)
MEDFileUMesh::MEDFileUMesh(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
try
{
- loadUMeshFromFile(fid,mName,dt,it,mrs);
- loadJointsFromFile(fid);
- }
+ loadLLWithAdditionalItems(fid,mName,dt,it,mrs);
+}
catch(INTERP_KERNEL::Exception& e)
{
throw e;
* This method loads only a part of specified cells (given by range of cell ID per geometric type)
* See MEDFileUMesh::LoadPartOf for detailed description.
*
- * \sa loadUMeshFromFile
+ * \sa loadLL
*/
void MEDFileUMesh::loadPartUMeshFromFile(med_idt fid, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
{
ParaMEDMEM::MEDCouplingMeshType meshType;
int dummy0,dummy1;
std::string dummy2;
- int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2));
+ ParaMEDMEM::MEDCouplingAxisType dummy3;
+ int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy3,dummy0,dummy1,dummy2));
if(meshType!=UNSTRUCTURED)
{
std::ostringstream oss; oss << "loadPartUMeshFromFile : Trying to load as unstructured an existing mesh with name '" << mName << "' !";
_joints = MEDFileJoints::New( fid, _name );
}
+void MEDFileMesh::loadEquivalences(med_idt fid)
+{
+ int nbOfEq(MEDFileEquivalences::PresenceOfEquivalences(fid,_name));
+ if(nbOfEq>0)
+ _equiv=MEDFileEquivalences::Load(fid,nbOfEq,this);
+}
+
+void MEDFileMesh::deepCpyEquivalences(const MEDFileMesh& other)
+{
+ const MEDFileEquivalences *equiv(other._equiv);
+ if(equiv)
+ _equiv=equiv->deepCpy(this);
+}
+
+bool MEDFileMesh::areEquivalencesEqual(const MEDFileMesh *other, std::string& what) const
+{
+ const MEDFileEquivalences *thisEq(_equiv),*otherEq(other->_equiv);
+ if(!thisEq && !otherEq)
+ return true;
+ if(thisEq && otherEq)
+ return thisEq->isEqual(otherEq,what);
+ else
+ {
+ what+="Equivalence differs : defined in this and not in other (or reversely) !";
+ return false;
+ }
+}
+
+void MEDFileMesh::getEquivalencesRepr(std::ostream& oss) const
+{
+ const MEDFileEquivalences *equiv(_equiv);
+ if(!equiv)
+ return ;
+ oss << "(******************************)\n(* EQUIVALENCES OF THE MESH : *)\n(******************************)\n";
+ _equiv->getRepr(oss);
+}
+
+void MEDFileMesh::checkCartesian() const
+{
+ if(getAxType()!=AX_CART)
+ {
+ std::ostringstream oss; oss << "MEDFileMesh::checkCartesian : request for method that is dedicated to a cartesian convention ! But you are not in cartesian convention (" << DataArray::GetAxTypeRepr(getAxType()) << ").";
+ oss << std::endl << "To perform operation you have two possiblities :" << std::endl;
+ oss << " - call setAxType(AX_CART)" << std::endl;
+ oss << " - call cartesianize()";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+}
+
/*!
* \brief Return number of joints, which is equal to number of adjacent mesh domains
*/
-int MEDFileMesh::getNumberOfJoints()
+int MEDFileMesh::getNumberOfJoints() const
{
- return ( (MEDFileJoints*) _joints ) ? _joints->getNumberOfJoints() : 0;
+ return ( (const MEDFileJoints *) _joints ) ? _joints->getNumberOfJoints() : 0;
}
/*!
*
* \sa loadPartUMeshFromFile
*/
-void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+void MEDFileUMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
{
MEDFileUMeshL2 loaderl2;
ParaMEDMEM::MEDCouplingMeshType meshType;
int dummy0,dummy1;
std::string dummy2;
- int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2));
+ ParaMEDMEM::MEDCouplingAxisType axType;
+ int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dummy2));
+ setAxType(axType);
if(meshType!=UNSTRUCTURED)
{
std::ostringstream oss; oss << "Trying to load as unstructured an existing mesh with name '" << mName << "' !";
MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
}
- MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit));
+ MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MEDFileMeshL2::TraduceAxisTypeRev(getAxType()),comp,unit));
if(_univ_wr_status)
MEDFILESAFECALLERWR0(MEDmeshUniversalNameWr,(fid,maa));
std::string meshName(MEDLoaderBase::buildStringFromFortran(maa,MED_NAME_SIZE));
if((const MEDFileUMeshSplitL1 *)(*it)!=0)
(*it)->write(fid,meshName,mdim);
MEDFileUMeshL2::WriteFamiliesAndGrps(fid,meshName,_families,_groups,_too_long_str);
-
- writeJoints(fid);
}
/*!
}
oss << std::endl << std::endl;
getFamilyRepr(oss);
+ getEquivalencesRepr(oss);
return oss.str();
}
}
}
+MEDFileMesh *MEDFileUMesh::cartesianize() const
+{
+ if(getAxType()==AX_CART)
+ {
+ incrRef();
+ return const_cast<MEDFileUMesh *>(this);
+ }
+ else
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(new MEDFileUMesh(*this));
+ const DataArrayDouble *coords(_coords);
+ if(!coords)
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::cartesianize : coordinates are null !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsCart(_coords->cartesianize(getAxType()));
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::iterator it=ret->_ms.begin();it!=ret->_ms.end();it++)
+ if((const MEDFileUMeshSplitL1 *)(*it))
+ *it=(*it)->shallowCpyUsingCoords(coordsCart);
+ ret->_coords=coordsCart;
+ ret->setAxType(AX_CART);
+ return ret.retn();
+ }
+}
+
/*!
* Returns the optional numbers of mesh entities of a given dimension transformed using
* DataArrayInt::invertArrayN2O2O2N().
* \return MEDCouplingUMesh * - a pointer to MEDCouplingUMesh that the caller is to
* delete using decrRef() as it is no more needed.
* \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
- * \sa getGenMeshAtLevel()
*/
MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const
{
return l1->getWholeMesh(renum);
}
-/*!
- * Returns a MEDCouplingUMesh of a given relative dimension.
- * \warning If \a meshDimRelToMaxExt == 1 (which means nodes), the returned mesh **is not
- * valid**. This is a feature, because MEDLoader does not create cells that do not exist!
- * To build a valid MEDCouplingUMesh from the returned one in this case,
- * call MEDCouplingUMesh::Build0DMeshFromCoords().
- * \param [in] meshDimRelToMax - the relative dimension of interest.
- * \param [in] renum - if \c true, the returned mesh is permuted according to the
- * optional numbers of mesh entities.
- * \return MEDCouplingMesh * - a pointer to MEDCouplingUMesh that the caller is to
- * delete using decrRef() as it is no more needed.
- * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a this mesh.
- * \sa getMeshAtLevel()
- */
-MEDCouplingMesh *MEDFileUMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const
-{
- return getMeshAtLevel(meshDimRelToMax,renum);
-}
-
std::vector<int> MEDFileUMesh::getDistributionOfTypes(int meshDimRelToMax) const
{
const MEDFileUMeshSplitL1 *l1(getMeshAtLevSafe(meshDimRelToMax));
return sp->getGeoTypes();
}
+int MEDFileUMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
+{
+ const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(ct);
+ const MEDFileUMeshSplitL1 *sp(getMeshAtLevSafe( ((int)cm.getDimension())-getMeshDimension() ));
+ return sp->getNumberOfCellsWithType(ct);
+}
+
/*!
* This method extracts from whole family field ids the part relative to the input parameter \a gt.
* \param [in] gt - the geometric type for which the family field is asked.
{
if(!coords)
throw INTERP_KERNEL::Exception("MEDFileUMesh::setCoords : null pointer in input !");
+ if(coords==(DataArrayDouble *)_coords)
+ return ;
coords->checkAllocated();
int nbOfTuples=coords->getNumberOfTuples();
_coords=coords;
return ret;
}
+/*! \cond HIDDEN_ITEMS */
struct MEDLoaderAccVisit1
{
MEDLoaderAccVisit1():_new_nb_of_nodes(0) { }
int operator()(bool val) { return val?_new_nb_of_nodes++:-1; }
int _new_nb_of_nodes;
};
+/*! \endcond */
/*!
* Array returned is the correspondance in \b old \b to \b new format. The returned array is newly created and should be dealt by the caller.
continue;
MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1Tmp(getMeshAtLevel(*lev));
MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1(dynamic_cast<MEDCouplingUMesh *>(m1Tmp->deepCpy()));
- {
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> notUsed(m1->convertLinearCellsToQuadratic(conversionType));
- }
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> m1Coords(m1->getCoords()->selectByTupleId2(initialNbNodes,m1->getNumberOfNodes(),1));
- DataArrayInt *b(0);
- bool a(partZeCoords->areIncludedInMe(m1Coords,eps,b));
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> bSafe(b);
- if(!a)
+ if(m1->getMeshDimension()!=0)
{
- std::ostringstream oss; oss << "MEDFileUMesh::linearCellsToQuadratic : for level " << *lev << " problem to identify nodes generated !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> notUsed(m1->convertLinearCellsToQuadratic(conversionType));
+ }//kill unused notUsed var
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> m1Coords(m1->getCoords()->selectByTupleId2(initialNbNodes,m1->getNumberOfNodes(),1));
+ DataArrayInt *b(0);
+ bool a(partZeCoords->areIncludedInMe(m1Coords,eps,b));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> bSafe(b);
+ if(!a)
+ {
+ std::ostringstream oss; oss << "MEDFileUMesh::linearCellsToQuadratic : for level " << *lev << " problem to identify nodes generated !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ b->applyLin(1,initialNbNodes);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> l0(DataArrayInt::New()); l0->alloc(initialNbNodes,1); l0->iota();
+ std::vector<const DataArrayInt *> v(2); v[0]=l0; v[1]=b;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renum(DataArrayInt::Aggregate(v));
+ m1->renumberNodesInConn(renum->begin());
}
- b->applyLin(1,initialNbNodes);
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> l0(DataArrayInt::New()); l0->alloc(initialNbNodes,1); l0->iota();
- std::vector<const DataArrayInt *> v(2); v[0]=l0; v[1]=b;
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renum(DataArrayInt::Aggregate(v));
- m1->renumberNodesInConn(renum->begin());
m1->setCoords(zeCoords);
ret->setMeshAtLevel(*lev,m1);
famField=getFamilyFieldAtLevel(*lev);
forceComputationOfParts();
tinyDouble.clear(); tinyInt.clear(); tinyStr.clear(); bigArraysI.clear(); bigArrayD=0;
std::vector<int> layer0;
- layer0.push_back(_order); //0 i
- layer0.push_back(_iteration);//1 i
- layer0.push_back(getSpaceDimension());//2 i
+ layer0.push_back(getAxType());//0 i
+ layer0.push_back(_order); //1 i
+ layer0.push_back(_iteration);//2 i
+ layer0.push_back(getSpaceDimension());//3 i
tinyDouble.push_back(_time);//0 d
tinyStr.push_back(_name);//0 s
tinyStr.push_back(_desc_name);//1 s
for(int i=0;i<getSpaceDimension();i++)
tinyStr.push_back(_coords->getInfoOnComponent(i));
- layer0.push_back((int)_families.size());//3 i <- key info aa layer#0
+ layer0.push_back((int)_families.size());//4 i <- key info aa layer#0
for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
{
tinyStr.push_back((*it).first);
layer0.push_back((*it).second);
}
- layer0.push_back((int)_groups.size());//3+aa i <- key info bb layer#0
+ layer0.push_back((int)_groups.size());//4+aa i <- key info bb layer#0
for(std::map<std::string, std::vector<std::string> >::const_iterator it0=_groups.begin();it0!=_groups.end();it0++)
{
layer0.push_back((int)(*it0).second.size());
for(std::vector<std::string>::const_iterator it1=((*it0).second).begin();it1!=((*it0).second).end();it1++)
tinyStr.push_back(*it1);
}
- // sizeof(layer0)==3+aa+1+bb layer#0
+ // sizeof(layer0)==4+aa+1+bb layer#0
bigArrayD=_coords;// 0 bd
bigArraysI.push_back(_fam_coords);// 0 bi
bigArraysI.push_back(_num_coords);// 1 bi
std::reverse(tinyStr.begin(),tinyStr.end());
std::reverse(bigArraysI.begin(),bigArraysI.end());
//
+ setAxType((MEDCouplingAxisType)layer0.back()); layer0.pop_back();
_order=layer0.back(); layer0.pop_back();
_iteration=layer0.back(); layer0.pop_back();
int spaceDim(layer0.back()); layer0.pop_back();
* \return MEDCouplingMesh * - a pointer to MEDCouplingMesh that the caller is to
* delete using decrRef() as it is no more needed.
*/
-MEDCouplingMesh *MEDFileStructuredMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const
+MEDCouplingMesh *MEDFileStructuredMesh::getMeshAtLevel(int meshDimRelToMax, bool renum) const
{
if(renum)
throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh does not support renumbering ! To do it perform request of renum array directly !");
case -1:
{
if(!m)
- throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGenMeshAtLevel : level -1 requested must be non empty to be able to compute unstructured sub mesh !");
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getMeshAtLevel : level -1 requested must be non empty to be able to compute unstructured sub mesh !");
buildMinusOneImplicitPartIfNeeded();
- MEDCouplingMesh *ret(_faces_if_necessary);
+ MEDCoupling1SGTUMesh *ret(_faces_if_necessary);
if(ret)
ret->incrRef();
return ret;
}
}
+int MEDFileStructuredMesh::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
+{
+ if(ct!=MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(getMeshDimension()))
+ return 0;
+ else
+ return getNumberOfCellsAtLevel(0);
+}
+
void MEDFileStructuredMesh::whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector<bool>& nodesFetched) const
{
if(st.getNumberOfItems()!=1)
int dt,it;
ParaMEDMEM::MEDCouplingMeshType meshType;
std::string dummy2;
- MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
+ ParaMEDMEM::MEDCouplingAxisType dummy3;
+ MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2);
return new MEDFileCMesh(fid,ms.front(),dt,it,mrs);
}
MEDFileMesh *MEDFileCMesh::shallowCpy() const
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=new MEDFileCMesh(*this);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret(new MEDFileCMesh(*this));
return ret.retn();
}
MEDFileMesh *MEDFileCMesh::deepCpy() const
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=new MEDFileCMesh(*this);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret(new MEDFileCMesh(*this));
+ ret->deepCpyEquivalences(*this);
if((const MEDCouplingCMesh*)_cmesh)
ret->_cmesh=static_cast<MEDCouplingCMesh*>(_cmesh->deepCpy());
ret->deepCpyAttributes();
MEDFileCMesh::MEDFileCMesh(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
try
{
- loadCMeshFromFile(fid,mName,dt,it,mrs);
- loadJointsFromFile(fid);
+ loadLLWithAdditionalItems(fid,mName,dt,it,mrs);
}
catch(INTERP_KERNEL::Exception& e)
{
throw e;
}
-void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+void MEDFileCMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
{
ParaMEDMEM::MEDCouplingMeshType meshType;
int dummy0,dummy1;
std::string dtunit;
- int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit);
+ ParaMEDMEM::MEDCouplingAxisType axType;
+ int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit);
if(meshType!=CARTESIAN)
{
std::ostringstream oss; oss << "Trying to load as cartesian an existing mesh with name '" << mName << "' that is NOT cartesian !";
}
MEDFileCMeshL2 loaderl2;
loaderl2.loadAll(fid,mid,mName,dt,it);
+ setAxType(loaderl2.getAxType());
MEDCouplingCMesh *mesh=loaderl2.getMesh();
mesh->incrRef();
_cmesh=mesh;
_cmesh=m;
}
+MEDFileMesh *MEDFileCMesh::cartesianize() const
+{
+ if(getAxType()==AX_CART)
+ {
+ incrRef();
+ return const_cast<MEDFileCMesh *>(this);
+ }
+ else
+ {
+ const MEDCouplingCMesh *cmesh(getMesh());
+ if(!cmesh)
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::cartesianize : impossible to turn into cartesian because the mesh is null !");
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> clmesh(cmesh->buildCurveLinear());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(clmesh->getCoords()->cartesianize(getAxType()));
+ clmesh->setCoords(coords);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret(MEDFileCurveLinearMesh::New());
+ ret->MEDFileStructuredMesh::operator=(*this);
+ ret->setMesh(clmesh);
+ ret->setAxType(AX_CART);
+ return ret.retn();
+ }
+}
+
void MEDFileCMesh::writeLL(med_idt fid) const
{
INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
}
+ // MED_CARTESIAN and not MEDFileMeshL2::TraduceAxisTypeRev(getAxType()) ! Yes it is not a bug. The discrimination is done in MEDmeshGridTypeWr.
MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,spaceDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit));
if(_univ_wr_status)
MEDFILESAFECALLERWR0(MEDmeshUniversalNameWr,(fid,maa));
- MEDFILESAFECALLERWR0(MEDmeshGridTypeWr,(fid,maa,MED_CARTESIAN_GRID));
+ MEDFILESAFECALLERWR0(MEDmeshGridTypeWr,(fid,maa,MEDFileMeshL2::TraduceAxisTypeRevStruct(getAxType())));
for(int i=0;i<spaceDim;i++)
{
const DataArrayDouble *da=_cmesh->getCoordsAt(i);
//
std::string meshName(MEDLoaderBase::buildStringFromFortran(maa,MED_NAME_SIZE));
MEDFileStructuredMesh::writeStructuredLL(fid,meshName);
-
- writeJoints(fid);
}
void MEDFileCMesh::synchronizeTinyInfoOnLeaves() const
MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
int dt,it;
ParaMEDMEM::MEDCouplingMeshType meshType;
+ ParaMEDMEM::MEDCouplingAxisType dummy3;
std::string dummy2;
- MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
+ MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2);
return new MEDFileCurveLinearMesh(fid,ms.front(),dt,it,mrs);
}
MEDFileMesh *MEDFileCurveLinearMesh::shallowCpy() const
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=new MEDFileCurveLinearMesh(*this);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret(new MEDFileCurveLinearMesh(*this));
return ret.retn();
}
MEDFileMesh *MEDFileCurveLinearMesh::deepCpy() const
{
- MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=new MEDFileCurveLinearMesh(*this);
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret(new MEDFileCurveLinearMesh(*this));
+ ret->deepCpyEquivalences(*this);
if((const MEDCouplingCurveLinearMesh*)_clmesh)
ret->_clmesh=static_cast<MEDCouplingCurveLinearMesh*>(_clmesh->deepCpy());
ret->deepCpyAttributes();
_clmesh=m;
}
+MEDFileMesh *MEDFileCurveLinearMesh::cartesianize() const
+{
+ if(getAxType()==AX_CART)
+ {
+ incrRef();
+ return const_cast<MEDFileCurveLinearMesh *>(this);
+ }
+ else
+ {
+ const MEDCouplingCurveLinearMesh *mesh(getMesh());
+ if(!mesh)
+ throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::cartesianize : impossible to turn into cartesian because the mesh is null !");
+ const DataArrayDouble *coords(mesh->getCoords());
+ if(!coords)
+ throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::cartesianize : coordinate pointer in mesh is null !");
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret(new MEDFileCurveLinearMesh(*this));
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> mesh2(mesh->clone(false));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coordsCart(coords->cartesianize(getAxType()));
+ mesh2->setCoords(coordsCart);
+ ret->setMesh(mesh2);
+ ret->setAxType(AX_CART);
+ return ret.retn();
+ }
+}
+
const MEDCouplingStructuredMesh *MEDFileCurveLinearMesh::getStructuredMesh() const
{
synchronizeTinyInfoOnLeaves();
MEDFileCurveLinearMesh::MEDFileCurveLinearMesh(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
try
{
- loadCLMeshFromFile(fid,mName,dt,it,mrs);
- loadJointsFromFile(fid);
+ loadLLWithAdditionalItems(fid,mName,dt,it,mrs);
}
catch(INTERP_KERNEL::Exception& e)
{
MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
}
- MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,meshDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit));
+ MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,meshDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MEDFileMeshL2::TraduceAxisTypeRev(getAxType()),comp,unit));
if(_univ_wr_status)
MEDFILESAFECALLERWR0(MEDmeshUniversalNameWr,(fid,maa));
MEDFILESAFECALLERWR0(MEDmeshGridTypeWr,(fid,maa,MED_CURVILINEAR_GRID));
//
std::string meshName(MEDLoaderBase::buildStringFromFortran(maa,MED_NAME_SIZE));
MEDFileStructuredMesh::writeStructuredLL(fid,meshName);
-
- writeJoints(fid);
}
-void MEDFileCurveLinearMesh::loadCLMeshFromFile(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+void MEDFileCurveLinearMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
{
ParaMEDMEM::MEDCouplingMeshType meshType;
int dummy0,dummy1;
std::string dtunit;
- int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit);
+ ParaMEDMEM::MEDCouplingAxisType axType;
+ int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit);
+ setAxType(axType);
if(meshType!=CURVE_LINEAR)
{
std::ostringstream oss; oss << "Trying to load as curve linear an existing mesh with name '" << mName << "' that is NOT curve linear !";
return ret;
}
+void MEDFileMeshMultiTS::cartesianizeMe()
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
+ {
+ MEDFileMesh *cur(*it);
+ if(cur)
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> ccur(cur->cartesianize());// Attention ! Do not wrap these two lines because memory leak !
+ *it=ccur;
+ }
+ }
+}
+
MEDFileMesh *MEDFileMeshMultiTS::getOneTimeStep() const
{
if(_mesh_one_ts.empty())
int dt,it;
ParaMEDMEM::MEDCouplingMeshType meshType;
std::string dummy2;
- MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
+ ParaMEDMEM::MEDCouplingAxisType dummy3;
+ MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2);
loadFromFile(fileName,ms.front());
}
catch(INTERP_KERNEL::Exception& e)
}
return ret;
}
-/*const MEDFileJoints* MEDFileMeshes::getJoints() const
-{
- const MEDFileJoints *ret=_joints;
- if(!ret)
- {
- std::ostringstream oss; oss << "MEDFileMeshes::getJoints : joints is not defined !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- return ret;
-}*/
bool MEDFileMeshes::changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
{
return ret;
}
+void MEDFileMeshes::cartesianizeMe()
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::iterator it=_meshes.begin();it!=_meshes.end();it++)
+ {
+ MEDFileMeshMultiTS *cur(*it);
+ if(cur)
+ cur->cartesianizeMe();
+ }
+}
+
void MEDFileMeshes::resize(int newSize)
{
_meshes.resize(newSize);