*/
void MEDCouplingCartesianAMRMesh::fillCellFieldOnPatchGhostAdv(int patchId, const DataArrayDouble *cellFieldOnThis, int ghostLev, const std::vector<const DataArrayDouble *>& arrsOnPatches) const
{
- int nbp(getNumberOfPatches());
+ int nbp(getNumberOfPatches()),dim(getSpaceDimension());
if(nbp!=(int)arrsOnPatches.size())
{
std::ostringstream oss; oss << "MEDCouplingCartesianAMRMesh::fillCellFieldOnPatchGhostAdv : there are " << nbp << " patches in this and " << arrsOnPatches.size() << " arrays in the last parameter !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
+ DataArrayDouble *theFieldToFill(const_cast<DataArrayDouble *>(arrsOnPatches[patchId]));
// first, do as usual
- fillCellFieldOnPatchGhost(patchId,cellFieldOnThis,const_cast<DataArrayDouble *>(arrsOnPatches[patchId]),ghostLev);
- //
+ fillCellFieldOnPatchGhost(patchId,cellFieldOnThis,theFieldToFill,ghostLev);
+ // all reference patch stuff
const MEDCouplingCartesianAMRPatch *refP(getPatch(patchId));
const std::vector< std::pair<int,int> >& refBLTR(refP->getBLTRRange());
+ std::vector<int> dimsCoarse(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(refBLTR));
+ std::transform(dimsCoarse.begin(),dimsCoarse.end(),_factors.begin(),dimsCoarse.begin(),std::multiplies<int>());
+ std::transform(dimsCoarse.begin(),dimsCoarse.end(),dimsCoarse.begin(),std::bind2nd(std::plus<int>(),2*ghostLev));
+ std::vector< std::pair<int,int> > rangeCoarse(MEDCouplingStructuredMesh::GetCompactFrmtFromDimensions(dimsCoarse));
+ std::vector<int> fakeFactors(dim,1);
+ //
for(int i=0;i<nbp;i++)
{
if(i!=patchId)
MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt(refBLTR,otherBLTR,tmp0);
ApplyFactorsOnCompactFrmt(tmp0,_factors);
ApplyGhostOnCompactFrmt(tmp0,ghostLev);
- //std::vector<int> dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse));
+ std::vector<int> dimsFine(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(otherBLTR));
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ghostVals;//(MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom(dimsFine,arrsOnPatches[i],));
+ std::vector< std::pair<int,int> > interstRange(MEDCouplingStructuredMesh::IntersectRanges(tmp0,rangeCoarse));
+ MEDCouplingIMesh::CondenseFineToCoarse(dimsCoarse,ghostVals,interstRange,fakeFactors,theFieldToFill);
}
}
}
}
}
+/*!
+ * This method takes in input a compact format [[Xmax,Xmin),[Ymin,Ymax)] and returns the corresponding dimensions for each axis that is to say
+ * [Xmax-Xmin,Ymax-Ymin].
+ *
+ * \throw if an axis range is so that max<min
+ * \sa GetCompactFrmtFromDimensions
+ */
std::vector<int> MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(const std::vector< std::pair<int,int> >& partCompactFormat)
{
std::vector<int> ret(partCompactFormat.size());
for(std::size_t i=0;i<partCompactFormat.size();i++)
- ret[i]=partCompactFormat[i].second-partCompactFormat[i].first;
+ {
+ if(partCompactFormat[i].first>partCompactFormat[i].second)
+ {
+ std::ostringstream oss; oss << "MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt : For axis #" << i << " end is before start !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ ret[i]=partCompactFormat[i].second-partCompactFormat[i].first;
+ }
+ return ret;
+}
+
+/*!
+ * This method takes in input a vector giving the number of entity per axis and returns for each axis a range starting from [0,0...]
+ *
+ * \throw if there is an axis in \a dims that is < 0.
+ * \sa GetDimensionsFromCompactFrmt, ChangeReferenceFromGlobalOfCompactFrmt, ChangeReferenceToGlobalOfCompactFrmt
+ */
+std::vector< std::pair<int,int> > MEDCouplingStructuredMesh::GetCompactFrmtFromDimensions(const std::vector<int>& dims)
+{
+ std::size_t sz(dims.size());
+ std::vector< std::pair<int,int> > ret(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ if(dims[i]<0)
+ {
+ std::ostringstream oss; oss << "MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt : For axis #" << i << " dimension < 0 !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ ret[i].first=0;
+ ret[i].second=dims[i];
+ }
+ return ret;
+}
+
+/*!
+ * This method returns the intersection zone of two ranges (in compact format) \a r1 and \a r2.
+ * This method will throw exception if on one axis the intersection is empty.
+ */
+std::vector< std::pair<int,int> > MEDCouplingStructuredMesh::IntersectRanges(const std::vector< std::pair<int,int> >& r1, const std::vector< std::pair<int,int> >& r2)
+{
+ std::size_t sz(r1.size());
+ if(sz!=r2.size())
+ throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IntersectRanges : the two ranges must have the same dimension !");
+ std::vector< std::pair<int,int> > ret(sz);
+ for(std::size_t i=0;i<sz;i++)
+ {
+ if(r1[i].first>r1[i].second)
+ {
+ std::ostringstream oss; oss << "MEDCouplingStructuredMesh::IntersectRanges : On axis " << i << " of range r1, end is before start !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if(r2[i].first>r2[i].second)
+ {
+ std::ostringstream oss; oss << "MEDCouplingStructuredMesh::IntersectRanges : On axis " << i << " of range r2, end is before start !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ ret[i].first=std::max(r1[i].first,r2[i].first);
+ ret[i].second=std::min(r1[i].second,r2[i].second);
+ if(ret[i].first>ret[i].second)
+ {
+ std::ostringstream oss; oss << "MEDCouplingStructuredMesh::IntersectRanges : On axis " << i << " the intersection of r1 and r2 is empty !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
return ret;
}
MEDCOUPLING_EXPORT static std::vector<int> GetSplitVectFromStruct(const std::vector<int>& strct);
MEDCOUPLING_EXPORT static bool IsPartStructured(const int *startIds, const int *stopIds, const std::vector<int>& st, std::vector< std::pair<int,int> >& partCompactFormat);
MEDCOUPLING_EXPORT static std::vector<int> GetDimensionsFromCompactFrmt(const std::vector< std::pair<int,int> >& partCompactFormat);
+ MEDCOUPLING_EXPORT static std::vector< std::pair<int,int> > GetCompactFrmtFromDimensions(const std::vector<int>& dims);
+ MEDCOUPLING_EXPORT static std::vector< std::pair<int,int> > IntersectRanges(const std::vector< std::pair<int,int> >& r1, const std::vector< std::pair<int,int> >& r2);
MEDCOUPLING_EXPORT static void SwitchOnIdsFrom(const std::vector<int>& st, const std::vector< std::pair<int,int> >& partCompactFormat, std::vector<bool>& vectToSwitchOn);
MEDCOUPLING_EXPORT static void ExtractFieldOfBoolFrom(const std::vector<int>& st, const std::vector<bool>& fieldOfBool, const std::vector< std::pair<int,int> >& partCompactFormat, std::vector<bool>& fieldOut);
MEDCOUPLING_EXPORT static DataArrayDouble *ExtractFieldOfDoubleFrom(const std::vector<int>& st, const DataArrayDouble *fieldOfDbl, const std::vector< std::pair<int,int> >& partCompactFormat);
return MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(inp);
}
+ static PyObject *GetCompactFrmtFromDimensions(const std::vector<int>& dims) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector< std::pair<int,int> > ret(MEDCouplingStructuredMesh::GetCompactFrmtFromDimensions(dims));
+ PyObject *retPy=PyList_New(ret.size());
+ for(std::size_t i=0;i<ret.size();i++)
+ {
+ PyObject *tmp=PyTuple_New(2);
+ PyTuple_SetItem(tmp,0,PyInt_FromLong(ret[i].first));
+ PyTuple_SetItem(tmp,1,PyInt_FromLong(ret[i].second));
+ PyList_SetItem(retPy,i,tmp);
+ }
+ return retPy;
+ }
+
+ static PyObject *IntersectRanges(PyObject *r1, PyObject *r2) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector< std::pair<int,int> > r1Cpp,r2Cpp;
+ convertPyToVectorPairInt(r1,r1Cpp);
+ convertPyToVectorPairInt(r2,r2Cpp);
+ std::vector< std::pair<int,int> > ret(MEDCouplingStructuredMesh::IntersectRanges(r1Cpp,r2Cpp));
+ PyObject *retPy=PyList_New(ret.size());
+ for(std::size_t i=0;i<ret.size();i++)
+ {
+ PyObject *tmp=PyTuple_New(2);
+ PyTuple_SetItem(tmp,0,PyInt_FromLong(ret[i].first));
+ PyTuple_SetItem(tmp,1,PyInt_FromLong(ret[i].second));
+ PyList_SetItem(retPy,i,tmp);
+ }
+ return retPy;
+ }
+
static PyObject *IsPartStructured(PyObject *li, PyObject *st) throw(INTERP_KERNEL::Exception)
{
int szArr,sw,iTypppArr;