00001 /************************************************************************* 00002 * CompuCell - A software framework for multimodel simulations of * 00003 * biocomplexity problems Copyright (C) 2003 University of Notre Dame, * 00004 * Indiana * 00005 * * 00006 * This program is free software; IF YOU AGREE TO CITE USE OF CompuCell * 00007 * IN ALL RELATED RESEARCH PUBLICATIONS according to the terms of the * 00008 * CompuCell GNU General Public License RIDER you can redistribute it * 00009 * and/or modify it under the terms of the GNU General Public License as * 00010 * published by the Free Software Foundation; either version 2 of the * 00011 * License, or (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, but * 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the Free Software * 00020 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00021 *************************************************************************/ 00022 00023 00024 #include <CompuCell3D/ClassRegistry.h> 00025 00026 using namespace CompuCell3D; 00027 00028 #include <CompuCell3D/Simulator.h> 00029 #include <CompuCell3D/Potts3D/Potts3D.h> 00030 00031 00032 #include <BasicUtils/BasicString.h> 00033 #include <BasicUtils/BasicException.h> 00034 00035 #include <iostream> 00036 using namespace std; 00037 00038 #define EXP_STL 00039 #include "PDESolverCallerPlugin.h" 00040 00041 PDESolverCallerPlugin::PDESolverCallerPlugin():sim(0), potts(0), xmlData(0) {} 00042 00043 PDESolverCallerPlugin::~PDESolverCallerPlugin() {} 00044 00045 void PDESolverCallerPlugin::init(Simulator *simulator, CC3DXMLElement *_xmlData) { 00046 00047 xmlData=_xmlData; 00048 sim=simulator; 00049 potts = sim->getPotts(); 00050 00051 potts->registerFixedStepper(this); 00052 00053 sim->registerSteerableObject(this); 00054 00055 } 00056 00057 void PDESolverCallerPlugin::extraInit(Simulator *simulator) { 00058 00059 update(xmlData,true); 00060 00061 } 00062 00063 void PDESolverCallerPlugin::step(){ 00064 00065 // cerr<<"inside STEP"<<endl; 00066 unsigned int currentStep; 00067 unsigned int currentAttempt; 00068 unsigned int numberOfAttempts; 00069 00070 00071 currentStep=sim->getStep(); 00072 currentAttempt=potts->getCurrentAttempt(); 00073 numberOfAttempts=potts->getNumberOfAttempts(); 00074 00075 00076 00077 00078 for(int i=0 ; i <solverDataVec.size() ; ++i){ 00079 int reminder= (numberOfAttempts % (solverDataVec[i].extraTimesPerMC+1)); 00080 00081 int ratio=(numberOfAttempts / (solverDataVec[i].extraTimesPerMC+1)); 00082 // cerr<<"pscpdPtr->solverDataVec[i].extraTimesPerMC="<<pscpdPtr->solverDataVec[i].extraTimesPerMC<<endl; 00083 // cerr<<"ratio="<<ratio<<" reminder="<<reminder<<endl; 00084 if( ! ((currentAttempt-reminder) % ratio ) && currentAttempt>reminder ){ 00085 // cerr<<"before calling step"<<endl; 00086 solverPtrVec[i]->step(currentStep); 00087 // float a=reminder+ratio; 00088 // cerr<<"calling Solver"<<pscpdPtr->solverDataVec[i].solverName<<" currentAttempt="<<currentAttempt<<" numberOfAttempts="<<numberOfAttempts<<endl; 00089 00090 } 00091 00092 } 00093 00094 00095 00096 00097 } 00098 00099 void PDESolverCallerPlugin::update(CC3DXMLElement *_xmlData, bool _fullInitFlag){ 00100 00101 solverPtrVec.clear(); 00102 ClassRegistry *classRegistry=sim->getClassRegistry(); 00103 Steppable * steppable; 00104 00105 00106 CC3DXMLElementList pdeSolversXMLList=_xmlData->getElements("CallPDE"); 00107 for(unsigned int i=0; i < pdeSolversXMLList.size() ; ++i ){ 00108 solverDataVec.push_back(SolverData(pdeSolversXMLList[i]->getAttribute("PDESolverName"),pdeSolversXMLList[i]->getAttributeAsUInt("ExtraTimesPerMC"))); 00109 SolverData & sd=solverDataVec[solverDataVec.size()-1]; 00110 00111 steppable=classRegistry->getStepper(sd.solverName); 00112 solverPtrVec.push_back(steppable); 00113 00114 } 00115 00116 00117 } 00118 00119 std::string PDESolverCallerPlugin::toString(){ 00120 00121 return "PDESolverCaller"; 00122 00123 } 00124 00125 std::string PDESolverCallerPlugin::steerableName(){ 00126 00127 return toString(); 00128 00129 }
1.5.6