← Back to team overview

dolfin team mailing list archive

Re: [Question #146882]: gradient operation for either a scalar or vector field

 

I think you have an old version of DOLFIN. Upgrade to the latest
version. Then you can easily compute the gradient by a direct
projection (which does the same thing as what Kent suggests):

  V = VectorFunctionSpace(mesh, "CG", 1)
  gradu = project(grad(u), V)

--
Anders



On Fri, Feb 25, 2011 at 07:59:01PM +0100, Kent-Andre Mardal wrote:
> The following works fine on my system:
>
>
> from dolfin import *
>
> mesh = UnitSquare(12,12)
>
> V = FunctionSpace(mesh, "CG", 1)
> scalar1 = Function(V)
>
> VV = VectorFunctionSpace(mesh, "CG", 1)
> u = TrialFunction(VV)
> v = TestFunction(VV)
>
> a = dot(u,v)*dx
> L = dot(grad(scalar1), v)*dx
>
> problem = VariationalProblem(a,L)
> c = problem.solve()
>
>
> On 25 February 2011 19:50, JJ Jiang <question146882@xxxxxxxxxxxxxxxxxxxxx>
> wrote:
>
>     Question #146882 on DOLFIN changed:
>     https://answers.launchpad.net/dolfin/+question/146882
>
>     JJ Jiang posted a new comment:
>     Hi Kent,
>       Thanks for the answer. I used the following script as you suggested. But
>     the compilation failed. Why?
>
>     VV = VectorFunctionSpace(mesh, "CG", 1)
>     u = TrialFunction(VV)
>     v = TestFunction(VV)
>
>     a = dot(u,v)*dx
>     L = dot(grad(scalar1), v)*dx
>
>     problem = VariationalProblem(a,L)
>     c = problem.solve()
>
>     Could you please guide me further on that?
>
>     The error message is the following:
>     In instant.recompile: The module did not compile, see '/tmp/
>     tmpCJTm9Y2011-2-25-12-46_instant/
>     form_6d04c7c3797b189ed231948384237bf909130ad7/compile.log'
>     Traceback (most recent call last):
>      File "demo.py", line 38, in <module>
>        problem = VariationalProblem(a,L)
>      File "/usr/local/lib/python2.6/site-packages/dolfin/fem/
>     variationalproblem.py", line 40, in __init__
>        self.L = Form(L, form_compiler_parameters=form_compiler_parameters)
>      File "/usr/local/lib/python2.6/site-packages/dolfin/fem/form.py", line 34,
>     in __init__
>        (self._compiled_form, module, self.form_data) = jit(form,
>     form_compiler_parameters, common_cell)
>      File "/usr/local/lib/python2.6/site-packages/dolfin/compilemodules/
>     jit.py", line 44, in mpi_jit
>        return local_jit(*args, **kwargs)
>      File "/usr/local/lib/python2.6/site-packages/dolfin/compilemodules/
>     jit.py", line 103, in jit
>        return jit_compile(form, parameters=p, common_cell=common_cell)
>      File "/usr/local/lib/python2.6/dist-packages/ffc/jitcompiler.py", line 58,
>     in jit
>        return jit_form(object, parameters, common_cell)
>      File "/usr/local/lib/python2.6/dist-packages/ffc/jitcompiler.py", line
>     107, in jit_form
>        cache_dir = cache_dir)
>      File "/usr/local/lib/python2.6/dist-packages/ufc_utils/build.py", line 63,
>     in build_ufc_module
>        **kwargs)
>      File "/usr/local/lib/python2.6/dist-packages/instant/build.py", line 474,
>     in build_module
>        recompile(modulename, module_path, setup_name, new_compilation_checksum)
>      File "/usr/local/lib/python2.6/dist-packages/instant/build.py", line 100,
>     in recompile
>        "compile, see '%s'" % compile_log_filename)
>      File "/usr/local/lib/python2.6/dist-packages/instant/output.py", line 49,
>     in instant_error
>        raise RuntimeError(text)
>     RuntimeError: In instant.recompile: The module did not compile, see '/tmp/
>     tmpCJTm9Y2011-2-25-12-46_instant/
>     form_6d04c7c3797b189ed231948384237bf909130ad7/compile.log'
>
>
>     _______________________________________________
>     Mailing list: https://launchpad.net/~dolfin
>     Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
>     Unsubscribe : https://launchpad.net/~dolfin
>     More help   : https://help.launchpad.net/ListHelp
>
>

> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp




Follow ups

References