Exemple #1
0
void run(casema::ModelData<mpfr::mpreal>& model, const ProgramOptions<mpfr::mpreal>& opts, casema::ConsensusEstimator<mpfr::mpreal>& estimator, bool useExtrapolation)
{
    if (!model.writeUserTimes)
    {
        std::cout << "Generating output time points" << std::endl;
        model.outletTimes.reserve(model.sectionTimes[model.sectionTimes.size()-1].toLong() + 1);

        mpfr::mpreal cur = mpfr::mpreal(1);
        while (cur <= model.sectionTimes[model.sectionTimes.size()-1])
        {
            model.outletTimes.push_back(cur);
            cur += mpfr::mpreal(1);
        }
    }

    std::size_t timeOffset = 0;
    if (model.outletTimes[0] <= mpfr::mpreal(0))
    {
        // Skip first time point
        std::cout << "Removed time point t = 0.0 since Laplace solution has a pole there" << std::endl;
        timeOffset = 1;
    }

    std::cout << "Starting Laplace inversion for Model" << std::endl;

    std::vector<mpfr::mpreal> output;
    Inlet_t inlet(model);
    if (model.kineticBinding)
    {
        typedef casema::laplaceSolution::SingleComponentLinearDynamic<mpfr::mpreal, mpfr::mpreal, Inlet_t> Solution_t;
        output = invert<casema::ModelData<mpfr::mpreal>, Solution_t, Inlet_t>(model, inlet, timeOffset, opts);
    }
    else
    {
        typedef casema::laplaceSolution::SingleComponentLinearRapidEquilibrium<mpfr::mpreal, mpfr::mpreal, Inlet_t> Solution_t;
        output = invert<casema::ModelData<mpfr::mpreal>, Solution_t, Inlet_t>(model, inlet, timeOffset, opts);
    }

    std::cout << "Writing output" << std::endl;
    if (opts.outFile.empty())
    {
        writeResult(std::cout, model.outletTimes, output, opts.outPrecision, timeOffset);
    }
    else
    {
        std::ofstream fs(opts.outFile, std::ofstream::out | std::ofstream::trunc);
        
        if (useExtrapolation)
            writeMeta<mpfr::mpreal>(fs, model, nullptr, opts);
        else
            writeMeta<mpfr::mpreal>(fs, model, nullptr, opts);

        writeResult(fs, model.outletTimes, output, opts.outPrecision, timeOffset);
    }
}
void run(casema::ModelData<mpfr::mpreal>& model, const ProgramOptions& opts)
{
    std::vector<mpfr::mpreal> points(opts.nPoints, opts.start);
    std::vector<mpfr::mpreal> output(opts.nPoints, 0);

    casema::MomentGenerator<mpfr::mpreal>* momGen = nullptr;
    Inlet_t inlet(model);

    if (model.kineticBinding)
    {
        typedef casema::laplaceSolution::SingleComponentLinearDynamic<mpfr::mpreal, mpfr::mpreal, Inlet_t> Solution_t;
        
        if (opts.useCppAD)
            momGen = new casema::CppADMomentGenerator<mpfr::mpreal, Solution_t>(Solution_t(model, inlet));
        else
        {
#ifdef CASEMA_USE_FADBAD
            momGen = new casema::FadBadMomentGenerator<mpfr::mpreal, Solution_t>(Solution_t(model, inlet));
#endif            
        }
    }
    else
    {
        typedef casema::laplaceSolution::SingleComponentLinearRapidEquilibrium<mpfr::mpreal, mpfr::mpreal, Inlet_t> Solution_t;

        if (opts.useCppAD)
            momGen = new casema::CppADMomentGenerator<mpfr::mpreal, Solution_t>(Solution_t(model,inlet));
        else
        {
#ifdef CASEMA_USE_FADBAD
            momGen = new casema::FadBadMomentGenerator<mpfr::mpreal, Solution_t>(Solution_t(model, inlet));
#endif            
        }
    }

    const mpfr::mpreal normalization = casema::detail::injectedMass(model);

    if (opts.linearSeq)
        calcLinearSpacing(*momGen, normalization, points, output, opts);
    else
        calcLogLinearSpacing(*momGen, normalization, points, output, opts);

    delete momGen;

    std::cout << "Writing output" << std::endl;
    if (opts.outFile.empty())
    {
        writeResult(std::cout, points, output, opts.outPrecision);
    }
    else
    {
        std::ofstream fs(opts.outFile, std::ofstream::out | std::ofstream::trunc);
        writeResult(fs, points, output, opts.outPrecision);
    }
}
void run(const casema::ModelData<mpfr::mpreal>& model, std::size_t summands, const mpfr::mpreal& tMax, const mpfr::mpreal& sigma, bool withoutInlet, std::size_t precision, std::size_t outPrecision, const std::string& outFile)
{
    std::vector<mpfr::mpcomplex> output;
    Inlet_t inlet(model);
    if (model.kineticBinding)
    {
        typedef casema::laplaceSolution::SingleComponentLinearDynamic<mpfr::mpreal, mpfr::mpreal, Inlet_t> Solution_t;
	    Solution_t solution(model, inlet);
    	output = fourierCoeff<Solution_t, mpfr::mpreal, mpfr::mpcomplex>(precision, summands, tMax, sigma, solution, withoutInlet);
    }
    else
    {
        typedef casema::laplaceSolution::SingleComponentLinearRapidEquilibrium<mpfr::mpreal, mpfr::mpreal, Inlet_t> Solution_t;
	    Solution_t solution(model, inlet);
    	output = fourierCoeff<Solution_t, mpfr::mpreal, mpfr::mpcomplex>(precision, summands, tMax, sigma, solution, withoutInlet);
    }

    // Write infos
    const mpfr::mpreal T = tMax / mpfr::mpreal(2) * mpfr::mpreal("1.01");
    
    std::ios_base::fmtflags curFlags = std::cout.flags();
    std::streamsize curPrec = std::cout.precision();
    std::cout.flags(std::ios::scientific);
    std::cout.precision(precision);

    std::cout << "T = " << T << std::endl;
    std::cout << "pi / T = " << casema::Constants<mpfr::mpreal>::pi() / T << std::endl;
    std::cout << "sigma = " << sigma << std::endl;
    std::cout << "Summands = " << summands << std::endl;
    std::cout << "Max arg = " << casema::Constants<mpfr::mpreal>::pi() / T * summands << std::endl;
    std::cout << "Error factor = " << sqrt(mpfr::mpreal(2)) * exp(model.colLength * model.velocity / (2 * model.colDispersion)) << std::endl;
    std::cout << "Log10(Error factor) = " << log10(sqrt(mpfr::mpreal(2)) * exp(model.colLength * model.velocity / (2 * model.colDispersion))) << std::endl;
    std::cout << "Error exponent factor = " << model.colLength * sqrt(casema::Constants<mpfr::mpreal>::pi() / (2 * T * model.colDispersion)) << std::endl;

    std::cout.precision(curPrec);
    std::cout.flags(curFlags);
    

    if (outFile.empty())
    {
        writeResult(std::cout, output, outPrecision);
    }
    else
    {
        std::ofstream fs(outFile, std::ofstream::out | std::ofstream::trunc);
        writeResult(fs, output, outPrecision);
    }
}
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 #5
0
bool network_generator::network_gen(){
	
	int inlet_dir = -1, outlet_dir = -1, line_layer = 0;
	pair <int, int> path_head;
	vector < pair <int, int> > inlet(channel_layer*4), outlet(channel_layer*4);
	vector <int> inlet_lock(channel_layer*4), outlet_lock(channel_layer*4);
	vector < pair <int, int> > centers(4);
	
	centers[0].first = 55;
	centers[0].second = 50;
	centers[1].first = 50;
	centers[1].second = 45;
	centers[2].first = 45;
	centers[2].second = 50;
	centers[3].first = 50;
	centers[3].second = 55;
	//random_in_out_let(inlet, outlet);
	
	inlet[0].first = 77;//53
    inlet[0].second = 100;//0
    inlet[1].first = 19;
    inlet[1].second = 0;
    inlet[2].first = 100;
    inlet[2].second = 23;
    inlet[3].first = 0;
    inlet[3].second = 27;
    outlet[0].first = 53;//77
    outlet[0].second = 0;//100
    outlet[1].first = 100;
    outlet[1].second = 35;
    outlet[2].first = 0;
    outlet[2].second = 65;
    outlet[3].first = 49;
    outlet[3].second = 100;
	
	for( int i=0;i<inlet.size();i++ ){
		pout(inlet[i]);
		cout << " ";
		pout(outlet[i]);
		cout << endl;
	}
	getchar();
	
	for( int line_num=0;line_num<channel_layer*4;line_num++ ){
		vector < vector <double> > temp_heat_map(101, vector <double>(101));
		bool reverse = 0;
		for( int x=0;x<101;x++ ){
			for( int y=0;y<101;y++ ){
				double distance_square = pow(x-outlet[line_num].first, 2) + pow(y-outlet[line_num].second, 2);
				temp_heat_map[y][x] += 1000 * 10 * (pow(30, 2) / (pow(30, 2) + distance_square));
			}
		}
		path_head = inlet[line_num];
		liquid_network[line_num/4][inlet[line_num].second][inlet[line_num].first] = 4;
		while(path_head != outlet[line_num]){
			//pout(path_head);
			//cout <<endl;
			//getchar();
			if(Is_close_center(path_head, centers[line_num%4]) && reverse == 0){
				for( int x=0;x<101;x++ ){
					for( int y=0;y<101;y++ ){
						if(liquid_network[line_num/4][y][x] == 4){
							liquid_network[line_num/4][y][x] = 1;
						}
					}
				}
				reverse = 1;
			}
			if(reverse){
				choose_dir(path_head, line_num/4, &temp_heat_map);
				liquid_network[line_num/4][path_head.second][path_head.first] = 4;
			}
			else{
				choose_dir(path_head, line_num/4, &init_heat_network[line_num%4]);
				liquid_network[line_num/4][path_head.second][path_head.first] = 4;
			}
		}
		
		for( int x=0;x<101;x++ ){
			for( int y=0;y<101;y++ ){
				if(liquid_network[line_num/4][y][x] == 4){
					liquid_network[line_num/4][y][x] = 1;
				}
			}
		}
		//cout << "line done !" << endl;
		//print_liquid_network();
		
		//getchar();
	}
	for( int i=0;i<channel_layer*4;i++ ){
		liquid_network[i/4][inlet[i].second][inlet[i].first] = 2;
		liquid_network[i/4][outlet[i].second][outlet[i].first] = 3;
	}
	for( int l=0;l<channel_layer;l++ ){
		for( int x=0;x<101;x++ ){
			for( int y=0;y<101;y++ ){
				if(liquid_network[l][y][x] == 7){
					liquid_network[l][y][x] = 0;
				}
			}
		}
	}
	
	print_liquid_network();
	//getchar();
	return true;
}