@@ -20,7 +20,7 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
20
20
# define the Nutils mesh
21
21
domain , geom = mesh .rectilinear ([x_grid , y_grid ])
22
22
coupling_boundary = domain .boundary ['right' if side == 'Dirichlet' else 'left' ]
23
- coupling_sample = coupling_boundary .sample ('gauss' , degree = degree * 2 )
23
+ read_sample = coupling_boundary .sample ('gauss' , degree = degree * 2 )
24
24
25
25
# Nutils namespace
26
26
ns = function .Namespace ()
@@ -33,7 +33,7 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
33
33
ns .flux = 'basis_n ?fluxdofs_n' # heat flux
34
34
ns .f = 'beta - 2 - 2 alpha' # rhs
35
35
ns .uexact = '1 + x_0 x_0 + alpha x_1 x_1 + beta ?t' # analytical solution
36
- ns .readbasis = coupling_sample .basis ()
36
+ ns .readbasis = read_sample .basis ()
37
37
ns .readfunc = 'readbasis_n ?readdata_n'
38
38
39
39
# define the weak form
@@ -45,18 +45,27 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
45
45
else 'top,bottom,right' ].integral ('(u - uexact)^2 d:x' @ ns , degree = degree * 2 )
46
46
47
47
if side == 'Dirichlet' :
48
- sqr += coupling_sample .integral ('(u - readfunc)^2 d:x' @ ns )
48
+ sqr += read_sample .integral ('(u - readfunc)^2 d:x' @ ns )
49
49
else :
50
- res += coupling_sample .integral ('basis_n readfunc d:x' @ ns )
50
+ res += read_sample .integral ('basis_n readfunc d:x' @ ns )
51
51
52
52
# preCICE setup
53
53
interface = precice .Interface (side , "../precice-config.xml" , 0 , 1 )
54
- mesh_id = interface .get_mesh_id (side + "-Mesh" )
55
- vertex_ids = interface .set_mesh_vertices (mesh_id , coupling_sample .eval (ns .x ))
54
+
55
+ mesh_id_read = interface .get_mesh_id ("Dirichlet-Mesh" if side == "Dirichlet" else "Neumann-Mesh" )
56
+ mesh_id_write = interface .get_mesh_id ("Neumann-Mesh" if side == "Dirichlet" else "Dirichlet-Mesh" )
57
+
58
+ vertex_ids_read = interface .set_mesh_vertices (mesh_id_read , read_sample .eval (ns .x ))
59
+ interface .set_mesh_access_region (mesh_id_write , [.9 , 1.1 , - .1 , 1.1 ])
60
+
61
+ precice_dt = interface .initialize ()
62
+
63
+ vertex_ids_write , coords = interface .get_mesh_vertices_and_ids (mesh_id_write )
64
+ write_sample = domain .locate (ns .x , coords , eps = 1e-10 )
56
65
precice_write = functools .partial (interface .write_block_scalar_data ,
57
- interface .get_data_id ("Temperature " if side == "Neumann " else "Heat-Flux " , mesh_id ), vertex_ids )
66
+ interface .get_data_id ("Heat-Flux " if side == "Dirichlet " else "Temperature " , mesh_id_write ), vertex_ids_write )
58
67
precice_read = functools .partial (interface .read_block_scalar_data ,
59
- interface .get_data_id ("Heat-Flux " if side == "Neumann " else "Temperature " , mesh_id ), vertex_ids )
68
+ interface .get_data_id ("Temperature " if side == "Dirichlet " else "Heat-Flux " , mesh_id_read ), vertex_ids_read )
60
69
61
70
# helper functions to project heat flux to coupling boundary
62
71
if side == 'Dirichlet' :
@@ -76,13 +85,11 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
76
85
fluxsqr = domain .boundary ['right' ].boundary ['top,bottom' ].integral ('(flux - uexact_,0)^2 d:x' @ ns , degree = degree * 2 )
77
86
fluxcons = solver .optimize ('fluxdofs' , fluxsqr , droptol = 1e-10 , constrain = np .choose (np .isnan (rightcons ), [np .nan , 0. ]))
78
87
# fluxcons is NaN in dofs that are supported on ONLY the right boundary
79
- fluxres = coupling_sample .integral ('basis_n flux d:x' @ ns ) - res
80
-
81
- precice_dt = interface .initialize ()
88
+ fluxres = read_sample .integral ('basis_n flux d:x' @ ns ) - res
82
89
83
90
# write initial data
84
91
if interface .is_action_required (precice .action_write_initial_data ()):
85
- precice_write (coupling_sample .eval (0. ))
92
+ precice_write (write_sample .eval (0. ))
86
93
interface .mark_action_fulfilled (precice .action_write_initial_data ())
87
94
88
95
interface .initialize_data ()
@@ -130,9 +137,9 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
130
137
if interface .is_write_data_required (dt ):
131
138
if side == 'Dirichlet' :
132
139
fluxdofs = solver .solve_linear ('fluxdofs' , fluxres , arguments = dict (lhs0 = lhs0 , lhs = lhs , dt = dt , t = t ), constrain = fluxcons )
133
- write_data = coupling_sample .eval ('flux' @ ns , fluxdofs = fluxdofs )
140
+ write_data = write_sample .eval ('flux' @ ns , fluxdofs = fluxdofs )
134
141
else :
135
- write_data = coupling_sample .eval ('u' @ ns , lhs = lhs )
142
+ write_data = write_sample .eval ('u' @ ns , lhs = lhs )
136
143
precice_write (write_data )
137
144
138
145
# do the coupling
0 commit comments