Píxel a nodo
Tiene dos utilidades: crea un archivo .sol sobre tu malla, mediante una plantilla que también podrás generar en esta herramienta.
Plantilla y archivo .sol
La plantilla aparecerá aquí.
- Malla
- Huecos y exterior
- Borde de la malla
- Vértices
- Triángulos
- Tamaño (píxeles)
- Un píxel mide
- Malla (blanco)
- Tiempo
- Vértices
- Triángulos
- Valor mínimo
- Valor máximo
- Vértices sin dato
- Tiempo
Usar el .sol
El .sol tiene un valor por vértice, en el mismo orden que la malla, en el formato de Medit: el que lee readsol de FreeFEM++. Sirve como condición inicial, coeficiente o dato de una simulación. Guárdalo junto a su malla: con otra malla los valores no corresponden, y readsol no revisa que la cantidad de valores coincida con la de vértices.
load "medit" // readsol
mesh Th = readmesh("malla.mesh");
fespace Vh(Th, P1);
Vh u0;
u0[] = readsol("campo.sol"); // un valor por vértice, en el orden de la malla
plot(u0, fill = true, value = true, wait = true);
import numpy as np
import matplotlib.pyplot as plt
def readMeditMesh(path):
tokens = open(path).read().split()
position = tokens.index("Vertices")
n = int(tokens[position + 1])
vertices = np.array(tokens[position + 2:position + 2 + 3*n], dtype=float).reshape(-1, 3)[:, :2]
position = tokens.index("Triangles")
m = int(tokens[position + 1])
triangles = np.array(tokens[position + 2:position + 2 + 4*m], dtype=np.int64).reshape(-1, 4)[:, :3] - 1
return np.ascontiguousarray(vertices), triangles
def readSol(path):
tokens = open(path).read().split()
position = tokens.index("SolAtVertices")
n = int(tokens[position + 1]) # luego "1 1": una solución, escalar
return np.array(tokens[position + 4:position + 4 + n], dtype=float)
vertices, triangles = readMeditMesh("malla.mesh")
values = readSol("campo.sol")
plt.tripcolor(vertices[:, 0], vertices[:, 1], triangles, values, shading="gouraud")
plt.gca().set_aspect("equal")
plt.colorbar()
plt.show()
import numpy as np
import ufl
import basix.ufl
from mpi4py import MPI
from dolfinx import fem, mesh
# readMeditMesh y readSol: los de la pestaña Python
vertices, triangles = readMeditMesh("malla.mesh")
values = readSol("campo.sol")
element = ufl.Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2,)))
Th = mesh.create_mesh(MPI.COMM_SELF, triangles, element, vertices) # dolfinx 0.10 y 0.11
Vh = fem.functionspace(Th, ("Lagrange", 1))
# dolfinx renumera los vértices: vertexOfDof[i] es el vértice de la malla del grado de libertad i
vertexOfDof = np.empty(Vh.dofmap.index_map.size_local, dtype=np.int64)
vertexOfDof[Vh.dofmap.list.ravel()] = np.asarray(Th.geometry.input_global_indices)[Th.geometry.dofmaps[0].ravel()]
u0 = fem.Function(Vh)
u0.x.array[:] = values[vertexOfDof]