Add example inputs
This commit is contained in:
72
examples/fem/fem.mc
Normal file
72
examples/fem/fem.mc
Normal file
@@ -0,0 +1,72 @@
|
||||
int main()
|
||||
{
|
||||
float Vbat;
|
||||
float Vc;
|
||||
float dt;
|
||||
float R;
|
||||
float C;
|
||||
int iter;
|
||||
float t;
|
||||
float Ic;
|
||||
float dV;
|
||||
|
||||
print("Battery voltage: ");
|
||||
Vbat = read_float();
|
||||
|
||||
if (Vbat < 0.0) {
|
||||
print("Please plug the battery in the right way");
|
||||
print_nl();
|
||||
return;
|
||||
}
|
||||
|
||||
print("Resistor value: ");
|
||||
R = read_float();
|
||||
|
||||
print("Capictor value: ");
|
||||
C = read_float();
|
||||
|
||||
if (R < 0.0 || C < 0.0) {
|
||||
print("Part values must be positive");
|
||||
print_nl();
|
||||
return;
|
||||
}
|
||||
|
||||
print("Time step: ");
|
||||
dt = read_float();
|
||||
|
||||
print("Number of iterations: ");
|
||||
iter = read_int();
|
||||
|
||||
if (dt < 0.0 && iter < 0) {
|
||||
dt = -dt;
|
||||
iter = -iter;
|
||||
print("IC what you did there");
|
||||
print_nl();
|
||||
}
|
||||
|
||||
if (dt < 0.0 || iter < 0) {
|
||||
print("Cowardly refusing to go backwards in time");
|
||||
print_nl();
|
||||
return;
|
||||
}
|
||||
|
||||
Vc = 0.0;
|
||||
t = 0.0;
|
||||
|
||||
while (iter > 0) {
|
||||
print("Capacitor voltage after ");
|
||||
print_float(t);
|
||||
print("s: ");
|
||||
print_float(Vc);
|
||||
print_nl();
|
||||
|
||||
Ic = (Vbat - Vc) / R;
|
||||
dV = (Ic * dt) / C;
|
||||
|
||||
Vc = Vc + dV;
|
||||
t = t + dt;
|
||||
iter = iter - 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
5
examples/fem/fem.stdin.txt
Normal file
5
examples/fem/fem.stdin.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
12
|
||||
1000
|
||||
0.000001
|
||||
0.0001
|
||||
25
|
25
examples/fem/fem.stdout.txt
Normal file
25
examples/fem/fem.stdout.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
Battery voltage: Resistor value: Capictor value: Time step: Number of iterations: Capacitor voltage after 0.00s: 0.00
|
||||
Capacitor voltage after 0.00s: 1.20
|
||||
Capacitor voltage after 0.00s: 2.28
|
||||
Capacitor voltage after 0.00s: 3.25
|
||||
Capacitor voltage after 0.00s: 4.13
|
||||
Capacitor voltage after 0.00s: 4.91
|
||||
Capacitor voltage after 0.00s: 5.62
|
||||
Capacitor voltage after 0.00s: 6.26
|
||||
Capacitor voltage after 0.00s: 6.83
|
||||
Capacitor voltage after 0.00s: 7.35
|
||||
Capacitor voltage after 0.00s: 7.82
|
||||
Capacitor voltage after 0.00s: 8.23
|
||||
Capacitor voltage after 0.00s: 8.61
|
||||
Capacitor voltage after 0.00s: 8.95
|
||||
Capacitor voltage after 0.00s: 9.25
|
||||
Capacitor voltage after 0.00s: 9.53
|
||||
Capacitor voltage after 0.00s: 9.78
|
||||
Capacitor voltage after 0.00s: 10.00
|
||||
Capacitor voltage after 0.00s: 10.20
|
||||
Capacitor voltage after 0.00s: 10.38
|
||||
Capacitor voltage after 0.00s: 10.54
|
||||
Capacitor voltage after 0.00s: 10.69
|
||||
Capacitor voltage after 0.00s: 10.82
|
||||
Capacitor voltage after 0.00s: 10.94
|
||||
Capacitor voltage after 0.00s: 11.04
|
Reference in New Issue
Block a user