Spaces:
Runtime error
Runtime error
| from fenics import * | |
| import pyvista as pv | |
| import numpy as np | |
| def run_fenics_simulation(): | |
| # Define mesh and function space | |
| mesh = UnitSquareMesh(10, 10) | |
| V = FunctionSpace(mesh, 'P', 1) | |
| # Define boundary condition | |
| u_D = Expression('x[0]*x[0] - x[1]*x[1]', degree=2) | |
| bc = DirichletBC(V, u_D, 'on_boundary') | |
| # Define variational problem | |
| u = TrialFunction(V) | |
| v = TestFunction(V) | |
| f = Constant(-6.0) | |
| a = inner(grad(u), grad(v)) * dx | |
| L = f * v * dx | |
| # Compute solution | |
| u = Function(V) | |
| solve(a == L, u, bc) | |
| # Visualize with PyVista | |
| u_array = np.array(u.vector()) | |
| grid = pv.StructuredGrid(mesh.coordinates()) | |
| grid.point_arrays['u'] = u_array | |
| plot = grid.plot(show_edges=True, title='FEniCS Simulation Result') | |
| return plot | |