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

📄 xmdsfield.cc

📁 XMDS is a code generator that integrates equations. You write them down in human readable form in a
💻 CC
📖 第 1 页 / 共 3 页
字号:
		  if(isKSpace[i-1]) {			  			  for(unsigned long j=0; j<i; j++) {				  fprintf(outfile,"	");			  }			  fprintf(outfile,"k%s += _%s_dk%li;\n",myGeometry.dimension(i-1)->name.c_str(),myName.c_str(),i-1);			  			  for(unsigned long j=0; j<i; j++) {				  fprintf(outfile,"	");			  }			  fprintf(outfile,"if(k%s>((_%s_lattice%li-1)/2 + 0.1)*_%s_dk%li)\n",					  myGeometry.dimension(i-1)->name.c_str(),myName.c_str(),i-1,myName.c_str(),i-1);				  			  for(unsigned long j=0; j<i; j++) {				  fprintf(outfile,"	");			  }			  fprintf(outfile,"	k%s -= _%s_lattice%li*_%s_dk%li;\n",					  myGeometry.dimension(i-1)->name.c_str(),myName.c_str(),i-1,myName.c_str(),i-1);		  }		  else {			  for(unsigned long j=0; j<i; j++) {				  fprintf(outfile,"	");			  }			  fprintf(outfile,"%s += _%s_dx%li;\n",myGeometry.dimension(i-1)->name.c_str(),myName.c_str(),i-1);		  }		  		  for(unsigned long j=0; j<i; j++) {			  fprintf(outfile,"	");		  }		  fprintf(outfile,"}\n");      }    }	    delete isKSpace;};// ******************************************************************************void xmdsField::writePlanCreationCalls(				       FILE *const outfile,				       const bool& useFFTWMeasure,				       const bool& useWisdom) const {  if(debugFlag) {    printf("xmdsField::writePlanCreationCalls\n");  }  if(!myNeedsFFTWPlans) {    return;  }  const char *useMeasureStr = "";  const char *useWisdomStr = "";  //const char *wisdomFname = simulation()->parameters()->simulationName.c_str();  if(useFFTWMeasure) {    useMeasureStr = "|FFTW_MEASURE";  }  if(useWisdom) {    useWisdomStr = "|FFTW_USE_WISDOM";  }  for(unsigned long i=0;i<myGeometry.nDims();i++) {    fprintf(outfile,"_fftw_lattice[%li]=_%s_lattice%li;\n",i,myName.c_str(),i);  }  if((!(simulation()->parameters()->stochastic))&(simulation()->parameters()->usempi)){    if (useWisdom) {      fprintf(outfile,           "{\n"	      "\nFILE *fWisdom;\n"	      "ifstream fIn;\n"	      "ofstream fOut;\n"	      "// this is a dodgy hack, but it should work\n"	      "string findHostString, findHomeString, hostStuff, homeStuff, rmString, rankString;\n"	      "ostringstream outString;\n"	      "outString << rank;\n"	      "rankString = outString.str();\n"	      "hostStuff = \"host_rank_\" + rankString + \".stuff\";\n"	      "findHostString = \"uname -n > \" + hostStuff;\n"	      "system(findHostString.c_str());\n"	      "homeStuff = \"home_rank_\" + rankString + \".stuff\";\n"	      "findHomeString = \"echo $HOME > \" + homeStuff;\n"	      "system(findHomeString.c_str());\n"	      "string hostName, homeDir;\n"	      "fIn.open(hostStuff.c_str());\n"	      "if (fIn.fail()) {\n"	      "    // do something\n"	      "}\n"	      "fIn >> hostName;\n"	      "fIn.close();\n"	      "fIn.open(homeStuff.c_str());\n"	      "if (fIn.fail()) {\n"	      "    // do something\n"	      "}\n"	      "fIn >> homeDir;\n"	      "fIn.close();\n"	      "rmString = \"rm \" + hostStuff + \" \" + homeStuff;\n"	      "system(rmString.c_str());\n\n"	      "string testFname, wisdomFname;\n"	      "testFname = homeDir + \"/.xmds/wisdom/test\";\n"	      "fOut.open(testFname.c_str());\n"	      "if (fOut.fail()) {\n"	      "    cout << \"Warning: ~/.xmds/wisdom directory doesn't seem to exist.\\n\";\n"	      "    cout << \"Using current directory instead\\n\";\n"	      "    wisdomFname = hostName + \".wisdom\";\n"	      "}\n"	      "else {\n"	      "    fOut.close();\n"	      "    rmString = \"rm \" + testFname;\n"	      "    system(rmString.c_str());\n"	      "    wisdomFname = homeDir + \"/.xmds/wisdom/\" + hostName + \".wisdom\";\n"	      "}\n"	      "printf(\"Performing fftw calculations\\n\");\n"	      "if ((fWisdom = fopen(wisdomFname.c_str(), \"r\")) != NULL) {\n"	      "    cout << \"Standing upon the shoulders of giants... (Importing wisdom)\\n\";\n"	      "    fftw_import_wisdom_from_file(fWisdom);\n"	      "    fclose(fWisdom);\n"	      "}\n"	      );    }    fprintf(outfile,"printf(\"Making forward plan\\n\");\n");    fprintf(outfile,"_%s_forward_plan = fftwnd_mpi_create_plan(MPI_COMM_WORLD,_%s_ndims,_fftw_lattice,FFTW_FORWARD,FFTW_IN_PLACE%s%s);\n",myName.c_str(),myName.c_str(),useMeasureStr,useWisdomStr);    // Using FFTW_TRANSPOSED_ORDER, so backward plan has different array sizes    fprintf(outfile,"_fftw_lattice[0]=_%s_lattice1;\n",myName.c_str());    fprintf(outfile,"_fftw_lattice[1]=_%s_lattice0;\n",myName.c_str());    for(unsigned long i=2;i<myGeometry.nDims();i++) {      fprintf(outfile,"_fftw_lattice[%li]=_%s_lattice%li;\n",i,myName.c_str(),i);    }    fprintf(outfile,"printf(\"Making backward plan\\n\");\n");    fprintf(outfile,"_%s_backward_plan = fftwnd_mpi_create_plan(MPI_COMM_WORLD,_%s_ndims,_fftw_lattice,FFTW_BACKWARD,FFTW_IN_PLACE%s%s);\n",myName.c_str(),myName.c_str(),useMeasureStr,useWisdomStr);    if (useWisdom) {      fprintf(outfile,"printf(\"Keeping accumulated wisdom\\n\");\n");      fprintf(outfile,"fWisdom = fopen(wisdomFname.c_str(), \"w\");\n");      fprintf(outfile,"fftw_export_wisdom_to_file(fWisdom);\n");      fprintf(outfile,"fclose(fWisdom);\n");      fprintf(outfile,"}\n");      fprintf(outfile,"printf(\"Finished fftw calculations\\n\");\n");    }  }  else {    if (useWisdom) {      fprintf(outfile,           "{\n"	      "FILE *fWisdom;\n"	      "ifstream fIn;\n"	      "ofstream fOut;\n"	      "// this is a dodgy hack, but it should work\n"	      "string findHostString, findHomeString, hostStuff, homeStuff, rmString, rankString;\n");      if (!simulation()->parameters()->usempi) {	fprintf(outfile, "int rank = 0;\n");      }      fprintf(outfile, 	      "ostringstream outString;\n"	      "outString << rank;\n"	      "rankString = outString.str();\n"	      "hostStuff = \"host_rank_\" + rankString + \".stuff\";\n"	      "findHostString = \"uname -n > \" + hostStuff;\n"	      "system(findHostString.c_str());\n"	      "homeStuff = \"home_rank_\" + rankString + \".stuff\";\n"	      "findHomeString = \"echo $HOME > \" + homeStuff;\n"	      "system(findHomeString.c_str());\n"	      "string hostName, homeDir;\n"	      "fIn.open(hostStuff.c_str());\n"	      "if (fIn.fail()) {\n"	      "    // do something\n"	      "}\n"	      "fIn >> hostName;\n"	      "fIn.close();\n"	      "fIn.open(homeStuff.c_str());\n"	      "if (fIn.fail()) {\n"	      "    // do something\n"	      "}\n"	      "fIn >> homeDir;\n"	      "fIn.close();\n"	      "rmString = \"rm \" + hostStuff + \" \" + homeStuff;\n"	      "system(rmString.c_str());\n\n"	      "string testFname, wisdomFname;\n"	      "testFname = homeDir + \"/.xmds/wisdom/test\";\n"	      "fOut.open(testFname.c_str());\n"	      "if (fOut.fail()) {\n"	      "    cout << \"Warning: ~/.xmds/wisdom directory doesn't seem to exist.\\n\";\n"	      "    cout << \"Using current directory instead\\n\";\n"	      "    wisdomFname = hostName + \".wisdom\";\n"	      "}\n"	      "else {\n"	      "    fOut.close();\n"	      "    wisdomFname = homeDir + \"/.xmds/wisdom/\" + hostName + \".wisdom\";\n"	      "    rmString = \"rm \" + testFname;\n"	      "    system(rmString.c_str());\n"	      "}\n"	      "printf(\"Performing fftw calculations\\n\");\n"	      "if ( (fWisdom = fopen(wisdomFname.c_str(), \"r\")) != NULL) {\n"	      "    cout << \"Standing upon the shoulders of giants... (Importing wisdom)\\n\";\n"	      "    fftw_import_wisdom_from_file(fWisdom);\n"	      "    fclose(fWisdom);\n"	      "}\n");    }    fprintf(outfile,"printf(\"Making forward plan\\n\");\n");    fprintf(outfile,"_%s_forward_plan = fftwnd_create_plan(_%s_ndims,_fftw_lattice,FFTW_FORWARD,FFTW_IN_PLACE%s%s);\n",myName.c_str(),myName.c_str(),useMeasureStr,useWisdomStr);    fprintf(outfile,"printf(\"Making backward plan\\n\");\n");    fprintf(outfile,"_%s_backward_plan = fftwnd_create_plan(_%s_ndims,_fftw_lattice,FFTW_BACKWARD,FFTW_IN_PLACE%s%s);\n",myName.c_str(),myName.c_str(),useMeasureStr,useWisdomStr);    if (useWisdom) {      fprintf(outfile,	      "printf(\"Keeping accumulated wisdom\\n\");\n"	      "fWisdom = fopen(wisdomFname.c_str(),\"w\");\n"	      "fftw_export_wisdom_to_file(fWisdom);\n"	      "fclose(fWisdom);\n"		  "}\n"	      "printf(\"Finished fftw calculations\\n\");\n");    }  }  fprintf(outfile,"\n");};// ******************************************************************************void xmdsField::writePlanDeletionCalls(				       FILE *const outfile) const {  if(debugFlag) {    printf("xmdsField::writePlanDeletionCalls\n");  }  if(!myNeedsFFTWPlans) {    return;  }  if((!(simulation()->parameters()->stochastic))&(simulation()->parameters()->usempi)){    fprintf(outfile,"fftwnd_mpi_destroy_plan(_%s_forward_plan);\n",myName.c_str());    fprintf(outfile,"fftwnd_mpi_destroy_plan(_%s_backward_plan);\n",myName.c_str());  }  else {    fprintf(outfile,"fftwnd_destroy_plan(_%s_forward_plan);\n",myName.c_str());    fprintf(outfile,"fftwnd_destroy_plan(_%s_backward_plan);\n",myName.c_str());  }  fprintf(outfile,"\n");};// ******************************************************************************xmdsVector* xmdsField::createxmdsVector() {  if(debugFlag) {    printf("xmdsField::createxmdsVector\n");  }  xmdsVector* newVector = new xmdsVector(this);  myVectorsList.push_back(newVector);  return newVector;};// ******************************************************************************// ******************************************************************************//                              xmdsField protected// ******************************************************************************// ******************************************************************************// ******************************************************************************void xmdsField::writeDefines(			     FILE *const outfile) const {  if(debugFlag) {    printf("xmdsField::writeDefines\n");  }  fprintf(outfile,"// ********************************************************\n");  fprintf(outfile,"// field %s defines\n",myName.c_str());  fprintf(outfile,"\n");  fprintf(outfile,"#define _%s_ndims %li\n",myName.c_str(),myGeometry.nDims());  for(unsigned long i=0; i<myGeometry.nDims(); i++) {    const dimensionStruct* dimI = myGeometry.dimension(i);    fprintf(outfile,"#define _%s_lattice%li %li\n",myName.c_str(),i,dimI->lattice);    fprintf(outfile,"#define _%s_xmin%li %e\n",myName.c_str(),i,dimI->domain.begin);    fprintf(outfile,"#define _%s_dx%li ((%e - %e)/(double)_%s_lattice%li)\n",myName.c_str(),i,dimI->domain.end,dimI->domain.begin,myName.c_str(),i);    fprintf(outfile,"#define _%s_dk%li (2*M_PI/(%e - %e))\n",myName.c_str(),i,dimI->domain.end,dimI->domain.begin);    fprintf(outfile,"#define d%s _%s_dx%li\n",dimI->name.c_str(),myName.c_str(),i);    fprintf(outfile,"#define dk%s _%s_dk%li\n",dimI->name.c_str(),myName.c_str(),i);  }  fprintf(outfile,"\n");  for(list<const xmdsVector*>::const_iterator ppxmdsVector = myVectorsList.begin(); ppxmdsVector != myVectorsList.end(); ppxmdsVector++) {    (*ppxmdsVector)->writeDefines(outfile);  }  fprintf(outfile,"\n");};// ******************************************************************************void xmdsField::writeGlobals(			     FILE *const outfile) const {  if(debugFlag) {    printf("xmdsField::writeGlobals\n");  }  fprintf(outfile,"// ********************************************************\n");  fprintf(outfile,"// field %s globals\n",myName.c_str());  fprintf(outfile,"\n");  if(myGeometry.nDims()>0) {    fprintf(outfile,"const unsigned long _%s_size=_%s_lattice0",myName.c_str(),myName.c_str());    for(unsigned long i=1; i<myGeometry.nDims(); i++) {      fprintf(outfile,"*_%s_lattice%li",myName.c_str(),i);    }    fprintf(outfile,";\n");  }  else    fprintf(outfile,"const unsigned long _%s_size=1;\n",myName.c_str());  fprintf(outfile,"\n");  if(myNeedsFFTWPlans) {    if((!(simulation()->parameters()->stochastic))&(simulation()->parameters()->usempi)) {	fprintf(outfile,"fftwnd_mpi_plan _%s_forward_plan;\n",myName.c_str());	fprintf(outfile,"fftwnd_mpi_plan _%s_backward_plan;\n",myName.c_str());      }    else {	fprintf(outfile,"fftwnd_plan _%s_forward_plan;\n",myName.c_str());	fprintf(outfile,"fftwnd_plan _%s_backward_plan;\n",myName.c_str());      }  }  fprintf(outfile,"\n");  for(list<const xmdsVector*>::const_iterator ppxmdsVector = myVectorsList.begin(); ppxmdsVector != myVectorsList.end(); ppxmdsVector++) {    (*ppxmdsVector)->writeGlobals(outfile);  }  fprintf(outfile,"\n");};// ******************************************************************************void xmdsField::writePrototypes(				FILE *const outfile) const {  if(debugFlag) {    printf("xmdsField::writePrototypes\n");  }  fprintf(outfile,"// ********************************************************\n");  fprintf(outfile,"// field %s prototypes\n",myName.c_str());  fprintf(outfile,"\n");  for(list<const xmdsVector*>::const_iterator ppxmdsVector = myVectorsList.begin(); ppxmdsVector != myVectorsList.end(); ppxmdsVector++) {    (*ppxmdsVector)->writePrototypes(outfile);  }  fprintf(outfile,"\n");};// ******************************************************************************void xmdsField::writeRoutines(			      FILE *const outfile) const {  if(debugFlag) {    printf("xmdsField::writeRoutines\n");  }  fprintf(outfile,"// ********************************************************\n");  fprintf(outfile,"//		field %s routines\n",myName.c_str());  fprintf(outfile,"// ********************************************************\n");  fprintf(outfile,"\n");  for(list<const xmdsVector*>::const_iterator ppxmdsVector = myVectorsList.begin(); ppxmdsVector != myVectorsList.end(); ppxmdsVector++) {    (*ppxmdsVector)->writeRoutines(outfile);  }  fprintf(outfile,"\n");};// ******************************************************************************void xmdsField::setName(			const XMLString& yourName) {  if(debugFlag) {    printf("xmdsField::setName\n");  }  myName=yourName;};// ******************************************************************************void xmdsField::setGeometry(			    const xmdsFieldGeometry& yourGeometry) {  if(debugFlag) {    printf("xmdsField::setGeometry\n");  }  myGeometry = yourGeometry;};// ******************************************************************************// ******************************************************************************//                              xmdsField private// ******************************************************************************// ******************************************************************************// ******************************************************************************xmdsVectorElement* xmdsField::createxmdsVectorElement() {  if( debugFlag) {    printf("xmdsField::createxmdsVectorElement\n");  }  xmdsVectorElement* newVectorElement = new xmdsVectorElement(simulation(),verbose(),this);  myVectorsList.push_back(newVectorElement);  return newVectorElement;};

⌨️ 快捷键说明

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