import { useState } from 'react'; import { poissonApi } from '../../api'; const DEFAULT_PARAMS = { name: 'Simulation Poisson', domain_x_min: 0, domain_x_max: 2, domain_y_min: 0, domain_y_max: 1, mesh_nx: 64, mesh_ny: 32, source_type: 'gaussian', source_amplitude: 10, source_center_x: 0.5, source_center_y: 0.5, source_width: 0.02, source_frequency: 1, dirichlet_enabled: true, dirichlet_boundaries: 'left,right', dirichlet_value: 0, neumann_enabled: true, neumann_boundaries: 'top,bottom', neumann_type: 'sinusoidal', neumann_amplitude: 1, neumann_frequency: 5, }; export default function PoissonForm({ onPreviewMesh, onSimulationCreated, loading, setLoading }) { const [params, setParams] = useState(DEFAULT_PARAMS); const [activeSection, setActiveSection] = useState('domain'); const handleChange = (field, value) => { setParams(prev => ({ ...prev, [field]: value })); }; const handlePreview = async () => { setLoading(true); try { await onPreviewMesh(params); } catch (err) { console.error('Erreur preview:', err); } setLoading(false); }; const handleSubmit = async (e) => { e.preventDefault(); setLoading(true); try { const simulation = await poissonApi.createSimulation(params); onSimulationCreated(simulation); } catch (err) { console.error('Erreur création:', err); alert('Erreur: ' + err.message); } setLoading(false); }; const toggleBoundary = (field, boundary) => { const current = params[field].split(',').filter(b => b); const index = current.indexOf(boundary); if (index >= 0) { current.splice(index, 1); } else { current.push(boundary); } handleChange(field, current.join(',')); }; const isBoundarySelected = (field, boundary) => { return params[field].split(',').includes(boundary); }; return (

Paramètres de simulation

{/* Section Domaine */}
{activeSection === 'domain' && (
handleChange('name', e.target.value)} />
handleChange('domain_x_min', parseFloat(e.target.value))} />
handleChange('domain_x_max', parseFloat(e.target.value))} />
handleChange('domain_y_min', parseFloat(e.target.value))} />
handleChange('domain_y_max', parseFloat(e.target.value))} />
handleChange('mesh_nx', parseInt(e.target.value))} />
handleChange('mesh_ny', parseInt(e.target.value))} />
)}
{/* Section Source */}
{activeSection === 'source' && (
handleChange('source_amplitude', parseFloat(e.target.value))} />
{params.source_type === 'gaussian' && ( <>
handleChange('source_center_x', parseFloat(e.target.value))} />
handleChange('source_center_y', parseFloat(e.target.value))} />
handleChange('source_width', parseFloat(e.target.value))} />
)} {params.source_type === 'sinusoidal' && (
handleChange('source_frequency', parseFloat(e.target.value))} />
)}
)}
{/* Section Dirichlet */}
{activeSection === 'dirichlet' && (
{params.dirichlet_enabled && ( <>
{['left', 'right', 'top', 'bottom'].map(b => ( ))}
handleChange('dirichlet_value', parseFloat(e.target.value))} />
)}
)}
{/* Section Neumann */}
{activeSection === 'neumann' && (
{params.neumann_enabled && ( <>
{['left', 'right', 'top', 'bottom'].map(b => ( ))}
handleChange('neumann_amplitude', parseFloat(e.target.value))} />
{params.neumann_type === 'sinusoidal' && (
handleChange('neumann_frequency', parseFloat(e.target.value))} />
)} )}
)}
{/* Boutons d'action */}
); }