diff --git a/backends/cbackend.py b/backends/cbackend.py index 67f25525381a2ea00f7dfbabea03aa017699de3b..f3336be4bf12ba210946f22055063a115ea1c9d8 100644 --- a/backends/cbackend.py +++ b/backends/cbackend.py @@ -333,7 +333,7 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter): if self.instruction_set['rsqrt']: return self.instruction_set['rsqrt'].format(self._print(expr.args[0])) else: - return "({})".format(self._print(1 / sp.sqrt(expr.args[0]))) + return "({})".format(self.doprint(1 / sp.sqrt(expr.args[0]))) return super(VectorizedCustomSympyPrinter, self)._print_Function(expr) def _print_And(self, expr): @@ -391,6 +391,8 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter): if result: return result + one = self.instruction_set['makeVec'].format(1.0) + if expr.exp.is_integer and expr.exp.is_number and 0 < expr.exp < 8: return "(" + self._print(sp.Mul(*[expr.base] * expr.exp, evaluate=False)) + ")" elif expr.exp == -1: @@ -398,8 +400,10 @@ class VectorizedCustomSympyPrinter(CustomSympyPrinter): return self.instruction_set['/'].format(one, self._print(expr.base)) elif expr.exp == 0.5: return self.instruction_set['sqrt'].format(self._print(expr.base)) + elif expr.exp == -0.5: + root = self.instruction_set['sqrt'].format(self._print(expr.base)) + return self.instruction_set['/'].format(one, root) elif expr.exp.is_integer and expr.exp.is_number and - 8 < expr.exp < 0: - one = self.instruction_set['makeVec'].format(1.0) return self.instruction_set['/'].format(one, self._print(sp.Mul(*[expr.base] * (-expr.exp), evaluate=False))) else: diff --git a/datahandling/datahandling_interface.py b/datahandling/datahandling_interface.py index b9e81c7f332fad60c122904ec5f32b3b74420541..da2108bfbdbdc3d09abfc4b6a55cda1c1850b63c 100644 --- a/datahandling/datahandling_interface.py +++ b/datahandling/datahandling_interface.py @@ -1,6 +1,6 @@ import numpy as np from abc import ABC, abstractmethod -from typing import Optional, Callable, Sequence, Iterable, Tuple, Dict +from typing import Optional, Callable, Sequence, Iterable, Tuple, Dict, Union from pystencils.field import Field @@ -32,7 +32,7 @@ class DataHandling(ABC): """Returns tuple of booleans for x,y,(z) directions with True if domain is periodic in that direction.""" @abstractmethod - def add_array(self, name: str, values_per_cell: int = 1, dtype=np.float64, + def add_array(self, name: str, values_per_cell, dtype=np.float64, latex_name: Optional[str] = None, ghost_layers: Optional[int] = None, layout: Optional[str] = None, cpu: bool = True, gpu: Optional[bool] = None, alignment=False) -> Field: """Adds a (possibly distributed) array to the handling that can be accessed using the given name. @@ -239,7 +239,7 @@ class DataHandling(ABC): # ------------------------------- Data access and modification ----------------------------------------------------- - def fill(self, array_name: str, val, value_idx: Optional[Tuple[int, ...]] = None, + def fill(self, array_name: str, val, value_idx: Optional[Union[int, Tuple[int, ...]]] = None, slice_obj=None, ghost_layers=False, inner_ghost_layers=False) -> None: """Sets all cells to the same value.