void CSimPetriDoc::CreateOMPDoc(CString pathToFile) { ompMode = TRUE; delete stepper; //Créer le squelette const std::wstring pathName(pathToFile); const wchar_t *separator = _T(";"); omp::Reader dataReader(pathName, separator); omp::PetriOMP omp(dataReader, skeleton); //Créer le stepper stepper = new pm::TrackableStepper(&skeleton, &timer); //Ajouter les places double radiusPlaces = ((double)(3)/4) * min(size.cx/2, size.cy/2); pm::Places places = skeleton.getPlaces(); unsigned index = 0; for(auto it=places.begin(); it!=places.end(); ++it) { int x(size.cx/2 + radiusPlaces*std::cos(((double)(index)/places.size())*2*3.14)); int y(-size.cy/2 + radiusPlaces*std::sin(((double)(index)/places.size())*2*3.14)); shapesMap.insert(std::make_pair(*it, AddPlace(Point(x,y), *it))); ++index; } //Ajouter les transitions double radiusTrans = ((double)(1)/2) * min(size.cx/2, size.cy/2); pm::Transitions transitions = skeleton.getTransitions(); index = 0; for(auto it=transitions.begin(); it!=transitions.end(); ++it) { Point source = shapesMap.at((*it)->getInputArcs().front()->getSourceNode())->GetPosition(); Point end = shapesMap.at((*it)->getOutputArcs().front()->getEndNode())->GetPosition(); //int x(size.cx/2 + radiusTrans*std::cos(((double)(index)/transitions.size())*2*3.14)); //int y(-size.cy/2 + radiusTrans*std::sin(((double)(index)/transitions.size())*2*3.14)); shapesMap.insert(std::make_pair(*it, AddTransition(Geometry::MiddlePoint(source, end), *it))); ++index; } //Ajouter les arcs pm::Arcs arcs = skeleton.getArcs(); std::vector<Point> nullVector; for(auto it=arcs.begin(); it!=arcs.end(); ++it) AddArc(shapesMap.at((*it)->getSourceNode()), shapesMap.at((*it)->getEndNode()), nullVector, *it); }
void txReducedPower::setSourceData() { QSharedPointer<txDataReader> dataReader(new txDataReader()); dataReader->readFile(m_commonParameters->val_srcFileNameRedPwr(), " "); QVector< QVector<double> > srcdata = dataReader->val_data(); if ( srcdata.isEmpty() ) { throw txError("No data to calculate!"); } // m_numberOfPoints = srcdata.size(); prepSrcArrays(srcdata); }
void KNSingletonApplication::onMessageReceive() { //Get the socket from the sender. QLocalSocket *client=m_messageServer->nextPendingConnection(); //Waiting for reading client data. if(!client->waitForReadyRead(TimeoutLimit)) { qDebug("Cannot read the client data."); return; } //Get the data, and parse it as string list. QByteArray messageData=client->readAll(); //Disconnect the socket. client->disconnectFromServer(); //Use a data stream to flush data to string list. QStringList messages; QDataStream dataReader(&messageData, QIODevice::ReadOnly); dataReader >> messages; //Emit the messages. emit messageAvailable(messages); }
void txPointsOfCycle::setSourceData() { const int currstd = m_calculationOptions->val_standard(); QSharedPointer<txDataReader> dataReader(new txDataReader()); if ( currstd == STD_EU6 || currstd == STD_EU5 || currstd == STD_EU4 || currstd == STD_EU3 ) { dataReader->readFile(m_commonParameters->val_srcFileNameEU3(), " "); } else { dataReader->readFile(m_commonParameters->val_srcFileNameEU0(), " "); } QVector< QVector<double> > srcdata = dataReader->val_data(); if ( srcdata.isEmpty() ) { throw txError("No data to calculate!"); } prepSrcData(srcdata); }
DataExtractor::DataExtractor(std::string name) // constructor { std::vector<std::string> buffer1; //string buffer number_of_lines = dataReader(name, &buffer1); //data reader puts the "name"d file into the buffer and returns its lenth in lines if(number_of_lines == 0) throw "File Not Found"; //empty file std::string ftype = ".dat"; //should be a .dat file char* p1 = (char*)name.c_str(); //converts name of file to a c string while(*p1!=NULL) { p1++; //goes to end of string } p1 = p1-4; //goes back 4 spaces if(ftype.compare(p1)!=0) throw "Wrong File Type"; //checks if the last 4 characters are .dat dataArray = ArrayAllocator::AllocateDynamicArray<double>(number_of_lines,4); //allocates an array of the appropriate size, right now 3 wide MAY NEED ADJUSTMENT bool y = dataConverter(&buffer1,dataArray); }
// Open a .obj, load its contents into 3 arrays: // 1. Vertices // 2. Normals // 3. Indices // Returns a vector of vectors containing this data std::vector<std::vector<double> > ObjLoader::readObjectFile(std::string path) { int const bufferSize(1024); char lineBuffer[bufferSize]; std::string line = ""; int lineNumber = 0; int i = 0; std::fstream dataReader(path.c_str()); std::string decimalNumberString = ""; std::string integerNumberString = ""; int coordinatesAdded = 0; double x, y, z = 0.0; int a, b, c = 0; std::vector<double> vertexData; // Read vertexes here std::vector<double> normalData; // Read normals here std::vector<double> indiceData; // Read indices here std::vector<std::vector<double> > out; // Return in this container if (!dataReader) std::cout << "Error opening model file: " << path.c_str() << std::endl; while (!dataReader.eof()) { #ifdef DEBUG std::cout << "Linebreak" << std::endl; #endif dataReader.getline(lineBuffer, bufferSize); line = lineBuffer; if (line[0] == 'v' && line[1] == ' ') // Vertex { coordinatesAdded = 0; decimalNumberString = ""; // Start reading from the first number. Skip the leading v and whitespace for (int i = 2; coordinatesAdded <= 3; i++) { if (line[i] == NULL) break; // If we are at a new coordinate if (line[i] == ' ' || i == line.size() - 1) { // Convert the string into a double if (coordinatesAdded == 0) x = atof(decimalNumberString.c_str()); else if (coordinatesAdded == 1) y = atof(decimalNumberString.c_str()); else if (coordinatesAdded == 2) z = atof(decimalNumberString.c_str()); coordinatesAdded++; decimalNumberString = ""; } // Add the number or decimal dot to the string to be converted decimalNumberString.append(tbox.charToString(line[i])); if (coordinatesAdded > 3 && i > 40) { std::cout << "Something broke reading a 3D object. Consult your 3D model exporter" << std::endl; break; } } vertexData.push_back(x); vertexData.push_back(y); vertexData.push_back(z); } else if (line[0] == 'v' && line[1] == 'n') // Vertex normal { coordinatesAdded = 0; decimalNumberString = ""; // Start reading from the first number. Skip the leading v and whitespace for (int i = 3; coordinatesAdded < 3; i++) { if (line[i] == NULL) break; // If we are at a new coordinate if (line[i] == ' ') { // Convert the string into a double if (coordinatesAdded == 0) x = atof(decimalNumberString.c_str()); else if (coordinatesAdded == 1) y = atof(decimalNumberString.c_str()); else if (coordinatesAdded == 2) z = atof(decimalNumberString.c_str()); coordinatesAdded++; decimalNumberString = ""; } // Add the number or decimal dot to the string to be converted decimalNumberString.append(tbox.charToString(line[i])); if (coordinatesAdded > 3 && i > 40) { std::cout << "Something broke reading a 3D object. Consult your 3D model exporter" << std::endl; break; } } normalData.push_back(x); normalData.push_back(y); normalData.push_back(z); } else if (line[0] == 'f' && line[1] == ' ') // Index { /* The syntax for indices is as follows: f 14//14474 4483//14474 7448//14474 Where the first value is the vertex index and the following is probably a texture index. There is one value missing, and thus there are two "/" in sequence */ coordinatesAdded = 0; integerNumberString = ""; bool valueAdded = false; a = 0; b = 0; c = 0; // Start reading from the first number. Skip the leading v and whitespace for (int i = 2; coordinatesAdded < 3; i++) { if (line[i] == NULL) break; // If we are at a new coordinate if (line[i] == ' ' || (coordinatesAdded == 2 && valueAdded == true) ) { // Convert the string into an int if (coordinatesAdded == 0) { a = atoi(integerNumberString.c_str()); #ifdef DEBUG std::cout << "a: " << a << std::endl; #endif } else if (coordinatesAdded == 1) { b = atoi(integerNumberString.c_str()); #ifdef DEBUG std::cout << "b: " << b << std::endl; #endif } else if (coordinatesAdded == 2) { c = atoi(integerNumberString.c_str()); #ifdef DEBUG std::cout << "c: " << c << std::endl; #endif } coordinatesAdded++; integerNumberString = ""; valueAdded = false; } if (line[i] == '/') { valueAdded = true; #ifdef DEBUG std::cout << "Hit /" << std::endl; #endif } // Add the number or decimal dot to the string to be converted if (valueAdded == false) { #ifdef DEBUG std::cout << "reading an integer into a string: " << line[i] << std::endl; #endif integerNumberString.append(tbox.charToString(line[i])); } if (coordinatesAdded > 3 && i > 40) { std::cout << "Something broke reading a 3D object. Consult your 3D model exporter" << std::endl; break; } } assert(a); assert(b); assert(c); #ifdef DEBUG std::cout << "Pushing indices to vector: " << a << ", " << b << ", " << c << std::endl; #endif indiceData.push_back(a-1); indiceData.push_back(b-1); indiceData.push_back(c-1); } else { // Non-interesting data } } out.push_back(vertexData); out.push_back(normalData); out.push_back(indiceData); dataReader.close(); return out; }
void StructuralFE2MaterialStatus :: copyStateVariables(const MaterialStatus &iStatus) { //static int num = 0; //printf("Entering StructuralFE2MaterialStatus :: copyStateVariables.\n"); this->oldTangent = true; // if ( !this->createRVE(this->giveNumber(), gp, mInputFile) ) { // OOFEM_ERROR("Couldn't create RVE"); // } StructuralMaterialStatus :: copyStateVariables(iStatus); ////////////////////////////// MaterialStatus &tmpStat = const_cast< MaterialStatus & >(iStatus); StructuralFE2MaterialStatus *fe2ms = dynamic_cast<StructuralFE2MaterialStatus*>(&tmpStat); if ( !fe2ms ) { OOFEM_ERROR("Failed to cast StructuralFE2MaterialStatus.") } this->mNewlyInitialized = fe2ms->mNewlyInitialized; // The proper way to do this would be to clone the RVE from iStatus. // However, this is a mess due to all pointers that need to be tracked. // Therefore, we consider a simplified version: copy only the enrichment items. Domain *ext_domain = fe2ms->giveRVE()->giveDomain(1); if ( ext_domain->hasXfemManager() ) { Domain *rve_domain = rve->giveDomain(1); XfemManager *ext_xMan = ext_domain->giveXfemManager(); XfemManager *this_xMan = rve->giveDomain(1)->giveXfemManager(); DynamicDataReader dataReader("fe2"); if ( ext_xMan != NULL ) { IRResultType result; // Required by IR_GIVE_FIELD macro std::vector<std::unique_ptr<EnrichmentItem>> eiList; //DynamicInputRecord *xmanRec = new DynamicInputRecord(); //ext_xMan->giveInputRecord(* xmanRec); //dataReader.insertInputRecord(DataReader :: IR_xfemManRec, xmanRec); // Enrichment items int nEI = ext_xMan->giveNumberOfEnrichmentItems(); for ( int i = 1; i <= nEI; i++ ) { EnrichmentItem *ext_ei = ext_xMan->giveEnrichmentItem(i); ext_ei->appendInputRecords(dataReader); InputRecord *mir = dataReader.giveInputRecord(DataReader :: IR_enrichItemRec, i); std :: string name; result = mir->giveRecordKeywordField(name); if ( result != IRRT_OK ) { mir->report_error(this->giveClassName(), __func__, "", result, __FILE__, __LINE__); } std :: unique_ptr< EnrichmentItem >ei( classFactory.createEnrichmentItem( name.c_str(), i, this_xMan, rve_domain ) ); if ( ei.get() == NULL ) { OOFEM_ERROR( "unknown enrichment item (%s)", name.c_str() ); } ei->initializeFrom(mir); ei->instanciateYourself(dataReader); eiList.push_back( std :: move(ei) ); } this_xMan->clearEnrichmentItems(); this_xMan->appendEnrichmentItems(eiList); rve_domain->postInitialize(); rve->forceEquationNumbering(); } } //printf("done.\n"); #if 0 Domain *newDomain = fe2ms->giveRVE()->giveDomain(1)->Clone(); newDomain->SetEngngModel(rve.get()); bool deallocateOld = true; rve->setDomain(1, newDomain, deallocateOld); //rve->giveDomain(1)->postInitialize(); rve->giveNumericalMethod(NULL)->setDomain(newDomain); rve->postInitialize(); //rve->forceEquationNumbering(); rve->initMetaStepAttributes( rve->giveMetaStep(1) ); rve->giveNextStep(); // Makes sure there is a timestep (which we will modify before solving a step) rve->init(); // std :: ostringstream name; // name << this->rve->giveOutputBaseFileName() << "-gp" << n; // this->rve->letOutputBaseFileNameBe( name.str() ); // n++; double crackLength = 0.0; XfemStructureManager *xMan = dynamic_cast<XfemStructureManager*>( rve->giveDomain(1)->giveXfemManager() ); if ( xMan ) { crackLength = xMan->computeTotalCrackLength(); } std :: ostringstream name; name << this->rve->giveOutputBaseFileName() << "-gp" << num << "crackLength" << crackLength; if ( this->domain->giveEngngModel()->isParallel() && this->domain->giveEngngModel()->giveNumberOfProcesses() > 1 ) { name << "." << this->domain->giveEngngModel()->giveRank(); } num++; this->rve->letOutputBaseFileNameBe( name.str() ); // Update BC this->bc = dynamic_cast< PrescribedGradientHomogenization * >( this->rve->giveDomain(1)->giveBc(1) ); #if 1 XfemSolverInterface *xfemSolInt = dynamic_cast<XfemSolverInterface*>(rve.get()); StaticStructural *statStruct = dynamic_cast<StaticStructural*>(rve.get()); if ( xfemSolInt && statStruct ) { //printf("Successfully casted to XfemSolverInterface.\n"); TimeStep *tStep = rve->giveCurrentStep(); EModelDefaultEquationNumbering num; int numDofsNew = rve->giveNumberOfDomainEquations( 1, num ); FloatArray u; u.resize(numDofsNew); u.zero(); xfemSolInt->xfemUpdatePrimaryField(*statStruct, tStep, u); // Set domain pointer to various components ... rve->giveNumericalMethod(NULL)->setDomain(newDomain); //ioEngngModel.nMethod->setDomain(domain); } // TimeStep *tStep = rve->giveNextStep(); // setTimeStep(tStep); // rve->solveYourselfAt(tStep); int numExpModules = rve->giveExportModuleManager()->giveNumberOfModules(); for ( int i = 1; i <= numExpModules; i++ ) { // ... by diving deep into the hierarchies ... :-/ VTKXMLExportModule *vtkxmlMod = dynamic_cast< VTKXMLExportModule * >( rve->giveExportModuleManager()->giveModule(i) ); if ( vtkxmlMod != NULL ) { vtkxmlMod->giveSmoother()->setDomain(newDomain); vtkxmlMod->givePrimVarSmoother()->setDomain(newDomain); } } #endif #endif }
void PackageWriter::_AddEntry(int dirFD, Entry* entry, const char* fileName) { printf("PackageWriter::_AddEntry(%d, %p, \"%s\")\n", dirFD, entry, fileName); bool isImplicitEntry = entry != NULL && entry->IsImplicit(); // open the node int fd = openat(dirFD, fileName, O_RDONLY | (isImplicitEntry ? 0 : O_NOTRAVERSE)); if (fd < 0) { fprintf(stderr, "Error: Failed to open entry \"%s\": %s\n", fileName, strerror(errno)); throw status_t(errno); } FDCloser fdCloser(fd); // stat the node struct stat st; if (fstat(fd, &st) < 0) { fprintf(stderr, "Error: Failed to fstat() file \"%s\": %s\n", fileName, strerror(errno)); throw status_t(errno); } // implicit entries must be directories if (isImplicitEntry && !S_ISDIR(st.st_mode)) { fprintf(stderr, "Error: Non-leaf path component \"%s\" is not a " "directory\n", fileName); throw status_t(B_BAD_VALUE); } // check/translate the node type uint8 fileType; uint32 defaultPermissions; if (S_ISREG(st.st_mode)) { fileType = B_HPKG_FILE_TYPE_FILE; defaultPermissions = B_HPKG_DEFAULT_FILE_PERMISSIONS; } else if (S_ISLNK(st.st_mode)) { fileType = B_HPKG_FILE_TYPE_SYMLINK; defaultPermissions = B_HPKG_DEFAULT_SYMLINK_PERMISSIONS; } else if (S_ISDIR(st.st_mode)) { fileType = B_HPKG_FILE_TYPE_DIRECTORY; defaultPermissions = B_HPKG_DEFAULT_DIRECTORY_PERMISSIONS; } else { // unsupported node type fprintf(stderr, "Error: Unsupported node type, entry: \"%s\"\n", fileName); throw status_t(B_UNSUPPORTED); } // add attribute entry Attribute* entryAttribute = _AddStringAttribute( B_HPKG_ATTRIBUTE_NAME_DIRECTORY_ENTRY, fileName); Stacker<Attribute> entryAttributeStacker(fTopAttribute, entryAttribute); // add stat data if (fileType != B_HPKG_DEFAULT_FILE_TYPE) _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_TYPE, fileType); if (defaultPermissions != uint32(st.st_mode & ALLPERMS)) { _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_PERMISSIONS, uint32(st.st_mode & ALLPERMS)); } _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_ATIME, uint32(st.st_atime)); _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_MTIME, uint32(st.st_mtime)); _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_CRTIME, uint32(st.st_crtime)); // TODO: File user/group! // add file data/symlink path if (S_ISREG(st.st_mode)) { // regular file -- add data if (st.st_size > 0) { FDDataReader dataReader(fd); status_t error = _AddData(dataReader, st.st_size); if (error != B_OK) throw status_t(error); } } else if (S_ISLNK(st.st_mode)) { // symlink -- add link address char path[B_PATH_NAME_LENGTH + 1]; ssize_t bytesRead = readlinkat(dirFD, fileName, path, B_PATH_NAME_LENGTH); if (bytesRead < 0) { fprintf(stderr, "Error: Failed to read symlink \"%s\": %s\n", fileName, strerror(errno)); throw status_t(errno); } path[bytesRead] = '\0'; _AddStringAttribute(B_HPKG_ATTRIBUTE_NAME_SYMLINK_PATH, path); } // add attributes if (DIR* attrDir = fs_fopen_attr_dir(fd)) { CObjectDeleter<DIR, int> attrDirCloser(attrDir, fs_close_attr_dir); while (dirent* entry = readdir(attrDir)) { attr_info attrInfo; if (fs_stat_attr(fd, entry->d_name, &attrInfo) < 0) { fprintf(stderr, "Error: Failed to stat attribute \"%s\" of " "file \"%s\": %s\n", entry->d_name, fileName, strerror(errno)); throw status_t(errno); } // create attribute entry Attribute* attributeAttribute = _AddStringAttribute( B_HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE, entry->d_name); Stacker<Attribute> attributeAttributeStacker(fTopAttribute, attributeAttribute); // add type _AddAttribute(B_HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE_TYPE, (uint32)attrInfo.type); // add data AttributeDataReader dataReader(fd, entry->d_name, attrInfo.type); status_t error = _AddData(dataReader, attrInfo.size); if (error != B_OK) throw status_t(error); } } if (S_ISDIR(st.st_mode)) { // directory -- recursively add children if (isImplicitEntry) { // this is an implicit entry -- just add it's children for (EntryList::ConstIterator it = entry->ChildIterator(); Entry* child = it.Next();) { _AddEntry(fd, child, child->Name()); } } else { // we need to clone the directory FD for fdopendir() int clonedFD = dup(fd); if (clonedFD < 0) { fprintf(stderr, "Error: Failed to dup() directory FD: %s\n", strerror(errno)); throw status_t(errno); } DIR* dir = fdopendir(clonedFD); if (dir == NULL) { fprintf(stderr, "Error: Failed to open directory \"%s\": %s\n", fileName, strerror(errno)); close(clonedFD); throw status_t(errno); } CObjectDeleter<DIR, int> dirCloser(dir, closedir); while (dirent* entry = readdir(dir)) { // skip "." and ".." if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { continue; } _AddEntry(fd, NULL, entry->d_name); } } } }