def __init__(self, block=None, block_coordinates=None, **kwargs): super().__init__(cs_from=Cartesian(), cs_to=Cartesian(), **kwargs) self.block = block if block_coordinates is None: block_coordinates = np.array([0, 0, 0]) if not isinstance(block_coordinates, np.ndarray): block_coordinates = np.array(block_coordinates) self.block_coordinates = block_coordinates
def parse_coordinate_system(coordinate_system, default=Cartesian(), name_key='name'): if coordinate_system is None: coordinate_system = default elif isinstance(coordinate_system, CoordinateSystem): pass elif isinstance(coordinate_system, str): coordinate_system = cs_factory[coordinate_system]() elif isinstance(coordinate_system, dict): name = coordinate_system[name_key] coordinate_system = cs_factory[name](**coordinate_system) else: raise ValueError(coordinate_system) return coordinate_system
def __init__(self, **kwargs): super().__init__(cs_to=Cartesian(), **kwargs)
def __init__(self, cs_from=None, **kwargs): super().__init__(cs_from=cs_from, cs_to=Cartesian(), **kwargs)
def __init__(self, **kwargs): super().__init__(cs_from=Tokamak(), cs_to=Cartesian(), **kwargs)
def __init__(self, **kwargs): super().__init__(cs_from=Spherical(), cs_to=Cartesian(), **kwargs)
def parse_args(args): """Parse list Patterns: 1. [coordinates] 2. [coordinates, meshSize] 3. [coordinates, coordinate_system] 4. [coordinates, zone] 5. [coordinates, meshSize, coordinate_system] 5. [coordinates, coordinate_system, zone] 5. [coordinates, meshSize, zone] 5. [coordinates, meshSize, coordinate_system, zone] Args: args (list): Returns: int or None, str or None, CoordinateSystem or None, list of float, dict: """ tag, zone = None, None coordinate_system, coordinates, kwargs = None, None, {} if len(args) == 1 and isinstance(args[0], list): # init by list a = args[0] n_nums = 0 # number of numerical items in a for x in a: if isinstance(x, float) or isinstance(x, int): n_nums += 1 else: break nums, others = a[:n_nums], a[n_nums:] # Process others if len(others) == 0: pass # default elif len(others) == 1: # coordinate system or zone o1 = others[0] if isinstance(o1, str): if o1 in cs_factory: # coordinate system coordinate_system = Point.parse_coordinate_system(o1) # logging.warning(f'May be a name conflict between zone and coordinate system: {o1}') else: # zone zone = o1 else: # coordinate system coordinate_system = Point.parse_coordinate_system(o1) elif len(others) == 2: # coordinate system and zone o1, o2 = others coordinate_system = Point.parse_coordinate_system(o1) zone = o2 else: raise ValueError(a) # Split nums into coordinates and meshSize dim = coordinate_system.dim if coordinate_system is not None else Cartesian( ).dim if n_nums == dim: # coordinates, ... coordinates = nums elif n_nums - 1 == dim: # coordinates, meshSize, ... coordinates = nums[:-1] kwargs['meshSize'] = nums[-1] else: raise ValueError(a) else: raise ValueError(args) return tag, zone, coordinate_system, coordinates, kwargs