allow scalar initial_conditions --> on-the-fly broadcasting
This commit is contained in:
parent
197e24ec0d
commit
1733c121f3
|
@ -3,6 +3,7 @@ import copy
|
||||||
import warnings
|
import warnings
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
import collections
|
||||||
import typing
|
import typing
|
||||||
from typing import Union, Optional, TextIO, List, Sequence, Dict
|
from typing import Union, Optional, TextIO, List, Sequence, Dict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -149,11 +150,15 @@ class Grid:
|
||||||
@property
|
@property
|
||||||
def initial_conditions(self) -> Dict[str,np.ndarray]:
|
def initial_conditions(self) -> Dict[str,np.ndarray]:
|
||||||
"""Fields of initial conditions."""
|
"""Fields of initial conditions."""
|
||||||
|
self._ic = dict(zip(self._ic.keys(),
|
||||||
|
[v if isinstance(v, collections.Sequence) else
|
||||||
|
np.broadcast_to(v,self.cells) for v in self._ic.values()]))
|
||||||
return self._ic
|
return self._ic
|
||||||
|
|
||||||
@initial_conditions.setter
|
@initial_conditions.setter
|
||||||
def initial_conditions(self,
|
def initial_conditions(self,
|
||||||
ic: Dict[str,np.ndarray]):
|
ic: Dict[str,np.ndarray]):
|
||||||
|
|
||||||
if not isinstance(ic,dict):
|
if not isinstance(ic,dict):
|
||||||
raise TypeError('initial conditions is not a dictionary')
|
raise TypeError('initial conditions is not a dictionary')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue