File size: 4,565 Bytes
0a7c6ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { useState } from 'react';
import { api } from '../api';

export default function SimulationForm({ onSimulationCreated }) {
    const [formData, setFormData] = useState({
        mesh_resolution: 32,
        diffusion_coefficient: 0.1,
        source_term: 1.0,
        time_final: 1.0,
        num_steps: 50
    });
    const [name, setName] = useState('');
    const [isSubmitting, setIsSubmitting] = useState(false);
    const [error, setError] = useState(null);

    const handleChange = (e) => {
        const { name, value } = e.target;
        setFormData(prev => ({
            ...prev,
            [name]: name === 'mesh_resolution' || name === 'num_steps' 
                ? parseInt(value) 
                : parseFloat(value)
        }));
    };

    const handleSubmit = async (e) => {
        e.preventDefault();
        setIsSubmitting(true);
        setError(null);

        try {
            const simulation = await api.createSimulation(name || 'Simulation sans nom', formData);
            onSimulationCreated(simulation);
            setName('');
        } catch (err) {
            setError('Erreur lors de la création de la simulation');
        } finally {
            setIsSubmitting(false);
        }
    };

    return (
        <div className="simulation-form">
            <h2>Nouvelle Simulation</h2>
            {error && <div className="error">{error}</div>}
            
            <form onSubmit={handleSubmit}>
                <div className="form-group">
                    <label>Nom de la simulation</label>
                    <input
                        type="text"
                        value={name}
                        onChange={(e) => setName(e.target.value)}
                        placeholder="Ma simulation"
                    />
                </div>
                
                <div className="form-group">
                    <label>Résolution du maillage: {formData.mesh_resolution}</label>
                    <input
                        type="range"
                        name="mesh_resolution"
                        min="8"
                        max="128"
                        step="8"
                        value={formData.mesh_resolution}
                        onChange={handleChange}
                    />
                </div>
                
                <div className="form-group">
                    <label>Coefficient de diffusion D: {formData.diffusion_coefficient}</label>
                    <input
                        type="range"
                        name="diffusion_coefficient"
                        min="0.01"
                        max="1.0"
                        step="0.01"
                        value={formData.diffusion_coefficient}
                        onChange={handleChange}
                    />
                </div>
                
                <div className="form-group">
                    <label>Terme source Q: {formData.source_term}</label>
                    <input
                        type="range"
                        name="source_term"
                        min="0.1"
                        max="5.0"
                        step="0.1"
                        value={formData.source_term}
                        onChange={handleChange}
                    />
                </div>
                
                <div className="form-group">
                    <label>Temps final: {formData.time_final}</label>
                    <input
                        type="range"
                        name="time_final"
                        min="0.1"
                        max="5.0"
                        step="0.1"
                        value={formData.time_final}
                        onChange={handleChange}
                    />
                </div>
                
                <div className="form-group">
                    <label>Nombre de pas de temps: {formData.num_steps}</label>
                    <input
                        type="range"
                        name="num_steps"
                        min="10"
                        max="200"
                        step="10"
                        value={formData.num_steps}
                        onChange={handleChange}
                    />
                </div>
                
                <button type="submit" disabled={isSubmitting}>
                    {isSubmitting ? 'Lancement...' : 'Lancer la simulation'}
                </button>
            </form>
        </div>
    );
}