Dear Konstantinos

This worked
Maybe not the most elegant solution
file  = open("Gfield.txt","r")
gdata = np.loadtxt(file,dtype=float)
#print(gdata)
x = gdata[:,0:3]
#print(x)
tree  = KDTree(x)
#print(tree)
print(mfpb.basic_dof_nodes(0))
Pt=mfpb.basic_dof_nodes(1)
print(Pt)
Pt=mfpb.basic_dof_nodes(2)
print(Pt)

a = np.empty([meshb.nbpts(),3])
for i in range(meshb.nbpts()):
    Pt=mfpb.basic_dof_nodes(i)
    a[i][0]=Pt[0]
    a[i][1]=Pt[1]
    a[i][2]=Pt[2]

#
#a = mfpb.basic_dof_nodes()
#y = a.transpose()
print(a[1][0])
dd,ii = tree.query(a)

for i in range(10):
    print(ii[i])

print('Read G as field on nodes');

md.add_fem_data("gf", mfpb)
md.set_variable("gf", gdata[ii,3])


mfoutb = gf.MeshFem(meshb)
mfoutb.set_classical_discontinuous_fem(2)

mfoutb.export_to_vtu("gf.vtu",
                      mfpb, md.variable("gf"), "ShearMod")


From: Lesage,Anne Cecile J <ajles...@mdanderson.org>
Sent: Monday, December 13, 2021 5:53 PM
To: Lesage,Anne Cecile J <ajles...@mdanderson.org>; Konstantinos Poulios 
<logar...@googlemail.com>
Cc: getfem-users@nongnu.org
Subject: RE: [EXT] Re: defining a field on the mesh dofs

It seems that mfpb.basic_dof_nodes() does not have the right structure to be 
compared to tree

From: Getfem-users 
<getfem-users-bounces+ajlesage=mdanderson....@nongnu.org<mailto:getfem-users-bounces+ajlesage=mdanderson....@nongnu.org>>
 On Behalf Of Lesage,Anne Cecile J
Sent: Monday, December 13, 2021 11:57 AM
To: Konstantinos Poulios 
<logar...@googlemail.com<mailto:logar...@googlemail.com>>
Cc: getfem-users@nongnu.org<mailto:getfem-users@nongnu.org>
Subject: RE: [EXT] Re: defining a field on the mesh dofs

WARNING: This email originated from outside of MD Anderson. Please validate the 
sender's email address before clicking on links or attachments as they may not 
be safe.



Dear Konstantinos

I adapted your solution to the interpolation of a shear modulus field on the 
mesh.

from scipy.spatial import KDTree
file  = open("Gfield.txt","r")
gdata = np.loadtxt(file,dtype=float)
tree  = KDTree(gdata[:,0:3])
dd,ii = tree.query(mfpb.basic_dof_nodes())
md.add_fem_data("gf", mfpb)
md.set_variable("gf", gdata[ii,3])

However I get the following error

Traceback (most recent call last):
  File "testresect5poroelasticbrainheadv1.py", line 208, in <module>
    dd,ii = tree.query(mfpb.basic_dof_nodes())
  File 
"/home/ajlesage/.local/lib/python3.8/site-packages/scipy/spatial/kdtree.py", 
line 472, in query
    d, i = super().query(x, k, eps, p, distance_upper_bound, workers)
  File "ckdtree.pyx", line 779, in scipy.spatial.ckdtree.cKDTree.query
  File "ckdtree.pyx", line 1604, in scipy.spatial.ckdtree.num_points
ValueError: x must consist of vectors of length 4 but has shape (3, 18154)

What do you think is the issue there?
My data is a four column ascii file x, y, z, value

From: Konstantinos Poulios 
<logar...@googlemail.com<mailto:logar...@googlemail.com>>
Sent: Thursday, December 2, 2021 2:09 AM
To: Lesage,Anne Cecile J 
<ajles...@mdanderson.org<mailto:ajles...@mdanderson.org>>
Cc: getfem-users@nongnu.org<mailto:getfem-users@nongnu.org>
Subject: [EXT] Re: defining a field on the mesh dofs

WARNING: This email originated from outside of MD Anderson. Please validate the 
sender's email address before clicking on links or attachments as they may not 
be safe.


Dear Anne-Ceclie

I guess what pfield.txt contains is a list of values ordered in the same order 
as the mesh nodes. In general there is no guarantee that the mesh nodes will be 
in the same order in GetFEM but if your original numbering of nodes is 
contiguous, chances are good that GetFEM will keep the same numbering. Then the 
next point is that dof numbering and mesh node numbering do not need to be the 
same. In fact you can even have a larger or smaller number of dofs than the 
number of mesh nodes.

A more general solution for you would be to save in the pfield.txt file 4 
values, x,y,z coordinates and field value. Then you can always read the value 
of the closest point for each dof with something like:

import numpy as np
from scipy.spatial import KDTree
file = open("pfield.txt", "r") # assuming it contains 4 columns: x,y,z,value
pdata = np.loadtxt(file,dtype=float)
tree = KDTree(pdata[:,0:3])
dd,ii = tree.query(mfp.basic_dof_nodes())
md.add_fem_data("pc", mfp)
md.set_variable("pc", pdata[ii,3])

Best regards
Kostas








On Wed, Dec 1, 2021 at 10:42 PM Lesage,Anne Cecile J 
<ajles...@mdanderson.org<mailto:ajles...@mdanderson.org>> wrote:
Dear all

I would like to define a non-constant pressure field on the mesh dofs
I would like to read the value from an ascii file

I am thinking of using the following python scripting

import numpy as np

file = open('pfield.txt', 'r') # 'r' = read
pfield = np.loadtxt(file,dtype=fload)

md.add_fem_data(“pc”,mfp)
md.set_variable("pc", pfield)

Will it be correct to use pc in building a week form?

Thank you
Regards
Anne-Cecile







The information contained in this e-mail message may be privileged, 
confidential, and/or protected from disclosure. This e-mail message may contain 
protected health information (PHI); dissemination of PHI should comply with 
applicable federal and state laws. If you are not the intended recipient, or an 
authorized representative of the intended recipient, any further review, 
disclosure, use, dissemination, distribution, or copying of this message or any 
attachment (or the information contained therein) is strictly prohibited. If 
you think that you have received this e-mail message in error, please notify 
the sender by return e-mail and delete all references to it and its contents 
from your systems.
The information contained in this e-mail message may be privileged, 
confidential, and/or protected from disclosure. This e-mail message may contain 
protected health information (PHI); dissemination of PHI should comply with 
applicable federal and state laws. If you are not the intended recipient, or an 
authorized representative of the intended recipient, any further review, 
disclosure, use, dissemination, distribution, or copying of this message or any 
attachment (or the information contained therein) is strictly prohibited. If 
you think that you have received this e-mail message in error, please notify 
the sender by return e-mail and delete all references to it and its contents 
from your systems.

The information contained in this e-mail message may be privileged, 
confidential, and/or protected from disclosure. This e-mail message may contain 
protected health information (PHI); dissemination of PHI should comply with 
applicable federal and state laws. If you are not the intended recipient, or an 
authorized representative of the intended recipient, any further review, 
disclosure, use, dissemination, distribution, or copying of this message or any 
attachment (or the information contained therein) is strictly prohibited. If 
you think that you have received this e-mail message in error, please notify 
the sender by return e-mail and delete all references to it and its contents 
from your systems.

Reply via email to