cpd_2022_energy/lib/provider/energy_model.dart

65 lines
1.8 KiB
Dart
Raw Permalink Normal View History

2023-02-05 21:46:05 +01:00
import 'package:flutter/material.dart';
class EnergyModel with ChangeNotifier {
2023-02-06 03:12:39 +01:00
final double weightForce = 9.81;
final double _waterStartTemp = 20.0;
final double _waterEndTemp = 100.0;
final double _waterHeatCapacity = 4.183;
final double _ironStartTemp = 20.0;
final double _ironEndTemp = 700.0;
final double _ironHeatCapacity = 0.444;
2023-02-05 21:46:05 +01:00
2023-02-06 03:12:39 +01:00
double heightStart = 0.0;
double heightEnd = 0.0;
double velocityStart = 0.0;
double velocityEnd = 0.0;
double weight = 0.0;
2023-02-05 21:46:05 +01:00
2023-02-06 03:12:39 +01:00
double totalEnergy = 0.0;
double boilingWaterAmount = 0.0;
double annealingIronAmount = 0.0;
2023-02-05 21:46:05 +01:00
2023-02-06 03:12:39 +01:00
double calcPotentialEnergy(m, g, h) {
return m * g * h;
2023-02-05 21:46:05 +01:00
}
2023-02-06 03:12:39 +01:00
double calcPotentialEnergyBetweenTwoPointsInJoule(
heightStart, heightEnd, weight) {
return calcPotentialEnergy(weight, weightForce, heightStart) -
calcPotentialEnergy(weight, weightForce, heightEnd);
}
double calcKineticEnergy(m, v) {
return (m * v * v) / 2.0;
}
double calcKineticEnergyBetweenTwoPointsInJoule(
velocityStart, velocityEnd, weight) {
return calcKineticEnergy(weight, velocityEnd) -
calcKineticEnergy(weight, velocityStart);
}
void calcBoilingWaterAmount() {
boilingWaterAmount = (totalEnergy /
(_waterHeatCapacity * (_waterEndTemp - _waterStartTemp)));
}
2023-02-05 21:46:05 +01:00
2023-02-06 03:12:39 +01:00
void calcIronAnnealingAmount() {
annealingIronAmount =
(totalEnergy / (_ironHeatCapacity * (_ironEndTemp - _ironStartTemp)));
2023-02-05 21:46:05 +01:00
}
2023-02-06 03:12:39 +01:00
void calcTotalEnergyInKiloJoule() {
totalEnergy = (calcKineticEnergyBetweenTwoPointsInJoule(velocityStart, velocityEnd, weight) +
calcPotentialEnergyBetweenTwoPointsInJoule(heightStart, heightEnd, weight))
/1000;
}
2023-02-05 21:46:05 +01:00
2023-02-06 03:12:39 +01:00
void calc() {
calcTotalEnergyInKiloJoule();
calcBoilingWaterAmount();
calcIronAnnealingAmount();
notifyListeners();
2023-02-05 21:46:05 +01:00
}
2023-02-06 03:12:39 +01:00
}