コード例 #1
0
ファイル: CalibratorPhase.cpp プロジェクト: WFRT/gridpp
TEST_F(TestCalibratorPhase, missingParameters) {
    FileArome file("testing/files/10x10.nc");
    ParameterFile parFile = getParameterFile(Util::MV,1.5);
    CalibratorPhase cal = getCalibrator(&parFile);

    cal.calibrate(file);
    FieldPtr phase = file.getField(Variable::Phase, 0);
    for(int i = 0; i < file.getNumLat(); i++) {
        for(int j = 0; j < file.getNumLon(); j++) {
            for(int e = 0; e < file.getNumEns(); e++) {
                EXPECT_FLOAT_EQ(Util::MV, (*phase)(i,j,e));
            }
        }
    }
}
コード例 #2
0
ファイル: CalibratorPhase.cpp プロジェクト: WFRT/gridpp
TEST_F(TestCalibratorPhase, phases) {
    FileFake file(1,1,1,1);
    FieldPtr phase = file.getField(Variable::Phase, 0);
    ParameterFile parFile = getParameterFile(273.7,274.7);
    CalibratorPhase cal = getCalibrator(&parFile);
    setValues(file, 5, 270, 0.95, 101325);
    cal.calibrate(file);
    EXPECT_FLOAT_EQ(Variable::PhaseSnow, (*phase)(0,0,0));

    setValues(file, 5, 274, 0.98, 101325);
    cal.calibrate(file);
    EXPECT_FLOAT_EQ(Variable::PhaseSleet, (*phase)(0,0,0));

    setValues(file, 0, 274, 0.5, 101325);
    cal.calibrate(file);
    EXPECT_FLOAT_EQ(Variable::PhaseNone, (*phase)(0,0,0));

    setValues(file, 5, 275, 0.5, 101325);
    cal.calibrate(file);
    EXPECT_FLOAT_EQ(Variable::PhaseSnow, (*phase)(0,0,0));
}
コード例 #3
0
ファイル: CalibratorPhase.cpp プロジェクト: WFRT/gridpp
TEST_F(TestCalibratorPhase, useWetbulb) {
    FileFake file(1,1,1,1);
    FieldPtr phase = file.getField(Variable::Phase, 0);
    ParameterFile parFile = getParameterFile(273.7,274.7);
    CalibratorPhase cal = getCalibrator(&parFile);
    setValues(file, 5, 275, 0.5, 101325);

    cal.setUseWetbulb(false);
    cal.calibrate(file);
    EXPECT_FLOAT_EQ(Variable::PhaseRain, (*phase)(0,0,0));

    cal.setUseWetbulb(true);
    cal.calibrate(file);
    EXPECT_FLOAT_EQ(Variable::PhaseSnow, (*phase)(0,0,0));

    setValues(file, 5, 274, 0.5, 101325);
    cal.setUseWetbulb(false);
    cal.calibrate(file);
    EXPECT_FLOAT_EQ(Variable::PhaseSleet, (*phase)(0,0,0));
    cal.setUseWetbulb(true);
    cal.calibrate(file);
    EXPECT_FLOAT_EQ(Variable::PhaseSnow, (*phase)(0,0,0));
}
コード例 #4
0
//int _tmain(int argc, _TCHAR* argv[])
uint main(uint argc, cstr argv[])
{
	printf("Random number from 0 to 1 == %lf\n", LRandomFromTo(0., 1.));
	LString typeOfCalc;
	Calibrator *pC = getCalibrator();
	Voltmeter *pV = getVoltmeter(Voltmeter::REFERENCE);
	Voltmeter *pVver = getVoltmeter(Voltmeter::VERIFIED);
	double Umax = 0., U = 0., step = 0., E1 = 0., E2 = 0., k = 0.1;
	const double minThreshold = 0.0000001;
	uint F = 0, i = 0, j = 0, ccount = 0;
	//char *command[4] = {"Umax","U","F","Eref"};
	// Umax = 0 volt U = 0 volt F = 0 Hz Eref = 0.0 volt
	// Umax=0 - обязательны параметр нужен для того, чтобы мы не установили напряжение больше порога
	// если передается параметр Eref - то устанавливаем эдс, возвращаем U
	// елси не передается параметр Eref - то устанавливаем U и возвращаем эдс
	// for example fix(equ) U=10 F=1000 Umax=20 Eref=0.508185
	typeOfCalc = argv[1];
	if (typeOfCalc == "fix") { // установить напряжение
		arg[3].seen = true;
	}
	else if (typeOfCalc == "equ") { // подобрать напряжение
		arg[3].req = true;
	}
	else if(typeOfCalc == "res") { // сбросить напряжение на 0 закрыть выход
		arg[0].req = false;
		arg[1].req = false;
		arg[2].req = false;
	}
	else if(typeOfCalc == "ref") { // вернуть эдс эталона
		arg[0].req = false;
		arg[1].req = false;
		arg[2].req = false;
	}
	else if(typeOfCalc == "ver") { // вернуть эдс тестируемого преобразователя
		arg[0].req = false;
		arg[1].req = false;
		arg[2].req = false;
	}
	else {
		fprintf(stderr, "Wrong command: %s\n", argv[1]);
		exit(1);
	}
	for (i = 2; i < argc; i++) {
		bool good = false;
		for (j = 0; j < countof(arg); j++) {
			LString res = getValue(arg[j].key, argv[i]);
			if (res == " ") continue;
			good = true;
			if (arg[j].seen) {
				fprintf(stderr, "Duplicate or prohibited: %s\n", arg[j].key);
				exit(1);
			}
			switch (j) {
			case 0:  Umax = LParseDbl(res); break;
			case 1:  U = LParseDbl(res); break;
			case 2:  F = LParseInt(res); break;
			case 3:  E1 = LParseDbl(res); break;
			}
			printf("%d=%s\n", j, (cstr)res);
			arg[j].seen = true;
		}
		if (!good) {
			fprintf(stderr, "Unexpected: %s\n", argv[i]);
			exit(1);
		}
	}
	for (j = 0; j < countof(arg); j++) {
		if (arg[j].req) if (!arg[j].seen) {
			fprintf(stderr, "Required but not seen: %s\n", arg[j].key);
			exit(1);
		}
	}
	if (Umax <= 0. && typeOfCalc != "res" && typeOfCalc != "ver" && typeOfCalc != "ref") {
		fprintf(stderr, "Invalid Umax: %lf\n", Umax);
		exit(1);
	}
	if (typeOfCalc == "fix") if (fabs(U) < EPSILON) {
		fprintf(stderr, "Invalid U: %lf\n", Umax);
		exit(1);
	}
	printf("Umax=%lf U=%lf F=%d Eref=%lf\n", Umax, U, F, E1);
	pC->setBarrier(Umax);
	if (typeOfCalc == "fix") {
		pC->setOutput(0);
		pC->setVoltage(0);
		runUpExact(U, F, pC);
		E1 = pV->getVoltage();
		printf("set voltage -> %2f V | set frequency -> %d Hz | thermo EMF -> %1f\n", U, F, E1);
		fprintf(stderr, "Eref=%f", E1);
	}
	if (typeOfCalc == "equ") {
		E2 = pV->getVoltage();
		if (E1 < E2) {
			step = U*k;
		}
		else{
			step = U*(-k);
		}
		while (fabs(step) > minThreshold) {
			if (Umax <= U) {
				fprintf(stderr, "U is greater than Umax\n");
				exit(1);
			}
			runUpExact(U, F, pC);
			E2 = pV->getVoltage();
			printf("set voltage -> %2f V | set frequency -> %d Hz | thermo EMF -> %1f\n", U, F, E2);

			U += step; // этот способ нахождения оказался быстрее всех
			if (((E1 < E2) && (step > 0)) || ((E1 > E2) && (step < 0))) {
				step *= (-k);
			}
		}
		fprintf(stderr, "Eref=%1f", pV->getVoltage());
	}
	if (typeOfCalc == "res"){
		printf("reset\n");
		pC->setOutput(0);
		pC->setVoltage(0);
	}
	if (typeOfCalc == "ref"){
		printf("pV->getVoltage=%1f\n", pV->getVoltage());
		fprintf(stderr, "Eref=%1f", pV->getVoltage());
		
	}
	if (typeOfCalc == "ver"){
		printf("pVver->getVoltage=%1f\n", pVver->getVoltage());
		fprintf(stderr, "Ever=%1f", pVver->getVoltage());
	}
	return 0;
}