Ejemplo n.º 1
0
inline void s2e(const std::string& name, GroupName& enum_ret)
{
    for (int enum_it = GroupName_begin; enum_it != GroupName_end; ++enum_it )
    {
        enum_ret = static_cast<GroupName>(enum_it);
        if (name == e2s(enum_ret)) return;
    }
    throw CadetException("No enum entry for given group name \"" + name + "\"!");
}
Ejemplo n.º 2
0
inline void s2e(const std::string& name, ReconstructionType& enum_ret)
{
    for (int enum_it = ReconstructionType_begin; enum_it != ReconstructionType_end; ++enum_it )
    {
        enum_ret = static_cast<ReconstructionType>(enum_it);
        if (name == e2s(enum_ret)) return;
    }
    throw CadetException("No enum entry for given reconstruction type \"" + name + "\"!");
}
Ejemplo n.º 3
0
inline void s2e(const std::string& name, ParticleDiscType& enum_ret)
{
    for (int enum_it = ParticleDiscType_begin; enum_it != ParticleDiscType_end; ++enum_it )
    {
        enum_ret = static_cast<ParticleDiscType>(enum_it);
        if (name == e2s(enum_ret)) return;
    }
    throw CadetException("No enum entry for given particle discretization type \"" + name + "\"!");
}
Ejemplo n.º 4
0
// the conversion is case sensitive !
inline void s2e(const std::string& name, ChromatographyType& enum_ret)
{
    for (int enum_it = ChromatographyType_begin; enum_it != ChromatographyType_end; ++enum_it )
    {
        enum_ret = static_cast<ChromatographyType>(enum_it);
        if (name == e2s(enum_ret)) return;
    }
    throw CadetException("No enum entry for given chromatography type \"" + name + "\"!");
}
Ejemplo n.º 5
0
static void
start_timer(struct timer_thread *t, void (*func)(void), const char *name, int msec)
{
	t->msec = msec;
	t->func = func;
	t->name = name;
	int r = thread_create(0, name, &net_timer, (uint32_t)t);
	if (r < 0)
		panic("cannot create timer thread: %s", e2s(r));
}
Ejemplo n.º 6
0
    // Constructor
    AdsorptionModel_LINEAR(const SimulatorPImpl& sim) :
        AdsorptionModel(sim, LINEAR)
    {
        log::emit<Trace1>() << CURRENT_FUNCTION << Color::cyan << ": Called!" << Color::reset << log::endl;

        const double inf = std::numeric_limits<double>::infinity();

        this->configure();
        log::emit<Debug1>() << CURRENT_FUNCTION << ": Configured" << log::endl;

        _kA.reserve(_cc.ncomp());
        _kD.reserve(_cc.ncomp());
        for (int comp = 0; comp < _cc.ncomp(); ++comp)
        {
            _kA.push_back(Parameter<active> (LIN_KA,   e2s(LIN_KA),   comp, -1, 0.0, 0.0, 0.0, false, inf, true));
            addParam(_kA[comp]);
            _kD.push_back(Parameter<active> (LIN_KD,   e2s(LIN_KD),   comp, -1, 0.0, 0.0, 0.0, false, inf, true));
            addParam(_kD[comp]);
        }

        log::emit<Trace1>() << CURRENT_FUNCTION << Color::green << ": Finished!" << Color::reset << log::endl;
    }
