@@ -39,12 +39,14 @@ class bd(Enum):
3939batmesh .dm .view ()
4040
4141# %%
42- Rayleigh_number = uw .function .expression (r"\textrm{Ra}" , sympy .sympify (10 ) ** 6 , "Rayleigh number" )
42+ Rayleigh_number = uw .function .expression (r"\textrm{Ra}" , sympy .sympify (10000000 ) , "Rayleigh number" )
4343
4444# %%
45- v_soln = uw .discretisation .MeshVariable ("U" , batmesh , batmesh .dim , degree = 2 , continuous = True )
46- p_soln = uw .discretisation .MeshVariable ("P" , batmesh , 1 , degree = 1 , continuous = True )
47- t_soln = uw .discretisation .MeshVariable ("T" , batmesh , 1 , degree = 2 )
45+ v_soln = uw .discretisation .MeshVariable ("U" , batmesh , batmesh .dim , degree = 2 , continuous = True )
46+ v_soln1 = uw .discretisation .MeshVariable ("U1" , batmesh , batmesh .dim , degree = 2 , continuous = True )
47+ p_soln = uw .discretisation .MeshVariable ("P" , batmesh , 1 , degree = 1 , continuous = True )
48+ t_soln = uw .discretisation .MeshVariable ("T" , batmesh , 1 , degree = 2 , varsymbol = r"T_0" )
49+ t_soln1 = uw .discretisation .MeshVariable ("T1" , batmesh , 1 , degree = 2 , varsymbol = r"T_1" )
4850cell_properties = uw .discretisation .MeshVariable ("Bat" , batmesh , 1 , degree = 0 )
4951
5052
@@ -68,18 +70,24 @@ class bd(Enum):
6870
6971stokes .constitutive_model = uw .constitutive_models .ViscousFlowModel
7072stokes .constitutive_model .Parameters .shear_viscosity_0 = 1
71- stokes .tolerance = 1.0e-3
73+ stokes .tolerance = 1.0e-5
7274
7375unit_r_vec = batmesh .CoordinateSystem .unit_e_0
76+ unit_y_vec = batmesh .CoordinateSystem .unit_j
7477
7578# free slip.
7679# note with petsc we always need to provide a vector of correct cardinality.
7780
78- stokes .add_natural_bc ( 10000 * unit_r_vec . dot ( v_soln . sym ) * unit_r_vec , "Upper" )
79- stokes .bodyforce = Rayleigh_number * unit_r_vec * t_soln . sym [ 0 ]
81+ stokes .add_essential_bc ([ 0 , 0 ] , "Upper" )
82+ # stokes.add_natural_bc(1e6 * Rayleigh_number * unit_r_vec.dot(v_soln.sym) * unit_r_vec, "Upper")
8083
81- # Make the bat stagnant
82- # stokes.bodyforce -= 10000 * (1-cell_properties.sym[0]) * v_soln.sym
84+ stokes .bodyforce = Rayleigh_number * unit_y_vec * t_soln .sym [0 ] + \
85+ Rayleigh_number * unit_y_vec * t_soln1 .sym [0 ]
86+
87+
88+ stokes .petsc_options .setValue ("ksp_monitor" , None )
89+ stokes .petsc_options .setValue ("snes_monitor" , None )
90+ stokes .petsc_options .setValue ("snes_min_it" , 1 )
8391
8492stokes .view ()
8593
@@ -92,48 +100,65 @@ class bd(Enum):
92100
93101adv_diff .constitutive_model = uw .constitutive_models .DiffusionModel
94102adv_diff .constitutive_model .Parameters .diffusivity = 1
95- adv_diff .f = 10 * (1 - cell_properties .sym [0 ])
96-
97103adv_diff .add_dirichlet_bc (0.0 , "Upper" )
98104
105+
106+ adv_diff1 = uw .systems .AdvDiffusionSLCN (
107+ batmesh ,
108+ u_Field = t_soln1 ,
109+ V_fn = v_soln1 ,
110+ )
111+
112+ adv_diff1 .constitutive_model = uw .constitutive_models .DiffusionModel
113+ adv_diff1 .constitutive_model .Parameters .diffusivity = 1
114+ adv_diff1 .add_dirichlet_bc (0.0 , "Upper" )
115+
99116t_init = 1 - cell_properties .sym [0 ]
100117
101- with batmesh .access (t_soln ):
118+ with batmesh .access (t_soln , t_soln1 ):
102119 t_soln .data [:,0 ] = uw .function .evalf (t_init , t_soln .coords )
120+ t_soln1 .data [:,0 ] = uw .function .evalf (t_init , t_soln1 .coords )
103121
104122
105- # %%
106- stokes .solve (zero_init_guess = True )
107123
108124# %%
109- v_soln .view ()
125+ stokes .solve (zero_init_guess = True , picard = 0 , verbose = False )
126+ with batmesh .access (v_soln1 ):
127+ v_soln1 .data [...] = - v_soln .data [...]
110128
111129# %%
130+
112131t_step = 0
113132
114133# %%
115134
116- for step in range (0 , 50 ):
135+ for step in range (0 , 250 ):
117136 stokes .solve (zero_init_guess = False )
118- delta_t = 2.0 * stokes .estimate_dt ()
119- adv_diff .solve (timestep = delta_t , zero_init_guess = False )
137+ with batmesh .access (v_soln1 ):
138+ v_soln1 .data [...] = - v_soln .data [...]
139+
140+
141+ delta_t = 5.0 * stokes .estimate_dt ()
142+ adv_diff .solve (timestep = delta_t , zero_init_guess = True )
143+ adv_diff1 .solve (timestep = delta_t , zero_init_guess = True )
120144
121145 # stats then loop
122146 tstats = t_soln .stats ()
123147
124148 if uw .mpi .rank == 0 :
125149 print ("Timestep {}, dt {}" .format (step , delta_t ))
126150
127- batmesh .write_timestep (
128- "Batmesh" ,
129- meshUpdates = True ,
130- meshVars = [p_soln , v_soln , t_soln ],
131- outputPath = "output" ,
132- index = t_step ,
133- )
151+ if t_step % 1 == 0 :
152+ batmesh .write_timestep (
153+ "Batmesh" ,
154+ meshUpdates = True ,
155+ meshVars = [p_soln , v_soln , t_soln , t_soln1 ],
156+ outputPath = "output" ,
157+ index = t_step ,
158+ )
134159
135- with batmesh .access (t_soln ):
136- t_soln .data [:,0 ] = np .maximum (t_soln .data [:,0 ], uw .function .evalf (t_init , t_soln .coords ))
160+ # with batmesh.access(t_soln):
161+ # t_soln.data[:,0] = np.maximum(t_soln.data[:,0], uw.function.evalf(t_init, t_soln.coords))
137162
138163 t_step += 1
139164
@@ -146,69 +171,133 @@ class bd(Enum):
146171
147172 pvmesh = vis .mesh_to_pv_mesh (batmesh )
148173 pvmesh .point_data ["T" ] = vis .scalar_fn_to_pv_points (pvmesh , t_soln .sym [0 ])
174+ pvmesh .point_data ["R" ] = vis .scalar_fn_to_pv_points (pvmesh , batmesh .CoordinateSystem .R [0 ])
175+ pvmesh .point_data ["T1" ] = vis .scalar_fn_to_pv_points (pvmesh , t_soln1 .sym [0 ])
149176 pvmesh .point_data ["V" ] = vis .vector_fn_to_pv_points (pvmesh , v_soln .sym )
150177 pvmesh .point_data ["L" ] = vis .scalar_fn_to_pv_points (pvmesh , cell_properties .sym [0 ])
151178
179+ pvmesh_t = vis .meshVariable_to_pv_mesh_object (t_soln )
180+ pvmesh_t .point_data ["T" ] = vis .scalar_fn_to_pv_points (pvmesh_t , t_soln .sym [0 ])
181+ pvmesh_t .point_data ["T1" ] = vis .scalar_fn_to_pv_points (pvmesh_t , t_soln1 .sym [0 ])
182+
183+ pvmesh_t .point_data ["To" ] = (pvmesh_t .point_data ["T" ] > 0.25 ).astype (float )
184+ pvmesh_t .point_data ["T1o" ] = (pvmesh_t .point_data ["T1" ] > 0.25 ).astype (float )
185+ pvmesh_t .point_data ["TD" ] = pvmesh_t .point_data ["T" ] - pvmesh_t .point_data ["T1" ]
186+
187+
152188 pl = pv .Plotter (window_size = (750 , 750 ))
189+ pl .enable_depth_peeling ()
153190
191+ doughnut = pvmesh .clip_scalar (scalars = "R" ,
192+ value = 0.3 ,
193+ invert = False )
194+
154195 pvstream = pvmesh .streamlines_from_source (
155- pvmesh . cell_centers (),
196+ pv . PointSet ( doughnut . cell_centers (). points [:: 5 ] ),
156197 vectors = "V" ,
157198 integrator_type = 45 ,
158199 surface_streamlines = True ,
159200 max_steps = 1000 ,
160201 max_time = 0.25 ,
161202 )
162203
204+
205+ # pl.add_mesh(pvmesh,
206+ # style="wireframe",
207+ # color="#FEFEF0",
208+ # opacity=0.1)
209+
210+ pl .add_mesh (pvstream ,
211+ cmap = ["orange" , "white" , "green" ],
212+ show_scalar_bar = False ,
213+ opacity = 0.1
214+ )
215+
216+
163217 pl .add_mesh (
164- pvmesh ,
218+ pvmesh_t ,
165219 cmap = "Oranges" ,
166220 scalars = "T" ,
221+ opacity = "sigmoid" ,
167222 edge_color = "Grey" ,
168223 show_edges = False ,
169224 use_transparency = False ,
170- opacity = 1.0 ,
171- show_scalar_bar = True ,
172- clim = [0 ,1 ]
225+ show_scalar_bar = False ,
173226 )
174227
175228 pl .add_mesh (
176- pvmesh ,
177- scalars = "L" ,
178- cmap = "Greys_r" ,
179- edge_color = "Black" ,
180- opacity = "L" ,
229+ pvmesh_t ,
230+ copy_mesh = True ,
231+ cmap = "Blues" ,
232+ scalars = "T1" ,
233+ opacity = "sigmoid" ,
234+ edge_color = "Grey" ,
181235 show_edges = False ,
182- use_transparency = True ,
236+ use_transparency = False ,
183237 show_scalar_bar = False ,
184-
238+ # clim=[0,2]
185239 )
186-
187- # pl.add_mesh(pvstream, cmap="jet", show_scalar_bar=False)
240+
188241
189242
243+ # pl.add_mesh(
244+ # pvmesh,
245+ # scalars="L",
246+ # cmap="Greys_r",
247+ # edge_color="Black",
248+ # opacity="L",
249+ # show_edges=False,
250+ # use_transparency=True,
251+ # show_scalar_bar=False,
252+ # )
253+
190254
191255 # pl.add_arrows(pvmesh.points, pvmesh.point_data["V"],
192- # mag=float(20.0 /Rayleigh_number.sym),
256+ # mag=float(0.2 /Rayleigh_number.sym),
193257 # show_scalar_bar=False)
194258
195259
196260 pl .show (jupyter_backend = 'html' )
197261
262+ # %%
263+ 0 / 0
264+
265+ # %%
266+
198267# %%
199268## Check the results saved to file
200269
201270expt_name = "Batmesh"
202271output_path = "output"
203- step = 20
272+ step = 50
204273
205274v_soln .read_timestep (expt_name , "U" , step , outputPath = output_path )
206275p_soln .read_timestep (expt_name , "P" , step , outputPath = output_path )
207276t_soln .read_timestep (expt_name , "T" , step , outputPath = output_path )
277+ t_soln1 .read_timestep (expt_name , "T1" , step , outputPath = output_path )
278+
208279
209280
281+ # %%
282+ t_soln .stats ()
283+
284+ # %%
285+ t_soln1 .stats ()
210286
211287# %%
212288adv_diff
213289
214290# %%
291+ adv_diff1
292+
293+ # %%
294+ adv_diff1 .DuDt .bdf (1 )
295+
296+ # %%
297+ adv_diff .DuDt .bdf (1 )
298+
299+ # %%
300+ batmesh .dm .view ()
301+
302+ # %% [markdown]
303+ # #
0 commit comments