DG and Newtons method linearization

More
6 years 9 months ago #342 by cwinters
Hi,

if I understand you correct, you just want do set more complicated functions for A and Sigma?
You can use a indicator function
Code:
Sigma.Set(IfPos(x-1800,x,0))
or any other "CoefficentFunction".
If you call
Code:
help(CoefficientFunction)
within python, you get some information what you can do with CoefficientFunctions.

Best,
Christoph
More
6 years 9 months ago #343 by Matejczyk
Thanks Christoph! I was looking for that for quite some time. I will try then to put it all together now.

Best wishes,
B
More
6 years 9 months ago #355 by Matejczyk
Dear Christoph,

I've managed to make my HDG with the Newton loop code running. As it is only a part of a bigger project I experienced some new problem. In order to use the command a.Apply where a is the bilinear form for the HDG formulation I need to increase the heap size by SetHeapSize(100000000). That works fine when I try to solve my equation once. Unfortunately, I would love to use it as a part of the som optimization problem and need to solve the equation in a loop with different parameters. When I solve the equation for the second time I encounter the problem with the heap size- the program freezes at the application of the form as it was because with the standard size of the heap. I believe I do something wrong with the memory management. I was trying to use the del and gc.collect() to free some memory but it did not help.

Any idea what might be the issue?
Best wishes,
Bart
Attachments:
More
6 years 9 months ago #356 by cwinters
Hi Bart,

there was a bug in the FacetFESpace for 1d. The fix should be available in the next days.

A few comments to your code:
  • If you want to visualize a 1d function you have to use Gridfunctions. Drawing CoefficientFunctions in 1d is not working. In case you don't want to draw your functions (like Sigma, R, A, xpoints, ...) a would advise to use the as CoefficientFunctions.
    Code:
    Sigma = IfPos(x-1200,1,0)*IfPos(-x+2400,1,0)
  • defines a CoefficientFunction which you can use as parameter in your BilinearForm.
  • When you calculate your output functions, you use
    Code:
    J1.vec[int(nel/2)]
    I guess you want the function value in the middle? If so, just leave c1, gradu1 and J1 as CoefficientFunctions and evaluate at the correct point. For the domain [0,length] this can be done with
    Code:
    J1(mesh(length/2))
    The entry of the vector is just a coefficient value and might be different than the function value.
  • You do not have to delete all the variables (you del ... statement). This should be done when the PNP_solver is finished.

Best,
Christoph
More
6 years 9 months ago #362 by Matejczyk
Dear Christoph,

I downloaded the new version of the library and now there is no problem with the heap size. So the update seems to work.

For the Grid/Coefficient function - I struggled a lot with plotting them and passing into my functions. As form time to time I want to plot some of them it is better to keep them as they are for now.

On more question - I would like to introduce some box constrain for a function and limit it value to (-2,2). I was trying with the Ifpos function but I'm missing the absolute value. What I would like to do is

Sigma. Set( IfPos(gd*gd-4,2*abs(gd),gd))

but the absolute value is not working. Any idea how to go over this problem?

Best wishes,
Bart
More
6 years 9 months ago - 6 years 9 months ago #363 by christopher
You can use the Norm CoefficientFunction, abs does not work with CFs (but I see no reason why, so I think we could add it as well...)
But if you want to limit it's values to [-2,2] you would have to cut them off at the top and the bottom:
Code:
Sigma. Set( IfPos(gd-2,2, IfPos(2-gd,gd,-2)))
Best
Christopher
Last edit: 6 years 9 months ago by christopher.
Time to create page: 0.112 seconds