Hi FreeFem++ developers!
Thank you very much for makingFF.
I’d like to perform the 3D topology optimization, where the 3D elasticity problem and reaction-diffusion equation (RDE) are included, using PETSc.
I am now attempting to add a parallelized RDE to my already parallelized 3D elasticity problem code as follows.
verbosity = 0;
load "medit" // for data save
load "msh3"
load "PETSc" // PETSc plugin
macro dimension()3// EOM // 2D or 3D
include "macro_ddm.idp"
real E; E = 1.0; // Young's modulus
real nu; nu = 0.3; // Poisson's ratio
real lambda; lambda = nu*1./(1+nu)/(1-2.*nu); // Lame coefficient
real mu; mu = 1./2./(1+nu); // Lame coefficient
real matd; matd = 1e-3;
real matw; matw = 0.5;
int[int] labs(6); // labels on boundaries of squre: (bottom, right, top, left)
mesh3 Shc1; // Mesh of the squre 1
labs = [1,0,3,0,0,6];
Shc1 = cube(5,10,1,[-0.25+(0.25+0.25)*x, 0.0+(1.0-0.0)*y, -0.25+(-0.15+0.25)*z],label=labs,flags=1,region=1);
mesh3 Shc2; // Mesh of the squre 2
labs = [7,8,9,100,11,12];
Shc2 = cube(5,10,4,[-0.25+(0.25+0.25)*x, 0.0+(1.0-0.0)*y, -0.15+(0.25+0.15)*z],label=labs,flags=1,region=1);
mesh3 Sh=Shc1+Shc2;//+Shc3;
mesh3 ShPlt=Sh;
mesh3 ShPltMoved;
mesh3 ShB=Sh;
int[int] wall(3); wall = [1,7]; // fixed displacement
fespace VhSB2(ShB,P2), VhSB1(ShB,P1), VhSB0(ShB,P0) ;
VhSB0 chi; // chi: characteristic function
VhSB0 chiP; // chiP: characteristic function with weak domain
int[int] n2o;
macro ShN2O()n2o// EOM
func Pk = [P2, P2, P2]; // finite element space
fespace Wh(Sh, Pk);
fespace WhPlt(ShPlt, Pk);
fespace WhPhi(ShPlt,P0);
buildDmesh(Sh);
Mat A;
macro def(i)[i, i#B, i#C]// EOM // vector field definition
macro init(i)[i, i, i]// EOM // vector field initialization
createMat(Sh, A, Pk)
Wh def(u);
WhPlt [gu1, gu2, gu3];
WhPlt [pltx, plty, pltz];
WhPlt [reducex, reducey, reducez];
macro gu [gu1,gu2,gu3] // Glabal displacement vector
macro epsilon(u) [dx(u),dy(u#B),dz(u#C),(dz(u#B)+dy(u#C)), (dz(u)+dx(u#C)), (dy(u)+dx(u#B))] // strain tensor
macro D [[2.*mu+lambda,lambda,lambda,0,0,0],[lambda,2.*mu+lambda,lambda,0,0,0],[lambda,lambda,2.*mu+lambda,0,0,0],[0,0,0,mu,0,0],[0,0,0,0,mu,0],[0,0,0,0,0,mu]] //elastic tensor
real gZ; gZ = -0.01;
macro div(u)(dx(u) + dy(u#B) + dz(u#C))// EOM
varf vPb(def(u), def(v)) = int3d(Sh)((D*epsilon(u))'*epsilon(v)*E*chiP)
+int2d(Sh,3)(gZ*vC)
+ on(wall, u = 0.0, uB = 0.0, uC = 0.0); // '
//-----------------------adding part------------------------
Mat B;
macro grad(phi)[dx(phi), dy(phi), dz(phi)]// EOM // three-dimensional gradient
createMat(Sh, B, P1)
fespace WhRDE(Sh, P1);
WhRDE phi,testphi; // level set function and its test function
WhRDE ophi; // ophi: previous level set function
//-----------------------adding part------------------------
phi = 1.0; // initialize level set function
ophi = phi*(phi<=1.0)*(phi>=-1.0)+1.*(phi>1.0)-1.*(phi<-1.0); // ophi is mapped to satisfy the upper and lower constraints.
plot(ophi,ShB,cmm="ophi",fill=1,wait=false,boundary=false,WindowIndex=0);
chi = (0.5+phi/matw*(15./16-phi^2/matw^2*(5./8-3./16*phi^2/matw^2)))*(phi>=-matw)*(phi<=matw)+1.*(phi>matw);
chiP = (1.-matd)*chi+matd;
real obj; //objective function
real objPre; //Previous objective function
for (int iter=0;iter<2;iter++) {
A = vPb(Wh, Wh);
real[int] rhs = vPb(0, Wh);
set(A, sparams = "-pc_type gamg -ksp_view -ksp_max_it 200", bs = 3);
u[] = A^-1 * rhs;
if(!NoGraphicWindow) {
real[int] sol;
ChangeNumbering(A, u[], sol);
ChangeNumbering(A, u[], sol, inverse = true);
int[int] rest=restrict(Wh, WhPlt, n2o);
for[i, v : rest] pltx[][v] = u[][i];
mpiReduce(pltx[], reducex[], processor(0, mpiCommWorld), mpiSUM);
}
if(mpirank==0){
gu1[]=reducex[];
gu2[]=reducey[];
gu3[]=reducez[];
ShPltMoved = movemesh3(ShPlt,transfo=[x+gu1,y+gu2,z+gu3]);
plot(ShPltMoved,cmm="Deformation");
obj = int2d(ShPlt,3)(gZ*gu3);
cout <<"+++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout << "!!! iter ObjF "<<endl;
cout << "!!! "<<iter<<" "<<obj<<endl;
cout <<"+++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
phi = 0.5*(cos((2*pi/1.0)*y)+0.3); // initialize level set function
cout <<"+++++++++++++++++++++++++++++++++++++++++++++++++++"<=-1.0)+1.*(phi>1.0)-1.*(phi<-1.0);
chi = (0.5+phi/matw*(15./16-phi^2/matw^2*(5./8-3./16*phi^2/matw^2)))*(phi>=-matw)*(phi<=matw)+1.*(phi>matw);
chiP = (1.-matd)*chi+matd;
plot(ophi,ShB,cmm="ophiO",fill=1,wait=false,boundary=false,WindowIndex=0);
}// End optimization loop
At this time, we obtained the following error.
Error line number 403, in file macro: partitionPrivate in C:\Program Files (x86)\FreeFem++\\idp\macro_ddm.idp, before token ;
Invalid array size for vectorial fespace function
current line = 403 mpirank 0 / 8
Compile error : Invalid array size for vectorial fespace function
line number :403, ;
error Compile error : Invalid array size for vectorial fespace function
line number :403, ;
code = 1 mpirank: 0
Is there any procedure required when two different PDEs coexist in the same code like this?
Sorry if there have been similar questions in the past.
I would appreciate your response.
Many thanks,
Keita Kambayashi