cpd_2022_energy/lib/models/EnergyBilanceModel.dart

58 lines
1.6 KiB
Dart

import 'dart:math';
import 'package:flutter/material.dart';
class EnergyBilanceModel extends ChangeNotifier {
double _startVelocity = 0;
double _endVelocity = 0;
double _startHeight = 0;
double _endHeight = 0;
double _weight = 0;
final double _gravity = 9.81; //in m/s^2
final double _waterHeatCapacity = 4.181; //J / (g * C°)
final double _ironHeatCapacity = 0.439; //in J / (g * C°)
double _waterTemparatureStart = 20; //in °C
final int _temparatureToBoilWater = 100; //in °C
double _ironTemparatureStart = 20; //in °C
final int _temparatureToMakeIronGlow = 700; //in °C
double get deltaVelocity => _endVelocity - _startVelocity;
double get deltaHeight => _endHeight - _startHeight;
double get potentialEnergy => _weight * _gravity * deltaHeight; //in Joule = m^2 kg/s^2
double get kineticEnergy => _weight * pow(deltaVelocity, 2) / 2;
double get amountOfBoilingWaterInL => (((potentialEnergy + kineticEnergy) / _waterHeatCapacity) / (_temparatureToBoilWater - _waterTemparatureStart)) / 1000; //in litre
double get amountOfGlowingIronInKg => (((potentialEnergy + kineticEnergy) / _ironHeatCapacity) / (_temparatureToMakeIronGlow - _ironTemparatureStart)) / 1000;
void setStartVelocity(double v){
_startVelocity = v;
notifyListeners();
}
void setEndVelocity(double v){
_endVelocity = v;
notifyListeners();
}
void setStartHeight(double h){
_startHeight = h;
notifyListeners();
}
void setEndHeight(double h){
_endHeight = h;
notifyListeners();
}
void setWeight(double m){
_weight = m;
notifyListeners();
}
}