Not able to evaluate point in a loop

hi all,

im trying to run a loop that will calculate the stress and deformation at different point across my model, but for some reason it is not able to evaluate the calculation in the point
im getting different shape for each point, any idea why? im using the (shape,scheme,degree) option per Dokken’s recommendation, maybe im using it wrong.

im attaching part of my code, hopefully it will be enough

import fenics as fe
from dolfin import *
import matplotlib.pyplot as plt
from ffc.fiatinterface import create_quadrature as cquad
import numpy as np
import meshio
import dolfin
from fenics import *
import sys, os, shutil, math
import matplotlib.pyplot as plt  # Plotting Library


F = variable(I + grad(u))
CL = F * F.T
# Deviatoric part
dev_stress = MU * (CL - I)

# Volumetric part
vol_stress = LAMBDA * (J - 1) * I

sigma = (1 / J) * dev_stress + vol_stress
S = FunctionSpace(mesh, "P", 1)
# Example function space
sigma_xx = project(sigma[0, 0], S)

stress123 = Function(S, name='stressi')
dt = 0.1
t, T = 0.0, 100 * dt
TT = Traction()

# creating functions in order to see the stress and deformation over time
V_tensor = TensorFunctionSpace(mesh, "DG", 0)
S = FunctionSpace(mesh, "P", 1)
print(f"V_tensor {V_tensor}")
defGrad = Function(V_tensor, name='F')
stress123 = Function(S, name='stressi')
shape = "interval"
deg =2
scheme = "default"

points1, weights = cquad(shape, deg, scheme)
print(f"weights{weights}")

# creating a file for paraview
stress123.rename("SRESS1", "")
subdomains_function.rename("subdomains", "")
defGrad.rename("Deformation_DRAD", "")
u.rename("Displacement Vector", "")
test_file = fe.XDMFFile("test.xdmf")
test_file.parameters["flush_output"] = True
test_file.parameters["functions_share_mesh"] = True
length = 1
absJ = 1
# Parameters

# Function to check if a point is outside both cylinders

beam_size = 0.2  # Beam side length
cylinder_radius_squared = 0.0182**2
num_points = 20
x_constant = 0.4  # The constant x value

# Function to check if a point is outside both cylinders
def is_outside_cylinders(y, z, y_center1, y_center2, cylinder_radius_squared):
    distance1 = (y - y_center1)**2 + (z - 0.1)**2
    distance2 = (y - y_center2)**2 + (z - 0.1)**2
    return distance1 > cylinder_radius_squared and distance2 > cylinder_radius_squared

# Generate random points
def generate_points(num_points, beam_size, cylinder_radius_squared, x_constant):
    points = []
    while len(points) < num_points:
        # Randomly sample within the beam's boundaries
        y = np.random.uniform(0, beam_size)
        z = np.random.uniform(0, beam_size)

        # Define cylinder centers based on the constant x
        y_center1 = 0.05 + 0.1 * x_constant
        y_center2 = 0.15 - 0.1 * x_constant

        # Check if the point is outside both cylinders
        if is_outside_cylinders(y, z, y_center1, y_center2, cylinder_radius_squared):
            points.append((x_constant, y, z))

    return np.array(points)

# Generate 20 points
points = generate_points(num_points, beam_size, cylinder_radius_squared, x_constant)

# Output points
print("Generated points:")
print(points)


# Function to check if a point is inside both cylinders
def is_inside_cylinders(y, z, y_center1, y_center2, cylinder_radius_squared):
    distance1 = (y - y_center1)**2 + (z - 0.1)**2
    distance2 = (y - y_center2)**2 + (z - 0.1)**2
    return distance1 <= cylinder_radius_squared or distance2 <= cylinder_radius_squared

