📄 xmdssimulation.cc
字号:
/* 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: xmdssimulation.cc,v 1.48 2004/08/02 08:02:18 paultcochrane Exp $*//*! @file xmdssimulation.cc @brief Simulation element parsing classes and methods More detailed explanation...*/#include<xmlbasics.h>#include<dom3.h>#include<xmdsutils.h>#include<xmdsclasses.h>#include<config.h>// ******************************************************************************// ******************************************************************************// xmdsSimulation public// ******************************************************************************// ******************************************************************************extern bool debugFlag;long nxmdsSimulations=0; //!< The number of xmds simulation objects// ******************************************************************************xmdsSimulation::xmdsSimulation( const char *const yourRawFileName, const bool& yourVerboseMode, const bool& mpiAvailable) : xmdsElement(this,yourVerboseMode){ if(debugFlag) { nxmdsSimulations++; printf("xmdsSimulation::xmdsSimulation\n"); printf("nxmdsSimulations=%li\n",nxmdsSimulations); } myParameters.rawFileName = yourRawFileName; myParameters.stochastic = 0; myParameters.nThreads = 1; myParameters.nPaths = 1; myParameters.mpiAvailable = mpiAvailable; myParameters.usempi = 0; myParameters.bing = 0; myParameters.seed[0] = 1; myParameters.seed[1] = 2; myParameters.nNoises = 0; myParameters.noiseKind = "gaussian"; myParameters.noiseMean = 5.0; myParameters.errorCheck = 1; myParameters.useWisdom = 0; myParameters.binaryOutput = 0; myParameters.useDouble = 1; myParameters.benchmark = 0; myParameters.version = VERSION; myParameters.release = RELEASE; myCurrentSegmentNumber = 0;};// ******************************************************************************xmdsSimulation::~xmdsSimulation() { if(debugFlag) { nxmdsSimulations--; printf("xmdsSimulation::~xmdsSimulation\n"); printf("nxmdsSimulations=%li\n",nxmdsSimulations); }};// ******************************************************************************void xmdsSimulation::processElement( const Element *const yourElement) { if(debugFlag) { printf("xmdsSimulation::processElement\n"); } // ************************************ // process parameters // ************************************ list<XMLString> myXMLStringList; list<bool> myBoolList; list<unsigned long> myULongList; // ************************************ // find 'name' getAssignmentStrings(yourElement,"name",0,1,myXMLStringList); if(myXMLStringList.size()==1) { myParameters.simulationName=*myXMLStringList.begin(); if(verbose()) { printf("simulation name = '%s'\n",myParameters.simulationName.c_str()); } } else { // Create default simulation file name unsigned long lastdot=0; const XMLString tempName = myParameters.rawFileName; unsigned long i=0; while(i<tempName.length()) { if(tempName.data(i)=='.') { lastdot=i; } i++; } if(lastdot>0) { tempName.subString(myParameters.simulationName,0,lastdot); } else { myParameters.simulationName=tempName; } if(verbose()) { printf("simulation name defaulting to '%s'\n",myParameters.simulationName.c_str()); } } // ************************************ // find 'prop_dim' getAssignmentStrings(yourElement,"prop_dim",1,1,myXMLStringList); myParameters.propDimName=*myXMLStringList.begin(); if(verbose()) { printf("simulation prop_dim = '%s'\n",myParameters.propDimName.c_str()); } // ************************************ // find 'author' getAssignmentStrings(yourElement,"author",NOT_REQD,0,myXMLStringList); if (myXMLStringList.size() > 0) { myParameters.authorName = *myXMLStringList.begin(); myXMLStringList.pop_front(); for(list<XMLString>::const_iterator pXMLString = myXMLStringList.begin(); pXMLString != myXMLStringList.end(); pXMLString++) { myParameters.authorName += " "; myParameters.authorName += *pXMLString; } if(verbose()) { printf("simulation author = '%s'\n",myParameters.authorName.c_str()); } } else { // this warning may need to be taken out somehow, but I sort of want people // to be nice little coders and document their code nicely, and this is // one way to do it... (PTC) printf("No <author> tag found. It's not required, but it's a Good Idea.\n"); } // ************************************ // find 'description' getAssignmentStrings(yourElement,"description",NOT_REQD,0,myXMLStringList); // Storing the description can cause overflow errors if it is too long, so we'll // comment out the actual loading of the description, and put into the description // variable a note that it actually exists. if (myXMLStringList.size() > 0) { myParameters.description += "Description found. See xmds file for the rest of it."; /* myParameters.description = *myXMLStringList.begin(); myXMLStringList.pop_front(); for(list<XMLString>::const_iterator pXMLString = myXMLStringList.begin(); pXMLString != myXMLStringList.end(); pXMLString++) { myParameters.description += " "; myParameters.description += *pXMLString; } */ if(verbose()) { printf("simulation description = '%s'\n",myParameters.description.c_str()); } } else { // this warning may need to be taken out somehow, but I sort of want people // to be nice little coders and document their code nicely, and this is // one way to do it... (PTC) printf("No <description> tag found. It's not required, but it's a Good Idea.\n"); } // ************************************ // find 'error_check' getAssignmentBools(yourElement,"error_check",0,1,myBoolList); if(myBoolList.size()==1) { myParameters.errorCheck=*myBoolList.begin(); if(verbose()) { if(myParameters.errorCheck) { printf("simulation error_check is 'yes'\n"); } else { printf("simulation error_check is 'no'\n"); } } } else { if(verbose()) { printf("simulation error_check defaulting to 'yes'\n"); } myParameters.errorCheck=1; } // ************************************ // find 'use_wisdom' getAssignmentBools(yourElement,"use_wisdom",0,1,myBoolList); if(myBoolList.size()==1) { myParameters.useWisdom=*myBoolList.begin(); if(verbose()) { if(myParameters.useWisdom) { printf("simulation use_wisdom is 'yes'\n"); } else { printf("simulation use_wisdom is 'no'\n"); } } } else { if(verbose()) { printf("simulation use_wisdom defaulting to 'no'\n"); } myParameters.useWisdom=0; } // ************************************ // find 'use_prefs' getAssignmentBools(yourElement,"use_prefs",0,1,myBoolList); if(myBoolList.size()==1) { myParameters.usePrefs=*myBoolList.begin(); if(verbose()) { if(myParameters.usePrefs) { printf("simulation use_prefs is 'yes'\n"); } else { printf("simulation use_prefs is 'no'\n"); } } } else { if(verbose()) { printf("simulation use_prefs defaulting to 'yes'\n"); } myParameters.usePrefs=1; } // *********************************** // find binary output flag getAssignmentBools(yourElement,"binary_output",0,1,myBoolList); if(myBoolList.size()==1) { // now we need to print a warning and tell the user what they can do to fix the problem sprintf(errorMessage(),"Using the <binary_output> tag is obsolete.\n" " Please replace this tag and use the format=\"ascii|binary\"\n" " attribute of the <output> tag instead."); throw xmdsException(errorMessage()); // this is the old code /* myParameters.binaryOutput=*myBoolList.begin(); if(verbose()) { if(myParameters.binaryOutput) { printf("simulation binary_output is 'yes'\n"); } else printf("simulation binary_output is 'no'\n"); } */ } else { if(verbose()) { printf("simulation binary_output defaulting to 'no'\n"); } myParameters.binaryOutput=0; } // *********************************** // find use_double element getAssignmentBools(yourElement,"use_double",0,1,myBoolList); if(myBoolList.size()==1) { // now we need to print a warning and tell the user what they can do to fix the problem sprintf(errorMessage(),"Using the <use_double> tag is obsolete.\n" " Please replace this tag and use the precision=\"double|single\"\n" " attribute of the <output> tag instead."); throw xmdsException(errorMessage()); // this is the old code /* myParameters.useDouble=*myBoolList.begin(); if(verbose()) { if(myParameters.useDouble) { printf("simulation use_double is 'yes'\n"); } else printf("simulation use_double is 'no'\n"); } */ } else { if(verbose()) { printf("simulation use_double defaulting to 'yes'\n"); } myParameters.useDouble=1; } // *********************************** // find benchmark element getAssignmentBools(yourElement,"benchmark",0,1,myBoolList); if(myBoolList.size()==1) { myParameters.benchmark=*myBoolList.begin(); if(verbose()) { if(myParameters.benchmark) { printf("simulation benchmark is 'yes'\n"); } else { printf("simulation benchmark is 'no'\n"); } } } else { if(verbose()) { printf("simulation benchmark defaulting to 'no'\n"); } myParameters.benchmark=0; } // ************************************ // find 'threads' getAssignmentULongs(yourElement,"threads",0,1,myULongList); if(myULongList.size()==1) { myParameters.nThreads = *myULongList.begin(); if(myParameters.nThreads < 1) { throw xmdsException(yourElement,"number of threads must be > 0"); } if(verbose()) { printf("number of threads = %li\n",myParameters.nThreads); } } else { if(verbose()) { printf("number of threads defaulting to 1\n"); } myParameters.nThreads=1; } // ************************************ // find 'stochastic' getAssignmentBools(yourElement,"stochastic",0,1,myBoolList); if(myBoolList.size()==1) { myParameters.stochastic=*myBoolList.begin(); if(verbose()) { if(myParameters.stochastic) { printf("simulation stochastic is 'yes'\n"); } else { printf("simulation stochastic is 'no'\n"); } } } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -