Beispiel #1
0
void Constants::parseFile(const char *filename) {
    std::ifstream file(filename);
    std::string str;
    while (std::getline(file, str))
    {
        std::vector<std::string> row;
        boost::split(row, str, boost::is_any_of(" "), boost::token_compress_on);
        for(int i=0; i< (int) row.size(); i++){
            double element = atof((row[i]).c_str());
            switch(i){
                case 0:{eps = element; continue;}
                case 1:{h = element; continue;}
                case 2:{alpha = element; continue;}
                case 3:{beta = element; continue;}
                case 4:{gamma = element; continue;}
                case 5:{t = element; continue;}
                case 6:{dx = element; continue;}
                case 7:{print = (int)element; continue;}
                case 8: {
                    golden = (int) element;
                    continue;
                }
                default: throw std::invalid_argument( "kriva ulazna datoteka");
            }
            break;
        }
        break;
    }
    printConstants();
}
int main(int argc, char *argv[]) {

	int NumCtrlVol = 5;
	if ( argc > 1 ) NumCtrlVol = atoi( argv[1] );

	std::cout << "The number of control volumes = " <<
			NumCtrlVol << std::endl;

	printConstants();


	// 1-dimensional grid with cetral differce scheme
	FVM::Grid1D< FVM::CentDiffSchemeTag > grid( NumCtrlVol, CylinderLength);

	grid.addDirichletBoundary(-1, 0, HotTemperature);
	grid.addNeumannBoundary( NumCtrlVol, NumCtrlVol - 1, 0.0);

	FVM::IdentityOperatorType const IdOpr = FVM::IdentityOperatorType();
	FVM::DifferentialOperatorType const DiffOpr =
								FVM::DifferentialOperatorType();

	// The operator part in the heat equation
    // which consists of a differential operator and identical one.
	auto opr = proto::deep_copy(
			ThermalConductivity * Area * DiffOpr * DiffOpr
			- ConvectiveHeatTransCoeff * Circumference * IdOpr );


	Matrix coeffMat( NumCtrlVol, NumCtrlVol);
	coeffMat = grid.discretizeOperator( opr );

	Vector rhsVec( NumCtrlVol);
	rhsVec = grid.discretizeFunction(
			- ConvectiveHeatTransCoeff * Circumference * AmbientTemperature );

	FVM::BoundaryCorrector bCorrector( grid, opr);
	bCorrector.applyTo( coeffMat);
	bCorrector.applyTo( rhsVec);


	const double scale = - ThermalConductivity * Area;
	std::cout << "scale = - ThermalConductivity * Area" <<
			std::endl;
	std::cout << "= " << scale << std::endl;

	printCoefficients( coeffMat, scale);
	printRHS( rhsVec, scale);


	SLA::DiagonalPreconditioner precond( coeffMat);
	SLA::ConjugateGradient< DLA::Matrix, SLA::DiagonalPreconditioner >
	                   							cg( coeffMat, precond);

	const Vector tempGuess( NumCtrlVol, (100.0 + 20.0) / 2.0);

	Vector temperature( NumCtrlVol);
	temperature = cg.solve(rhsVec, tempGuess, convergenceCriterion);

	printCalculatedAndExactTemperatureDistributions< Vector >(
														temperature);

	return 0;
}
Beispiel #3
0
void _pblaze_genInitStartup(FILE * of)
{
    printConstants(of);
}