6 numberOfUnknownsToCopy,
9 @coupling: This function can be used to copy values and transform them while doing so. Particularly nice for momenta and the like.
12 The solver to copy values from.
15 The solver to copy values to.
17 indexArrayDestination:
18 Array of indices of length numberOfUnknownsToCopy providing a local index to copy source to. Source value depends on function.
21 A function applied to source values before copying. Unknown to copy is given by "unknown" and source cell base index by "sourceIndexLinearised".
23 numberOfUnknownsToCopy:
24 Number of unknowns to copy in loop for each cell in patch.
26 assert solverSource.patch_size == solverDestination.patch_size
27 patch_size = solverSource.patch_size
28 numberOfVariablesSource = solverSource.unknowns + solverSource.auxiliary_variables
29 numberOfVariablesDestination = (
30 solverDestination.unknowns + solverDestination.auxiliary_variables
33 // this is copied and adapted from toolbox::blockstructured::copyUnknown()
35 for (int x=0; x<{patch_size}; x++)
36 for (int y=0; y<{patch_size}; y++)
37 for (int unknown = 0; unknown < {numberOfUnknownsToCopy}; ++unknown) {{
38 const int sourceIndexLinearised = (x + y * {patch_size} ) * {numberOfVariablesSource};
39 const int destIndexLinearised = (x + y * {patch_size} ) * {numberOfVariablesDestination} + {indexArrayDestination}[unknown];
40 // apply any function to source value
41 const auto sourceValue = {function};
42 fineGridCell{solverDestination.name}Q.data()[destIndexLinearised] = sourceValue;
45 for (int x=0; x<{solverSource.patch_size}; x++)
46 for (int y=0; y<{solverSource.patch_size}; y++)
47 for (int z=0; z<{solverSource.patch_size}; z++)
48 for (int unknown = 0; unknown < {numberOfUnknownsToCopy}; ++unknown) {{
49 const int sourceIndexLinearised = (x + y * {patch_size} + z * {patch_size} * {patch_size}) * {numberOfVariablesSource};
50 const int destIndexLinearised = (x + y * {patch_size} + z * {patch_size} * {patch_size}) * {numberOfVariablesDestination} + {indexArrayDestination}[unknown];
51 // apply any function to source value
52 const auto sourceValue = {function}
53 fineGridCell{solverDestination.name}Q.data()[destIndexLinearised] = sourceValue;
56 #error DIMENSIONS not supported
62 couple_chemical_solver =
False
63 couple_diffusion_solver =
False
64 if atmospheric_solver
is not None:
66 couple_chemical_solver = chemical_solver
is not None
67 couple_diffusion_solver = diffusion_solver
is not None
69 return couple_diffusion_solver, couple_chemical_solver
72def setLastSolver(atmospheric_solver, diffusion_solver, chemical_solver):
74 atmospheric_solver=atmospheric_solver,
75 diffusion_solver=diffusion_solver,
76 chemical_solver=chemical_solver,
79 if couple_chemical_solver:
81 atmospheric_solver.last_solver = chemical_solver
82 if couple_diffusion_solver:
84 diffusion_solver.last_solver = chemical_solver
85 chemical_solver.last_solver = chemical_solver
87 elif couple_diffusion_solver:
89 atmospheric_solver.last_solver = diffusion_solver
90 diffusion_solver.last_solver = diffusion_solver
95 atmospheric_solver=atmospheric_solver,
96 diffusion_solver=diffusion_solver,
97 chemical_solver=chemical_solver,
100 atmospheric_solver
is not None
101 or couple_chemical_solver
102 or couple_diffusion_solver
104 dimensions = atmospheric_solver._dimensions
106 dimensions = chemical_solver._dimensions
108 if couple_chemical_solver
or couple_diffusion_solver:
110 atmospheric_solver.add_user_action_set_includes(
111 '#include "toolbox/blockstructured/Copy.h"\n'
113 numberOfVariablesAtmospheric = (
114 atmospheric_solver.auxiliary_variables + atmospheric_solver.unknowns
117 if couple_chemical_solver:
118 chemical_solver.add_user_action_set_includes(
119 '#include "toolbox/blockstructured/Copy.h"\n'
121 numberOfVariablesChemical = (
122 chemical_solver.auxiliary_variables + chemical_solver.unknowns
125 if not couple_diffusion_solver:
128 atmospheric_solver=atmospheric_solver,
129 chemical_solver=chemical_solver,
130 numberOfVariablesAtmospheric=numberOfVariablesAtmospheric,
131 numberOfVariablesChemical=numberOfVariablesChemical,
132 dimensions=dimensions,
137 atmospheric_solver=atmospheric_solver, chemical_solver=chemical_solver
140 if couple_diffusion_solver:
141 numberOfVariablesDiffusion = (
142 diffusion_solver.auxiliary_variables + diffusion_solver.unknowns
145 diffusion_solver.add_user_action_set_includes(
146 '#include "toolbox/blockstructured/Copy.h"\n'
151 atmospheric_solver=atmospheric_solver,
152 diffusion_solver=diffusion_solver,
153 dimensions=dimensions,
158 atmospheric_solver=atmospheric_solver,
159 diffusion_solver=diffusion_solver,
160 numberOfVariablesAtmospheric=numberOfVariablesAtmospheric,
161 numberOfVariablesDiffusion=numberOfVariablesDiffusion,
162 dimensions=dimensions,
165 if couple_chemical_solver:
168 diffusion_solver=diffusion_solver,
169 chemical_solver=chemical_solver,
170 numberOfVariablesDiffusion=numberOfVariablesDiffusion,
171 numberOfVariablesChemical=numberOfVariablesChemical,
172 dimensions=dimensions,
178 atmospheric_solver=atmospheric_solver,
179 diffusion_solver=diffusion_solver,
180 chemical_solver=chemical_solver,
183 if couple_diffusion_solver:
185 diffusion_solver._compute_time_step_size = (
187 const double timeStepSize = repositories::"""
188 + atmospheric_solver.get_name_of_global_instance()
189 +
""".getAdmissibleTimeStepSize();
193 if couple_chemical_solver:
196 chemical_solver._compute_time_step_size = (
198 const double timeStepSize = repositories::"""
199 + atmospheric_solver.get_name_of_global_instance()
200 +
""".getAdmissibleTimeStepSize();
208 numberOfVariablesAtmospheric,
209 numberOfVariablesChemical,
213 solverSource=atmospheric_solver,
214 solverDestination=chemical_solver,
215 indexArrayDestination=
"chemicalIndices",
216 function=f
"fineGridCell{atmospheric_solver.name}Q.data()[sourceIndexLinearised + atmosphericIndices[unknown]] / fineGridCell{atmospheric_solver.name}Q.data()[sourceIndexLinearised + densityIndex]",
217 numberOfUnknownsToCopy=dimensions,
220 atmospheric_solver.postprocess_updated_patch += f
"""// copy velocities to chemical solver
222 const int atmosphericIndices[DIMENSIONS] = {{
223 {atmospheric_solver.variable_names.index("rhou")},
224 {atmospheric_solver.variable_names.index("rhov")}{"," + str(atmospheric_solver.variable_names.index("rhow")) if dimensions == 3 else ""}
227 const int chemicalIndices[DIMENSIONS] = {{
228 {chemical_solver.variable_names.index("u")},
229 {chemical_solver.variable_names.index("v")}{"," + str(chemical_solver.variable_names.index("w")) if dimensions == 3 else ""}
232 const int densityIndex = {atmospheric_solver.variable_names.index("rho")};
237 atmospheric_solver.postprocess_updated_patch += f
"""// copy temperature
238 ::toolbox::blockstructured::copyUnknown(
239 {atmospheric_solver.patch_size}, // no of unknowns per dimension
240 fineGridCell{atmospheric_solver.name}Q.data(), // source
241 {atmospheric_solver.variable_names.index("T")}, // temperature in source
242 {numberOfVariablesAtmospheric}, // unknowns in source (incl material parameters)
243 0, // no overlap/halo here
244 fineGridCell{chemical_solver.name}Q.data(), // dest
245 {chemical_solver.variable_names.index("T")} , // temperature in dest
246 {numberOfVariablesChemical}, // unknowns in dest (incl material parameters)
247 0 // no overlap/halo here
255 solverSource=atmospheric_solver,
256 solverDestination=diffusion_solver,
257 indexArrayDestination=
"diffusionIndices",
258 function=f
"fineGridCell{atmospheric_solver.name}Q.data()[sourceIndexLinearised + atmosphericIndices[unknown]] / fineGridCell{atmospheric_solver.name}Q.data()[sourceIndexLinearised + densityIndex]",
259 numberOfUnknownsToCopy=dimensions,
262 atmospheric_solver.postprocess_updated_patch += f
"""// copy velocities to diffusion solver
264 const int atmosphericIndices[DIMENSIONS] = {{
265 {atmospheric_solver.variable_names.index("rhou")},
266 {atmospheric_solver.variable_names.index("rhov")}{"," + str(atmospheric_solver.variable_names.index("rhow")) if dimensions == 3 else ""}
269 const int diffusionIndices[DIMENSIONS] = {{
270 {diffusion_solver.variable_names.index("u")},
271 {diffusion_solver.variable_names.index("v")}{"," + str(diffusion_solver.variable_names.index("w")) if dimensions == 3 else ""}
274 const int densityIndex = {atmospheric_solver.variable_names.index("rho")};
282 solverSource=atmospheric_solver,
283 solverDestination=diffusion_solver,
284 indexArrayDestination=
"diffusionIndices",
285 function=f
"fineGridCell{atmospheric_solver.name}Q.data()[sourceIndexLinearised + atmosphericIndices[unknown]]",
286 numberOfUnknownsToCopy=dimensions,
289 atmospheric_solver.postprocess_updated_patch += f
"""// copy other unknowns to diffusion solver
291 const int atmosphericIndices[] = {{
292 {atmospheric_solver.variable_names.index("rho")},
293 {atmospheric_solver.variable_names.index("E")},
294 {atmospheric_solver.variable_names.index("O")},
295 {atmospheric_solver.variable_names.index("O2")},
296 {atmospheric_solver.variable_names.index("N2")},
297 {atmospheric_solver.variable_names.index("T")}
300 const int diffusionIndices[] = {{
301 {diffusion_solver.variable_names.index("rho")},
302 {diffusion_solver.variable_names.index("E")},
303 {diffusion_solver.variable_names.index("O")},
304 {diffusion_solver.variable_names.index("O2")},
305 {diffusion_solver.variable_names.index("N2")},
306 {diffusion_solver.variable_names.index("T")}
317 numberOfVariablesAtmospheric,
318 numberOfVariablesDiffusion,
323 solverSource=diffusion_solver,
324 solverDestination=atmospheric_solver,
325 indexArrayDestination=
"atmosphericIndices",
326 function=f
"fineGridCell{diffusion_solver.name}Q.data()[sourceIndexLinearised + diffusionIndices[unknown]] * fineGridCell{atmospheric_solver.name}Q.data()[destIndexLinearised - atmosphericIndices[unknown] + densityIndex]",
327 numberOfUnknownsToCopy=dimensions,
330 diffusion_solver.postprocess_updated_patch += f
"""// copy velocities to atmospheric solver
332 const int atmosphericIndices[DIMENSIONS] = {{
333 {atmospheric_solver.variable_names.index("rhou")},
334 {atmospheric_solver.variable_names.index("rhov")}{"," + str(atmospheric_solver.variable_names.index("rhow")) if dimensions == 3 else ""}
337 const int diffusionIndices[DIMENSIONS] = {{
338 {diffusion_solver.variable_names.index("u")},
339 {diffusion_solver.variable_names.index("v")}{"," + str(diffusion_solver.variable_names.index("w")) if dimensions == 3 else ""}
342 const int densityIndex = {atmospheric_solver.variable_names.index("rho")};
349 diffusion_solver.postprocess_updated_patch += f
"""// copy temperature
350 ::toolbox::blockstructured::copyUnknown(
351 {atmospheric_solver.patch_size}, // no of unknowns per dimension
352 fineGridCell{diffusion_solver.name}Q.data(), // source
353 {diffusion_solver.variable_names.index("T")}, // temperature in source
354 {numberOfVariablesDiffusion}, // unknowns in source (incl material parameters)
355 0, // no overlap/halo here
356 fineGridCell{atmospheric_solver.name}Q.data(), // dest
357 {atmospheric_solver.variable_names.index("T")} , // temperature in dest
358 {numberOfVariablesAtmospheric}, // unknowns in dest (incl material parameters)
359 0 // no overlap/halo here
364 diffusion_solver.postprocess_updated_patch += f
""" // copy new energy for atmosphere
365 ::toolbox::blockstructured::copyUnknown(
366 {atmospheric_solver.patch_size}, // no of unknowns per dimension
367 fineGridCell{diffusion_solver.name}Q.data(), // source
368 {diffusion_solver.variable_names.index("E")}, // temperature in source
369 {numberOfVariablesDiffusion}, // unknowns in source (incl material parameters)
370 0, // no overlap/halo here
371 fineGridCell{atmospheric_solver.name}Q.data(), // dest
372 {atmospheric_solver.variable_names.index("E")} , // temperature in dest
373 {numberOfVariablesAtmospheric}, // unknowns in dest (incl material parameters)
374 0 // no overlap/halo here
382 numberOfVariablesDiffusion,
383 numberOfVariablesChemical,
388 solverSource=diffusion_solver,
389 solverDestination=chemical_solver,
390 indexArrayDestination=
"chemicalIndicies",
391 function=f
"fineGridCell{chemical_solver.name}Q.data()[sourceIndexLinearised + diffusionIndicies[unknown]]",
392 numberOfUnknownsToCopy=dimensions,
395 diffusion_solver.postprocess_updated_patch += f
"""// copy velocities to chemical solver
397 const int chemicalIndices[DIMENSIONS] = {{
398 {chemical_solver.variable_names.index("u")},
399 {chemical_solver.variable_names.index("v")}{"," + str(chemical_solver.variable_names.index("w")) if dimensions == 3 else ""}
402 const int diffusionIndices[DIMENSIONS] = {{
403 {diffusion_solver.variable_names.index("u")},
404 {diffusion_solver.variable_names.index("v")}{"," + str(diffusion_solver.variable_names.index("w")) if dimensions == 3 else ""}
412 diffusion_solver.postprocess_updated_patch += f
"""// copy temperature
413 ::toolbox::blockstructured::copyUnknown(
414 {chemical_solver.patch_size}, // no of unknowns per dimension
415 fineGridCell{diffusion_solver.name}Q.data(), // source
416 {diffusion_solver.variable_names.index("T")}, // temperature in source
417 {numberOfVariablesDiffusion}, // unknowns in source (incl material parameters)
418 0, // no overlap/halo here
419 fineGridCell{chemical_solver.name}Q.data(), // dest
420 {chemical_solver.variable_names.index("T")} , // temperature in dest
421 {numberOfVariablesChemical}, // unknowns in dest (incl material parameters)
422 0 // no overlap/halo here
430 solverSource=chemical_solver,
431 solverDestination=atmospheric_solver,
432 indexArrayDestination=
"atmosphericIndices",
433 function=f
"fineGridCell{chemical_solver.name}Q.data()[sourceIndexLinearised + chemicalIndices[unknown]]",
434 numberOfUnknownsToCopy=3,
437 chemical_solver.postprocess_updated_patch += f
"""
438 // copy major species densities
440 const int chemicalIndices[3] = {{
441 {chemical_solver.variable_names.index("O")},
442 {chemical_solver.variable_names.index("O2")},
443 {chemical_solver.variable_names.index("N2")}
446 const int atmosphericIndices[3] = {{
447 {atmospheric_solver.variable_names.index("O")},
448 {atmospheric_solver.variable_names.index("O2")},
449 {atmospheric_solver.variable_names.index("N2")}
copyPatchAndApplyFunction(solverSource, solverDestination, indexArrayDestination, function, numberOfUnknownsToCopy)
@coupling: This function can be used to copy values and transform them while doing so.