Peano
Loading...
Searching...
No Matches
AuxiliaryVariables.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from __future__ import annotations
4
5import enum
6import re
7from typing import Dict, List
8
12
13
15 """!
16
17 A set of auxiliary variables of a solver
18
19 Auxiliary variables are quantities such as the sea floor, a mesh
20 distortion or a density which live in every Finite Volume (or Finite
21 Difference point) next to the unknowns, but which are not evolved by the
22 PDE. A solver can have an arbitrary number of such sets, each of them
23 vector-valued, e.g. ten bathymetry entries and another five entries
24 describing a mesh distortion. Each set is held by its own cell data
25 object, i.e. its own patch, rather than by the patch of the unknowns.
26
27 Create a set with a name and a dictionary which maps the names of the
28 parameters onto their multiplicities,
29
30 bathymetry = exahype2.api.AuxiliaryVariables("Bathymetry", {"b": 1})
31
32 and attach it to a solver via exahype2.api.Solver.add_auxiliary_variables().
33 The name is also the name of a struct within the generated abstract
34 solver, so you can write bathymetry[Bathymetry::b] in your C++ code.
35
36 ## Impact on the C++ signatures
37
38 Every PDE term of a solver with auxiliary variables receives, directly
39 behind each Q (and each deltaQ), one pointer per attached set. The
40 pointers come in the order in which the sets have been attached. The
41 pointer is named after the set (first letter in lower case), the pointers
42 behind deltaQ carry the prefix delta. For the set above and the flux, the
43 signature therefore reads
44
45 flux(const double* Q, const double* bathymetry, const Vector& x, int normal, double* F)
46
47 and the signature of the non-conservative product is
48
49 nonconservativeProduct(Q, bathymetry, deltaQ, deltaBathymetry, x, ...)
50
51 Solvers without auxiliary variables keep their original signatures.
52
53 ## Ownership and sharing
54
55 The first solver a set is attached to owns it. Only the owner's
56 initPointWisely() receives the set as writable argument and initialises
57 it. Further solvers can attach the same set object. They share the data,
58 i.e. they do not hold an additional copy, and initPointWisely() sees the
59 set as const.
60
61 @remark Naming
62 These quantities used to be called material parameters. "Material"
63 suggests that they are invariant, but they do not have to be: an
64 auxiliary variable is any quantity that lives next to the unknowns and
65 is not evolved by the PDE terms of the solver. It may well change over
66 time if some other mechanism updates it. The current implementation
67 writes the variables once during the setup, i.e. they are constant in
68 time, but this is a restriction of the implementation, not part of the
69 concept.
70
71 Besides periodic boundaries, the halo layer of the volumes at the
72 domain boundary is not available for auxiliary variables.
73
74 """
75
76 RECONSTRUCTION_TASK_NAME = "Reconstruct auxiliary variables {}"
77 """!
78 Name of the task that reconstructs the halo of a set, without solver prefix and
79 stage suffix. The argument is the name of the set.
80 """
81
82 class Mode(enum.Enum):
83 """!
84
85 Where the values of a set live and whether they change
86
87 Data on faces are always interpolated onto hanging faces before
88 anybody reads them (see
89 src/exahype2/api/adrs/0001-interpolation-and-restriction-ride-along-with-face-users.md).
90
91 - CELL_WISE: The values only sit in the cells, i.e. the faces hold no
92 overlap of the set. Reconstructing the halo of a cell, interpolating,
93 projecting and rolling over need face data, so the solver schemes
94 reject such sets for the time being.
95 - STATIONARY_ON_FACES: The values also sit on the faces, and they do
96 not change after the setup. The faces are interpolated, but nobody
97 projects new values onto them.
98 - CHANGING_ON_FACES: The values also sit on the faces, and some solver
99 updates them after the setup (such as
100 exagrype.api.FOSOReconstructionSolver). That solver projects the new
101 values onto the faces after each (intermediate) step, restricts them
102 on hanging faces and rolls the face data over.
103 - STATIONARY_THROUGHOUT_TIME_STEPS_ON_FACES: The values sit on the
104 faces and change between time steps (some task, such as the
105 preamble of a coupling, projects new values onto the faces and
106 restricts them at the begin of each time step), but not within a
107 time step. A scheme with several stages per time step (Runge-Kutta)
108 reconstructs the halo of such a set in the first stage only,
109 holds it persistently through the later stages, and discards it
110 in the last stage. The halo thus does not survive a time step. For
111 the other modes, the schemes reconstruct the halo in every stage.
112 """
113
114 CELL_WISE = 0
115 STATIONARY_ON_FACES = 1
116 CHANGING_ON_FACES = 2
117 STATIONARY_THROUGHOUT_TIME_STEPS_ON_FACES = 3
118
120 self,
121 name: str,
122 variables: Dict[str, int],
123 mode: "AuxiliaryVariables.Mode" = Mode.STATIONARY_ON_FACES,
124 data_name: str = None,
125 ):
126 """!
127
128 @param name: str
129 Name of the set. Has to be a valid C++ identifier starting with a
130 capital letter. It feeds into the names of the data structures, the
131 name of the struct which hosts the positions of the variables
132 within the set, and - with a lower-case first letter - into the
133 name of the arguments in the PDE term signatures.
134
135 @param variables: dict
136 Maps the name of each parameter onto its multiplicity.
137
138 @param mode: AuxiliaryVariables.Mode
139 Whether the values also sit on the faces and whether they change
140 after the setup. Defaults to STATIONARY_ON_FACES. See
141 AuxiliaryVariables.Mode.
142
143 @param data_name: str
144 Name of the generated data (patch and face overlaps). Defaults to
145 the name of the set plus "AuxiliaryVariables".
146 """
147 if not re.fullmatch(r"[A-Z][A-Za-z0-9_]*", name):
148 raise ValueError(
149 f"The name of a set of auxiliary variables has to be a valid C++ identifier starting with a capital letter, but got {name!r}"
150 )
151 if not isinstance(variables, dict) or not variables:
152 raise TypeError(
153 "variables has to be a non-empty dict which maps variable names onto multiplicities"
154 )
155 self._name = name
156 self._variables: Dict[str, int] = dict(variables)
157 self._positions: Dict[str, int] = {}
158 offset = 0
159 for variable_name, multiplicity in self._variables.items():
160 if multiplicity < 1:
161 raise ValueError(
162 f"Auxiliary variable {variable_name} of {name} has multiplicity {multiplicity}"
163 )
164 self._positions[variable_name] = offset
165 offset += multiplicity
166 self._size = offset
167 self._owner = None
168 if not isinstance(mode, AuxiliaryVariables.Mode):
169 raise TypeError(
170 f"mode has to be an AuxiliaryVariables.Mode, but got {mode!r}"
171 )
172 self._mode = mode
173 self._data_name = (
174 data_name if data_name is not None else name + "AuxiliaryVariables"
175 )
176
177 # Created by create_data_structures()
181 self._patch_size = None
182 self._overlap = None
183 self._added_to = set()
184
185 @property
186 def name(self) -> str:
187 return self._name
188
189 @property
190 def mode(self) -> "AuxiliaryVariables.Mode":
191 """! Whether the values sit on the faces, and whether they change after the setup"""
192 return self._mode
193
194 @property
195 def data_name(self) -> str:
196 """! Name of the generated data"""
197 return self._data_name
198
199 @property
200 def size(self) -> int:
201 """! Total number of entries of the set, i.e. the sum of all multiplicities"""
202 return self._size
203
204 @property
205 def variables(self) -> Dict[str, int]:
206 return dict(self._variables)
207
208 @property
209 def variable_positions(self) -> Dict[str, int]:
210 """! Position of each named variable within the set"""
211 return dict(self._positions)
212
213 @property
214 def owner(self):
215 """! The solver which initialises the set, i.e. the first one it was attached to"""
216 return self._owner
217
218 @property
219 def argument_name(self) -> str:
220 """! Name of the argument of the PDE terms"""
221 return self._name[0].lower() + self._name[1:]
222
223 @property
225 """!
226
227 Whether the halo has to be reconstructed in the first stage of a time step only
228
229 True for AuxiliaryVariables.Mode.STATIONARY_THROUGHOUT_TIME_STEPS_ON_FACES.
230
231 """
232 return (
233 self._mode
234 == AuxiliaryVariables.Mode.STATIONARY_THROUGHOUT_TIME_STEPS_ON_FACES
235 )
236
237 @property
238 def delta_argument_name(self) -> str:
239 """! Name of the argument behind deltaQ"""
240 return "delta" + self._name
241
242 def variable_names_per_entry(self) -> List[str]:
243 """!
244 One name per entry of the set, qualified by the set's name. A
245 variable of multiplicity k yields k names with an index.
246 """
247 names = []
248 for variable_name, multiplicity in self._variables.items():
249 if multiplicity == 1:
250 names.append(f"{self._name}.{variable_name}")
251 else:
252 names += [
253 f"{self._name}.{variable_name}[{j}]" for j in range(multiplicity)
254 ]
255 return names
256
257 def variables_declaration(self) -> str:
258 """! C++ struct which hosts the positions of the variables within the set"""
259 constants = "\n".join(
260 f" static constexpr int {variable_name} = {position};"
261 for variable_name, position in self._positions.items()
262 )
263 return (
264 f" /**\n * Positions of the variables of the auxiliary variables {self._name}\n */\n"
265 f" struct {self._name} {{\n{constants}\n }};"
266 )
267
268 def create_data_structures(self, patch_size: int, overlap: int, grid_selector):
269 """!
270
271 Create the cell and face data of the set
272
273 The routine is idempotent, as a set may be shared by several solvers:
274 the first call creates the data, any further call checks that the
275 numerical schemes of the solvers agree on the patch size and halo.
276
277 @param patch_size: int
278 Number of volumes per axis within a patch.
279
280 @param overlap: int
281 Width of the halo layer.
282
283 @param grid_selector: peano4.api.toolbox.GridSelector
284 Selects the mesh entities which hold data.
285
286 """
287 if self.patch is not None:
288 if self._patch_size != patch_size or self._overlap != overlap:
289 raise ValueError(
290 f"The auxiliary variables {self._name} are shared by solvers with different patch sizes or halos: "
291 f"{self._patch_size}/{self._overlap} vs {patch_size}/{overlap}"
292 )
293 return
294 self._patch_size = patch_size
295 self._overlap = overlap
296 identifier = self._data_name
298 (patch_size, patch_size, patch_size), self._size, identifier
299 )
301 (2 * overlap, patch_size, patch_size),
302 self._size,
303 identifier + "CurrentTimeStep",
304 )
306 (2 * overlap, patch_size, patch_size), self._size, identifier + "Update"
307 )
308 for patch in (
309 self.patch,
312 ):
313 patch.grid_selector = grid_selector
315 patch, "double"
316 )
317 self.patch_overlap_current_time_step.generator.merge_method_definition = (
318 toolbox.blockstructured.api.get_face_merge_implementation(
320 )
321 )
322 self.patch_overlap_current_time_step.generator.includes += """
323#include "peano4/utils/Loop.h"
324"""
325 self.patch_overlap_current_time_step.generator.send_condition = (
326 grid_selector.createFaceGuard()
327 )
328 self.patch_overlap_current_time_step.generator.receive_and_merge_condition = (
329 grid_selector.createFaceGuard()
330 )
331 self.patch_overlap_update.generator.send_condition = "false"
332 self.patch_overlap_update.generator.receive_and_merge_condition = "false"
333
334 def add_to_datamodel(self, peano_project):
335 """! Register the data with the project (once, even if the set is shared)"""
336 if id(peano_project) in self._added_to:
337 return
338 self._added_to.add(id(peano_project))
339 peano_project.datamodel.add_cell(self.patch)
340 peano_project.datamodel.add_face(self.patch_overlap_current_time_step)
341 peano_project.datamodel.add_face(self.patch_overlap_update)
342
343 def __str__(self) -> str:
344 return f"{self._name}: {self._variables}"
345
346
347def split_signature(signature: str) -> List[str]:
348 """! Split a C++ parameter list at the commas that are not within template brackets"""
349 return [
350 parameter.strip()
351 for parameter in re.split(r",(?![^<]*>)", signature)
352 if parameter.strip()
353 ]
354
355
356def extend_signature(signature: str, solver) -> str:
357 """!
358
359 Add the pointers to the auxiliary variables of a solver to a PDE term's
360 signature
361
362 Each argument named Q is followed by one pointer per set, each argument
363 named deltaQ is followed by one pointer to the jump of each set. The
364 pointers are non-const iff Q is non-const (the initial condition) and the
365 solver owns the set.
366
367 @param signature: str
368 The signature without auxiliary variables
369
370 @param solver: exahype2.api.Solver
371
372 """
373 sets = solver.auxiliary_variables
374 if not sets:
375 return signature
376 result = []
377 for parameter in split_signature(signature):
378 result.append(parameter)
379 name = parameter.split()[-1]
380 if name == "Q":
381 writable = not parameter.startswith("const")
382 for auxiliary in sets:
383 qualifier = "" if writable and auxiliary.owner is solver else "const "
384 result.append(
385 f"{qualifier}double* __restrict__ {auxiliary.argument_name}"
386 )
387 elif name == "deltaQ":
388 for auxiliary in sets:
389 result.append(
390 f"const double* __restrict__ {auxiliary.delta_argument_name}"
391 )
392 return ", ".join(result)
393
394
395def forwarding_arguments(signature: str, solver) -> List[str]:
396 """!
397
398 Arguments to call the version of a PDE term with auxiliary variables
399 from a caller that holds the original signature
400
401 The caller's Q (and deltaQ) points to a volume in a buffer which hosts
402 the unknowns followed by the entries of all auxiliary variables (the
403 layout the compute kernels work on). The auxiliary variables are slices
404 of this buffer.
405
406 """
407 arguments = []
408 for parameter in split_signature(signature):
409 name = parameter.split()[-1]
410 arguments.append(name)
411 if name in ("Q", "deltaQ"):
412 for auxiliary in solver.auxiliary_variables:
413 arguments.append(
414 f"{name} + {solver.auxiliary_variable_offset(auxiliary)}"
415 )
416 return arguments
417
418
419def register_auxiliary_variables(solver, peano_project, patch_size: int, overlap: int):
420 """!
421
422 Create and register the data of all auxiliary variables of a solver
423
424 The persistent data of a set (its patch and the face overlaps) exists only
425 once, even if several solvers share it. Each solver gets its own
426 temporary patch with halo per set (solver._auxiliary_variable_halos, a
427 dict from the name of the set to the patch), so concurrently running
428 solvers do not overwrite each other's halos.
429
430 """
431 solver._auxiliary_variable_halos = {}
432 for auxiliary in solver.auxiliary_variables:
433 if auxiliary.mode == AuxiliaryVariables.Mode.CELL_WISE:
434 raise NotImplementedError(
435 f"Solver {solver.name}: the auxiliary variables {auxiliary.name} are cell-wise, i.e. not on the faces. "
436 "The numerical schemes reconstruct the halos of auxiliary variables from the face data."
437 )
438 auxiliary.create_data_structures(patch_size, overlap, solver.grid_selector)
439 auxiliary.add_to_datamodel(peano_project)
441 (
442 patch_size + 2 * overlap,
443 patch_size + 2 * overlap,
444 patch_size + 2 * overlap,
445 ),
446 auxiliary.size,
447 auxiliary.data_name + "WithHaloOf" + solver.name,
448 )
449 halo.grid_selector = solver.grid_selector
451 halo, "double"
452 )
453 peano_project.datamodel.add_cell(halo)
454 solver._auxiliary_variable_halos[auxiliary.name] = halo
455
456
457def add_reconstruction_of_auxiliary_variables(task, solver, auxiliaries=None):
458 """!
459
460 Make a reconstruction task of a solver fill the halos of the solver's
461 auxiliary variables
462
463 @param task: peano4.api.taskgraph.Task
464 The task which reconstructs the halos.
465
466 @param auxiliaries: List[AuxiliaryVariables]
467 The sets to reconstruct. Defaults to all sets of the solver.
468
469 """
470 Access = peano4.api.taskgraph.Task.DataAccess
471 if auxiliaries is None:
472 auxiliaries = solver.auxiliary_variables
473 for auxiliary in auxiliaries:
474 halo = solver._auxiliary_variable_halos[auxiliary.name]
475 task.use_cell(auxiliary.patch, Access.READ_AND_WRITE)
476 task.use_cell(halo, Access.WRITE)
477 task.use_face(auxiliary.patch_overlap_current_time_step, Access.READ_AND_WRITE)
478 task.add_action_set(
479 toolbox.blockstructured.api.ReconstructPatchWithHalo(
480 patch=auxiliary.patch,
481 patch_overlap=auxiliary.patch_overlap_current_time_step,
482 reconstructed_patch=halo,
483 guard=solver.grid_selector.createCellGuard(),
484 add_assertions_to_halo_exchange=False,
485 additional_includes=solver._get_default_includes()
486 + solver.user_solver_includes,
487 )
488 )
489
490
492 solver, time_step, interpolation, predecessors=(), name_suffix="", auxiliaries=None
493):
494 """!
495
496 Add the tasks that interpolate and reconstruct the auxiliary variables
497
498 Each set of auxiliary variables gets a task of its own that interpolates
499 its coarse face data onto the hanging faces and reconstructs its halo
500 (register_auxiliary_variables() rejects cell-wise sets).
501 Interpolation is no task of its own, see
502 src/exahype2/api/adrs/0001-interpolation-and-restriction-ride-along-with-face-users.md.
503 All tasks depend on the predecessors only, i.e. the reconstructions of all
504 sets (and of the unknowns, which the caller creates) run in parallel.
505
506 @param solver: exahype2.api.Solver
507 The solver whose sets are reconstructed.
508
509 @param time_step: peano4.api.taskgraph.Graph
510 Receives the tasks.
511
512 @param interpolation: toolbox.blockstructured.api.InterpolateHangingFaces.Scheme
513 Interpolation scheme.
514
515 @param predecessors: List[peano4.api.taskgraph.Task]
516 Tasks which the new tasks wait for.
517
518 @param name_suffix: str
519 Appended to the names of the tasks, e.g. " stage 1".
520
521 @param auxiliaries: List[AuxiliaryVariables]
522 The sets to reconstruct. Defaults to all sets of the solver. A scheme
523 with several stages passes only the sets whose halo has not been
524 held through the stages (AuxiliaryVariables.halo_is_held_through_stages).
525
526 @return List[peano4.api.taskgraph.Task]
527 The reconstruction tasks, one per set. The update of the cells has to
528 wait for all of them.
529
530 """
531 Entity = peano4.api.taskgraph.Task.GridEntity
532 reconstructions = []
533 for auxiliary in (
534 solver.auxiliary_variables if auxiliaries is None else auxiliaries
535 ):
536 reconstruction = peano4.api.taskgraph.Task(
537 name=f"{solver.name}_{AuxiliaryVariables.RECONSTRUCTION_TASK_NAME.format(auxiliary.name)}{name_suffix}",
538 entity=Entity.CELL,
539 )
540 # The reconstruction interpolates the faces itself, before it acts on the cell
541 reconstruction.add_action_set(
542 toolbox.blockstructured.api.InterpolateHangingFaces(
543 auxiliary.patch_overlap_current_time_step,
544 scheme=interpolation,
545 additional_includes=solver._get_default_includes()
546 + solver.user_solver_includes,
547 )
548 )
549 add_reconstruction_of_auxiliary_variables(reconstruction, solver, [auxiliary])
550 for predecessor in predecessors:
551 reconstruction.add_dependency(predecessor)
552 time_step.add_task(reconstruction)
553 reconstructions.append(reconstruction)
554 return reconstructions
555
556
557def use_halos_of_auxiliary_variables(task, solver, access=None, held_access=None):
558 """!
559
560 Let a task (typically the update of the cells) read the halos of the auxiliary variables
561
562 @param access: peano4.api.taskgraph.Task.DataAccess
563 How the task uses the halos. Defaults to READ_AND_DISCARD. Pass another
564 qualifier if the halos have to survive the task, e.g. because a later
565 task of the same chain reads them, too.
566
567 @param held_access: peano4.api.taskgraph.Task.DataAccess
568 How the task uses the halos of the sets whose halo is held through
569 the stages of a time step
570 (AuxiliaryVariables.halo_is_held_through_stages). Defaults to access.
571 Schemes with several stages pass a qualifier that keeps the halo alive
572 unless the task belongs to the last stage.
573
574 """
575 if access is None:
576 access = peano4.api.taskgraph.Task.DataAccess.READ_AND_DISCARD
577 if held_access is None:
578 held_access = access
579 for auxiliary in solver.auxiliary_variables:
580 task.use_cell(
581 solver._auxiliary_variable_halos[auxiliary.name],
582 held_access if auxiliary.halo_is_held_through_stages else access,
583 )
584
585
586def volumes_expression(patch_size: int, halo: int) -> str:
587 """! C++ expression for the number of volumes of a patch with halo"""
588 edge = f"({patch_size} + 2 * {halo})"
589 return f"({edge} * {edge} * (Dimensions == 3 ? {edge} : 1))"
590
591
593 solver, buffer: str, unknowns: str, halo_size: int, parameters_of=None
594) -> str:
595 """!
596
597 C++ code which assembles the input buffer of the compute kernels
598
599 The kernels work on one buffer that holds the unknowns of a volume
600 followed by the entries of all sets of auxiliary variables. The code
601 defines a std::vector<double> named buffer. It is empty if the solver has
602 no auxiliary variables.
603
604 @param unknowns: str
605 C++ expression for the unknowns of the patch with halo.
606
607 @param parameters_of: function
608 Maps a set onto the C++ expression of its patch with halo. Defaults to
609 the halo patches of the solver.
610
611 """
612 if not solver.auxiliary_variables:
613 return ""
614 if parameters_of is None:
615 parameters_of = (
616 lambda auxiliary: f"fineGridCell{solver._auxiliary_variable_halos[auxiliary.name].name}.value"
617 )
618 volumes = volumes_expression(solver.numerical_scheme.patch_size, halo_size)
619 stride = solver.unknowns + solver.number_of_auxiliary_variables
620 copies = "".join(
621 f"""
622 for (int k=0; k<{auxiliary.size}; k++) {{
623 {buffer}[volume*{stride} + {solver.auxiliary_variable_offset(auxiliary)} + k] = {parameters_of(auxiliary)}[volume*{auxiliary.size} + k];
624 }}"""
625 for auxiliary in solver.auxiliary_variables
626 )
627 return f"""
628 const int {buffer}Volumes = {volumes};
629 std::vector<double> {buffer}( {buffer}Volumes * {stride}, 0.0 );
630 for (int volume=0; volume<{buffer}Volumes; volume++) {{
631 for (int k=0; k<{solver.unknowns}; k++) {{
632 {buffer}[volume*{stride} + k] = {unknowns}[volume*{solver.unknowns} + k];
633 }}{copies}
634 }}
635"""
636
637
638def code_to_allocate_kernel_output(solver, buffer: str) -> str:
639 """! C++ code which defines the output buffer (a std::vector<double>) of the compute kernels"""
640 if not solver.auxiliary_variables:
641 return ""
642 volumes = volumes_expression(solver.numerical_scheme.patch_size, 0)
643 stride = solver.unknowns + solver.number_of_auxiliary_variables
644 return f"""
645 const int {buffer}Volumes = {volumes};
646 std::vector<double> {buffer}( {buffer}Volumes * {stride}, 0.0 );
647"""
648
649
650def code_to_copy_back_kernel_output(solver, buffer: str, unknowns: str) -> str:
651 """! C++ code which copies the unknowns of the output buffer back into the patch"""
652 if not solver.auxiliary_variables:
653 return ""
654 stride = solver.unknowns + solver.number_of_auxiliary_variables
655 return f"""
656 for (int volume=0; volume<{buffer}Volumes; volume++) {{
657 for (int k=0; k<{solver.unknowns}; k++) {{
658 {unknowns}[volume*{solver.unknowns} + k] = {buffer}[volume*{stride} + k];
659 }}
660 }}
661"""
662
663
665 solver,
666 initial_condition_task,
667 project_on_faces_task,
668 project_patch_onto_faces,
669 roll_over_updated_face,
670):
671 """!
672
673 Let the setup of a solver write its auxiliary variables
674
675 Auxiliary variables are written once, by their owner: the owner
676 initialises them in its initial condition task and projects them onto the
677 faces, so the halos can be reconstructed later on. A solver that merely
678 shares a set reads it after the owner has written it.
679
680 @param project_patch_onto_faces: class
681 The action set that projects a patch onto the faces
682 (exahype2.api.fv.actionsets.ProjectPatchOntoFaces).
683
684 @param roll_over_updated_face: class
685 The action set that rolls the projection over
686 (exahype2.api.fv.actionsets.RollOverUpdatedFace).
687
688 """
689 Access = peano4.api.taskgraph.Task.DataAccess
690 includes = solver._get_default_includes() + solver.user_solver_includes
691 for auxiliary in solver.auxiliary_variables:
692 # The setup is created before the numerical scheme adds the data to the project
693 auxiliary.create_data_structures(
694 solver.numerical_scheme.patch_size,
695 solver.numerical_scheme.halo_size,
696 solver.grid_selector,
697 )
698 if auxiliary.owner is solver:
699 initial_condition_task.use_cell(auxiliary.patch, Access.WRITE)
700 project_on_faces_task.use_cell(auxiliary.patch, Access.READ_AND_WRITE)
701 project_on_faces_task.use_face(
702 auxiliary.patch_overlap_update, Access.TEMPORARY
703 )
704 project_on_faces_task.use_face(
705 auxiliary.patch_overlap_current_time_step, Access.WRITE
706 )
707 project_on_faces_task.add_action_set(
708 project_patch_onto_faces(
709 auxiliary.patch,
710 auxiliary.patch_overlap_update,
711 guard=solver.grid_selector.createCellGuard(),
712 includes=includes,
713 )
714 )
715 project_on_faces_task.add_action_set(
716 roll_over_updated_face(
717 auxiliary.patch_overlap_current_time_step,
718 auxiliary.patch_overlap_update,
719 guard=solver.grid_selector.createFaceGuard(),
720 includes=includes,
721 )
722 )
723 auxiliary._setup_initial_condition_task = initial_condition_task
724 else:
725 owners_task = getattr(auxiliary, "_setup_initial_condition_task", None)
726 if owners_task is None:
727 raise ValueError(
728 f"Solver {solver.name} shares the auxiliary variables {auxiliary.name} with "
729 f"{auxiliary.owner.name}, but the setup of {auxiliary.owner.name} has not been created yet. "
730 f"Add {auxiliary.owner.name} to the project before {solver.name}."
731 )
732 initial_condition_task.add_dependency(owners_task)
733 initial_condition_task.use_cell(auxiliary.patch, Access.READ_AND_DISCARD)
734 project_on_faces_task.use_cell(auxiliary.patch, Access.READ_AND_WRITE)
Where the values of a set live and whether they change.
A set of auxiliary variables of a solver.
owner(self)
The solver which initialises the set, i.e.
__init__(self, str name, Dict[str, int] variables, "AuxiliaryVariables.Mode" mode=Mode.STATIONARY_ON_FACES, str data_name=None)
int size(self)
Total number of entries of the set, i.e.
Dict[str, int] variable_positions(self)
Position of each named variable within the set.
List[str] variable_names_per_entry(self)
One name per entry of the set, qualified by the set's name.
str data_name(self)
Name of the generated data.
str variables_declaration(self)
C++ struct which hosts the positions of the variables within the set.
bool halo_is_held_through_stages(self)
Whether the halo has to be reconstructed in the first stage of a time step only.
create_data_structures(self, int patch_size, int overlap, grid_selector)
Create the cell and face data of the set.
"AuxiliaryVariables.Mode" mode(self)
Whether the values sit on the faces, and whether they change after the setup.
str delta_argument_name(self)
Name of the argument behind deltaQ.
str argument_name(self)
Name of the argument of the PDE terms.
add_to_datamodel(self, peano_project)
Register the data with the project (once, even if the set is shared).
Patch implementation of a degree of freedom.
Definition Patch.py:7
One task within a peano4.api.taskgraph.Graph.
Definition Task.py:8
List[str] split_signature(str signature)
Split a C++ parameter list at the commas that are not within template brackets.
str volumes_expression(int patch_size, int halo)
C++ expression for the number of volumes of a patch with halo.
str code_to_assemble_kernel_input(solver, str buffer, str unknowns, int halo_size, parameters_of=None)
C++ code which assembles the input buffer of the compute kernels.
List[str] forwarding_arguments(str signature, solver)
Arguments to call the version of a PDE term with auxiliary variables from a caller that holds the ori...
use_halos_of_auxiliary_variables(task, solver, access=None, held_access=None)
Let a task (typically the update of the cells) read the halos of the auxiliary variables.
str extend_signature(str signature, solver)
Add the pointers to the auxiliary variables of a solver to a PDE term's signature.
add_reconstruction_of_auxiliary_variables(task, solver, auxiliaries=None)
Make a reconstruction task of a solver fill the halos of the solver's auxiliary variables.
str code_to_copy_back_kernel_output(solver, str buffer, str unknowns)
C++ code which copies the unknowns of the output buffer back into the patch.
str code_to_allocate_kernel_output(solver, str buffer)
C++ code which defines the output buffer (a std.vector<double>) of the compute kernels.
add_auxiliary_variables_to_setup(solver, initial_condition_task, project_on_faces_task, project_patch_onto_faces, roll_over_updated_face)
Let the setup of a solver write its auxiliary variables.
add_reconstruction_tasks_of_auxiliary_variables(solver, time_step, interpolation, predecessors=(), name_suffix="", auxiliaries=None)
Add the tasks that interpolate and reconstruct the auxiliary variables.
register_auxiliary_variables(solver, peano_project, int patch_size, int overlap)
Create and register the data of all auxiliary variables of a solver.
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...
Definition __init__.py:1