- Thank you received: 0
a.Energy(gfu) - elementwise possible?
- creativeworker
- Topic Author
- Offline
- Senior Member
Less
More
4 years 2 months ago #3155
by creativeworker
a.Energy(gfu) - elementwise possible? was created by creativeworker
Hello,
is there a possibility to receive the energy of each element in an elegant way?
For the global energy, I know the a.Energy(gfu) function which is very handy.
Thanks in advance!
is there a possibility to receive the energy of each element in an elegant way?
For the global energy, I know the a.Energy(gfu) function which is very handy.
Thanks in advance!
- creativeworker
- Topic Author
- Offline
- Senior Member
Less
More
- Thank you received: 0
4 years 2 months ago - 4 years 2 months ago #3158
by creativeworker
Replied by creativeworker on topic a.Energy(gfu) - elementwise possible?
Update:
I built a workaround to get the Energy per Element.
My BilinearForm a is non-linear. How can I say at which point the ElementMatrices are built?
Still the question: Is there any function to directly get the energy distribution as a CoefficientFunction?
I built a workaround to get the Energy per Element.
My BilinearForm a is non-linear. How can I say at which point the ElementMatrices are built?
Code:
e_int_list = list()
a.AssembleLinearization(gfu.vec)
for el in fes.Elements(VOL):
elmat = a.integrators[0].CalcElementMatrix (el.GetFE(), el.GetTrafo())
el_dofs = el.dofs
u_el = np.array([gfu.vec[i] for i in el_dofs])
e = 0.5 * u_el.T@elmat.NumPy()@u_el
e_int_list.append(e)
elwise_vol = Integrate(CoefficientFunction(1),mesh,VOL, element_wise=True)
W2 = sum(e_int_list)
print('Energy sum Element energy: ', W2)
fesL2 = L2(mesh, order=0)
energy_gf = GridFunction(fesL2)
vol_gf = GridFunction(fesL2)
energy_gf.vec.FV().NumPy()[:] = np.array(e_int_list)
vol_gf.vec.FV().NumPy()[:] = elwise_vol.NumPy()
energy_cf1 = CoefficientFunction(energy_gf/vol_gf)
W1 = Integrate(energy_cf1,mesh)
print('Energy: 1*', W1)
Still the question: Is there any function to directly get the energy distribution as a CoefficientFunction?
Last edit: 4 years 2 months ago by creativeworker.
4 years 2 months ago #3159
by joachim
Replied by joachim on topic a.Energy(gfu) - elementwise possible?
Hi,
You can use
It will provide a vector of dimension of number of elements, where every entry has the contribution of that element
An example is here:
ngsolve.org/docu/latest/i-tutorials/unit...vity/adaptivity.html
best,
Joachim
You can use
Code:
elwise_energy = Integrate(energy(gfu), mesh, VOL, element_wise=True)
It will provide a vector of dimension of number of elements, where every entry has the contribution of that element
An example is here:
ngsolve.org/docu/latest/i-tutorials/unit...vity/adaptivity.html
best,
Joachim
- creativeworker
- Topic Author
- Offline
- Senior Member
Less
More
- Thank you received: 0
4 years 2 months ago #3164
by creativeworker
Replied by creativeworker on topic a.Energy(gfu) - elementwise possible?
Hello,
thanks for your respond. My question was more into the direction whether there is a inbuilt CF "energy"?
Best
thanks for your respond. My question was more into the direction whether there is a inbuilt CF "energy"?
Best
- creativeworker
- Topic Author
- Offline
- Senior Member
Less
More
- Thank you received: 0
4 years 2 months ago #3169
by creativeworker
Replied by creativeworker on topic a.Energy(gfu) - elementwise possible?
Hello,
some update from my side: I searched in the C++ Code and found the function "ApplyElementMatrix" or "ApplyLinearizedElementMatrix". I think this is exactly what I would need to call from Python.
Also the function "CalcLinearizedElementMatrix" would be neat to have access to.
some update from my side: I searched in the C++ Code and found the function "ApplyElementMatrix" or "ApplyLinearizedElementMatrix". I think this is exactly what I would need to call from Python.
Also the function "CalcLinearizedElementMatrix" would be neat to have access to.
- creativeworker
- Topic Author
- Offline
- Senior Member
Less
More
- Thank you received: 0
4 years 1 month ago #3227
by creativeworker
Replied by creativeworker on topic a.Energy(gfu) - elementwise possible?
Hi, may I ask for any comment of the developers about future integration of the showed functions? Or is there already a python interface to it which I didn't find?
Time to create page: 0.114 seconds