def main(): temperature = named_parameter('t', 25.0) um = named_parameter('um', -13.0 * 10**(-3)) phase = named_parameter('phase', 'i') radius = named_parameter('radius', 25) upot = named_parameter('upot', numpy.arange(0.0, 10.0, 1.0)) shift = named_parameter('shift', '10') needprev = named_parameter('needprev', [False] + [True] * (len(upot) - 1)) ischeme_elements = Constants(temperature, um, phase, radius, shift) \ >> ISE(upot, needprev) ischeme = namedtuple_adapter(IS(ischeme_elements)) subs_history = [] compute_substitutions = partial(_compute_substitutions, subs_history) for values in ischeme: subs = compute_substitutions(values) sim_config = prepare_config('./sim.i') new_config = sim_config(subs) sim_filename = f"{subs['filebase']}.i" with open(sim_filename, 'w') as simfile: simfile.writelines(new_config) ferret_run = f'mpiexec -n 28 ferret-opt -i {sim_filename}' procresult = run(ferret_run, shell=True) if procresult.returncode != 0: exit(1)
def test_named_numpy_2(): c1 = named_parameter('c1', 0.5) x = named_parameter('x', numpy.array([1.0,2.0,3.0])) ischeme = Constants(c1) >> ISE(x) ischeme_content = list(namedtuple_adapter(IS(ischeme))) assert(len(ischeme_content) == 3) for entry, xval in zip(ischeme_content, [1.0,2.0,3.0]): assert(entry.c1 == 0.5) assert(entry.x == xval)
def test_namedtuple_adapter(): c1 = named_parameter('c1', 0.5) x = named_parameter('x', [1,2,3]) y = named_parameter('y', ['a','b','c']) ischeme = Constants(c1) >> ISE(x) >> ISE(y) ischeme_content = list(namedtuple_adapter(IS(ischeme.nested_variables))) assert(len(ischeme_content) == 9) for entry, xval, yval in zip(ischeme_content, [1,1,1,2,2,2,3,3,3], ['a','b','c']*3): assert(entry.c1 == 0.5) assert(entry.x == xval) assert(entry.y == yval)