# Generate random points inside the cylinders
def generate_points_inside_cylinders(num_points, beam_size, cylinder_radius_squared, x_constant):
    physical_points2 = []
    while len(physical_points2) < num_points:
        # Randomly sample within the beam's boundaries
        y = np.random.uniform(0, beam_size)
        z = np.random.uniform(0, beam_size)

        # Define cylinder centers based on the constant x
        y_center1 = 0.05 + 0.1 * x_constant
        y_center2 = 0.15 - 0.1 * x_constant

        # Check if the point is inside either of the cylinders
        if is_inside_cylinders(y, z, y_center1, y_center2, cylinder_radius_squared):
            physical_points2.append((x_constant, y, z))

    return np.array(physical_points2)

# Generate 20 points inside the cylinders
physical_points2 = generate_points_inside_cylinders(num_points, beam_size, cylinder_radius_squared, x_constant)

# Output points
print("Generated points inside cylinders:")
print(physical_points2)
# creating a loop with time dependent in order to apply force over time
while t <= T:
    print('time: ', t)

    # Increase traction
    TT.t = t
    tDirBC.time_ = t
    tDirBC4.time_ = t

    solver.solve()
    F = variable(I + grad(u))
    J = det(F)
    CL = F * F.T
    # Deviatoric part
    dev_stress = MU * (CL - I)

    # Volumetric part
    vol_stress = LAMBDA * (J - 1) * I

    sigma = (1 / J) * dev_stress + vol_stress
    u.rename("u", "displacement")

    DF = I + grad(u)  # Compute the deformation gradient
    defGrad.assign(project(DF, V_tensor))  # Project the deformation gradient
    sigma_xx = project(sigma[0, 0], S)
    # Extravgacting the xx component of the stress tensor
    stress_xx_projected = project(sigma_xx, S)  # Projecting this scalar component
    stress123.assign(stress_xx_projected)  # Assigning the projected stress

    print(f"stress_xx_projected {stress_xx_projected}")
    stress123.assign(stress_xx_projected)  # Assigning the projected stress

    # get stretch at a point for plotting
    # trying to create avarage stress and deformation


    for point in points:
        try:
            deformation_gradient_values_all11.append(defGrad(point)[0])  # Store the value at the current point
            stress_values_all11.append(stress123(point))
            stress_values_all111.append(np.dot(stress_values_all11, weights) * absJ)
            deformation_gradient_values_all222.append(np.dot(deformation_gradient_values_all11, weights) * absJ)
        except Exception as e:
            print(f"Could not evaluate at {point}: {e}")

    # Loop for physical_points2
    for point in physical_points2:
        try:
            deformation_gradient_values_all4.append(defGrad(point)[0])  # Store the value at the current point
            stress_values_all4.append(stress123(point))
            stress_values_all5.append(np.dot(stress_values_all4, weights) * absJ)
            deformation_gradient_values_all6.append(np.dot(deformation_gradient_values_all4, weights) * absJ)
        except Exception as e:
            print(f"Could not evaluate at {point}: {e}")

    # Print the evaluated values for debugging purposes

    print(stress_values_all111)
    print(deformation_gradient_values_all222)
    print(stress_values_all5)
    print(deformation_gradient_values_all6)

    deformation_gradient_values_all11 = []
    stress_values_all11 = []

    deformation_gradient_values_all4 = []
    stress_values_all4 = []

    # time increment
    t += float(dt)

deformation_gradient_values_all333 = np.array(deformation_gradient_values_all222)
stress_values_all222 = np.array(stress_values_all111)

deformation_gradient_values_all7 = np.array(deformation_gradient_values_all6)
stress_values_all6 = np.array(stress_values_all5)
A_tag=0.0002624;
A_0=0.0394752;
stress_body=(((stress_values_all6*A_tag)+(stress_values_all222*A_0))/0.04)
deformation_gradient_body=np.array(((deformation_gradient_values_all7*A_tag)+(deformation_gradient_values_all333*A_0))/0.04)

this is what im getting

Could not evaluate at [0.4        0.01093385 0.13524289]: shapes (1,) and (2,) not aligned: 1 (dim 0) != 2 (dim 0)
Could not evaluate at [0.4        0.16278207 0.16510247]: shapes (3,) and (2,) not aligned: 3 (dim 0) != 2 (dim 0)
Could not evaluate at [0.4        0.07372184 0.19482677]: shapes (4,) and (2,) not aligned: 4 (dim 0) != 2 (dim 0)
Could not evaluate at [0.4        0.19559365 0.0247406 ]: shapes (5,) and (2,) not aligned: 5 (dim 0) != 2 (dim 0)
and so on...

