📄 xmdsfilter.cc
字号:
for(long unsigned int j=0; j<nDimsRemaining-1; j++) { fprintf(outfile,"("); } long unsigned int whichMoment = 0; list<bool>::const_iterator nextIntegrateDimension = tempNextMGElement->integrateDimensionList.begin(); while(*nextIntegrateDimension) { nextIntegrateDimension++; whichMoment++; } fprintf(outfile,"_i%li",whichMoment); nextIntegrateDimension++; whichMoment++; for(long unsigned int k=0; k<nDimsRemaining-1; k++) { while(*nextIntegrateDimension) { nextIntegrateDimension++; whichMoment++; } if(swapped&&(whichMoment==1)) { fprintf(outfile,"*_%s_lattice0+_i1)",fieldName); } else { fprintf(outfile,"*_%s_lattice%li+_i%li)",fieldName,whichMoment,whichMoment); } nextIntegrateDimension++; whichMoment++; } fprintf(outfile,"*%i;\n",tempNextMGElement->momentNameList.size()); } } fprintf(outfile,"// *************** Filter code ******************\n"); fprintf(outfile,"%s\n",myCode.c_str()); fprintf(outfile,"// **********************************************\n"); simulation()->field()->closeLoops(outfile,mySpace,myVectorNamesList); fprintf(outfile,"\n"); } else if(!strcmp(codeElement->c_str(),"functions")) { fprintf(outfile,"// ************** propagation code **************\n"); fprintf(outfile,"%s\n",nextNLPElement->c_str()); fprintf(outfile,"// **********************************************\n"); fprintf(outfile,"\n"); nextNLPElement++; } else if(!strcmp(codeElement->c_str(),"moment_group")) { whichMG++; long unsigned int nDimsRemaining = simulation()->field()->geometry()->nDims(); for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++){ if(*nextIntegrateDimension) { nDimsRemaining--; } } if(nDimsRemaining>0) { deleteMGArrayList.push_back(whichMG); } fprintf(outfile,"// ************** integrate moment group code **************\n"); //setup defines for the integrate_moment_groups if they are arrays long unsigned int whichMoment=0; if(nDimsRemaining>0) { for(list<XMLString>::const_iterator nextMomentName = nextMGElement->momentNameList.begin(); nextMomentName != nextMGElement->momentNameList.end(); nextMomentName++){ fprintf(outfile,"#define %s _img%li_array[_img%li_pointer+%li]\n",nextMomentName->c_str(),whichMG,whichMG,whichMoment); whichMoment++; } } fprintf(outfile,"\n"); //setup actual arrays for the integrate_moment_groups (MPI and non-MPI) if(nDimsRemaining>0) { fprintf(outfile,"complex *_img%li_array = new complex[%i",whichMG,nextMGElement->momentNameList.size()); if(simulation()->parameters()->usempi&!simulation()->parameters()->stochastic) { whichMoment=0; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++) { if(!*nextIntegrateDimension) { if(whichMoment==0) { if(swapped) { fprintf(outfile,"*_%s_lattice0",fieldName); } else { fprintf(outfile,"*local_nx"); } } else if(whichMoment==1) { if(!swapped) { fprintf(outfile,"*_%s_lattice1",fieldName); } else { fprintf(outfile,"*local_ny_after_transpose"); } } else { fprintf(outfile,"*_%s_lattice%li",fieldName,whichMoment); } } whichMoment++; } } else { whichMoment=0; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++) { if(!*nextIntegrateDimension) { fprintf(outfile,"*_%s_lattice%li",fieldName,whichMoment); } whichMoment++; } } fprintf(outfile,"];\n"); } else { for(list<XMLString>::const_iterator nextMomentName = nextMGElement->momentNameList.begin(); nextMomentName != nextMGElement->momentNameList.end(); nextMomentName++) { fprintf(outfile,"complex %s = rcomplex(0,0);\n",nextMomentName->c_str()); } } fprintf(outfile,"\n"); //zero the arrays and setup a local environment for the sum if(nDimsRemaining>0) { fprintf(outfile,"for(long _i0=0; _i0<%i",nextMGElement->momentNameList.size()); if(simulation()->parameters()->usempi&!simulation()->parameters()->stochastic) { whichMoment=0; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++) { if(!*nextIntegrateDimension) { if(whichMoment==0) { if(swapped) { fprintf(outfile,"*_%s_lattice0",fieldName); } else { fprintf(outfile,"*local_nx"); } } else if(whichMoment==1) { if(!swapped) { fprintf(outfile,"*_%s_lattice1",fieldName); } else { fprintf(outfile,"*local_ny_after_transpose"); } } else { fprintf(outfile,"*_%s_lattice%li",fieldName,whichMoment); } } whichMoment++; } } else { whichMoment=0; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++) { if(!*nextIntegrateDimension) { fprintf(outfile,"*_%s_lattice%li",fieldName,whichMoment); } whichMoment++; } } fprintf(outfile,"; _i0++) {\n"); fprintf(outfile," _img%li_array[_i0] = rcomplex(0,0);\n",whichMG); fprintf(outfile,"}\n"); } fprintf(outfile,"{\n"); // open loops simulation()->field()->openLoops(outfile,mySpace,myVectorNamesList); // pointer definition if(nDimsRemaining>0) { fprintf(outfile," long _img%li_pointer = ",whichMG); for(long unsigned int j=0; j<nDimsRemaining-1; j++) { fprintf(outfile,"("); } whichMoment = 0; list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); while(*nextIntegrateDimension) { nextIntegrateDimension++; whichMoment++; } fprintf(outfile,"_i%li",whichMoment); nextIntegrateDimension++; whichMoment++; for(long unsigned int k=0; k<nDimsRemaining-1; k++) { while(*nextIntegrateDimension) { nextIntegrateDimension++; whichMoment++; } if(swapped&&(whichMoment==1)) { fprintf(outfile,"*_%s_lattice0+_i1)",fieldName); } else { fprintf(outfile,"*_%s_lattice%li+_i%li)",fieldName,whichMoment,whichMoment); } nextIntegrateDimension++; whichMoment++; } fprintf(outfile,"*%i;\n",nextMGElement->momentNameList.size()); } // code fprintf(outfile,"%s\n",nextMGElement->integrateMomentGroupCode.c_str()); // close loops simulation()->field()->closeLoops(outfile,mySpace,myVectorNamesList); fprintf(outfile,"}\n"); // if there was any integration, multiply by the relevant volume element if(nDimsRemaining < simulation()->field()->geometry()->nDims()) { if(nDimsRemaining > 0) { fprintf(outfile,"\nfor(long _i0=0; _i0<%i",nextMGElement->momentNameList.size()); if(simulation()->parameters()->usempi&!simulation()->parameters()->stochastic) { whichMoment=0; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++) { if(!*nextIntegrateDimension) { if(whichMoment==0) { if(swapped) { fprintf(outfile,"*_%s_lattice0",fieldName); } else { fprintf(outfile,"*local_nx"); } } else if(whichMoment==1) { if(!swapped) { fprintf(outfile,"*_%s_lattice1",fieldName); } else { fprintf(outfile,"*local_ny_after_transpose"); } } else { fprintf(outfile,"*_%s_lattice%li",fieldName,whichMoment); } } whichMoment++; } } else { whichMoment=0; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++) { if(!*nextIntegrateDimension) { fprintf(outfile,"*_%s_lattice%li",fieldName,whichMoment); } whichMoment++; } } whichMoment=0; fprintf(outfile,"; _i0++) {\n"); fprintf(outfile," _img%li_array[_i0] = _img%li_array[_i0]",whichMG,whichMG); long unsigned int tempSpace = mySpace; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++){ if(*nextIntegrateDimension) { if(tempSpace&1) { fprintf(outfile,"*_%s_dk%li",fieldName,whichMoment); } else { fprintf(outfile,"*_%s_dx%li",fieldName,whichMoment); } } tempSpace >>= 1; whichMoment++; } fprintf(outfile,";\n"); fprintf(outfile," }\n"); } else { for(list<XMLString>::const_iterator nextMomentName = nextMGElement->momentNameList.begin(); nextMomentName != nextMGElement->momentNameList.end(); nextMomentName++) { whichMoment = 0; fprintf(outfile," %s = %s",nextMomentName->c_str(),nextMomentName->c_str()); long unsigned int tempSpace = mySpace; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++){ if(*nextIntegrateDimension) { if(tempSpace&1) { fprintf(outfile,"*_%s_dk%li",fieldName,whichMoment); } else { fprintf(outfile,"*_%s_dx%li",fieldName,whichMoment); } } tempSpace >>= 1; whichMoment++; } fprintf(outfile,";\n"); } } } // if mpi and first variable integrated then mpireduce if(simulation()->parameters()->usempi&!simulation()->parameters()->stochastic) { if(swapped) { // have to predicate on the second field at least if(* nextMGElement->integrateDimensionList.begin()++) { if(nDimsRemaining>0) { fprintf(outfile,"\n complex *_temp_img%li_array = new complex[%i",whichMG,nextMGElement->momentNameList.size()); whichMoment=0; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++) { if(!*nextIntegrateDimension) { fprintf(outfile,"*_%s_lattice%li",fieldName,whichMoment); } whichMoment++; } fprintf(outfile,"];\n"); fprintf(outfile," MPI_Reduce(_img%li_array,_temp_img%li_array,2*%i",whichMG,whichMG,nextMGElement->momentNameList.size()); whichMoment=0; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++) { if(!*nextIntegrateDimension) { fprintf(outfile,"*_%s_lattice%li",fieldName,whichMoment); } whichMoment++; } fprintf(outfile,",MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);\n"); fprintf(outfile,"\n delete[] _temp_img%li_array;\n",whichMG); } else { fprintf(outfile,"\n complex *_temp%li_mpireduce = new complex;\n",whichMG); for(list<XMLString>::const_iterator nextMomentName = nextMGElement->momentNameList.begin(); nextMomentName != nextMGElement->momentNameList.end(); nextMomentName++) { fprintf(outfile," MPI_Reduce(&%s,_temp%li_mpireduce,2,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);\n",nextMomentName->c_str(),whichMG); fprintf(outfile,"\n delete _temp%li_mpireduce;\n",whichMG); } } } } else { if(* nextMGElement->integrateDimensionList.begin()) { if(nDimsRemaining>0) { fprintf(outfile,"\n complex *_temp_img%li_array = new complex[%i",whichMG,nextMGElement->momentNameList.size()); whichMoment=0; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++) { if(!*nextIntegrateDimension) { fprintf(outfile,"*_%s_lattice%li",fieldName,whichMoment); } whichMoment++; } fprintf(outfile,"];\n"); fprintf(outfile," MPI_Reduce(_img%li_array,_temp_img%li_array,2*%i",whichMG,whichMG,nextMGElement->momentNameList.size()); whichMoment=0; for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++) { if(!*nextIntegrateDimension) { fprintf(outfile,"*_%s_lattice%li",fieldName,whichMoment); } whichMoment++; } fprintf(outfile,",MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);\n"); fprintf(outfile,"\n delete[] _temp_img%li_array;\n",whichMG); } else { fprintf(outfile,"\n complex *_temp%li_mpireduce = new complex;\n",whichMG); for(list<XMLString>::const_iterator nextMomentName = nextMGElement->momentNameList.begin(); nextMomentName != nextMGElement->momentNameList.end(); nextMomentName++) { fprintf(outfile," MPI_Reduce(&%s,_temp%li_mpireduce,2,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);\n",nextMomentName->c_str(),whichMG); fprintf(outfile,"\n delete _temp%li_mpireduce;\n",whichMG); } } } } } fprintf(outfile,"\n"); fprintf(outfile,"// *********************************************************\n"); fprintf(outfile,"\n"); nextMGElement++; } else { throw xmdsException("Unknown code element in the integrate block!"); } } // delete any arrays that were generated for(list<long>::const_iterator deleteMGArray = deleteMGArrayList.begin(); deleteMGArray != deleteMGArrayList.end(); deleteMGArray++) { fprintf(outfile,"delete[] _img%li_array;\n",*deleteMGArray); } fprintf(outfile,"}\n"); fprintf(outfile,"\n");};// ******************************************************************************//! Returns space at index. Don't ask me why this returns booleanbool xmdsFilter::space( const long unsigned int& index) const { if(debugFlag) { printf("xmdsFilter::space\n"); } if(index>=simulation()->field()->geometry()->nDims()) { throw xmdsException("Internal range error in xmdsFilter::space()"); } return (mySpace >> index)&1;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -