From 79e2ba68de95b02b93f5e7f5827a110c1411ef12 Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 27 Sep 2010 06:27:49 +0000 Subject: [PATCH] Some code factorization. --- src/MEDCoupling/MEDCouplingMemArray.cxx | 138 ++++++++++++++++++ src/MEDCoupling/MEDCouplingMemArray.hxx | 6 + .../MEDCouplingTimeDiscretization.cxx | 133 +---------------- src/MEDCoupling/MEDCouplingUMesh.cxx | 1 - 4 files changed, 151 insertions(+), 127 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index c778fd8c9..65d3d9ee3 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -19,10 +19,14 @@ #include "MEDCouplingMemArray.txx" +#include "InterpKernelExprParser.hxx" + #include #include #include +typedef double (*MYFUNCPTR)(double); + using namespace ParaMEDMEM; void DataArray::setName(const char *name) @@ -326,6 +330,140 @@ double DataArrayDouble::accumulate(int compId) const 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;ialloc(nbOfTuples,nbOfComp); + const double *ptr=getConstPointer(); + double *ptrToFill=newArr->getPointer(); + for(int i=0;i(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 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(oss," ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + std::vector 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(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(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 #include -typedef double (*MYFUNCPTR)(double); - using namespace ParaMEDMEM; const double MEDCouplingTimeDiscretization::TIME_TOLERANCE_DFT=1.e-12; @@ -284,14 +280,7 @@ void MEDCouplingTimeDiscretization::applyLin(double a, double b, int compoId) 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;ideclareAsNew(); - } + arrays[j]->applyLin(a,b,compoId); } } @@ -303,26 +292,7 @@ void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate f 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(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; } @@ -334,51 +304,13 @@ void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, FunctionToEvaluate f void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const char *func) { - INTERP_KERNEL::ExprParser expr(func); - expr.parse(); - std::set vars; - expr.getTrueSetOfVars(vars); - // - std::vector arrays; + std::vector arrays; getArrays(arrays); std::vector 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(oss," ")); - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - std::vector 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(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; } @@ -390,40 +322,13 @@ void MEDCouplingTimeDiscretization::applyFunc(int nbOfComp, const char *func) void MEDCouplingTimeDiscretization::applyFunc(const char *func) { - INTERP_KERNEL::ExprParser expr(func); - expr.parse(); - expr.prepareExprEvaluationVec(); - // std::vector arrays; getArrays(arrays); std::vector 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(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; } @@ -435,47 +340,23 @@ void MEDCouplingTimeDiscretization::applyFunc(const char *func) 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 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;ideclareAsNew(); - } + 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 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;ideclareAsNew(); - } + arrays[j]->applyFuncFast64(func); } } diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 32bec6151..e77d8bba4 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -498,7 +498,6 @@ void MEDCouplingUMesh::convertToPolyTypes(const std::vector& cellIdsToConve DataArrayInt *MEDCouplingUMesh::zipCoordsTraducer() { int nbOfNodes=getNumberOfNodes(); - int spaceDim=getSpaceDimension(); int *traducer=new int[nbOfNodes]; std::fill(traducer,traducer+nbOfNodes,-1); int nbOfCells=getNumberOfCells(); -- 2.39.2