virtual void initialize() { if(isInitialized) { return; } theInterfaceVariable = createVariable("Interface"); theVacantVariable = createVariable("Vacant"); if(LipidRadius) { if(LipidRadius < 0) { LipidRadius = 0; } else { theLipidVariable = createVariable("Lipid"); } } SpatiocyteProcess::initialize(); theInterfaceSpecies = theSpatiocyteStepper->addSpecies( theInterfaceVariable); theVacantSpecies = theSpatiocyteStepper->addSpecies(theVacantVariable); if(LipidRadius) { theLipidSpecies = theSpatiocyteStepper->addSpecies( theLipidVariable); } for(VariableReferenceVector::iterator i(theVariableReferenceVector.begin()); i != theVariableReferenceVector.end(); ++i) { Species* aSpecies(theSpatiocyteStepper->variable2species( (*i).getVariable())); if((*i).getCoefficient()) { theLipidCompSpecies.push_back(aSpecies); } else { theVacantCompSpecies.push_back(aSpecies); } } if(!DiffuseRadius) { DiffuseRadius = theSpatiocyteStepper->getVoxelRadius(); } if(!SubunitRadius) { SubunitRadius = DiffuseRadius; } //Lattice voxel radius: VoxelRadius = theSpatiocyteStepper->getVoxelRadius(); //Normalized off-lattice voxel radius: nSubunitRadius = SubunitRadius/(VoxelRadius*2); nDiffuseRadius = DiffuseRadius/(VoxelRadius*2); //Normalized lipid voxel radius: nLipidRadius = LipidRadius/(VoxelRadius*2); }
int main() { double T(1e-1); double L(1e-6); double N(1e+4); double R(2.5e-9); double D(1e-12); double stirTime(T*0.5); libecs::initialize(); libecs::Model& model(*(new libecs::Model(*libecs::createDefaultModuleMaker()))); model.setup(); libecs::Stepper& stepper(*model.createStepper("SpatiocyteStepper", "SS")); stepper.setProperty("VoxelRadius", libecs::Polymorph(R)); stepper.setProperty("ThreadSize", libecs::Polymorph(libecs::Integer(2))); model.getRootSystem()->setProperty("StepperID", libecs::Polymorph("SS")); createVariable(model, "Variable:/:GEOMETRY", CUBOID); createVariable(model, "Variable:/:LENGTHX", L); createVariable(model, "Variable:/:LENGTHY", L); createVariable(model, "Variable:/:LENGTHZ", L); createVariable(model, "Variable:/:XYPLANE", PERIODIC); createVariable(model, "Variable:/:XZPLANE", PERIODIC); createVariable(model, "Variable:/:YZPLANE", PERIODIC); createVariable(model, "Variable:/:VACANT", 0); createVariable(model, "Variable:/:A", N); createVariable(model, "Variable:/:B", 0); /* libecs::Process& vis(createProcess(model, "VisualizationLogProcess", "Process:/:logger")); vis.registerVariableReference("_", libecs::String("Variable:/Surface:A"), 0); vis.registerVariableReference("_", libecs::String("Variable:/Surface:As"), 0); vis.loadProperty("LogInterval", libecs::Polymorph(0.01)); */ libecs::Process& pop(createProcess(model, "MoleculePopulateProcess", "Process:/:pop")); pop.registerVariableReference("_", libecs::String("Variable:/:A"), 0); libecs::Process& dif(createProcess(model, "DiffusionProcess", "Process:/:diffuseA")); dif.registerVariableReference("_", libecs::String("Variable:/:A"), 0); dif.loadProperty("D", libecs::Polymorph(D)); model.initialize(); run(model, stirTime); boost::posix_time::ptime start( boost::posix_time::microsec_clock::universal_time()); run(model, T); boost::posix_time::ptime end( boost::posix_time::microsec_clock::universal_time()); std::cout << "duration:" << end-start << std::endl; delete &model; libecs::finalize(); }
llvm::Function* FunctionAST::codegen() { debug_info_helper->emitLocation(getLoc()); llvm::Function* function = prototype_->codegen(); CHECK(function != nullptr); CurFunctionGuard guard(function); debug_info_helper->createFunction(function, getLoc(), false); std::string body_label = stringPrintf("%s.entry", function->getName().data()); llvm::BasicBlock* basic_block = llvm::BasicBlock::Create(*context, body_label, function); llvm::IRBuilder<>::InsertPointGuard InsertPointGuard(*cur_builder); cur_builder->SetInsertPoint(basic_block); // Don't allow to break on argument initialization. // global_debug_info.emitLocation(nullptr); auto arg_it = function->arg_begin(); for (size_t i = 0; i < function->arg_size(); ++i, ++arg_it) { llvm::Value* variable = createVariable(arg_it->getName(), getLoc(), i + 1); cur_builder->CreateStore(&*arg_it, variable); } // global_debug_info.emitLocation(nullptr); llvm::Value* ret_val = body_->codegen(); CHECK(ret_val != nullptr); cur_builder->CreateRet(ret_val); debug_info_helper->endFunction(); return function; }
TacValuePtr TacFunction::createTemporary(TypePtr type) { std::stringstream name; name << "__temp__" << (++g_labelUid); IdentifierPtr id(new Identifier); id->id = Token(name.str(), -1, -1); return createVariable(id, type); }
llvm::Value* AssignmentExprAST::codegen() { debug_info_helper->emitLocation(getLoc()); llvm::Value* variable = getVariable(var_name_); if (variable == nullptr) { variable = createVariable(var_name_, getLoc(), 0); } CHECK(variable != nullptr); llvm::Value* value = right_->codegen(); cur_builder->CreateStore(value, variable); return value; }
// get a variable entry, creating a new one if necessary inline RexxVariable *getVariable(RexxString *name) { // find the entry RexxVariable *variable = resolveVariable(name); if (variable == OREF_NULL) { // create a new one if not there. variable = createVariable(name); } return variable; }
Entity* Model::createEntity( String const& aClassname, FullID const& aFullID ) { if( aFullID.getSystemPath().isModel() ) { THROW_EXCEPTION( BadSystemPath, "empty SystemPath" ); } System* aContainerSystemPtr( getSystem( aFullID.getSystemPath() ) ); Entity* retval( 0 ); if ( !aContainerSystemPtr ) { THROW_EXCEPTION( BadSystemPath, "[" + aFullID.getSystemPath().asString() + "] cannot be reached" ); } switch( aFullID.getEntityType() ) { case EntityType::VARIABLE: { retval = createVariable( aClassname ); retval->setID( aFullID.getID() ); aContainerSystemPtr->registerEntity( static_cast< Variable* >( retval ) ); } break; case EntityType::PROCESS: { retval = createProcess( aClassname ); retval->setID( aFullID.getID() ); aContainerSystemPtr->registerEntity( static_cast< Process* >( retval ) ); } break; case EntityType::SYSTEM: { retval = createSystem( aClassname ); retval->setID( aFullID.getID() ); aContainerSystemPtr->registerEntity( static_cast< System* >( retval ) ); } break; default: THROW_EXCEPTION( InvalidEntityType, "invalid EntityType specified" ); } return retval; }
//Input: A variable as lhs and another variable as rhs //Output: A data transformation with rhs assigned to lhs DATA_TRANS* createDataTransVarRead( char *lhs, char *rhs ) { DATA_TRANS *newDataTrans; int symbolIndexLHS; symbolIndexLHS = indexof_symtab(lhs); newDataTrans = (DATA_TRANS*) malloc (sizeof(DATA_TRANS)); newDataTrans->lhs = symbolIndexLHS; newDataTrans->rhs = createVariable(rhs); //The next statement adds the lhs variable to corresponding var_list if(!(flagVar_List)) indexof_varlist(lhs, &V0); else indexof_varlist(lhs, &V1); return newDataTrans; }
int INIparser::setData(string filename, string data, string value, bool createIfNotExist) { if(data.contains('=')) { // qDebug() << "Invalid characters in data"; // qDebug() << "User cannot use '='"; return -4; } string temp = filename.toLower(); if(!filename.contains(".ini")) { temp = temp + ".ini"; } File file(temp); if(!file.exists()) { // qDebug() << "File does not exists"; return -1; } if(!file.open(QIODevice::ReadWrite)) { // qDebug() << "Cannot open file"; return -2; } string string = file.readAll(); if(!string.contains(data + '=')) { if(!createIfNotExist) { // qDebug() << "Data does not exists, Stopping"; file.close(); return -3; } else { // qDebug() << "Data does not exist, creating new variable"; file.close(); return createVariable(filename, data, value); } } file.seek(0); // Reset pos to start of file temp = ""; // Clear temp while(!file.atEnd()) { // Add all the lines which don't contain <data> string = file.readLine(); if(!string.contains(data + '=')) { temp.append(string); } else { // Add new value instead of old one temp.append(data + '=' + value); if(!file.atEnd()) { temp.append("\r\n"); } } } file.resize(0); // Empty the file file.write(temp.toUtf8()); // Write to the file file.close(); return 0; }
Variable* createVariable(String anID) { return createVariable(anID, getSuperSystem()); }