#include "IO/Writer.h" #include "IO/MeshDatabase.h" #include "IO/IOHelpers.h" #include "common/MPI_Helpers.h" #include "common/Utilities.h" #include "shared_ptr.h" #include #include #include #include static bool global_summary_created = false; // Write the mesh data in the original format static std::vector writeMeshesOrigFormat( const std::vector& meshData, const char* path ) { int rank = MPI_WORLD_RANK(); std::vector meshes_written; for (size_t i=0; i mesh = meshData[i].mesh; IO::MeshDatabase mesh_entry; mesh_entry.name = meshData[i].meshName; mesh_entry.type = meshType(*mesh); mesh_entry.meshClass = meshData[i].mesh->className(); mesh_entry.format = 1; IO::DatabaseEntry domain; domain.name = domainname; domain.file = filename; domain.offset = 0; mesh_entry.domains.push_back(domain); if ( !meshData[i].vars.empty() ) { printf("Warning: variables are not supported with this format\n"); //for (size_t j=0; jname ); } const std::string meshClass = mesh->className(); if ( meshClass=="PointList" ) { // List of points std::shared_ptr pointlist = std::dynamic_pointer_cast(mesh); const std::vector& P = pointlist->points; for (size_t i=0; i trilist = IO::getTriList(mesh); const std::vector& A = trilist->A; const std::vector& B = trilist->B; const std::vector& C = trilist->C; for (size_t i=0; iclassName(); database.format = format; // Write the mesh IO::DatabaseEntry domain; domain.name = domainname; domain.file = filename; domain.offset = ftell(fid); database.domains.push_back(domain); std::pair data = mesh.mesh->pack(level); fprintf(fid,"Mesh: %s-%05i: %lu\n",mesh.meshName.c_str(),rank,data.first); fwrite(data.second,1,data.first,fid); fprintf(fid,"\n"); delete [] (char*) data.second; // Write the variables for (size_t i=0; iname; variable.file = filename; variable.offset = ftell(fid); IO::VariableDatabase info; info.name = variable.name; info.type = mesh.vars[i]->type; info.dim = mesh.vars[i]->dim; database.variables.push_back(info); std::pair key(domainname,variable.name); database.variable_data.insert( std::pair,IO::DatabaseEntry>(key,variable) ); int dim = mesh.vars[i]->dim; int type = static_cast(mesh.vars[i]->type); size_t N = mesh.vars[i]->data.length(); const double* data = N==0 ? NULL:mesh.vars[i]->data.get(); if ( type == static_cast(IO::NullVariable) ) { ERROR("Variable type not set"); } size_t N_mesh = mesh.mesh->numberPointsVar(mesh.vars[i]->type); ASSERT(N==dim*N_mesh); fprintf(fid,"Var: %s-%05i-%s: %i, %i, %lu, %lu, double\n", database.name.c_str(), rank, variable.name.c_str(), dim, type, N, dim*N*sizeof(double) ); fwrite(data,sizeof(double),dim*N,fid); fprintf(fid,"\n"); } return database; } // Write the mesh data in the new format static std::vector writeMeshesNewFormat( const std::vector& meshData, const char* path, int format ) { int rank = MPI_WORLD_RANK(); std::vector meshes_written; char filename[100], fullpath[200]; sprintf(filename,"%05i",rank); sprintf(fullpath,"%s/%s",path,filename); FILE *fid = fopen(fullpath,"wb"); for (size_t i=0; i mesh = meshData[i].mesh; meshes_written.push_back( write_domain(fid,filename,meshData[i],format) ); } fclose(fid); return meshes_written; } // Write the mesh data void IO::writeData( int timestep, const std::vector& meshData, int format, MPI_Comm comm ) { PROFILE_START("writeData"); int rank = comm_rank(comm); // Create the output directory char path[100]; sprintf(path,"vis%03i",timestep); if ( rank == 0 ) mkdir(path,S_IRWXU|S_IRGRP); MPI_Barrier(comm); // Write the mesh files std::vector meshes_written; if ( format == 1 ) { // Write the original triangle format meshes_written = writeMeshesOrigFormat( meshData, path ); } else if ( format == 2 ) { // Write the new format meshes_written = writeMeshesNewFormat( meshData, path, format ); } else { ERROR("Unknown format"); } // Gather a complete list of files on rank 0 meshes_written = gatherAll(meshes_written,comm); // Write the summary files if ( rank == 0 ) { // Write the summary file for the current timestep char filename[200]; sprintf(filename,"%s/LBM.summary",path); write(meshes_written,filename); // Add the timestep to the global summary file FILE *fid = NULL; if ( !global_summary_created ) { fid = fopen("summary.LBM","wb"); global_summary_created = true; } else { fid = fopen("summary.LBM","ab"); } fprintf(fid,"%s\n",path); fclose(fid); } PROFILE_STOP("writeData"); }