return true;
}
+bool MEDCouplingFieldDouble::areCompatibleForMul(const MEDCouplingField *other) const
+{
+ if(!MEDCouplingField::areCompatible(other))
+ return false;
+ const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
+ if(!otherC)
+ return false;
+ if(_nature!=otherC->_nature)
+ return false;
+ if(!_time_discr->areCompatibleForMul(otherC->_time_discr))
+ return false;
+ return true;
+}
+
TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const
{
return _time_discr->getEnum();
MEDCouplingFieldDouble *MEDCouplingFieldDouble::multiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
{
- if(!f1->areCompatible(f2))
+ if(!f1->areCompatibleForMul(f2))
throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to applymultiplyFields on them !");
MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr);
MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->getTypeOfField());
static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=NO_TIME);
bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const;
bool areCompatible(const MEDCouplingField *other) const;
+ bool areCompatibleForMul(const MEDCouplingField *other) const;
MEDCouplingFieldDouble *clone(bool recDeepCpy) const;
MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const;
TypeOfTimeDiscretization getTimeDiscretization() const;
DataArrayDouble *DataArrayDouble::multiply(const DataArrayDouble *a1, const DataArrayDouble *a2)
{
- int nbOfComp=a1->getNumberOfComponents();
- if(nbOfComp!=a2->getNumberOfComponents())
- throw INTERP_KERNEL::Exception("Nb of components mismatch for array multiply !");
int nbOfTuple=a1->getNumberOfTuples();
- if(nbOfTuple!=a2->getNumberOfTuples())
+ int nbOfTuple2=a2->getNumberOfTuples();
+ int nbOfComp=a1->getNumberOfComponents();
+ int nbOfComp2=a2->getNumberOfComponents();
+ if(nbOfTuple!=nbOfTuple2)
throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array multiply !");
- DataArrayDouble *ret=DataArrayDouble::New();
- ret->alloc(nbOfTuple,nbOfComp);
- std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::multiplies<double>());
+ DataArrayDouble *ret=0;
+ if(nbOfComp==nbOfComp2)
+ {
+ ret=DataArrayDouble::New();
+ ret->alloc(nbOfTuple,nbOfComp);
+ std::transform(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple*nbOfComp,a2->getConstPointer(),ret->getPointer(),std::multiplies<double>());
+ }
+ else
+ {
+ int nbOfCompMin,nbOfCompMax;
+ const DataArrayDouble *aMin, *aMax;
+ if(nbOfComp>nbOfComp2)
+ {
+ nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
+ aMin=a2; aMax=a1;
+ }
+ else
+ {
+ nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
+ aMin=a1; aMax=a2;
+ }
+ if(nbOfCompMin==1)
+ {
+ ret=DataArrayDouble::New();
+ ret->alloc(nbOfTuple,nbOfCompMax);
+ const double *aMinPtr=aMin->getConstPointer();
+ const double *aMaxPtr=aMax->getConstPointer();
+ double *res=ret->getPointer();
+ for(int i=0;i<nbOfTuple;i++)
+ res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<double>(),aMinPtr[i]));
+ }
+ else
+ throw INTERP_KERNEL::Exception("Nb of components mismatch for array multiply !");
+ }
ret->copyStringInfoFrom(*a1);
return ret;
}
return true;
}
+bool MEDCouplingTimeDiscretization::areCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
+{
+ if(std::fabs(_time_tolerance-other->_time_tolerance)>1.e-16)
+ return false;
+ if(_array==0 && other->_array==0)
+ return true;
+ if(_array==0 || other->_array==0)
+ return false;
+ int nbC1=_array->getNumberOfComponents();
+ int nbC2=other->_array->getNumberOfComponents();
+ int nbMin=std::min(nbC1,nbC2);
+ if(nbC1!=nbC2 && nbMin!=1)
+ return false;
+ return true;
+}
+
bool MEDCouplingTimeDiscretization::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
{
if(!areCompatible(other))
return otherC!=0;
}
+bool MEDCouplingNoTimeLabel::areCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
+{
+ if(!MEDCouplingTimeDiscretization::areCompatibleForMul(other))
+ return false;
+ const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
+ return otherC!=0;
+}
+
bool MEDCouplingNoTimeLabel::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
{
const MEDCouplingNoTimeLabel *otherC=dynamic_cast<const MEDCouplingNoTimeLabel *>(other);
return std::fabs(_time-otherC->_time)<_time_tolerance;
}
+bool MEDCouplingWithTimeStep::areCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
+{
+ if(!MEDCouplingTimeDiscretization::areCompatibleForMul(other))
+ return false;
+ const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
+ if(!otherC)
+ return false;
+ return std::fabs(_time-otherC->_time)<_time_tolerance;
+}
+
bool MEDCouplingWithTimeStep::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
{
const MEDCouplingWithTimeStep *otherC=dynamic_cast<const MEDCouplingWithTimeStep *>(other);
return (std::fabs(_start_time-otherC->_start_time)<_time_tolerance && std::fabs(_end_time-otherC->_end_time)<_time_tolerance);
}
+bool MEDCouplingConstOnTimeInterval::areCompatibleForMul(const MEDCouplingTimeDiscretization *other) const
+{
+ if(!MEDCouplingTimeDiscretization::areCompatible(other))
+ return false;
+ const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
+ if(!otherC)
+ return false;
+ return (std::fabs(_start_time-otherC->_start_time)<_time_tolerance && std::fabs(_end_time-otherC->_end_time)<_time_tolerance);
+}
+
bool MEDCouplingConstOnTimeInterval::isEqual(const MEDCouplingTimeDiscretization *other, double prec) const
{
const MEDCouplingConstOnTimeInterval *otherC=dynamic_cast<const MEDCouplingConstOnTimeInterval *>(other);
void updateTime();
static MEDCouplingTimeDiscretization *New(TypeOfTimeDiscretization type);
virtual bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
+ virtual bool areCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
virtual bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const;
virtual MEDCouplingTimeDiscretization *buildNewTimeReprFromThis(const MEDCouplingTimeDiscretization *other,
TypeOfTimeDiscretization type, bool deepCpy) const;
MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const;
bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const;
bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
+ bool areCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const;
void checkNoTimePresence() const throw(INTERP_KERNEL::Exception) { }
void checkTimePresence(double time) const throw(INTERP_KERNEL::Exception);
MEDCouplingTimeDiscretization *divide(const MEDCouplingTimeDiscretization *other) const;
bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const;
bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
+ bool areCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
void getTinySerializationIntInformation(std::vector<int>& tinyInfo) const;
void getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const;
void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
void finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS);
MEDCouplingTimeDiscretization *performCpy(bool deepCpy) const;
bool areCompatible(const MEDCouplingTimeDiscretization *other) const;
+ bool areCompatibleForMul(const MEDCouplingTimeDiscretization *other) const;
bool isEqual(const MEDCouplingTimeDiscretization *other, double prec) const;
std::vector< const DataArrayDouble *> getArraysForTime(double time) const throw(INTERP_KERNEL::Exception);
void getValueForTime(double time, const std::vector<double>& vals, double *res) const;