Beispiel #1
0
def build_hit(expr, name, **kwargs):
    """
    Create a hit node containing a ParsedFunction of the given expression

    Inputs:
        expr[sympy.core.Expr]: The sympy expression to convert
        name[str]: The name of the input file block to create
        kwargs: Key, value pairs for val, vals input parameters (defaults to 1.0) if not provided
    """
    import pyhit

    symbols = set([str(s) for s in expr.free_symbols
                   ]).difference(set(['R.x', 'R.y', 'R.z', 't']))
    for symbol in symbols:
        kwargs.setdefault(symbol, 1.)

    root = pyhit.Node(None, name)
    root['type'] = 'ParsedFunction'
    root['value'] = "'{}'".format(str(fparser(expr)))

    if kwargs:
        pvars = ' '.join(kwargs.keys())
        pvals = ' '.join([str(v) for v in kwargs.values()])
        root['vars'] = "'{}'".format(pvars)
        root['vals'] = "'{}'".format(pvals)

    return root
Beispiel #2
0
 def testCreate(self):
     root = pyhit.Node()
     bcs = root.append('BCs')
     bcs.append('left', type='NeumannBC', value=1980, boundary='left')
     self.assertEqual(len(root), 1)
     out = root.render()
     self.assertIn('[BCs]', out)
     self.assertIn('type = NeumannBC', out)
     self.assertIn('boundary = left', out)