+
+//=
+
+MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0)
+{
+}
+
+void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
+{
+ std::size_t sz(mParts.size());
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > ret(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ const MEDCoupling1GTUMesh *elt(mParts[i]);
+ if(!elt)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignParts : presence of null pointer !");
+ ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt); elt->incrRef();
+ }
+ _m_parts=ret;
+ _mp_time=std::max(_mp_time,_m_time)+1;
+ _m=0;
+}
+
+void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m)
+{
+ _m=m;
+ _m_parts.clear();
+ _m_time=std::max(_mp_time,_m_time)+1;
+}
+
+MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
+{
+ if(_mp_time<=_m_time)
+ return _m;
+ std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size());
+ std::copy(_m_parts.begin(),_m_parts.end(),mp.begin());
+ _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp);
+ _m_parts.clear();//to avoid memory peak !
+ _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared !
+ return _m;
+}
+
+std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getPartsWithoutComputation() const
+{
+ if(_mp_time<_m_time)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !");
+ //
+ std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
+ std::size_t i(0);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
+ {
+ const MEDCoupling1GTUMesh *elt(*it);
+ ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
+ }
+ return ret;
+}
+
+std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getParts() const
+{
+ if(_mp_time<_m_time)
+ forceComputationOfPartsFromUMesh();
+ return getPartsWithoutComputation();
+}
+
+MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::getPartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
+{
+ std::vector<MEDCoupling1GTUMesh *> v(getPartsWithoutComputation());
+ std::size_t sz(v.size());
+ for(std::size_t i=0;i<sz;i++)
+ {
+ if(v[i])
+ if(v[i]->getCellModelEnum()==gt)
+ return v[i];
+ }
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !");
+}
+
+void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
+{
+ const MEDCouplingUMesh *m(_m);
+ if(!m)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !");
+ std::vector<MEDCouplingUMesh *> ms(m->splitByType());
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
+ std::size_t sz(msMSafe.size());
+ _m_parts.resize(sz);
+ for(std::size_t i=0;i<sz;i++)
+ _m_parts[i]=MEDCoupling1GTUMesh::New(ms[i]);
+ _mp_time=std::max(_mp_time,_m_time)+1;
+}
+
+std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
+{
+ if(_mp_time>_m_time)
+ return getTimeOfParts();
+ if(_m_time>_mp_time)
+ return getTimeOfUMesh();
+ return std::max(getTimeOfParts(),getTimeOfUMesh());
+}
+
+std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
+{
+ std::size_t ret(0);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+ {
+ const MEDCoupling1GTUMesh *elt(*it);
+ if(!elt)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !");
+ ret=std::max(ret,elt->getTimeOfThis());
+ }
+ if(ret==0)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !");
+ return ret;
+}
+
+std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
+{
+ const MEDCouplingUMesh *m(_m);
+ if(!m)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !");
+ return m->getTimeOfThis();
+}
+
+std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const
+{
+ std::size_t ret(_m_parts.size()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>));
+ return ret;
+}
+
+std::vector<const BigMemoryObject *> MEDFileUMeshAggregateCompute::getDirectChildren() const
+{
+ std::vector<const BigMemoryObject *> ret;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+ {
+ const MEDCoupling1GTUMesh *cur(*it);
+ if(cur)
+ ret.push_back(cur);
+ }
+ const MEDCouplingUMesh *m(_m);
+ if(m)
+ ret.push_back(m);
+ return ret;
+}
+
+MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDouble *coords) const
+{
+ MEDFileUMeshAggregateCompute ret;
+ ret._m_parts.resize(_m_parts.size());
+ for(std::size_t i=0;i<_m_parts.size();i++)
+ {
+ const MEDCoupling1GTUMesh *elt(_m_parts[i]);
+ if(elt)
+ {
+ ret._m_parts[i]=static_cast<ParaMEDMEM::MEDCoupling1GTUMesh*>(elt->deepCpy());
+ ret._m_parts[i]->setCoords(coords);
+ }
+ }
+ ret._mp_time=_mp_time; ret._m_time=_m_time;
+ if((const MEDCouplingUMesh *)_m)
+ {
+ ret._m=static_cast<ParaMEDMEM::MEDCouplingUMesh*>(_m->deepCpy());
+ ret._m->setCoords(coords);
+ }
+ return ret;
+}
+
+bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
+{
+ const MEDCouplingUMesh *m1(getUmesh());
+ const MEDCouplingUMesh *m2(other.getUmesh());
+ if((m1==0 && m2!=0) || (m1!=0 && m2==0))
+ {
+ what="Presence of mesh in one sublevel and not in other!";
+ return false;
+ }
+ if(m1)
+ {
+ std::string what2;
+ if(!m1->isEqualIfNotWhy(m2,eps,what2))
+ {
+ what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!");
+ return false;
+ }
+ }
+ return true;
+}
+
+void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+ MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
+ MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
+}
+
+void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+ {
+ const MEDCoupling1GTUMesh *tmp(*it);
+ if(tmp)
+ {
+ (const_cast<MEDCoupling1GTUMesh *>(tmp))->setName(master.getName().c_str());
+ (const_cast<MEDCoupling1GTUMesh *>(tmp))->setDescription(master.getDescription().c_str());
+ (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
+ (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
+ }
+ }
+ const MEDCouplingUMesh *m(_m);
+ if(m)
+ {
+ (const_cast<MEDCouplingUMesh *>(m))->setName(master.getName().c_str());
+ (const_cast<MEDCouplingUMesh *>(m))->setDescription(master.getDescription().c_str());
+ (const_cast<MEDCouplingUMesh *>(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
+ (const_cast<MEDCouplingUMesh *>(m))->setTimeUnit(master.getTimeUnit());
+ }
+}
+
+bool MEDFileUMeshAggregateCompute::empty() const
+{
+ if(_mp_time<_m_time)
+ return ((const MEDCouplingUMesh *)_m)==0;
+ //else _mp_time>=_m_time)
+ return _m_parts.empty();
+
+}
+
+int MEDFileUMeshAggregateCompute::getMeshDimension() const
+{
+ if(_mp_time<_m_time)
+ {
+ const MEDCouplingUMesh *m(_m);
+ if(!m)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !");
+ return m->getMeshDimension();
+ }
+ else
+ {
+ if(_m_parts.empty())
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !");
+ const MEDCoupling1GTUMesh *m(_m_parts[0]);
+ if(!m)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !");
+ return m->getMeshDimension();
+ }
+}
+
+std::vector<int> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
+{
+ if(_mp_time<_m_time)
+ {
+ const MEDCouplingUMesh *m(_m);
+ if(!m)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !");
+ return m->getDistributionOfTypes();
+ }
+ else
+ {
+ std::vector<int> ret;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+ {
+ const MEDCoupling1GTUMesh *tmp(*it);
+ if(!tmp)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !");
+ std::vector<int> ret0(tmp->getDistributionOfTypes());
+ ret.insert(ret.end(),ret0.begin(),ret0.end());
+ }
+ return ret;
+ }
+}
+
+int MEDFileUMeshAggregateCompute::getSize() const
+{
+ if(_mp_time<_m_time)
+ {
+ const MEDCouplingUMesh *m(_m);
+ if(!m)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !");
+ return m->getNumberOfCells();
+ }
+ else
+ {
+ int ret=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+ {
+ const MEDCoupling1GTUMesh *m(*it);
+ if(!m)
+ throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !");
+ ret+=m->getNumberOfCells();
+ }
+ return ret;
+ }
+}
+
+void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
+{
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
+ {
+ MEDCoupling1GTUMesh *tmp(*it);
+ if(tmp)
+ (*it)->setCoords(coords);
+ }
+ MEDCouplingUMesh *m(_m);
+ if(m)
+ m->setCoords(coords);
+}