File: isotropic_adaptation.py

package info (click to toggle)
petsc4py 3.23.1-1exp2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,448 kB
  • sloc: python: 12,503; ansic: 1,697; makefile: 343; f90: 313; sh: 14
file content (32 lines) | stat: -rw-r--r-- 943 bytes parent folder | download | duplicates (3)
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
import sys,petsc4py
petsc4py.init(sys.argv)
from petsc4py import PETSc
import numpy as np

OptDB = PETSc.Options()

dim = OptDB.getInt('dim', 2)
plex = PETSc.DMPlex().createBoxMesh([4]*dim, simplex=True)
plex.distribute()
plex.view()

# Create two metric tensor fields corresponding to uniform mesh sizes of 0.1 and 0.2
metric1 = plex.metricCreateUniform(100.0)
metric2 = plex.metricCreateUniform(25.0)

# The metrics can be combined using intersection, the result of which corresponds to
# the maximum ellipsoid at each point
metric = plex.metricCreate()
plex.metricIntersection2(metric1, metric2, metric)
metric1.axpy(-1, metric)
assert np.isclose(metric1.norm(), 0.0)

# Call adapt routine - boundary label None by default
newplex = plex.adaptMetric(metric)
newplex.view()

# Write to VTK file
viewer = PETSc.Viewer().createVTK('base_mesh.vtk', 'w')
viewer(plex)
viewer = PETSc.Viewer().createVTK('isotropic_mesh.vtk', 'w')
viewer(newplex)