void run(const casema::ModelData<mpfr::mpreal>& model, ProgramOptions<mpfr::mpreal>& opts)
{
    // Log10(errorPrefactor)
    const mpfr::mpreal errorPrefactor = log10(sqrt(mpfr::mpreal(2))) + model.colLength * model.velocity / (2 * model.colDispersion * log(mpfr::mpreal(10)));
    const mpfr::mpreal T = opts.tMax / mpfr::mpreal(2) * mpfr::mpreal("1.01");
    const mpfr::mpreal errorExponentFactor = model.colLength * sqrt(casema::Constants<mpfr::mpreal>::pi() / (2 * T * model.colDispersion)) / log(mpfr::mpreal(10));

    std::vector<mpfr::mpcomplex> output(opts.summands);
    std::vector<mpfr::mpreal> error(opts.summands, errorPrefactor);
    Inlet_t inlet(model);

    if (model.kineticBinding)
    {
        typedef casema::laplaceSolution::SingleComponentLinearDynamic<mpfr::mpreal, mpfr::mpreal, Inlet_t> Solution_t;
	    Solution_t solution(model, inlet);
        if (opts.withoutInlet)
            fourierCoeff<Solution_t, mpfr::mpreal, mpfr::mpcomplex>(opts.precision, opts.summands, opts.tMax, opts.sigma, solution, errorExponentFactor, output, error);
        else
            fourierCoeff<Solution_t, mpfr::mpreal, mpfr::mpcomplex>(opts.precision, opts.summands, opts.tMax, opts.sigma, solution, inlet, errorExponentFactor, output, error);
    }
    else
    {
        typedef casema::laplaceSolution::SingleComponentLinearRapidEquilibrium<mpfr::mpreal, mpfr::mpreal, Inlet_t> Solution_t;
	    Solution_t solution(model, inlet);
        if (opts.withoutInlet)
            fourierCoeff<Solution_t, mpfr::mpreal, mpfr::mpcomplex>(opts.precision, opts.summands, opts.tMax, opts.sigma, solution, errorExponentFactor, output, error);
        else
            fourierCoeff<Solution_t, mpfr::mpreal, mpfr::mpcomplex>(opts.precision, opts.summands, opts.tMax, opts.sigma, solution, inlet, errorExponentFactor, output, error);
    }

    if (opts.outFile.empty())
    {
        writeMeta(std::cout, model.kineticBinding, opts);
        writeResult(std::cout, output, error, opts.outPrecision, opts.skipSummands);
    }
    else
    {
        std::ofstream fs(opts.outFile, std::ofstream::out | std::ofstream::trunc);
        writeMeta(fs, model.kineticBinding, opts);
        writeResult(fs, output, error, opts.outPrecision, opts.skipSummands);
    }
}
Exemple #2
0
void gff3FileWrite(struct gff3File *g3f, char *fileName)
/* write contents of an GFF3File object to a file */
{
FILE *fh = mustOpen(fileName, "w");
writeMeta(g3f, fh);
struct gff3Ann *g3a;
for (g3a = g3f->anns; g3a != NULL; g3a = g3a->next)
    writeAnn(g3a, fh);
writeFastas(g3f, fh);
carefulClose(&fh);
}
Exemple #3
0
PtexMainWriter::PtexMainWriter(const char* path, PtexTexture* tex,
			       Ptex::MeshType mt, Ptex::DataType dt,
			       int nchannels, int alphachan, int nfaces, bool genmipmaps)
    : PtexWriterBase(path, mt, dt, nchannels, alphachan, nfaces,
		     /* compress */ true),
      _hasNewData(false),
      _genmipmaps(genmipmaps),
      _reader(0)
{
    _tmpfp = OpenTempFile(_tmppath);
    if (!_tmpfp) {
	setError(fileError("Error creating temp file: ", _tmppath.c_str()));
	return;
    }

    // data will be written to a ".new" path and then renamed to final location
    _newpath = path; _newpath += ".new";

    _levels.reserve(20);
    _levels.resize(1);

    // init faceinfo and set flags to -1 to mark as uninitialized
    _faceinfo.resize(nfaces);
    for (int i = 0; i < nfaces; i++) _faceinfo[i].flags = uint8_t(-1);

    _levels.front().pos.resize(nfaces);
    _levels.front().fdh.resize(nfaces);
    _rpos.resize(nfaces);
    _constdata.resize(nfaces*_pixelSize);

    if (tex) {
	// access reader implementation
	_reader = dynamic_cast<PtexReader*>(tex);
	if (!_reader) {
	    setError("Internal error: dynamic_cast<PtexReader*> failed");
	    tex->release();
	    return;
	}

	// copy border modes
	setBorderModes(tex->uBorderMode(), tex->vBorderMode());

	// copy meta data from existing file
	PtexPtr<PtexMetaData> meta ( _reader->getMetaData() );
	writeMeta(meta);

	// see if we have any edits
	_hasNewData = _reader->hasEdits();
    }
}
Exemple #4
0
void PtexWriterBase::writeMeta(PtexMetaData* data)
{
    int nkeys = data->numKeys();
    for (int i = 0; i < nkeys; i++) {
	const char* key = 0;
	MetaDataType type;
	data->getKey(i, key, type);
	int count;
	switch (type) {
	case mdt_string:
	    {
		const char* val=0;
		data->getValue(key, val);
		writeMeta(key, val);
	    }
	    break;
	case mdt_int8:
	    {
		const int8_t* val=0;
		data->getValue(key, val, count);
		writeMeta(key, val, count);
	    }
	    break;
	case mdt_int16:
	    {
		const int16_t* val=0;
		data->getValue(key, val, count);
		writeMeta(key, val, count);
	    }
	    break;
	case mdt_int32:
	    {
		const int32_t* val=0;
		data->getValue(key, val, count);
		writeMeta(key, val, count);
	    }
	    break;
	case mdt_float:
	    {
		const float* val=0;
		data->getValue(key, val, count);
		writeMeta(key, val, count);
	    }
	    break;
	case mdt_double:
	    {
		const double* val=0;
		data->getValue(key, val, count);
		writeMeta(key, val, count);
	    }
	    break;
	}
    }
}
Exemple #5
0
int mkdir_op(const char *path, mode_t mode) {
	return create_file(path, mode | S_IFDIR);

static int unlink(const char* path) {
    if (deleteFile(path) != 0) return -1;
    return 0;
}

static int write(const char *path, const char *buf, size_t off_t offset, struct fuse_file_info *fi) {
	fmeta *meta;
	int metaNum = getMeta(path, &meta);
	if (metaNum == -1) return -ENOENT;
	int s = writeData(meta, buf, nbytes, offset);
	if (s != -1) {
		writeMeta(metaNum);
		return s;
	}
	return -1;
}
Exemple #6
0
int main(int /*argc*/, char** /*argv*/)
{
    static Ptex::Res res[] = { Ptex::Res(8,7),
			       Ptex::Res(1,2),
			       Ptex::Res(3,1),
			       Ptex::Res(5,4),
			       Ptex::Res(9,8),
			       Ptex::Res(2,4),
			       Ptex::Res(6,2),
			       Ptex::Res(7,4),
			       Ptex::Res(2,1)};
    static int adjedges[][4] = {{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 }};
    static int adjfaces[][4] ={{ 3, 1, -1, -1 },
			       { 4, 2, -1, 0 },
			       { 5, -1, -1, 1 },
			       { 6, 4, 0, -1 },
			       { 7, 5, 1, 3 },
			       { 8, -1, 2, 4 },
			       { -1, 7, 3, -1 },
			       { -1, 8, 4, 6 },
			       { -1, -1, 5, 7 }};

    int nfaces = sizeof(res)/sizeof(res[0]);
    Ptex::DataType dt = Ptex::dt_half;
#define DTYPE PtexHalf
    int alpha = -1;
    int nchan = 3;

    Ptex::String error;
    PtexWriter* w =
	PtexWriter::open("test.ptx", Ptex::mt_quad, dt, nchan, alpha, nfaces, error);
    if (!w) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }
    int size = 0;
    for (int i = 0; i < nfaces; i++)
	size = std::max(size, res[i].size());
    size *= Ptex::DataSize(dt) * nchan;

    void* buff = malloc(size);
    for (int i = 0; i < nfaces; i++)
    {
	memset(buff, 0, size);
	DTYPE* fbuff = (DTYPE*)buff;
	int ures = res[i].u(), vres = res[i].v();
	for (int v = 0; v < vres; v++) {
	    for (int u = 0; u < ures; u++) {
		float c = (u ^ v) & 1;
		fbuff[(v*ures+u)*nchan] = u/float(ures-1);
		fbuff[(v*ures+u)*nchan+1] = v/float(vres-1);
		fbuff[(v*ures+u)*nchan+2] = c;
	    }
	}

	w->writeFace(i, Ptex::FaceInfo(res[i], adjfaces[i], adjedges[i]), buff);
    }
    free(buff);

    char* sval = "a str val";
    int ndvals = 3;
    double dvals_buff[3] = { 1.1,2.2,3.3 };
    double* dvals = dvals_buff;
    int nivals = 4;
    int16_t ivals[4] = { 2, 4, 6, 8 };
    char* xval = 0;

    writeMeta(w, sval, dvals, ndvals, ivals, nivals, xval);
    if (!w->close(error)) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }
    w->release();
    if (!checkMeta("test.ptx", sval, dvals, ndvals, ivals, nivals, xval))
	return 1;

    // add some incremental edits
    w = PtexWriter::edit("test.ptx", true, Ptex::mt_quad, dt, nchan, alpha, nfaces, error);
    sval = "a string value";
    dvals[2] = 0;
    writeMeta(w, sval, dvals, ndvals, 0, 0, 0);

    if (!w->close(error)) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }
    w->release();
    if (!checkMeta("test.ptx", sval, dvals, ndvals, ivals, nivals, xval))
	return 1;

    // add some non-incremental edits, including some large meta data
    ndvals = 500;
    dvals = (double*)malloc(ndvals * sizeof(dvals[0]));
    for (int i = 0; i < ndvals; i++) dvals[i] = i;

    w = PtexWriter::edit("test.ptx", false, Ptex::mt_quad, dt, nchan, alpha, nfaces, error);
    xval = "another string value";
    writeMeta(w, 0, dvals, ndvals, 0, 0, xval);
    if (!w->close(error)) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }
    w->release();
    if (!checkMeta("test.ptx", sval, dvals, ndvals, ivals, nivals, xval))
	return 1;

    return 0;
}