cpd_2022_energy/lib/provider/energy_model.dart

65 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
class EnergyModel with ChangeNotifier {
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;
double heightStart = 0.0;
double heightEnd = 0.0;
double velocityStart = 0.0;
double velocityEnd = 0.0;
double weight = 0.0;
double totalEnergy = 0.0;
double boilingWaterAmount = 0.0;
double annealingIronAmount = 0.0;
double calcPotentialEnergy(m, g, h) {
return m * g * h;
}
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)));
}
void calcIronAnnealingAmount() {
annealingIronAmount =
(totalEnergy / (_ironHeatCapacity * (_ironEndTemp - _ironStartTemp)));
}
void calcTotalEnergyInKiloJoule() {
totalEnergy = (calcKineticEnergyBetweenTwoPointsInJoule(velocityStart, velocityEnd, weight) +
calcPotentialEnergyBetweenTwoPointsInJoule(heightStart, heightEnd, weight))
/1000;
}
void calc() {
calcTotalEnergyInKiloJoule();
calcBoilingWaterAmount();
calcIronAnnealingAmount();
notifyListeners();
}
}