📄 advisman.cpp
字号:
//advisman.cpp#include "speciesg.h"#include "spatialg.h"#include "species.h"#include "advisman.h"#include "varg.h"#include "part1g.h"#include "spbound.h"#ifdef UNIX#include "ptclgrp.h"#include "diags.h"#endifextern "C++" void printf(char *); #ifdef MPI_VERSION#include "mpi.h"extern MPI_Comm XOOPIC_COMM;extern int MPI_RANK;#define SRB_ANNOUNCE_TAG 100#define SRB_LINK_TAG 200typedef struct { char *name; int index; int linkedP;} SRBdat;#endif /*MPI_VERSION*/Evaluator *adv_eval;using namespace std;// (10-29-94 Hadon) added AdvisorManager::getSpatialRegionGroupList()// (JohnV 01-29-95) Support SpeciesParamsList and SpeciesList// (JohnV 08-21-95) Support for DielectricRegion// these could be placed in a service class rather than C-style funcsostring getname(ostring line, int pos);ostring getvalue(ostring line, int pos);ostring Standardize(ostring in);ostring parseFirst(ostring str);ostring parseSecond(ostring str);int member(ostring s, oopicList<ostring>* l);AdvisorManager::AdvisorManager(const char* fileName){ adv_eval = new Evaluator(); // list for GUI ListOfAllBoundaryTypes.add(new ostring("Conductor")); ListOfAllBoundaryTypes.add(new ostring("Polarizer")); ListOfAllBoundaryTypes.add(new ostring("SpatialRegionBoundary")); ListOfAllBoundaryTypes.add(new ostring("CylindricalAxis")); ListOfAllBoundaryTypes.add(new ostring("FieldEmitter")); ListOfAllBoundaryTypes.add(new ostring("FieldEmitter2")); ListOfAllBoundaryTypes.add(new ostring("BeamEmitter")); ListOfAllBoundaryTypes.add(new ostring("FowlerNordheimEmitter")); ListOfAllBoundaryTypes.add(new ostring("PlasmaSource")); ListOfAllBoundaryTypes.add(new ostring("LaserPlasmaSource")); ListOfAllBoundaryTypes.add(new ostring("EmitPort")); ListOfAllBoundaryTypes.add(new ostring("VarWeightBeamEmitter")); ListOfAllBoundaryTypes.add(new ostring("Iloop")); ListOfAllBoundaryTypes.add(new ostring("CurrentRegion")); ListOfAllBoundaryTypes.add(new ostring("PortTM")); ListOfAllBoundaryTypes.add(new ostring("PortTE")); ListOfAllBoundaryTypes.add(new ostring("PortGauss")); ListOfAllBoundaryTypes.add(new ostring("ExitPort")); ListOfAllBoundaryTypes.add(new ostring("Gap")); ListOfAllBoundaryTypes.add(new ostring("AbsorbWave")); ListOfAllBoundaryTypes.add(new ostring("LaunchWave")); ListOfAllBoundaryTypes.add(new ostring("Equipotential")); ListOfAllBoundaryTypes.add(new ostring("Dielectric")); ListOfAllBoundaryTypes.add(new ostring("DielectricRegion")); ListOfAllBoundaryTypes.add(new ostring("DielectricTriangle")); ListOfAllBoundaryTypes.add(new ostring("Foil")); ListOfAllBoundaryTypes.add(new ostring("SingleParticleEmitter")); ListOfAllBoundaryTypes.add(new ostring("PortTEM_MW")); ListOfAllBoundaryTypes.add(new ostring("CurrentSource")); ListOfAllParameterGroups.add(new ostring("Control")); ListOfAllParameterGroups.add(new ostring("Variables")); ListOfAllParameterGroups.add(new ostring("Grid")); ListOfAllParameterGroups.add(new ostring("Species")); ListOfAllParameterGroups.add(new ostring("MCC")); ListOfAllParameterGroups.add(new ostring("Load")); ListOfAllParameterGroups.add(new ostring("VarWeightLoad")); ListOfAllParameterGroups.add(new ostring("Load_PW")); ListOfAllParameterGroups.add(new ostring("Diagnostic")); ListOfAllParameterGroups.add(new ostring("H5Diagnostic")); oopicListIter<ostring> sI(ListOfAllBoundaryTypes); for (sI.restart(); !sI.Done(); sI++) {ListOfAllParameterGroups.add(sI.current());} ListOfAllProbeTypes.add(new ostring("E Field")); ListOfAllProbeTypes.add(new ostring("B Field")); ListOfAllProbeTypes.add(new ostring("Current")); ListOfAllProbeTypes.add(new ostring("DivDerror")); speciesParamsList = new SpeciesParamsList; speciesList = NULL; // JohnV 03-15-95// speciesList = new SpeciesList; setFileName(fileName);}AdvisorManager::~AdvisorManager(){// speciesParamsList->deleteAll(); oopicListIter<SpeciesParams> spIter(*speciesParamsList); for (spIter.restart(); !spIter.Done(); spIter++) spIter.deleteCurrent(); speciesParamsList->removeAll(); srgList.deleteAll(); delete speciesParamsList; // do NOT delete speciesList here; it gets passed to PlasmaDevice!}// return message ...void AdvisorManager::setFileName(const char* fileName){ InputErrorMessage = ostring(""); inputFile.open(fileName); char buffer[512]; inputFile.getline(buffer, 511); // first line should be caseTitle caseTitle = Standardize(ostring(buffer)); // this reads the case description while(inputFile) {inputFile.getline(buffer, 511); // get a line ostring line = stripWS(ostring(buffer)); printf(line); if (line == (ostring)"{") { // skip this line and read another inputFile.getline(buffer, 511); line = stripWS(ostring(buffer)); } if (line == (ostring)"}") // terminates the input for this group break; else { // push this line of text into caseDescription ostring* oline = new ostring(line); caseDescription.add(oline); } } // Read the regions and the variables group, if any while(inputFile) { ostring line; buffer[0]=0; // fixes a "getline" bug on cray T3E inputFile.getline(buffer,511); line=stripWS(Standardize(buffer)); if(line == (ostring)"Region") { SpatialRegionGroup* srg = new SpatialRegionGroup(this); ostring message = readSpatialRegionGroup(*srg); if (message.length() > 1) {/* cout << "ERROR READING INPUT FILE!!!" << TXSTRSTD::endl << "FILE NAME = " << fileName << TXSTRSTD::endl << "BAD LINE = " << message << TXSTRSTD::endl;*/ printf("ERROR READING INPUT FILE!!!"); char buffer[512]; sprintf(buffer,"FILE NAME = %s" ,fileName); printf(buffer); printf(strdup("BAD LINE = " + message)); sprintf(buffer, "ERROR READING INPUT FILE!!!\nFILE NAME = %s\nBAD LINE = %s\n", fileName, message.c_str()); InputErrorMessage = ostring(buffer); inputFile.close(); return; } srgList.add(srg); } else if(line == (ostring)"Variables") { VG.InitializeFromStream(inputFile); } else { if(line != (ostring)"") { // cout << "Warning: Unrecognized line: check your input file for:\n" << line << "\n"; // cout << "Expected 'Region' or 'Variables' or description.\n"; printf("Warning: Unrecognized line: check your input file for:"); printf(line); printf("Expected 'Region' or 'Variables' or description."); } } } inputFile.close();}void AdvisorManager::writeOutputFile(const char* fileName){ outputFile.open(fileName); // writes the caseName and caseDescription outputFile << caseTitle << TXSTRSTD::endl; outputFile << "{" << TXSTRSTD::endl; oopicListIter<ostring> sI(caseDescription); for (sI.restart(); !sI.Done(); sI++) outputFile << *sI.current() << TXSTRSTD::endl; outputFile << "}" << TXSTRSTD::endl; oopicListIter<SpeciesParams> sIter(*speciesParamsList); // write out all species for (sIter.restart(); !sIter.Done(); sIter++) // JohnV 06-26-95 sIter.current()->writeOutputFile(outputFile); oopicListIter<SpatialRegionGroup> srgIter(srgList); for (srgIter.restart(); !srgIter.Done(); srgIter++) srgIter.current()->writeOutputFile(outputFile); outputFile.close();} ostring AdvisorManager::readSpatialRegionGroup(SpatialRegionGroup& srg) { char buffer[512]; oopicList<ostring> alist; ostring name,value,message; while (inputFile) { inputFile.getline(buffer, 511); // first line should be groupname ostring line = stripWS(Standardize(ostring(buffer))); int pos = line.find("=", 0); // is this a parameter = value line? if (pos > 0) { name = getname(line, pos); if(srg.LegalParamName(name)) { value = getvalue(line, pos); alist.add(new ostring(name + ostring(" ") + value)); } else { return(line); } } else if(line == (ostring)"{") { //skip this line and get another continue; } else if(line== ostring("")) { continue; } else if (member(line, &ListOfAllParameterGroups) == 1) { // cout << "creating " << line << TXSTRSTD::endl; // JRC: memory leak. printf is not a handoff. // printf(strdup("creating " +line)); printf(strdup("creating " +line)); message = srg.CreateParamGroup(inputFile, line); if (message.length() > 1) {return(message);} } else if (line == (ostring)"}") { srg.setValues(alist); break; } else { return(line); } } return (ostring(""));}//-------------------------------------------------------------------// describe each SpatialRegionGroupvoid AdvisorManager::describe(){ oopicListIter<SpatialRegionGroup> srgIter(srgList); for (srgIter.restart(); !srgIter.Done(); srgIter++) srgIter.current()->describe();}//-------------------------------------------------------------------// check rules for each SpatialRegionGroupvoid AdvisorManager::checkRules(){ oopicListIter<SpatialRegionGroup> srgIter(srgList); for (srgIter.restart(); !srgIter.Done(); srgIter++) { SpatialRegionGroup* srg = srgIter.current(); srg->checkRules(); srg->showRuleMessages(); } oopicListIter<SpeciesParams> sIter(*speciesParamsList); for (sIter.restart(); !sIter.Done(); sIter++) { SpeciesParams *s = sIter.current(); s->checkRules(); s->showRuleMessages(); }}//-------------------------------------------------------------------// create the SpatialRegionList for PlasmaDeviceSpatialRegionList* AdvisorManager::createDevice() throw(Oops){ // Build a SpeciesList: speciesList = new SpeciesList; Species::reset_idCount(); // start speciesID from 0 oopicListIter<SpeciesParams> spIter(*speciesParamsList);#ifdef TXQ_GUI setProgress(1, "Creating AdvisorManger::SpeciesParam");#endif for (spIter.restart(); !spIter.Done(); spIter++) speciesList->add(spIter.current()->createCounterPart()); SpatialRegionList* srList = new SpatialRegionList; oopicListIter<SpatialRegionGroup> srgIter(srgList);#ifdef TXQ_GUI setProgress(1, "Creating AdvisorManger::SpatialRegionGroup");#endif// the MPI version only has 1 region per process#ifndef MPI_VERSION for (srgIter.restart(); !srgIter.Done(); srgIter++) { try{ srList->add(srgIter.current()->CreateCounterPart()); } catch(Oops& oops2){
oops2.prepend("AdvisorManager::createDevice: Error: \n");//done
throw oops2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -