#include "MEDCouplingMemArray.txx"
+#include "InterpKernelExprParser.hxx"
+
#include <set>
#include <numeric>
#include <functional>
+typedef double (*MYFUNCPTR)(double);
+
using namespace ParaMEDMEM;
void DataArray::setName(const char *name)
return ret;
}
+void DataArrayDouble::applyLin(double a, double b, int compoId)
+{
+ double *ptr=getPointer()+compoId;
+ int nbOfComp=getNumberOfComponents();
+ int nbOfTuple=getNumberOfTuples();
+ for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
+ *ptr=a*(*ptr)+b;
+ declareAsNew();
+}
+
+DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception)
+{
+ DataArrayDouble *newArr=DataArrayDouble::New();
+ int nbOfTuples=getNumberOfTuples();
+ int oldNbOfComp=getNumberOfComponents();
+ newArr->alloc(nbOfTuples,nbOfComp);
+ const double *ptr=getConstPointer();
+ double *ptrToFill=newArr->getPointer();
+ for(int i=0;i<nbOfTuples;i++)
+ {
+ if(!func(ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp))
+ {
+ std::ostringstream oss; oss << "For tuple # " << i << " with value (";
+ std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
+ oss << ") : Evaluation of function failed !";
+ newArr->decrRef();
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ return newArr;
+}
+
+DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
+{
+ INTERP_KERNEL::ExprParser expr(func);
+ expr.parse();
+ std::set<std::string> vars;
+ expr.getTrueSetOfVars(vars);
+ int oldNbOfComp=getNumberOfComponents();
+ if((int)vars.size()>oldNbOfComp)
+ {
+ std::ostringstream oss; oss << "The field has a " << oldNbOfComp << " components and there are ";
+ oss << vars.size() << " variables : ";
+ std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ std::vector<std::string> varsV(vars.begin(),vars.end());
+ expr.prepareExprEvaluation(varsV);
+ //
+ DataArrayDouble *newArr=DataArrayDouble::New();
+ int nbOfTuples=getNumberOfTuples();
+ newArr->alloc(nbOfTuples,nbOfComp);
+ const double *ptr=getConstPointer();
+ double *ptrToFill=newArr->getPointer();
+ for(int i=0;i<nbOfTuples;i++)
+ {
+ try
+ {
+ expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
+ }
+ catch(INTERP_KERNEL::Exception& e)
+ {
+ std::ostringstream oss; oss << "For tuple # " << i << " with value (";
+ std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
+ oss << ") : Evaluation of function failed !" << e.what();
+ newArr->decrRef();
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ return newArr;
+}
+
+DataArrayDouble *DataArrayDouble::applyFunc(const char *func) const throw(INTERP_KERNEL::Exception)
+{
+ INTERP_KERNEL::ExprParser expr(func);
+ expr.parse();
+ expr.prepareExprEvaluationVec();
+ //
+ DataArrayDouble *newArr=DataArrayDouble::New();
+ int nbOfTuples=getNumberOfTuples();
+ int nbOfComp=getNumberOfComponents();
+ newArr->alloc(nbOfTuples,nbOfComp);
+ const double *ptr=getConstPointer();
+ double *ptrToFill=newArr->getPointer();
+ for(int i=0;i<nbOfTuples;i++)
+ {
+ try
+ {
+ expr.evaluateExpr(nbOfComp,ptr+i*nbOfComp,ptrToFill+i*nbOfComp);
+ }
+ catch(INTERP_KERNEL::Exception& e)
+ {
+ std::ostringstream oss; oss << "For tuple # " << i << " with value (";
+ std::copy(ptr+nbOfComp*i,ptr+nbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
+ oss << ") : Evaluation of function failed ! " << e.what();
+ newArr->decrRef();
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ return newArr;
+}
+
+void DataArrayDouble::applyFuncFast32(const char *func)
+{
+ INTERP_KERNEL::ExprParser expr(func);
+ expr.parse();
+ char *funcStr=expr.compileX86();
+ MYFUNCPTR funcPtr=(MYFUNCPTR)funcStr;//he he...
+ //
+ double *ptr=getPointer();
+ int nbOfComp=getNumberOfComponents();
+ int nbOfTuples=getNumberOfTuples();
+ int nbOfElems=nbOfTuples*nbOfComp;
+ for(int i=0;i<nbOfElems;i++,ptr++)
+ *ptr=funcPtr(*ptr);
+ declareAsNew();
+}
+
+void DataArrayDouble::applyFuncFast64(const char *func)
+{
+ INTERP_KERNEL::ExprParser expr(func);
+ expr.parse();
+ char *funcStr=expr.compileX86_64();
+ MYFUNCPTR funcPtr=(MYFUNCPTR)funcStr;//he he...
+ //
+ double *ptr=getPointer();
+ int nbOfComp=getNumberOfComponents();
+ int nbOfTuples=getNumberOfTuples();
+ int nbOfElems=nbOfTuples*nbOfComp;
+ for(int i=0;i<nbOfElems;i++,ptr++)
+ *ptr=funcPtr(*ptr);
+ declareAsNew();
+}
+
DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception)
{
if(getNumberOfComponents()!=1)
MEDCOUPLING_EXPORT double getAverageValue() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void accumulate(double *res) const;
MEDCOUPLING_EXPORT double accumulate(int compId) const;
+ MEDCOUPLING_EXPORT void applyLin(double a, double b, int compoId);
+ MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT DataArrayDouble *applyFunc(const char *func) const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void applyFuncFast32(const char *func);
+ MEDCOUPLING_EXPORT void applyFuncFast64(const char *func);
MEDCOUPLING_EXPORT DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT static DataArrayDouble *aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT static DataArrayDouble *dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception);
#include "MEDCouplingTimeDiscretization.hxx"
#include "MEDCouplingMemArray.hxx"
-#include "InterpKernelExprParser.hxx"
-
#include <cmath>
#include <iterator>
-typedef double (*MYFUNCPTR)(double);
-
using namespace ParaMEDMEM;
const double MEDCouplingTimeDiscretization::TIME_TOLERANCE_DFT=1.e-12;
for(int j=0;j<(int)arrays.size();j++)
{
if(arrays[j])
- {
- double *ptr=arrays[j]->getPointer()+compoId;
- int nbOfComp=arrays[j]->getNumberOfComponents();
- int nbOfTuple=arrays[j]->getNumberOfTuples();
- for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
- *ptr=a*(*ptr)+b;
- arrays[j]->declareAsNew();
- }
+ arrays[j]->applyLin(a,b,compoId);
}
}
for(int j=0;j<(int)arrays.size();j++)
{
if(arrays[j])
- {
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=arrays[j]->getNumberOfTuples();
- int oldNbOfComp=arrays[j]->getNumberOfComponents();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *ptr=arrays[j]->getConstPointer();
- double *ptrToFill=newArr->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- if(!func(ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp))
- {
- std::ostringstream oss; oss << "For tuple # " << i << " with value (";
- std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed !";
- newArr->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- arrays2[j]=newArr;
- }
+ arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
else
arrays2[j]=0;
}
void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const char *func)
{
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- std::set<std::string> vars;
- expr.getTrueSetOfVars(vars);
- //
- std::vector<DataArrayDouble *> arrays;
+ std::vector<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector<DataArrayDouble *> arrays2(arrays.size());
for(int j=0;j<(int)arrays.size();j++)
{
if(arrays[j])
- {
- int oldNbOfComp=arrays[j]->getNumberOfComponents();
- if((int)vars.size()>oldNbOfComp)
- {
- std::ostringstream oss; oss << "The field has a " << oldNbOfComp << " components and there are ";
- oss << vars.size() << " variables : ";
- std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- std::vector<std::string> varsV(vars.begin(),vars.end());
- expr.prepareExprEvaluation(varsV);
- //
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=arrays[j]->getNumberOfTuples();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *ptr=arrays[j]->getConstPointer();
- double *ptrToFill=newArr->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- try
- {
- expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
- }
- catch(INTERP_KERNEL::Exception& e)
- {
- std::ostringstream oss; oss << "For tuple # " << i << " with value (";
- std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed !" << e.what();
- newArr->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- arrays2[j]=newArr;
- }
+ arrays2[j]=arrays[j]->applyFunc(nbOfComp,func);
else
arrays2[j]=0;
}
void MEDCouplingTimeDiscretization::applyFunc(const char *func)
{
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- expr.prepareExprEvaluationVec();
- //
std::vector<DataArrayDouble *> arrays;
getArrays(arrays);
std::vector<DataArrayDouble *> arrays2(arrays.size());
for(int j=0;j<(int)arrays.size();j++)
{
if(arrays[j])
- {
- DataArrayDouble *newArr=DataArrayDouble::New();
- int nbOfTuples=arrays[j]->getNumberOfTuples();
- int nbOfComp=arrays[j]->getNumberOfComponents();
- newArr->alloc(nbOfTuples,nbOfComp);
- const double *ptr=arrays[j]->getConstPointer();
- double *ptrToFill=newArr->getPointer();
- for(int i=0;i<nbOfTuples;i++)
- {
- try
- {
- expr.evaluateExpr(nbOfComp,ptr+i*nbOfComp,ptrToFill+i*nbOfComp);
- }
- catch(INTERP_KERNEL::Exception& e)
- {
- std::ostringstream oss; oss << "For tuple # " << i << " with value (";
- std::copy(ptr+nbOfComp*i,ptr+nbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
- oss << ") : Evaluation of function failed ! " << e.what();
- newArr->decrRef();
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- arrays2[j]=newArr;
- }
+ arrays2[j]=arrays[j]->applyFunc(func);
else
arrays2[j]=0;
}
void MEDCouplingTimeDiscretization::applyFuncFast32(const char *func)
{
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- char *funcStr=expr.compileX86();
- MYFUNCPTR funcPtr=(MYFUNCPTR)funcStr;//he he...
std::vector<DataArrayDouble *> arrays;
getArrays(arrays);
for(int j=0;j<(int)arrays.size();j++)
{
if(arrays[j])
- {
- double *ptr=arrays[j]->getPointer();
- int nbOfComp=arrays[j]->getNumberOfComponents();
- int nbOfTuples=arrays[j]->getNumberOfTuples();
- int nbOfElems=nbOfTuples*nbOfComp;
- for(int i=0;i<nbOfElems;i++,ptr++)
- *ptr=funcPtr(*ptr);
- arrays[j]->declareAsNew();
- }
+ arrays[j]->applyFuncFast32(func);
}
}
void MEDCouplingTimeDiscretization::applyFuncFast64(const char *func)
{
- INTERP_KERNEL::ExprParser expr(func);
- expr.parse();
- char *funcStr=expr.compileX86_64();
- MYFUNCPTR funcPtr=(MYFUNCPTR)funcStr;//he he...
std::vector<DataArrayDouble *> arrays;
getArrays(arrays);
for(int j=0;j<(int)arrays.size();j++)
{
if(arrays[j])
- {
- double *ptr=arrays[j]->getPointer();
- int nbOfComp=arrays[j]->getNumberOfComponents();
- int nbOfTuples=arrays[j]->getNumberOfTuples();
- int nbOfElems=nbOfTuples*nbOfComp;
- for(int i=0;i<nbOfElems;i++,ptr++)
- *ptr=funcPtr(*ptr);
- arrays[j]->declareAsNew();
- }
+ arrays[j]->applyFuncFast64(func);
}
}
DataArrayInt *MEDCouplingUMesh::zipCoordsTraducer()
{
int nbOfNodes=getNumberOfNodes();
- int spaceDim=getSpaceDimension();
int *traducer=new int[nbOfNodes];
std::fill(traducer,traducer+nbOfNodes,-1);
int nbOfCells=getNumberOfCells();