Hi,
Relying on element numbering for transferring data is not be very reliable
because GetFEM may use a different element numbering. I would recommend you
to save your values in a text file with 4 columns (or 3 for 2D):
x,y,z,val
where the first 3 columns (2 for 2D) contain the coordinates of the center
of the element
Then you can use the following snippet for reading and transferring the
values to a model variable/data defined on a discontinuous MeshFem mf:
import numpy as np
from scipy.spatial import KDTree
file = open("source_data.txt", "r") # assuming it contains 4 columns:
x,y,z,value
source_data = np.loadtxt(file,dtype=float)
tree = KDTree(source_data[:,0:3])
dd,ii = tree.query(mf.basic_dof_nodes())
md.add_fem_data("source", mf)
md.set_variable("source", source_data[ii,3])
BR
Kostas
On Thu, Jun 2, 2022 at 2:14 PM Bourriche Lahoussaine <
[email protected]> wrote:
> Hello,
> No it's a list of values ( not expression).
> Do you have an idea how to deal with this
>
> Cordialement
>
> Lahoussaine BOURRICHE
> 3A, ENSEEIHT , Physique numérique
> +33 6 20 76 17 12
>
> ----- Mail d’origine -----
> De: Konstantinos Poulios <[email protected]>
> À: Bourriche Lahoussaine <[email protected]>
> Cc: getfem-users <[email protected]>
> Envoyé: Thu, 02 Jun 2022 13:54:57 +0200 (CEST)
> Objet: Re: Source term
>
> Hello,
>
> When you say that you have a value for each element, do you have an
> analytic expression for that, or do you have something like a list with
> element number --> value?
>
> If you have an analytic expression then you can use md.interpolation(....)
> to assign your source data to a model variable. Something like this
> (assuming that your problem variable is called u):
>
> N = m.dim()
> mf = gf.MeshFem(m,N)
> mf.set_classical_fem(0) # zero degree fem, i.e. discontinuous
> ...
> md.add_fem_data("source", md.interpolation(".....", mf, RG_ID))
> md.add_linear_term(mim, "source.Test_u", RG_ID)
>
> BR
> Kostas
>
> On Thu, Jun 2, 2022 at 11:54 AM Bourriche Lahoussaine <
> [email protected]> wrote:
>
> > Hello
> > I want to define a source term in a specific region, the source is a
> > vector of values ( for each elemnt i have a source value ).
> > How it will be?
> > Cordialement
> >
> > Lahoussaine BOURRICHE
> >
> >
>
>