Element weighting

More
5 years 3 weeks ago #2005 by NilsHM
Element weighting was created by NilsHM
Hello everyone!

I'm working on a hyper-reduction method where each element in the mesh has a unique weight.

The weights must be applied to the local element stiffness matrices during the assembly to the bilinear form.
Is there a way of doing that given a vector of element weights?

Or else is there a way to get single element stiffness matrices in global coordinates?

Thank you
Nils
More
5 years 3 weeks ago - 5 years 3 weeks ago #2006 by christopher
Replied by christopher on topic Element weighting
You can do this quite easily with a c++ extension. Basically you need to follow the first two steps of the c++ tutorial here: ngsolve.org/docu/latest/mylittlengs/1_Basic/README.html

You can for example parse the elementwise coefficients as a list or a numpy array and store them in a c++ array. Then in the evaluate function of your coefficient you query the element number by
Code:
int elnr = mip.GetTransformation().GetElementNr();
Then return the corresponding value from the array.

You can then use this CoefficientFunction in your stiffness bilinearform.

I hope this helps, if you run into problems write again. This part of the documentation is not often used yet.

Best
Christopher
Last edit: 5 years 3 weeks ago by christopher.
The following user(s) said Thank You: NilsHM
More
5 years 2 weeks ago #2057 by NilsHM
Replied by NilsHM on topic Element weighting
Hello Christopher,

thank you for the help.
I got as far as making a CoefficientFunction that gives the element number.

But I need the CoefficientFunction to know the element weights. You said to store the weights in an array. At what point can I do that?

I tried to initialize with the array.
The idea was to initialize my custom CoefficientFunction like this:
Code:
cf = ElementWeightCF(weights)
But that didn't work:
Code:
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported: 1. CppExtension.cppextension.ElementWeightCF()
It seems like the issue is to initialize the ngsolve CoefficientFunction with to many arguments.
You can find my .hpp file in the attachments.

How can I fix that issue or is there a better way of passing the element weights to my c++ CoefficientFunction?

Thanks in advance
Nils


File Attachment:

File Name: ElementWeightCF.hpp
File Size:1 KB
More
5 years 2 weeks ago #2058 by christopher
Replied by christopher on topic Element weighting
Hi Nils,
the code in your hpp seems ok, I expect the problem is in the binding code. Can you send the cpp file as well?
Best
More
5 years 2 weeks ago - 5 years 2 weeks ago #2059 by NilsHM
Replied by NilsHM on topic Element weighting
You can find the remaining code in the attachments.

File Attachment:

File Name: ElementWeightCF.cpp
File Size:1 KB

File Attachment:

File Name: cppextension.cpp
File Size:1 KB
Last edit: 5 years 2 weeks ago by NilsHM.
More
5 years 2 weeks ago #2060 by christopher
Replied by christopher on topic Element weighting
The export of the constructor is wrong, the template arguments for the py::init must be the arguments for the constructor:
Code:
.def(py::init<py::array_t<double>>())
best
The following user(s) said Thank You: NilsHM
Time to create page: 0.106 seconds