⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmdsintegratesiip.cc

📁 XMDS is a code generator that integrates equations. You write them down in human readable form in a
💻 CC
📖 第 1 页 / 共 3 页
字号:
	  }	}	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){		fprintf(outfile,"*local_nx");	      }	      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,0,myTotalVectorsList);      // 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++;	  }	  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,0,myTotalVectorsList);			        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,"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){		  fprintf(outfile,"*local_nx");		}		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);	  for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); 	      nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++){	    if(*nextIntegrateDimension) {	      fprintf(outfile,"*_%s_dx%li",fieldName,whichMoment);	    }	    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());	    for(list<bool>::const_iterator nextIntegrateDimension = nextMGElement->integrateDimensionList.begin(); 		nextIntegrateDimension != nextMGElement->integrateDimensionList.end(); nextIntegrateDimension++){	      if(*nextIntegrateDimension) {		fprintf(outfile,"*_%s_dx%li",fieldName,whichMoment);	      }	      whichMoment++;	    }	    fprintf(outfile,";\n");	  }	}      }      // if mpi and first variable integrated then mpireduce      if(simulation()->parameters()->usempi&!simulation()->parameters()->stochastic) {	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);					  }    // clean up mallocs  fprintf(outfile,"    delete[] _%s_main_old;\n",fieldName);  for(list<XMLString>::const_iterator pXMLString = crossVectorNamesList()->begin(); pXMLString != crossVectorNamesList()->end(); pXMLString++) {    fprintf(outfile,"    delete[] _%s_%s_old;\n",	    fieldName,pXMLString->c_str());  }  if((simulation()->parameters()->stochastic)&&(!noNoises())) {    fprintf(outfile,"    delete[] _noises;\n");    if(simulation()->parameters()->errorCheck) {      fprintf(outfile,"    delete[] _noises2;\n");    }    fprintf(outfile,"\n");  }  fprintf(outfile,"}\n");  fprintf(outfile,"\n");};// ******************************************************************************void xmdsIntegrateSIIP::writeSingleStepCode(					    FILE *const outfile,					    const stepCaseEnum& stepCase) const {  if(debugFlag) {    printf("xmdsIntegrateSIIP::writeSingleStepCode\n");  }  const char *const propDim = simulation()->parameters()->propDimName.c_str();  const char* kStep="";  if(!constantK()) {    kStep="_step/2";  }  const char* generatorFlag="";  if((simulation()->parameters()->stochastic)&&(!noNoises())) {    if(stepCase==FULLSTEP) {      generatorFlag=",0";    }    else if(stepCase==FIRST_HALFSTEP) {      generatorFlag=",1";    }    else if(stepCase==SECOND_HALFSTEP) {      generatorFlag=",2";    }  }  const char* indent = "	";  if(simulation()->parameters()->errorCheck) {    indent = "		";  }  if(usesKOperators()) {    fprintf(outfile,"%s_segment%li_k_propagate(%s);\n",indent,segmentNumber,kStep);    fprintf(outfile,"\n");  }  fprintf(outfile,"%s%s += _step/2;\n",indent,propDim);  fprintf(outfile,"\n");  fprintf(outfile,"%s_segment%li_x_propagate(_step,cycle%s);\n",indent,segmentNumber,generatorFlag);  fprintf(outfile,"\n");  if(usesKOperators()) {    fprintf(outfile,"%s_segment%li_k_propagate(%s);\n",indent,segmentNumber,kStep);    fprintf(outfile,"\n");  }  fprintf(outfile,"%s%s += _step/2;\n",indent,propDim);  fprintf(outfile,"\n");};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -