← Back to team overview

dolfin team mailing list archive

Re: [HG DOLFIN] Several Python assembly optimizations and new options:

 

Ok, I've added all functions in
http://www.cplusplus.com/reference/clibrary/cmath/

-- 
Martin


2008/6/5 Johan Hake <hake@xxxxxxxxx>:
> On Wednesday 04 June 2008 23:34:16 Martin Sandve Alnæs wrote:
>> Nice :)
>>
>> It should also be easy to extend this to support sympy and swiginac
>> expressions, which can easily be converted to C strings.
>
> Does sympy support conversion to C strings?
>
> Btw: Feature request. Add support for abs too, i.e., fabs.
>
> Johan
>
>> --
>> Martin
>>
>> 2008/6/4 Johan Hake <hake@xxxxxxxxx>:
>> > Hello!
>> >
>> > This is just insanely cool!
>> >
>> > I got a 20 time speed up while assembling a simple advection form.
>> >
>> > I suppose with more complex forms the speedup would be much more!
>> >
>> > This levels the python users with the cpp users even more!
>> >
>> > And of course instant caches the compiled functions so no recompile for
>> > each time.
>> >
>> > Thanks!
>> >
>> > Johan
>> >
>> > On Wednesday 04 June 2008 12:44:17 Martin Sandve Alnæs wrote:
>> >> 2008/6/3 Anders Logg <logg@xxxxxxxxx>:
>> >> > On Tue, Jun 03, 2008 at 11:23:41PM +0200, Martin Sandve Alnæs wrote:
>> >> >> It's easy with some helper functions I have, I can show you tomorrow.
>> >> >> It only depends on dolfin::Function (i.e. dolfin.cpp_Function) and
>> >> >> Instant.
>> >> >
>> >> > ok, nice. Maybe we can add the helper functions to assemble.py.
>> >>
>> >> Now you can do things like this:
>> >>
>> >> A = assemble(..., coefficients=[myfunction, 1.23, "sin(x[0])"])
>> >>
>> >> 1.23 is wrapped in a cpp_Function (i.e. a constant Function), and
>> >> the string is compiled as a C++ dolfin::Function like "v[0] = ...;".
>> >>
>> >> If you want more control over the implementation
>> >> (i.e. temporary variables in eval for efficiency, if-checks, etc.)
>> >> you can also do this:
>> >>
>> >> code = """
>> >> class F: dolfin::Function {
>> >>  ...
>> >> };
>> >> class G: dolfin::Function {
>> >>  ...
>> >> };
>> >> """
>> >>
>> >> f, g = compile_functions(code, mesh)
>> >>
>> >>
>> >> Or, if you just want to precompile but don't need anything too fancy:
>> >>
>> >> expressions = ["sin(x[0])",
>> >>                          ("a*x[1]", "b*x[0]")]
>> >> f, g = compile_functions(expressions, mesh)
>> >> assert f.rank() == 0
>> >> assert g.rank() == 1
>> >> g.a = 1.23
>> >> g.b = 3.21
>> >>
>> >> Note that:
>> >> - a tuple is interpreted as a vector expression
>> >>
>> >> - a tuple of tuples is interpreted as a matrix expression
>> >>
>> >> - variables like a and b in the strings above are detected
>> >>   automatically, but this requires all builtin names to be
>> >>   registered in the variable dolfin.compile_functions._builtins,
>> >>   which currently contains some common mathematical
>> >>   functions like sqrt, pow, exp, sin, pi etc.
>> >>
>> >> - variables are initialized to 0.0, so use compile_functions if
>> >>   you need control over variable values.
>> >>
>> >> - assemble also accepts tuples like in compile_functions
>> >>
>> >> - assemble only calls on instant once independently of
>> >>   the number of string expressions, to reduce compilation time
>> >>
>> >> - Error checks are not extensive!
>> >>
>> >> --
>> >> Martin
>> >> _______________________________________________
>> >> DOLFIN-dev mailing list
>> >> DOLFIN-dev@xxxxxxxxxx
>> >> http://www.fenics.org/mailman/listinfo/dolfin-dev
>
>
>


References