int main(int argc, char *argv[]) { register int k, l, n, la; int Nspace, result, NmaxIter, Ngdelay, Ngorder, Ngperiod, btype[3], inputs[N_INPUTS], nwrite, Nx, Nz; double iterLimit, *lambda, Adamp; stats.printCPU = TRUE; commandline.quiet = FALSE; commandline.logfile = stderr; input.Eddington = FALSE; getCPU(0, TIME_START, NULL); SetFPEtraps(); fpin = fopen("2dinput.dat", "r"); xdrstdio_create(&xdrs, fpin, XDR_DECODE); result = xdr_vector(&xdrs, (char *) inputs, N_INPUTS, sizeof(int), (xdrproc_t) xdr_int); atmos.angleSet.set = (enum angleset) inputs[0]; if (atmos.angleSet.set == SET_GL) { result = xdr_int(&xdrs, &atmos.angleSet.Ninclination); result = xdr_int(&xdrs, &atmos.angleSet.Nazimuth); } result = xdr_double(&xdrs, &iterLimit); result = xdr_double(&xdrs, &Adamp); Nx = geometry.Nx = inputs[1]; Nz = geometry.Nz = inputs[2]; NmaxIter = inputs[3]; Ngdelay = inputs[4]; Ngorder = inputs[5]; Ngperiod = inputs[6]; Nlambda = inputs[7]; Nspace = atmos.Nspace = geometry.Nx * geometry.Nz; result = xdr_vector(&xdrs, (char *) btype, 3, sizeof(int), (xdrproc_t) xdr_int); geometry.hboundary = (enum boundary) btype[0]; for (n = 0; n < 2; n++) geometry.bvalue[n] = (enum boundval) btype[1+n]; /* --- Check the validity of boundary conditions and values -- ---- */ switch (geometry.hboundary) { case FIXED: break; case PERIODIC: break; default: sprintf(messageStr, "Invalid horizontal boundary condition: %d", geometry.hboundary); Error(ERROR_LEVEL_2, argv[0], messageStr); break; } switch (geometry.bvalue[TOP]) { case IRRADIATED: break; case ZERO: break; case THERMALIZED: break; default: sprintf(messageStr, "Invalid boundary value at TOP: %d\n", geometry.bvalue[TOP]); Error(ERROR_LEVEL_2, argv[0], messageStr); break; } switch (geometry.bvalue[BOTTOM]) { case IRRADIATED: break; case ZERO: break; case THERMALIZED: break; default: sprintf(messageStr, "Invalid boundary value at BOTTOM: %d", geometry.bvalue[BOTTOM]); Error(ERROR_LEVEL_2, argv[0], messageStr); break; } /* --- Get increments in x, store and check for monotonicity -- --- */ geometry.dx = (double *) malloc(Nx * sizeof(double)); result = xdr_vector(&xdrs, (char *) geometry.dx, Nx, sizeof(double), (xdrproc_t) xdr_double); for (l = 0; l < ((geometry.hboundary == PERIODIC) ? Nx : Nx-1); l++) { geometry.dx[l] *= KM_TO_M; if (geometry.dx[l] <= 0.0) { sprintf(messageStr, "At l = %d:\n x does not increase strictly " "monotonically towards the right", l); Error(ERROR_LEVEL_2, argv[0], messageStr); } } geometry.x = (double *) malloc(Nx * sizeof(double)); geometry.x[0] = 0.0; for (l = 0; l < Nx-1; l++) geometry.x[l+1] = geometry.x[l] + geometry.dx[l]; /* --- Get vertical grid -- -------------- */ geometry.z = (double *) malloc(Nz * sizeof(double)); result = xdr_vector(&xdrs, (char *) geometry.z, Nz, sizeof(double), (xdrproc_t) xdr_double); for (k = 0; k < Nz; k++) geometry.z[k] *= KM_TO_M; geometry.dz = (double *) malloc(Nz * sizeof(double)); for (k = 0; k < Nz-1; k++) { geometry.dz[k] = geometry.z[k] - geometry.z[k+1]; if (geometry.dz[k] <= 0.0) { sprintf(messageStr, "At k = %d:\n z does not decrease strictly " "monotonically towards the bottom", k); Error(ERROR_LEVEL_2, argv[0], messageStr); } } geometry.dz[Nz-1] = 0.0; chi = (double *) malloc(Nspace * sizeof(double)); S = (double *) malloc(Nspace * sizeof(double)); Bp = (double *) malloc(Nspace * sizeof(double)); epsilon = (double *) malloc(Nspace * sizeof(double)); result = xdr_vector(&xdrs, (char *) chi, Nspace, sizeof(double), (xdrproc_t) xdr_double); result = xdr_vector(&xdrs, (char *) Bp, Nspace, sizeof(double), (xdrproc_t) xdr_double); result = xdr_vector(&xdrs, (char *) epsilon, Nspace, sizeof(double), (xdrproc_t) xdr_double); getBoundary(&atmos, &geometry); getAngleQuadr(&geometry); atmos.Nrays = geometry.Nrays; atmos.wmu = geometry.wmu; fillMesh(&geometry); lambda = (double *) malloc(Nlambda * sizeof(double)); phi = (double *) malloc(Nlambda * sizeof(double)); wlamb = (double *) malloc(Nlambda * sizeof(double)); result = xdr_vector(&xdrs, (char *) lambda, Nlambda, sizeof(double), (xdrproc_t) xdr_double); wlamb[0] = (lambda[1] - lambda[0]); for (la = 1; la < Nlambda-1; la++) wlamb[la] = (lambda[la+1] - lambda[la-1]); wlamb[Nlambda-1] = (lambda[Nlambda-1] - lambda[Nlambda-2]); wphi = 0.0; for (la = 0; la < Nlambda; la++) { phi[la] = Voigt(Adamp, lambda[la], NULL, RYBICKI)/SQRTPI; wphi += wlamb[la]*phi[la]; } wphi = 1.0/wphi; xdr_destroy(&xdrs); fclose(fpin); for (k = 0; k < Nspace; k++) S[k] = Bp[k]; Ng_S = NgInit(Nspace, Ngdelay, Ngorder, Ngperiod, S); Iterate(NmaxIter, iterLimit); nwrite = fwrite(S, sizeof(double), Nspace, stdout); printTotalCPU(); }
std::vector<Mesh> loadMeshesFromObj(const char *filename, float scale) { printf("Attempting to load mesh->from %s\n", filename); std::ifstream filehandle; filehandle.open(filename, std::ios::in); std::vector<Mesh> meshes; if(filehandle.fail()) { printf("Could not open file.\n"); return meshes; } std::vector<std::list<sVertexIndex> > existingVertexTable; std::vector<sVertexIndex> vertexTable; std::vector<Mesh::sFace> faceTable; std::vector<sVec3> positionTable; std::vector<sVec3> normalTable; std::vector<sVec2> texcoordTable; std::string line; std::string name; std::string material; int sg = 0; int count = 0; clock_t start, end; start = clock(); printf("Reading data... "); while( filehandle.good() && !filehandle.eof() ) { std::getline(filehandle, line); if(line[0] == 'v') { if(line[1] == 't') readTexcoord(line, texcoordTable); else if(line[1] == 'n') readNormal(line, normalTable); else readPosition(line, positionTable, scale); } else if(line[0] == 'f') readFace(line, vertexTable, existingVertexTable, faceTable, sg); else if(line[0] == 's') readSG(line, sg); else if(line[0] == 'g') { readG(line, name); } else if(line[0] == 'u') { char str[32]; char mtl[128]; int success = sscanf(line.c_str(), "%s %s", str, mtl); if(success && strcmp(str, "usemtl") == 0) { if(count > 0) { meshes.push_back(Mesh()); fillMesh( meshes[count-1], name, vertexTable, faceTable, positionTable, normalTable, texcoordTable); meshes[count-1].material = material; vertexTable.clear(); faceTable.clear(); existingVertexTable.clear(); } ++count; if(success > 1) material = std::string(mtl); } } } if(count > 0) { meshes.push_back(Mesh()); fillMesh( meshes[count-1], name, vertexTable, faceTable, positionTable, normalTable, texcoordTable); meshes[count-1].material = material; } printf("done!\n"); //printf("total vertex count %i\n", vertexTable.size()); //printf("total face count %i\n", faceTable.size()); end = clock(); double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("Time taken %3.3fs \n", cpu_time_used); //printf("meshes.size() = %i\n", meshes.size()); return meshes; }
Mesh loadMeshFromObj(const char *filename, float scale) { printf("Attempting to load mesh->from %s\n", filename); std::ifstream filehandle; filehandle.open(filename, std::ios::in); if(filehandle.fail()) { printf("Could not open file.\n"); return Mesh(); } std::vector<std::list<sVertexIndex> > existingVertexTable; std::vector<sVertexIndex> vertexTable; std::vector<Mesh::sFace> faceTable; std::vector<sVec3> positionTable; std::vector<sVec3> normalTable; std::vector<sVec2> texcoordTable; std::string line; std::string name(filename); int sg = 0; clock_t start, end; start = clock(); printf("Reading data... "); while( filehandle.good() && !filehandle.eof() ) { std::getline(filehandle, line); if(line[0] == 'v') { if(line[1] == 't') readTexcoord(line, texcoordTable); else if(line[1] == 'n') readNormal(line, normalTable); else readPosition(line, positionTable, scale); } else if(line[0] == 'f') readFace(line, vertexTable, existingVertexTable, faceTable, sg); else if(line[0] == 's') readSG(line, sg); } Mesh m; fillMesh( m, name, vertexTable, faceTable, positionTable, normalTable, texcoordTable); printf("done!\n"); printf("total vertex count %i\n", vertexTable.size()); printf("total face count %i\n", faceTable.size()); end = clock(); double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("Time taken %3.3fs \n", cpu_time_used); return m; }
int main(int argc, char *argv[]) { bool_t analyze_output, equilibria_only; int niter, nact; Atom *atom; Molecule *molecule; /* --- Read input data and initialize -- -------------- */ setOptions(argc, argv); getCPU(0, TIME_START, NULL); SetFPEtraps(); readInput(); spectrum.updateJ = TRUE; getCPU(1, TIME_START, NULL); readAtmos(&atmos, &geometry); if (atmos.Stokes) Bproject(); fillMesh(&geometry); readAtomicModels(); readMolecularModels(); SortLambda(); getBoundary(&atmos, &geometry); Background(analyze_output=TRUE, equilibria_only=FALSE); getProfiles(); initSolution(); initScatter(); getCPU(1, TIME_POLL, "Total initialize"); /* --- Solve radiative transfer for active ingredients -- --------- */ Iterate(input.NmaxIter, input.iterLimit); adjustStokesMode(atom); niter = 0; while (niter < input.NmaxScatter) { if (solveSpectrum(FALSE, FALSE) <= input.iterLimit) break; niter++; } /* --- Write output files -- ------------------ */ getCPU(1, TIME_START, NULL); writeInput(); writeAtmos(&atmos); writeGeometry(&geometry); writeSpectrum(&spectrum); writeFlux(FLUX_DOT_OUT); for (nact = 0; nact < atmos.Nactiveatom; nact++) { atom = atmos.activeatoms[nact]; writeAtom(atom); writePopulations(atom); writeRadRate(atom); writeCollisionRate(atom); writeDamping(atom); } for (nact = 0; nact < atmos.Nactivemol; nact++) { molecule = atmos.activemols[nact]; writeMolPops(molecule); } writeOpacity(); getCPU(1, TIME_POLL, "Write output"); printTotalCPU(); }