Ejemplo n.º 7
0
static void to_subpaving(cmd_context & ctx, expr * t) {
    ast_manager & m = ctx.m();
    unsynch_mpq_manager qm;
    scoped_ptr<subpaving::context> s;
    s = subpaving::mk_mpq_context(ctx.m().limit(), qm);
    expr2var e2v(m);
    expr2subpaving e2s(m, *s, &e2v);
    params_ref p;
    p.set_bool("mul_to_power", true);
    th_rewriter simp(m, p);
    expr_ref t_s(m);
    simp(t, t_s);
    scoped_mpz n(qm), d(qm);
    ctx.regular_stream() << mk_ismt2_pp(t_s, m) << "\n=======>" << std::endl;
    subpaving::var x = e2s.internalize_term(t_s, n, d);
    expr2var::iterator it  = e2v.begin();
    expr2var::iterator end = e2v.end();
    for (; it != end; ++it) {
        ctx.regular_stream() << "x" << it->m_value << " := " << mk_ismt2_pp(it->m_key, m) << "\n";
    }
    s->display_constraints(ctx.regular_stream());
    ctx.regular_stream() << n << "/" << d << " x" << x << "\n";
}
Ejemplo n.º 8
0
int main() {
    const size_t N = 64;
    const size_t n_iter = 20;
    const size_t newton_iter = 4;
    const bool verbose = false;

    std::vector<float> volume(N*N*N, 0.0f);
    std::mt19937 mt(0);
    std::uniform_real_distribution<> uniform(-1.0f, 1.0f);
    for (size_t i=0; i<volume.size(); ++i) {
        volume[i] = uniform(mt);
    }

    std::vector<float> e0s(N*N*N, 0.0f);
    std::vector<float> e1s(N*N*N, 0.0f);
    std::vector<float> e2s(N*N*N, 0.0f);
    timer("reference", n_iter, [&] {
        eigen_hessian_3d<newton_iter>(e0s.data(), e1s.data(), e2s.data(), volume.data(), N, N, N, true);
    });

    std::vector<float> e0s_simd(N*N*N, 0.0f);
    std::vector<float> e1s_simd(N*N*N, 0.0f);
    std::vector<float> e2s_simd(N*N*N, 0.0f);
    timer("SSE1", n_iter, [&] {
        eigen_hessian_3d<1>(e0s_simd.data(), e1s_simd.data(), e2s_simd.data(), volume.data(), N, N, N, false);
    });
    timer("SSE2", n_iter, [&] {
        eigen_hessian_3d<2>(e0s_simd.data(), e1s_simd.data(), e2s_simd.data(), volume.data(), N, N, N, false);
    });
    timer("SSE3", n_iter, [&] {
        eigen_hessian_3d<3>(e0s_simd.data(), e1s_simd.data(), e2s_simd.data(), volume.data(), N, N, N, false);
    });
    timer("SSE", n_iter, [&] {
        eigen_hessian_3d<newton_iter>(e0s_simd.data(), e1s_simd.data(), e2s_simd.data(), volume.data(), N, N, N, false);
    });

    float e0_diff_sum = 0.0f;
    float e1_diff_sum = 0.0f;
    float e2_diff_sum = 0.0f;
    for (size_t i=0; i<volume.size(); ++i) {
        if (verbose) {
            std::cout << ""
                      << e0s[i] << ","
                      << e1s[i] << ","
                      << e2s[i] << " "
                      << e0s_simd[i] << ","
                      << e1s_simd[i] << ","
                      << e2s_simd[i] << " "
                      << std::endl;
        }
        e0_diff_sum += std::abs(e0s[i] - e0s_simd[i]);
        e1_diff_sum += std::abs(e1s[i] - e1s_simd[i]);
        e2_diff_sum += std::abs(e2s[i] - e2s_simd[i]);
    }
    std::cout << N << "x" << N << "x" << N << " volume. Newton iter = " << newton_iter << std::endl;
    std::cout << "mean abs error: "
              << e0_diff_sum/volume.size() << ", "
              << e1_diff_sum/volume.size() << ", "
              << e2_diff_sum/volume.size() << std::endl;
    return 0;
}
Ejemplo n.º 9
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void StatsGenODFWidget::on_loadODFTextureBtn_clicked()
{

  QString file = angleFilePath->text();
  if(true == file.isEmpty())
  {
    return;
  }

  QFileInfo fi(angleFilePath->text());
  if(fi.exists() == false)
  {
    return;
  }

  size_t count = 0;
  QVector<float> e1s(count);
  QVector<float> e2s(count);
  QVector<float> e3s(count);
  QVector<float> weights(count);
  QVector<float> sigmas(count);

  QProgressDialog progress("Loading Data ....", "Cancel", 0, 3, this);
  progress.setWindowModality(Qt::WindowModal);
  progress.setMinimumDuration(2000);

  if (fi.suffix().compare(Ebsd::Ang::FileExt) == 0)
  {
    progress.setValue(1);
    progress.setLabelText("[1/3] Reading File ...");
    AngReader loader;
    loader.setFileName(angleFilePath->text());
    int err = loader.readFile();
    if(err < 0)
    {
      QMessageBox::critical(this, "Error loading the ANG file", loader.getErrorMessage(), QMessageBox::Ok);
      return;
    }
    float* phi1 = loader.getPhi1Pointer();
    float* phi = loader.getPhiPointer();
    float* phi2 = loader.getPhi2Pointer();

    int xDim = loader.getXDimension();
    int yDim = loader.getYDimension();
    count = xDim * yDim;
    e1s.resize(count);
    e2s.resize(count);
    e3s.resize(count);
    weights.resize(count);
    sigmas.resize(count);
    for(size_t i = 0; i < count; ++i)
    {
      e1s[i] = phi1[i];
      e2s[i] = phi[i];
      e3s[i] = phi2[i];
      weights[i] = 1.0;
      sigmas[i] = 0.0;
    }
  }
  else if (fi.suffix().compare(Ebsd::Ctf::FileExt) == 0)
  {
    progress.setValue(1);
    progress.setLabelText("[1/3] Reading File ...");
    CtfReader loader;
    loader.setFileName(angleFilePath->text());
    int err = loader.readFile();
    if(err < 0)
    {
      QMessageBox::critical(this, "Error loading the CTF file", loader.getErrorMessage(), QMessageBox::Ok);
      return;
    }
    float* phi1 = loader.getEuler1Pointer();
    float* phi = loader.getEuler2Pointer();
    float* phi2 = loader.getEuler3Pointer();

    int xDim = loader.getXDimension();
    int yDim = loader.getYDimension();
    count = xDim * yDim;
    e1s.resize(count);
    e2s.resize(count);
    e3s.resize(count);
    weights.resize(count);
    sigmas.resize(count);
    for(size_t i = 0; i < count; ++i)
    {
      e1s[i] = phi1[i];
      e2s[i] = phi[i];
      e3s[i] = phi2[i];
      weights[i] = 1.0;
      sigmas[i] = 0.0;
    }
  }
  else
  {
    progress.setValue(1);
    progress.setLabelText("[1/3] Reading File ...");
    AngleFileLoader::Pointer loader = AngleFileLoader::New();
    loader->setInputFile(angleFilePath->text());
    loader->setAngleRepresentation(angleRepresentation->currentIndex());
    loader->setFileAnglesInDegrees(anglesInDegrees->isChecked());
    loader->setOutputAnglesInDegrees(true);
    QString delim;
    int index = delimiter->currentIndex();
    switch(index)
    {
      case 0:
        delim = " ";
        break;
      case 1:
        delim = "\t";
        break;
      case 2:
        delim = ",";
        break;
      case 3:
        delim = ";";
        break;
      default:
        delim = " ";

    }

    loader->setDelimiter(delim);
    FloatArrayType::Pointer data = loader->loadData();
    if (loader->getErrorCode() < 0)
    {
      QMessageBox::critical(this, "Error Loading Angle data", loader->getErrorMessage(), QMessageBox::Ok);
      return;
    }
    count = data->getNumberOfTuples();
    e1s.resize(count);
    e2s.resize(count);
    e3s.resize(count);
    weights.resize(count);
    sigmas.resize(count);
    for(size_t i = 0; i < count; ++i)
    {
      e1s[i] = data->getComponent(i, 0);
      e2s[i] = data->getComponent(i, 1);
      e3s[i] = data->getComponent(i, 2);
      weights[i] = data->getComponent(i, 3);
      sigmas[i] = data->getComponent(i, 4);
    }

  }

  progress.setValue(2);
  progress.setLabelText("[2/3] Rendering Pole Figure ...");

  m_OdfBulkTableModel->removeRows(0, m_OdfBulkTableModel->rowCount());

#if 1
  m_OdfBulkTableModel->blockSignals(true);
  m_OdfBulkTableModel->setColumnData(SGODFTableModel::Euler1, e1s);
  m_OdfBulkTableModel->setColumnData(SGODFTableModel::Euler2, e2s);
  m_OdfBulkTableModel->setColumnData(SGODFTableModel::Euler3, e3s);
  m_OdfBulkTableModel->setColumnData(SGODFTableModel::Weight, weights);
  m_OdfBulkTableModel->setColumnData(SGODFTableModel::Sigma, sigmas);
  m_OdfBulkTableModel->blockSignals(false);
#endif
  on_m_CalculateODFBtn_clicked();
  progress.setValue(3);
}
Ejemplo n.º 10
0
	ModelData<real_t> readModel(reader_t& reader)
	{
		ModelData<real_t> data;

	    reader.setGroup(e2s(GRP_IN_MODEL));
	    s2e(reader.template scalar<std::string>(e2s(ADSORPTION_TYPE)), data.bindingModel);
	    data.nComponents = reader.template scalar<int>(e2s(NCOMP));

	    reader.setGroup(e2s(GRP_IN_INLET));
	    data.nInletSections  = reader.template scalar<int>(e2s(NSEC));

	    // Reserve space
	    data.initialLiquidConcentration.reserve(data.nComponents);
	    data.initialSolidConcentration.reserve(data.nComponents);
	    data.filmDiffusion.reserve(data.nComponents);
		data.particleDiffusion.reserve(data.nComponents);
		data.surfaceDiffusion.reserve(data.nComponents);
		data.linearKA.reserve(data.nComponents);
		data.linearKD.reserve(data.nComponents);

		data.sectionTimes.reserve(data.nInletSections);
		data.constCoeff.reserve(data.nInletSections * data.nComponents);
        data.linCoeff.reserve(data.nInletSections * data.nComponents);
        data.quadCoeff.reserve(data.nInletSections * data.nComponents);
        data.cubicCoeff.reserve(data.nInletSections * data.nComponents);

		// Read inlet specs
        reader.setGroup(e2s(GRP_IN_INLET));
        const std::vector<double> sectionTimes = reader.template vector<double>(e2s(SECTION_TIMES));
        for(std::vector<double>::const_iterator it = sectionTimes.begin(); it != sectionTimes.end(); ++it)
        {
        	data.sectionTimes.push_back(real_t(*it));
        }

        for (std::size_t sec = 0; sec < data.nInletSections; ++sec)
        {
        	std::ostringstream oss;
            oss.str("");
            oss << e2s(GRP_IN_INLET) << "/sec_" << std::setfill('0') << std::setw(3) << std::setprecision(0) << sec;
            reader.setGroup(oss.str());
            const std::vector<double> const_coeff = reader.template vector<double>("CONST_COEFF");
            const std::vector<double> linear_coeff = reader.template vector<double>("LIN_COEFF");
            const std::vector<double> quad_coeff = reader.template vector<double>("QUAD_COEFF");
            const std::vector<double> cubic_coeff = reader.template vector<double>("CUBE_COEFF");
	        for(std::size_t i = 0; i < const_coeff.size(); ++i)
	        {
	        	data.constCoeff.push_back(real_t(const_coeff[i]));
                data.linCoeff.push_back(real_t(linear_coeff[i]));
                data.quadCoeff.push_back(real_t(quad_coeff[i]));
                data.cubicCoeff.push_back(real_t(cubic_coeff[i]));
	        }
        }

        // Read binding model specs
        reader.setGroup(e2s(GRP_IN_ADSORPTION));
        data.kineticBinding = reader.template scalar<int>(e2s(IS_KINETIC));

        if (data.bindingModel == LINEAR)
        {
            const std::vector<double> linKA = reader.template vector<double>(e2s(LIN_KA));
            const std::vector<double> linKD = reader.template vector<double>(e2s(LIN_KD));

	        for(std::size_t i = 0; i < data.nComponents; ++i)
	        {
	        	data.linearKA.push_back(real_t(linKA[i]));
	        	data.linearKD.push_back(real_t(linKD[i]));
	        }
        }

        // Chromatography model parameters
        reader.setGroup(e2s(GRP_IN_MODEL));

        data.colDispersion = real_t(reader.template scalar<double>(e2s(COL_DISPERSION)));
        data.velocity = real_t(reader.template scalar<double>(e2s(VELOCITY)));
        data.colLength = real_t(reader.template scalar<double>(e2s(COL_LENGTH)));
        data.colPorosity = real_t(reader.template scalar<double>(e2s(COL_POROSITY)));
        data.parRadius = real_t(reader.template scalar<double>(e2s(PAR_RADIUS)));
        data.parPorosity = real_t(reader.template scalar<double>(e2s(PAR_POROSITY)));

        // Vectorial parameters
        const std::vector<double> initialSolid = reader.template vector<double>(e2s(INIT_Q));
        const std::vector<double> initialLiquid = reader.template vector<double>(e2s(INIT_C));
        const std::vector<double> filmDiff = reader.template vector<double>(e2s(FILM_DIFFUSION));
        const std::vector<double> parDiff = reader.template vector<double>(e2s(PAR_DIFFUSION));
        const std::vector<double> parSurfDiff = reader.template vector<double>(e2s(PAR_SURFDIFFUSION));
        for(std::size_t i = 0; i < data.nComponents; ++i)
        {
            data.initialSolidConcentration.push_back(real_t(initialSolid[i]));
            data.initialLiquidConcentration.push_back(real_t(initialLiquid[i]));
        	data.filmDiffusion.push_back(real_t(filmDiff[i]));
        	data.particleDiffusion.push_back(real_t(parDiff[i]));
        	data.surfaceDiffusion.push_back(real_t(parSurfDiff[i]));
        }

        // Read outlet times
        reader.setGroup(e2s(GRP_IN_SOLVER));
        data.writeUserTimes = reader.template scalar<int>(e2s(WRITE_AT_USER_TIMES));

        if (data.writeUserTimes)
        {
        	const std::vector<double> out = reader.template vector<double>(e2s(USER_SOLUTION_TIMES));
        	data.outletTimes.reserve(out.size());
	        for(std::vector<double>::const_iterator it = out.begin(); it != out.end(); ++it)
	        {
	        	data.outletTimes.push_back(real_t(*it));
	        }

        }

        return data;			
	}
Ejemplo n.º 11
0
void
perror(const char *s) {
	int err = errno;
	cprintf("%s: %s\n", s, e2s(err));
}