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

📄 xmdssequence.cc

📁 XMDS is a code generator that integrates equations. You write them down in human readable form in a
💻 CC
📖 第 1 页 / 共 3 页
字号:
/* Copyright (C) 2000-2004 Code contributed by Greg Collecutt, Joseph Hope and Paul Cochrane This file is part of xmds.  This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*//*  $Id: xmdssequence.cc,v 1.35 2004/10/06 07:52:39 joehope Exp $*//*! @file xmdssequence.cc  @brief Sequence element parsing classes and methods  More detailed explanation...*/#include<xmlbasics.h>#include<dom3.h>#include<xmdsutils.h>#include<xmdsclasses.h>// ******************************************************************************// *****************************************************************************//                             xmdsSequence public// *****************************************************************************// ******************************************************************************extern bool debugFlag;long nxmdsSequences=0;  //!< Number of xmds sequence objects// ******************************************************************************xmdsSequence::xmdsSequence(			   const xmdsSimulation *const yourSimulation,			   const bool& yourVerboseMode) :  xmdsSegment(yourSimulation,yourVerboseMode) {  if(debugFlag) {    nxmdsSequences++;    printf("xmdsSequence::xmdsSequence\n");    printf("nxmdsSequences=%li\n",nxmdsSequences);  }  nCycles=1;};// ******************************************************************************xmdsSequence::~xmdsSequence() {  if(debugFlag) {    nxmdsSequences--;    printf("xmdsSequence::~xmdsSequence\n");    printf("nxmdsSequences=%li\n",nxmdsSequences);  }};// ******************************************************************************void xmdsSequence::processElement(				  const Element *const yourElement) {  if(debugFlag) {    printf("xmdsSequence::processElement\n");  }  unsigned long i;  const NodeList* myElements;  const Element* nextElement;  xmdsSegment* newSegment;  if(verbose()) {    printf("Processing sequence element ...\n");  }  // ************************************  // process elements in order  myElements = yourElement->getElementsByTagName("*",0);  i=0;  nextElement = dynamic_cast<const Element*> (myElements->item(0));  if(*nextElement->nodeName() == "cycles") {    if(segmentNumber==0) {      throw xmdsException(nextElement,"Cannot have cycles in top level sequence");    }    if(!nextElement->textContent(0)->asULong(nCycles)) {      throw xmdsException(nextElement,"invalid positive integer format");    }    i++;  }  else    // default number of cycles    nCycles=1;  while(i<myElements->length()) {    nextElement = dynamic_cast<const Element*> (myElements->item(i));    if(*nextElement->nodeName() == "sequence") {      newSegment = createxmdsSequence();    }    else if(*nextElement->nodeName() == "integrate") {      // ************************************      // find 'algorithm' so that we can create the appropriate      // type of xmdsIntegrate class      list<XMLString> tempXMLStringList;      getAssignmentStrings(nextElement,"algorithm",0,1,tempXMLStringList);      if(tempXMLStringList.size()==0) {	// need default algorithm	if(simulation()->parameters()->stochastic) {	  printf("Algorithm defaulting to SIEX.\n");	  tempXMLStringList.push_back("SIEX");	}	else {	  printf("Algorithm defaulting to RK4EX.\n");	  tempXMLStringList.push_back("RK4EX");	}      }      if(*tempXMLStringList.begin()=="RK4EX") {	newSegment = createxmdsIntegrateRK4EX();      }      else if(*tempXMLStringList.begin()=="RK4IP") {	newSegment = createxmdsIntegrateRK4IP();      }      else if(*tempXMLStringList.begin()=="SIEX") {	newSegment = createxmdsIntegrateSIEX();      }      else if(*tempXMLStringList.begin()=="SIIP") {	newSegment = createxmdsIntegrateSIIP();      }      else {	sprintf(errorMessage(),"Integrate algorithm '%s' unknown.\nCurrent algorithms are SIEX, RK4EX, SIIP, and RK4IP.",		tempXMLStringList.begin()->c_str());	throw xmdsException(yourElement,errorMessage());      }    }    else if(*nextElement->nodeName() == "filter") {      newSegment = createxmdsFilter();    }    else {      sprintf(errorMessage(),"segment <%s> unknown",nextElement->nodeName()->c_str());      throw xmdsException(yourElement,errorMessage());    }    newSegment->processElement(nextElement);    i++;  }};// ******************************************************************************void xmdsSequence::outputSampleCount() const {  if(debugFlag) {    printf("xmdsSequence::outputSampleCount\n");  }  for(unsigned long i=0;i<nCycles;i++) {    for(list<const xmdsSegment*>:: const_iterator ppxmdsSegment	  = mySegmentList.begin(); ppxmdsSegment !=	  mySegmentList.end(); ppxmdsSegment++) {      (*ppxmdsSegment)->outputSampleCount();    }  }};// ******************************************************************************// ******************************************************************************//                              xmdsSequence private// ******************************************************************************// ******************************************************************************// ******************************************************************************void xmdsSequence::writeDefines(				FILE *const outfile) const {  if(debugFlag) {    printf("xmdsSequence::writeDefines\n");  }  if(verbose()) {    printf("Writing sequence defines ...\n");  }  if(segmentNumber==0) {    fprintf(outfile,	    "// ********************************************************\n"	    "// segment defines\n"	    "\n");  }  xmdsElement::writeDefines(outfile);  fprintf(outfile,"\n");};// ******************************************************************************void xmdsSequence::writeGlobals(				FILE *const outfile) const {  if(debugFlag) {    printf("xmdsSequence::writeGlobals\n");  }  if(verbose()) {    printf("Writing sequence globals ...\n");  }  if(segmentNumber==0) {    fprintf(outfile,	    "// ********************************************************\n"	    "// segment globals\n"	    "\n");  }  xmdsElement::writeGlobals(outfile);  fprintf(outfile,"\n");};// ******************************************************************************void xmdsSequence::writePrototypes(				   FILE *const outfile) const {  if(debugFlag) {    printf("xmdsSequence::writePrototypes\n");  }  if(verbose()) {    printf("Writing sequence prototypes ...\n");  }  if(segmentNumber==0) {    fprintf(outfile,	    "// ********************************************************\n"	    "// segment prototypes\n"	    "\n");    if(simulation()->parameters()->usempi) {      fprintf(outfile,	      "void _segment0(\n"	      "	const int& size); // top level sequence\n");    }    else      fprintf(outfile,"void _segment0(); // top level sequence\n");    fprintf(outfile,"\n");  }  else    fprintf(outfile,"void _segment%li(unsigned long cycle); // sequence\n",segmentNumber);          xmdsElement::writePrototypes(outfile);  fprintf(outfile,"\n");};// ******************************************************************************void xmdsSequence::writeRoutines(				 FILE *const outfile) const {  if(debugFlag) {    printf("xmdsSequence::writeRoutines\n");  }  if(segmentNumber==0) {    // I am the main routine    if(verbose()) {      printf("Writing main routine ...\n");    }    fprintf(outfile,	    "// ********************************************************\n"	    "//		main routine\n"	    "// ********************************************************\n"	    "\n"	    "// *************************\n");    if (verbose()) {      printf("argStruct()->nameList.size() = %i\n",simulation()->argStruct()->nameList.size());      printf("argStruct()->typeList.size() = %i\n",simulation()->argStruct()->typeList.size());       printf("argStruct()->defaultValueList.size() = %i\n",simulation()->argStruct()->defaultValueList.size());      printf("argStruct()->nameList.size() = %i\n",simulation()->argStruct()->shortOptionList.size());      printf("argStruct()->typeConversionList.size() = %i\n",simulation()->argStruct()->typeConversionList.size());      list<string>::const_iterator inameList = simulation()->argStruct()->nameList.begin();      list<string>::const_iterator itypeList = simulation()->argStruct()->typeList.begin();      list<string>::const_iterator idefaultValueList = simulation()->argStruct()->defaultValueList.begin();      list<string>::const_iterator ishortOptionList = simulation()->argStruct()->shortOptionList.begin();      list<string>::const_iterator itypeConversionList = simulation()->argStruct()->typeConversionList.begin();      printf("argvStruct()->nameList = \n");      for (unsigned long int i=0; i<simulation()->argStruct()->nameList.size(); i++) {	printf("\t%s\n",inameList->c_str());	inameList++;      }      printf("argvStruct()->typeList = \n");      for (unsigned long int i=0; i<simulation()->argStruct()->typeList.size(); i++) {	printf("\t%s\n",itypeList->c_str());	itypeList++;      }      printf("argvStruct()->defaultValueList = \n");      for (unsigned long int i=0; i<simulation()->argStruct()->defaultValueList.size(); i++) {	printf("\t%s\n",idefaultValueList->c_str());	idefaultValueList++;

⌨️ 快捷键说明

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