About extracting Stiffness Matrix

Dear all,
I want to use FreeFEM to implement 99 lines of code in topology optimization design.
Code Reference: An 89-line code for geometrically nonlinear topology optimization written in FreeFEM | SpringerLink

When extracting the stiffness matrix, it prompts the following errors.


It seems that my vElasticity is not defined before. But I did define it. I don’t know why.
Here’s my code
1.edp (2.1 KB)

Macros need to end with // symbols, e.g.,

macro Epsilon(ux, uy) [dx(ux), dy(uy), (dy(ux)+dx(uy))/sqrt2] //
macro Divergence(ux, uy) (dx(ux) + dy(uy)) //

is the proper way to define the macros.

1 Like

Thank you very much. That is right.
I have another question.I want to get [ux, uy] * [ux, uy] '.
So I entered the following code, but it didn’t seem to work.

sens = [ux,uy]*[ux,uy]';
Can you help me find out what the problem is?

Could you please share your code?

7.edp (1.9 KB)

The correct way to calculate it is the following:

real[int] auxVec(ux[].n);
auxVec = k*ux[];
real com = auxVec'*ux[];
cout << "com=" << com << endl;

[ux,uy] is a vectorial finite element function, while ux[] is a vector that contains all the values at the gridpoints of [ux,uy]. Consult the documentation for more details.

I’m sorry to bother you again.
I have the following code. I print ux uy, they are the same. I think they both represent all the values at the gridpoints of [ux,uy].As you said above.
But if I modify the code as follows:
Replace

fespace Vh(Th,[P1,P1]);
Vh [ux,uy],[uu,vv];

as
fespace Vh(Th,P1);
Vh ux,uy,uu,vv;

The printed ux and uy seem different.
What is the difference between the two?

What do you mean by printing?
If you write

fespace Vh(Th,[P1,P1]);
Vh [ux,uy],[uu,vv];

either ux[] or uy[] is a vector containing all the function values at the grid points for a [P1,P1]. If you do

fespace Vh(Th,P1);
Vh ux,uy,uu,vv;

then ux[] and uy[] is each a vector of values of a P1 FE space.

Oh, I see,thank you very much.