PRAgMaTIc  master
play_multigrid.py
Go to the documentation of this file.
1 ### this a testcase for use with DOLFIN/FEniCS and PRAgMaTIc
2 ### by Gerard Gorman, Imperial College London
3 ### the purpose of the test case is to illustrate the use of the refine_metric function.
4 ### The idea is to use the functionality in a multigrid algorithm.
5 
6 from dolfin import *
7 from adaptivity import refine_metric, adapt, metric_pnorm, mesh_metric
8 set_log_level(WARNING)
9 
11  # from mpi4py import MPI
12  import sys
13 
14 # comm = MPI.COMM_WORLD
15 
16  # mesh = Mesh("greenland.xml.gz")
17  mesh = UnitSquareMesh(100, 100)
18 
19  V = FunctionSpace(mesh, "CG", 2)
20  f = interpolate(Expression("0.1*sin(50.*(2*x[0]-1)) + atan2(-0.1, (2.0*(2*x[0]-1) - sin(5.*(2*x[1]-1))))"), V)
21 
22  eta = 0.01
23  #Mp = metric_pnorm(f, mesh, eta, max_edge_ratio=5)
24  #mesh = adapt(Mp)
25 
26  if True:
27  level = 0.5
28  Mp = refine_metric(mesh_metric(mesh), level)
29  new_mesh1 = adapt(Mp)
30 
31  level *= 0.5
32  Mp = refine_metric(mesh_metric(mesh), level)
33  new_mesh2 = adapt(Mp)
34 
35  level *= 0.5
36  Mp = refine_metric(mesh_metric(mesh), level)
37  new_mesh3 = adapt(Mp)
38 
39  level *= 0.5
40  Mp = refine_metric(mesh_metric(mesh), level)
41  new_mesh4 = adapt(Mp)
42 
43  level *= 0.5
44  Mp = refine_metric(mesh_metric(mesh), level)
45  new_mesh5 = adapt(Mp)
46 
47  level *= 0.5
48  Mp = refine_metric(mesh_metric(mesh), level)
49  new_mesh6 = adapt(Mp)
50  else:
51  eta *= 2
52  Mp = metric_pnorm(f, mesh, eta, max_edge_ratio=5)
53  new_mesh1 = adapt(Mp)
54 
55  eta *= 2
56  Mp = metric_pnorm(f, mesh, eta, max_edge_ratio=5)
57  new_mesh2 = adapt(Mp)
58 
59  eta *= 2
60  Mp = metric_pnorm(f, mesh, eta, max_edge_ratio=5)
61  new_mesh3 = adapt(Mp)
62 
63  eta *= 2
64  Mp = metric_pnorm(f, mesh, eta, max_edge_ratio=5)
65  new_mesh4 = adapt(Mp)
66 
67  eta *= 2
68  Mp = metric_pnorm(f, mesh, eta, max_edge_ratio=5)
69  new_mesh5 = adapt(Mp)
70 
71  eta *= 2
72  Mp = metric_pnorm(f, mesh, eta, max_edge_ratio=5)
73  new_mesh6 = adapt(Mp)
74 
75  # plot(Mp[0,0])
76  # from IPython import embed
77  # embed()
78 
79  plot(mesh, title="initial mesh")
80  plot(new_mesh1, title="coarsen 1")
81  plot(new_mesh2, title="coarsen 2")
82  plot(new_mesh3, title="coarsen 3")
83  plot(new_mesh4, title="coarsen 4")
84  plot(new_mesh5, title="coarsen 5")
85  plot(new_mesh6, title="coarsen 6")
86 
87  interactive()
88 
89 if __name__=="__main__":
def refine_metric
Definition: adaptivity.py:86
def metric_pnorm
Definition: adaptivity.py:535
def mesh_metric
Definition: adaptivity.py:980