/* bibl_copy() * * returns 1 on success, 0 on failure (memory error) */ int bibl_copy( bibl *bout, bibl *bin ) { fields *refin, *refout; int i, j, n, status, ok, level; char *tag, *value; for ( i=0; i<bin->nrefs; ++i ) { refin = bin->ref[i]; refout = fields_new(); if ( !refout ) return 0; n = fields_num( refin ); for ( j=0; j<n; ++j ) { tag = fields_tag( refin, j, FIELDS_CHRP ); value = fields_value( refin, j, FIELDS_CHRP ); level = fields_level( refin, j ); if ( tag && value ) { status = fields_add( refout, tag, value, level ); if ( status!=FIELDS_OK ) return 0; } } ok = bibl_addref( bout, refout ); if ( !ok ) return 0; } return 1; }
static int read_ref( FILE *fp, bibl *bin, char *filename, convert_rules *r, param *p ) { newstr reference, line; fields *ref; char buf[256]=""; int nrefs = 0, bufpos = 0, fcharset; newstr_init( &reference ); newstr_init( &line ); while ( r->readf( fp, buf, sizeof(buf), &bufpos, &line, &reference, &fcharset ) ) { if ( reference.len==0 ) continue; ref = fields_new(); if ( !ref ) return BIBL_ERR_MEMERR; if ( r->processf( ref, reference.data, filename, nrefs+1 )){ bibl_addref( bin, ref ); } else { fields_free( ref ); free( ref ); } newstr_empty( &reference ); if ( fcharset!=CHARSET_UNKNOWN ) { /* charset from file takes priority over default, but * not user-specified */ if ( p->charsetin_src!=BIBL_SRC_USER ) { p->charsetin_src = BIBL_SRC_FILE; p->charsetin = fcharset; if ( fcharset!=CHARSET_UNICODE ) p->utf8in = 0; } } } newstr_free( &line ); newstr_free( &reference ); return BIBL_OK; }
static int convert_ref( bibl *bin, char *fname, bibl *bout, convert_rules *r, param *p ) { fields *rin, *rout; long i; int reftype; if ( r->cleanf ) r->cleanf( bin, p ); for ( i=0; i<bin->nrefs; ++i ) { rin = bin->ref[i]; rout = fields_new(); if ( !rout ) return BIBL_ERR_MEMERR; if ( r->typef ) reftype = r->typef( rin, fname, i+1, p, r->all, r->nall ); else reftype = 0; r->convertf( rin, rout, reftype, p, r->all, r->nall ); if ( r->all ) process_alwaysadd( rout, reftype, r ); if ( p->verbose ) bibl_verbose1( rout, rin, fname, i+1 ); bibl_addref( bout, rout ); } uniqueify_citekeys( bout ); return BIBL_OK; }
int main(int argc, char *argv[]) { int sts; int ctx; int c; char *infile; int nfilelist; int filenum; char *archive = NULL; int j; char *buf; fields_t *f; char *s; int gzipped; FILE *fp; metric_t *m; handler_t *h; int unhandled_metric_cnt = 0; while ((c = pmGetOptions(argc, argv, &opts)) != EOF) { switch (c) { case 'F': Fflag = 1; break; case 'v': vflag++; break; } } nfilelist = argc - opts.optind - 1; if (nfilelist < 1) opts.errors++; else archive = argv[argc - 1]; if (opts.errors) { pmUsageMessage(&opts); exit(1); } if ((buf = malloc(BUFSIZE)) == NULL) { perror("Error: out of memory:"); exit(1); } if (Fflag) { snprintf(buf, BUFSIZE, "%s.meta", archive); unlink(buf); snprintf(buf, BUFSIZE, "%s.index", archive); unlink(buf); for (j=0;; j++) { snprintf(buf, BUFSIZE, "%s.%d", archive, j); if (unlink(buf) < 0) break; } } ctx = pmiStart(archive, 0); if ((sts = pmiUseContext(ctx)) < 0) { fprintf(stderr, "Error: pmiUseContext failed: %s\n", pmiErrStr(sts)); exit(1); } /* * Define the metrics name space, see metrics.c (generated by pmdesc) */ for (m = metrics; m->name; m++) { pmDesc *d = &m->desc; sts = pmiAddMetric(m->name, d->pmid, d->type, d->indom, d->sem, d->units); if (sts < 0) { fprintf(stderr, "Error: failed to add metric %s: %s\n", m->name, pmiErrStr(sts)); exit(1); } } /* * Populate special case instance domains */ pmiAddInstance(pmInDom_build(LINUX_DOMAIN, LOADAVG_INDOM), "1 minute", 1); pmiAddInstance(pmInDom_build(LINUX_DOMAIN, LOADAVG_INDOM), "5 minute", 5); pmiAddInstance(pmInDom_build(LINUX_DOMAIN, LOADAVG_INDOM), "15 minute", 15); indom_cnt[LOADAVG_INDOM] = 3; for (filenum=0; filenum < nfilelist; filenum++) { infile = argv[opts.optind + filenum]; gzipped = strstr(infile, ".gz") != NULL; if (gzipped) { snprintf(buf, BUFSIZE, "gzip -c -d %s", infile); if ((fp = popen(buf, "r")) == NULL) perror(buf); } else if ((fp = fopen(infile, "r")) == NULL) perror(infile); if (fp == NULL) { pmUsageMessage(&opts); exit(1); } /* * parse the header */ sts = header_handler(fp, infile, buf, BUFSIZE); /* * Parse remaining data stream for this input file */ while(fgets(buf, BUFSIZE, fp)) { if ((s = strrchr(buf, '\n')) != NULL) *s = '\0'; if (!buf[0]) continue; f = fields_new(buf, strlen(buf)+1); if (f->nfields > 0) { if ((h = find_handler(f->fields[0])) == NULL) { unhandled_metric_cnt++; if (vflag > 1) printf("Unhandled tag: \"%s\"\n", f->fields[0]); } else { sts = h->handler(h, f); if (sts < 0 && h->handler == timestamp_handler) { fprintf(stderr, "Error: %s\n", pmiErrStr(sts)); exit(1); } } } fields_free(f); } /* final flush for this file */ if ((sts = timestamp_flush()) < 0) { fprintf(stderr, "Error: failed to write final timestamp: %s\n", pmiErrStr(sts)); exit(1); } if (gzipped) pclose(fp); else fclose(fp); } sts = pmiEnd(); if (unhandled_metric_cnt && vflag) fprintf(stderr, "Warning: %d unhandled metric/values\n", unhandled_metric_cnt); exit(0); }
void MappingExtrapolate::v_CalcNeumannPressureBCs( const Array<OneD, const Array<OneD, NekDouble> > &fields, const Array<OneD, const Array<OneD, NekDouble> > &N, NekDouble kinvis) { if (m_mapping->HasConstantJacobian() && !m_implicitViscous) { Extrapolate::v_CalcNeumannPressureBCs( fields, N, kinvis); } else { int physTot = m_fields[0]->GetTotPoints(); int nvel = m_fields.num_elements()-1; Array<OneD, NekDouble> Pvals; StdRegions::StdExpansionSharedPtr Pbc; StdRegions::StdExpansionSharedPtr elmt; Array<OneD, Array<OneD, const NekDouble> > Velocity(m_bnd_dim); Array<OneD, Array<OneD, const NekDouble> > Advection(m_bnd_dim); // Get transformation Jacobian Array<OneD, NekDouble> Jac(physTot,0.0); m_mapping->GetJacobian(Jac); // Declare variables Array<OneD, Array<OneD, NekDouble> > BndValues(m_bnd_dim); Array<OneD, Array<OneD, NekDouble> > Q(m_bnd_dim); Array<OneD, Array<OneD, NekDouble> > Q_field(nvel); Array<OneD, Array<OneD, NekDouble> > fields_new(nvel); Array<OneD, Array<OneD, NekDouble> > N_new(m_bnd_dim); // Temporary variables Array<OneD, NekDouble> tmp(physTot,0.0); Array<OneD, NekDouble> tmp2(physTot,0.0); for(int i = 0; i < m_bnd_dim; i++) { BndValues[i] = Array<OneD, NekDouble> (m_pressureBCsMaxPts,0.0); Q[i] = Array<OneD, NekDouble> (m_pressureBCsElmtMaxPts,0.0); N_new[i] = Array<OneD, NekDouble> (physTot,0.0); } for(int i = 0; i < nvel; i++) { Q_field[i] = Array<OneD, NekDouble> (physTot,0.0); fields_new[i] = Array<OneD, NekDouble> (physTot,0.0); } // Multiply convective terms by Jacobian for(int i = 0; i < m_bnd_dim; i++) { if (m_fields[0]->GetWaveSpace()) { m_fields[0]->HomogeneousBwdTrans(N[i],N_new[i]); } else { Vmath::Vcopy(physTot, N[i], 1, N_new[i], 1); } Vmath::Vmul(physTot, Jac, 1, N_new[i], 1, N_new[i], 1); if (m_fields[0]->GetWaveSpace()) { m_fields[0]->HomogeneousFwdTrans(N_new[i],N_new[i]); } } // Get velocity in physical space for(int i = 0; i < nvel; i++) { if (m_fields[0]->GetWaveSpace()) { m_fields[0]->HomogeneousBwdTrans(fields[i],fields_new[i]); } else { Vmath::Vcopy(physTot, fields[i], 1, fields_new[i], 1); } } // Calculate appropriate form of the CurlCurl operator m_mapping->CurlCurlField(fields_new, Q_field, m_implicitViscous); // If viscous terms are treated explicitly, // add grad(U/J \dot grad J) to CurlCurl if ( !m_implicitViscous) { m_mapping->DotGradJacobian(fields_new, tmp); Vmath::Vdiv(physTot, tmp, 1, Jac, 1, tmp, 1); bool wavespace = m_fields[0]->GetWaveSpace(); m_fields[0]->SetWaveSpace(false); for(int i = 0; i < m_bnd_dim; i++) { m_fields[0]->PhysDeriv(MultiRegions::DirCartesianMap[i], tmp, tmp2); Vmath::Vadd(physTot, Q_field[i], 1, tmp2, 1, Q_field[i], 1); } m_fields[0]->SetWaveSpace(wavespace); } // Multiply by Jacobian and convert to wavespace (if necessary) for(int i = 0; i < m_bnd_dim; i++) { Vmath::Vmul(physTot, Jac, 1, fields_new[i], 1, fields_new[i], 1); Vmath::Vmul(physTot, Jac, 1, Q_field[i] , 1, Q_field[i] , 1); if (m_fields[0]->GetWaveSpace()) { m_fields[0]->HomogeneousFwdTrans(fields_new[i],fields_new[i]); m_fields[0]->HomogeneousFwdTrans(Q_field[i],Q_field[i]); } } for(int j = 0 ; j < m_HBCdata.num_elements() ; j++) { /// Casting the boundary expansion to the specific case Pbc = boost::dynamic_pointer_cast<StdRegions::StdExpansion> (m_PBndExp[m_HBCdata[j].m_bndryID] ->GetExp(m_HBCdata[j].m_bndElmtID)); /// Picking up the element where the HOPBc is located elmt = m_pressure->GetExp(m_HBCdata[j].m_globalElmtID); /// Assigning for(int i = 0; i < m_bnd_dim; i++) { Velocity[i] = fields_new[i] + m_HBCdata[j].m_physOffset; Advection[i] = N_new[i] + m_HBCdata[j].m_physOffset; Q[i] = Q_field[i] + m_HBCdata[j].m_physOffset; } // Mounting advection component into the high-order condition for(int i = 0; i < m_bnd_dim; i++) { MountHOPBCs(m_HBCdata[j].m_ptsInElmt,kinvis,Q[i],Advection[i]); } Pvals = m_pressureHBCs[0] + m_HBCdata[j].m_coeffOffset; // Getting values on the edge and filling the pressure boundary // expansion and the acceleration term. Multiplication by the // normal is required switch(m_pressure->GetExpType()) { case MultiRegions::e2D: case MultiRegions::e3DH1D: { elmt->GetEdgePhysVals(m_HBCdata[j].m_elmtTraceID, Pbc, Q[0], BndValues[0]); elmt->GetEdgePhysVals(m_HBCdata[j].m_elmtTraceID, Pbc, Q[1], BndValues[1]); // InnerProduct Pbc->NormVectorIProductWRTBase(BndValues[0], BndValues[1], Pvals); } break; case MultiRegions::e3DH2D: { if(m_HBCdata[j].m_elmtTraceID == 0) { (m_PBndExp[m_HBCdata[j].m_bndryID]->UpdateCoeffs() + m_PBndExp[m_HBCdata[j].m_bndryID] ->GetCoeff_Offset( m_HBCdata[j].m_bndElmtID))[0] = -1.0*Q[0][0]; } else if (m_HBCdata[j].m_elmtTraceID == 1) { (m_PBndExp[m_HBCdata[j].m_bndryID]->UpdateCoeffs() + m_PBndExp[m_HBCdata[j].m_bndryID] ->GetCoeff_Offset( m_HBCdata[j].m_bndElmtID))[0] = Q[0][m_HBCdata[j].m_ptsInElmt-1]; } else { ASSERTL0(false, "In the 3D homogeneous 2D approach BCs edge " "ID can be just 0 or 1 "); } } break; case MultiRegions::e3D: { elmt->GetFacePhysVals(m_HBCdata[j].m_elmtTraceID, Pbc, Q[0], BndValues[0]); elmt->GetFacePhysVals(m_HBCdata[j].m_elmtTraceID, Pbc, Q[1], BndValues[1]); elmt->GetFacePhysVals(m_HBCdata[j].m_elmtTraceID, Pbc, Q[2], BndValues[2]); Pbc->NormVectorIProductWRTBase(BndValues[0], BndValues[1], BndValues[2], Pvals); } break; default: ASSERTL0(0,"Dimension not supported"); break; } } } // If pressure terms are treated implicitly, we need to multiply // by the relaxation parameter, and zero the correction term if (m_implicitPressure) { Vmath::Smul(m_pressureHBCs[0].num_elements(), m_pressureRelaxation, m_pressureHBCs[0], 1, m_pressureHBCs[0], 1); } m_bcCorrection = Array<OneD, NekDouble> (m_pressureHBCs[0].num_elements(), 0.0); }