i tried to change the scheme and degree

will appreciate any help

You are not new to the forum, and you have been already instructed to make your code reproducible (eg at Solver cannot converge - #2 by bleyerj) and to try to make an effort to keep it minimal (eg at Defining an equation - #2 by dokken).

I am not posting this warnings for fun, only so that you are aware that repeatedly failing to adhere to the best practices of the community in the long run will only decrease your chances of getting an answer.

i tried to keep my code minimal hence i didnt attached the entire code or more parts of it , i tried to attach only the relevant parts
i tried to remove parts of it in my first comment

this is the geo file i created

// Gmsh project created on Thu Jul 25 18:42:45 2024
//+
SetFactory("OpenCASCADE");
Box(1) = {0, 0, 0, 1, 0.2, 0.2};
//+
Cylinder(2) = {-0.1, 0.04, 0.1, 1.6, 0.16, 0, 0.0182, 2*Pi};
//+
Cylinder(3) = {-0.1, 0.16, 0.1, 1.6, -0.16, 0, 0.0182, 2*Pi};
//+
BooleanDifference{ Volume{1}; Delete; }{ Volume{3}; Volume{2}; Delete; }
//+
Cylinder(2) = {-0.1, 0.16, 0.1, 1.6, -0.16, 0, 0.0182, 2*Pi};
//+
Cylinder(3) = {-0.1, 0.04, 0.1, 1.6, 0.16, 0, 0.0182, 2*Pi};
//+
BooleanDifference{ Volume{3}; Delete; }{ Volume{2}; Delete; }
//+
Cylinder(4) = {-0.1, 0.16, 0.1, 1.6, -0.16, 0, 0.0182, 2*Pi};
//+
Box(5) = {1, 0, 0, 0.6, 0.2, 0.2};
//+
Box(6) = {0, 0, 0, -0.3, 0.2, 0.2};
//+
BooleanDifference{ Volume{3}; Volume{1}; Volume{4}; Volume{2}; Delete; }{ Volume{5}; Volume{6}; Delete; }
//+
Recursive Delete {
  Point{9}; Point{10}; Point{14}; Point{15}; Point{12}; Point{13}; Curve{14}; Curve{16}; Curve{15}; Curve{24}; Curve{21}; Curve{22}; Curve{20}; Curve{19}; Curve{23}; Surface{9}; Surface{8}; Surface{10}; Surface{16}; Surface{13}; Surface{14}; Surface{15}; Volume{5}; Volume{7}; 
}
//+
BooleanUnion{ Volume{3}; Volume{6}; Delete; }{ Volume{4}; Delete; }
//+
Recursive Delete {
  Surface{25};Surface{27};Surface{28};Surface{30};
}
//+
Physical Surface("left", 55) = {19, 29, 26};
//+
Physical Surface("right", 56) = {32, 31, 24};
//+
Physical Surface("up", 57) = {21};
//+
Physical Surface("down", 58) = {22};
//+
Physical Surface("front", 59) = {20};
//+
Physical Surface("back", 60) = {23};
//+
Physical Volume("boxer", 61) = {1};
//+
Physical Volume("fibers", 62) = {2};
//+
Transfinite Curve {34, 33, 31, 36} = 30 Using Progression 1;
//+
Transfinite Curve {28, 30, 29, 27, 35, 38, 37, 32} = 10 Using Progression 1;
//+
Transfinite Curve {13, 26, 18, 6} = 10 Using Progression 1;
//+
Transfinite Surface {20,21,22,23};
//+
Mesh.MeshSizeFromCurvature = 5;
//+
Coherence;

hope its better

It is unclear why:

  1. You have to solve a PDE to reproduce the error, you would simply have to define a function u in the appropriate function space
  2. Why not use a built in mesh to reproduce this error
  3. Make sure that the code can run (and avoid complicated and unclear redefinitions of functions)

General cleanup of imports, as you are importing fenics 4 times:

hi, thanks for the reply

  1. if you could advise why does the function space is not correct, i will appreciate
  2. you mean to use a simpler mesh using the build in options to reproduce it ?

The point is that you redefine S for no particular reason.
Adding extra initializations makes it harder for anyone to parse your code.

Yes.

yes i wrote it twice by mistake , i removed it now

i think that my issue is related to this part
shape = “interval”
deg =12
scheme = “default”
points1, weights = cquad(shape, deg, scheme)

i tried to search more info about it but did found much explanations on previous posts.

im not sure if any more info is needed in order to simplify the issue or make it more readable

Please provide a updated minimal code following the suggestions I made above.

i tried to avoid any un-necessary lines of code
i didnt tried to use a build in mesh

im not sure if was spouse also to attach the part of the code where im importing the geo file and the entire definition of the pde

if you will be able to help me this way, would be more than happy, if not , understandable

import fenics as fe
from ffc.fiatinterface import create_quadrature as cquad
import numpy as np
import meshio
import dolfin
import os
import matplotlib.pyplot as plt

du = TrialFunction(V)  # Incremental displacement
v = TestFunction(V)  # Test function
u = Function(V)  # Displacement from previous iteration
B = Constant((0.0, 0.0, 0.0))  # Body force per unit volume
T = Constant((0.0, 0.0, 0.0))  # Traction force on the boundary

d = len(u)
I = Identity(d)  # Identity tensor
F = variable(I + grad(u))  # Deformation gradient
C = F.T * F  # Right Cauchy-Green tensor

# Invariants of deformation tensors
Ic = tr(C)
J = det(F)

# Stored strain energy density (compressible neo-Hookean model)

W = MU / 2 * (tr(C) - 3 - 2 * ln(J)) + LAMBDA / 2 * pow((J - 1), 2)

n = FacetNormal(mesh)
P = diff(W, F)
# Total potential energy
L = inner(P, grad(v)) * dx - dot(B, v) * dx - dot(T, v) * ds

Je = derivative(L, u, du)

problem = NonlinearVariationalProblem(L, u, bcs=bcs, J=Je)

solver = NonlinearVariationalSolver(problem)
solver.parameters['newton_solver']['relative_tolerance'] = 2e-6
solver.parameters['newton_solver']['absolute_tolerance'] = 2e-7
solver.parameters['newton_solver']['linear_solver'] = 'lu'
# solver.parameters['newton_solver']['linear_solver'] = 'mumps'
file_1 << u
F = variable(I + grad(u))
CL = F * F.T
# Deviatoric part
dev_stress = MU * (CL - I)

# Volumetric part
vol_stress = LAMBDA * (J - 1) * I

sigma = (1 / J) * dev_stress + vol_stress
S = FunctionSpace(mesh, "P", 1)
V_tensor = TensorFunctionSpace(mesh, "DG", 0)
# Example function space
sigma_xx = project(sigma[0, 0], S)
stress123 = Function(S, name='stressi')
dt = 0.1
t, T = 0.0, 100 * dt
TT = Traction()

# creating functions in order to see the stress and deformation over time

defGrad = Function(V_tensor, name='F')
stress123 = Function(S, name='stressi')
# F_projected = project(F, V_tensor)
# F_xx = project(F_projected[0, 0], S)
shape = "interval"
deg =20
scheme = "default"

points1, weights = cquad(shape, deg, scheme)
length = 1
absJ = 1

beam_size = 0.2  # Beam side length
cylinder_radius_squared = 0.0182**2
num_points = 20
x_constant = 0.1  # The constant x value

# Function to check if a point is outside both cylinders
def is_outside_cylinders(y, z, y_center1, y_center2, cylinder_radius_squared):
    distance1 = (y - y_center1)**2 + (z - 0.1)**2
    distance2 = (y - y_center2)**2 + (z - 0.1)**2
    return distance1 > cylinder_radius_squared and distance2 > cylinder_radius_squared

# Generate random points
def generate_points(num_points, beam_size, cylinder_radius_squared, x_constant):
    points = []
    while len(points) < len(points1):
        # Randomly sample within the beam's boundaries
        y = np.random.uniform(0, 0.1)
        z = np.random.uniform(0, beam_size)

        # Define cylinder centers based on the constant x
        y_center1 = 0.05 + 0.1 * x_constant
        y_center2 = 0.15 - 0.1 * x_constant

        # Check if the point is outside both cylinders
        if is_outside_cylinders(y, z, y_center1, y_center2, cylinder_radius_squared):
            points.append((x_constant, y, z))

    return np.array(points)

# Generate 20 points
points = generate_points(num_points, beam_size, cylinder_radius_squared, x_constant)

while t <= T:
    print('time: ', t)

    # Increase traction
    TT.t = t
    tDirBC.time_ = t
    tDirBC4.time_ = t

    solver.solve()
    F = variable(I + grad(u))
    J = det(F)
    CL = F * F.T
    # Deviatoric part
    dev_stress = MU * (CL - I)

    # Volumetric part
    vol_stress = LAMBDA * (J - 1) * I

    sigma = (1 / J) * dev_stress + vol_stress
    u.rename("u", "displacement")

    DF = I + grad(u)  # Compute the deformation gradient
    defGrad.assign(project(DF, V_tensor))  # Project the deformation gradient
    sigma_xx = project(sigma[0, 0], S)
    # Extravgacting the xx component of the stress tensor
    stress_xx_projected = project(sigma_xx, S)  # Projecting this scalar component
    stress123.assign(stress_xx_projected)  # Assigning the projected stress

    print(f"stress_xx_projected {stress_xx_projected}")
    for point in points:
        try:
            deformation_gradient_values_all11.append(defGrad(point)[0])  # Store the value at the current point
            stress_values_all11.append(stress123(point))
            stress_values_all111.append(np.dot(stress_values_all11, weights) * absJ)
            deformation_gradient_values_all222.append(np.dot(deformation_gradient_values_all11, weights) * absJ)
        except Exception as e:
            print(f"Could not evaluate at {point}: {e}")
    deformation_gradient_values_all11 = []
    stress_values_all11 = []
    t += float(dt)
    deformation_gradient_values_all333 = np.array(deformation_gradient_values_all222)
stress_values_all222 = np.array(stress_values_all111)

That code still doesn’t have the mesh (make an effort to use a built in mesh), contains an useless PDE solve, is not reproducible (e.g. due to the missing mesh, definition of V), is not deterministic (due to the random generation of points: how are we supposed to know which points give the error and which don’t? they’ll change at every run).

Finally, for debugging purposes try to split the try-except block with a try-except for each of the four lines in the block, otherwise you’ll never know which one is causing the failure.

I am not willing to help any further until all of these points are addressed. After one year, you should have enough experience to realize most of these on your own.

hi,

im adding here the code with build in mesh and boundaries , i will be a bit long but in order to provide everything you wanted, i dont know how do make it shorter
well basically the issue is in here , i guess

            stress_values_all1.append(np.dot(stress_values_all, weights) * absJ)
            deformation_gradient_values_all2.append(np.dot(deformation_gradient_values_all, weights) * absJ)

since the weight is always a shape of 20(or any other degree that i set) while deformation_gradient_values_all or stress_values_all changes his shape accordantly to the number of point (append list) its not able to evaluate the issue
i tried to play with it but im not sure how to fix it

i entered the dot into the loop per Dokken’s recommendation previously

how can i make the weight shape match the deformation and stress

i hope now it clearer and more comfortable, if not thank for the try

import fenics as fe
from dolfin import *
import matplotlib.pyplot as plt
from ffc.fiatinterface import create_quadrature as cquad
import numpy as np
E1, E2, nu = 30e6, 3e6, 0.49

# Create mesh and define function space

length, width, height = 1.0, 0.2, 0.2  # Dimensions of the rod
num_elements = 40  # Number of elements along each dimension
mesh = BoxMesh(Point(0, 0, 0), Point(length, width, height), num_elements, 4, 4)

V = VectorFunctionSpace(mesh, "Lagrange", 1)

#creating subtomains and boundaty conditions

class Omega_0(SubDomain):
    def inside(self, x, on_boundary):
        return x[0] <= 0.5 + DOLFIN_EPS


class Omega_1(SubDomain):
    def inside(self, x, on_boundary):
        return x[0] > 0.5 - DOLFIN_EPS


subdomain_0 = Omega_0()
subdomain_1 = Omega_1()
materials = MeshFunction('size_t', mesh, mesh.topology().dim())
materials.set_all(0)
subdomain_0.mark(materials, 1)
subdomain_1.mark(materials, 2)

boundary_parts = MeshFunction('size_t', mesh, mesh.topology().dim() - 1)

left = AutoSubDomain(lambda x: near(x[0], 0))
right = AutoSubDomain(lambda x: near(x[0], 1))
up = AutoSubDomain(lambda x: near(x[2], 0.2))
down = AutoSubDomain(lambda x: near(x[2], 0))
front = AutoSubDomain(lambda x: near(x[1], 0))
back = AutoSubDomain(lambda x: near(x[1], 0.2))

left.mark(boundary_parts, 1)
right.mark(boundary_parts, 2)
up.mark(boundary_parts, 5)
down.mark(boundary_parts, 6)
front.mark(boundary_parts, 3)
back.mark(boundary_parts, 4)

bc1 = DirichletBC(V.sub(0), Constant(0), boundary_parts, 1)
bc3 = DirichletBC(V.sub(1), Constant(0), boundary_parts, 3)
bc5 = DirichletBC(V.sub(2), Constant(0), boundary_parts, 5)
bc6 = DirichletBC(V.sub(2), Constant(0), boundary_parts, 6)
tDirBC = Expression(('1.0*time_'), time_=0.0, degree=0)
tDirBC4 = Expression(('((1/(time_+1))-1)*0.2'), time_=0.0, degree=0)
bc2 = DirichletBC(V.sub(0), tDirBC, boundary_parts, 2)
bc4 = DirichletBC(V.sub(1), tDirBC4, boundary_parts, 4)

bcs = [bc1, bc2, bc3, bc4, bc5, bc6]
subdomain_ids = [2, 4]
ds = Measure("ds", subdomain_data=boundary_parts, subdomain_id=(2,4))
ds = ds(degree=4)

du = TrialFunction(V)  # Incremental displacement
v = TestFunction(V)  # Test function
u = Function(V)  # Displacement from previous iteration
B = Constant((0.0, 0.0, 0.0))  # Body force per unit volume
T = Constant((0.0, 0.0, 0.0))  # Traction force on the boundary

# Project or interpolate the initial guess onto u
initial_guess = Expression(("x[0]", "x[1]", "x[2]"), degree=1)
# Project or interpolate the initial guess onto u
u.interpolate(initial_guess)
# u.interpolate(Constant((0,0,0)))

# Kinematics
d = len(u)
I = Identity(d)  # Identity tensor
F = variable(I + grad(u))  # Deformation gradient
C = F.T * F  # Right Cauchy-Green tensor

# Invariants of deformation tensors
Ic = tr(C)
J = det(F)

# Stored strain energy density (compressible neo-Hookean model)

W = MU / 2 * (tr(C) - 3 - 2 * ln(J)) + LAMBDA / 2 * pow((J - 1), 2)

n = FacetNormal(mesh)
P = diff(W, F)
# Total potential energy
L = inner(P, grad(v)) * dx - dot(B, v) * dx - dot(T, v) * ds

Je = derivative(L, u, du)

problem = NonlinearVariationalProblem(L, u, bcs=bcs,J=Je)

solver = NonlinearVariationalSolver(problem)
solver.parameters['newton_solver']['relative_tolerance'] = 1e-6
solver.parameters['newton_solver']['linear_solver'] = 'lu'

F = variable(I + grad(u))
CL = F * F.T
# Deviatoric part
dev_stress = MU * (CL - I)

# Volumetric part
vol_stress = LAMBDA * (J - 1) * I

sigma = (1 / J) * dev_stress + vol_stress
S = FunctionSpace(mesh, "P", 1)  # Example function space
sigma_xx = project(sigma[0,0], S)

stress_values_all = []
deformation_gradient_values_all = []
stress_values_all1 = []
deformation_gradient_values_all2 = []
stress_values_all2 = []
deformation_gradient_values_all3 = []

stress123 = Function(S, name='stressi')
dt = 0.1
t, T = 0.0, 100 * dt
TT = Traction()

#creating functions in order to see the stress and deformation over time
V_tensor = TensorFunctionSpace(mesh, "DG", 0)

print(f"V_tensor {V_tensor}")
defGrad = Function(V_tensor, name='F')

# F_projected = project(F, V_tensor)
# F_xx = project(F_projected[0, 0], S)
shape = "interval"
deg = 10
scheme = "default"

points, weights = cquad(shape, deg, scheme)
print(f"weights{weights}")

#creating a file for paraview
stress123.rename("SRESS1", "")
materials_function.rename("materials", "")
defGrad.rename("Deformation_DRAD", "")
u.rename("Displacement Vector", "")
test_file = fe.XDMFFile("test.xdmf")
test_file.parameters["flush_output"] = True
test_file.parameters["functions_share_mesh"] = True

absJ = abs(length)
physical_points = np.zeros((len(points), 3))
physical_points[:, 0] = np.asarray([p * absJ for p in points]).reshape(-1)
physical_points[:, 1] = 0.1
physical_points[:, 1] = 0.1

print(f"weights{physical_points}")

#creating a loop with time dependent in order to apply force over time
while t <= T:
    print('time: ', t)

    # Increase traction
    TT.t = t
    tDirBC.time_ = t
    tDirBC4.time_ = t
    solver.solve()
    F = variable(I + grad(u))
    J = det(F)
    CL = F * F.T
    # Deviatoric part
    dev_stress = MU * (CL - I)

    # Volumetric part
    vol_stress = LAMBDA * (J - 1) * I

    sigma = (1 / J) * dev_stress + vol_stress
    u.rename("u", "displacement")

    DF = I + grad(u)  # Compute the deformation gradient
    defGrad.assign(project(DF, V_tensor))  # Project the deformation gradient
    sigma_xx = project(sigma[0, 0], S)
    # Extravgacting the xx component of the stress tensor
    stress_xx_projected = project(sigma_xx, S)  # Projecting this scalar component
    stress123.assign(stress_xx_projected)  # Assigning the projected stress
    print(f"stress_xx_projected {stress_xx_projected}")
    stress123.assign(stress_xx_projected)  # Assigning the projected stress


    for point in physical_points:
        # is to return the coordinates of all degrees of freedom (DOFs) associated with the finite element function space "S."

        try:
            deformation_gradient_values_all.append(defGrad(point)[0])# Store the value at the current point
            stress_values_all.append(stress123(point))
            stress_values_all1.append(np.dot(stress_values_all, weights) * absJ)
            deformation_gradient_values_all2.append(np.dot(deformation_gradient_values_all, weights) * absJ)
        except Exception as e:
            print(f"Could not evaluate at {point}: {e}")

    deformation_gradient_values_all=[]
    stress_values_all=[]

    # save xdmf file
    test_file.write(u, t)
    test_file.write(materials_function, t)
    test_file.write(stress123, t)
    test_file.write(defGrad, t)



    # time increment
    t += float(dt)

deformation_gradient_values_all3 = np.array(deformation_gradient_values_all2)
stress_values_all2 = np.array(stress_values_all1)

well now i did set the dot outside the point loop and i guess its helped

    for point in points:
        try:
            deformation_gradient_values_all11.append(defGrad(point)[0])  # Store the value at the current point
            stress_values_all11.append(stress123(point))
        except Exception as e:
            print(f"Could not evaluate at {point}: {e}")
    stress_values_all111.append(np.dot(stress_values_all11, weights) * absJ)
    deformation_gradient_values_all222.append(np.dot(deformation_gradient_values_all11, weights) * absJ)