getfem-users
[Top][All Lists]

## Re: Fast computation of a quantity

 From: Konstantinos Poulios Subject: Re: Fast computation of a quantity Date: Fri, 30 Sep 2022 15:55:15 +0200

this is a minor problem, try:

grad_norm = gf.asm_generic(self.IM, 1, "(2+2*p)*sign(u)*pow(abs(u), 1+2*p)*Test_phi", -1, md, "select_output", "phi")

or even better:

grad_norm = gf.asm_generic(self.IM, 1, "(2+2*p)*u*pow(u, 2*p)*Test_phi", -1, md, "select_output", "phi")

BR
Kostas

On Fri, Sep 30, 2022 at 2:05 PM Eloi Martinet <eloi.martinet@gmail.com> wrote:
I actually tried it, but the problem was that u was declared as a fem_variable and not fem_data and getfem kept telling me "Cannot derive function sign. No derivative provided or not derivable function."
Could you explain this behaviour to me? I would like to understand what happens when u is declared as a variable.
Thank you for your help and kindness.
Best,
Eloi.

Le ven. 30 sept. 2022 à 11:16, Konstantinos Poulios <logari81@googlemail.com> a écrit :
ok, what you are doing is equivalent to

grad_norm = gf.asm_generic(self.IM, 1, "(2+2*p)*sign(u)*pow(abs(u), 1+2*p)*Test_phi", -1, md)

This is the definition of assembling a residual vector, assembling the product with each basis function.

BR
Kostas

On Fri, Sep 30, 2022 at 10:01 AM Eloi Martinet <eloi.martinet@gmail.com> wrote:
Hello,
Here is what I do currently :

md = gf.Model("real")
md.add_fem_variable("phi", self.V) # Represents a basis function
md.set_variable("p", p)
md.set_variable("u", u)

for i in tqdm(range(nbdof_V)):
phi = np.zeros(self.nbdof_V)
phi[i] = 1
self.md.set_variable("phi", phi)

grad_norm[i] = (2+2*p)*gf.asm_generic(self.IM, 0, "sign(u)*pow(abs(u), 1+2*p)*phi", -1, md)

Sorry I should have included this snippet from the beginning.
Have a great day.
Best,
Eloi.

Le jeu. 29 sept. 2022 à 21:39, Konstantinos Poulios <logari81@googlemail.com> a écrit :
Hello, would you like to send us a naive implementation of your assembly with asm_generic (and a loop) to take it from there?

BR
Kostas

On Thu, Sep 29, 2022 at 6:27 PM Eloi Martinet <eloi.martinet@univ-smb.fr> wrote:
Hello everyone,
My problem is the following : I have a FE space V with basis phi_i. Let u be a function on V and f a real valued function. What is the quickest way to compute the vector (\int f(u)*phi_i)_i ? I would like to use asm_generic but I don't see how to do it without looping on i and computing it for all i, which is way too long.

Thank you, have a good day.
Best regards,
Eloi.