5656 kind = 'linear' )
5757print ('2 = \n core {}' .format (MPI .COMM_WORLD .rank ))
5858
59- material_data_field_C_0 = discretization .get_material_data_size_field (name = 'elastic_tensor' )
59+ material_data_field_C_0 = discretization .get_material_data_size_field_mugrid (name = 'elastic_tensor' )
6060
6161material_data_field_C_0 .s = np .einsum ('ijkl,qxy->ijklqxy' , elastic_C_0 ,
6262 np .ones (np .array ([discretization .nb_quad_points_per_pixel ,
6363 * discretization .nb_of_pixels ])))
6464print ('3 = \n core {}' .format (MPI .COMM_WORLD .rank ))
6565# Set up preconditioner
66- preconditioner_fnfnqks = discretization .get_preconditioner_NEW (reference_material_data_ijkl = elastic_C_0 )
66+ preconditioner_fnfnqks = discretization .get_preconditioner_Green_mugrid (reference_material_data_ijkl = elastic_C_0 )
67+
68+
69+ # M_fun = lambda x: discretization.apply_preconditioner_NEW(
70+ # preconditioner_Fourier_fnfnqks=preconditioner_fnfnqks,
71+ # nodal_field_fnxyz=x)
72+ def M_fun (x , Px ):
73+ """
74+ Function to compute the product of the Preconditioner matrix with a vector.
75+ The Preconditioner is represented by the convolution operator.
76+ """
77+ discretization .fft .communicate_ghosts (x )
78+ discretization .apply_preconditioner_mugrid (preconditioner_Fourier_fnfnqks = preconditioner_fnfnqks ,
79+ input_nodal_field_fnxyz = x ,
80+ output_nodal_field_fnxyz = Px )
6781
68- M_fun = lambda x : discretization .apply_preconditioner_NEW (
69- preconditioner_Fourier_fnfnqks = preconditioner_fnfnqks ,
70- nodal_field_fnxyz = x )
7182
7283# set up load cases
7384nb_load_cases = 3
8091 [0.5 , .0 ]])
8192
8293left_macro_gradients = np .zeros ([nb_load_cases , dim , dim ])
83- # left_macro_gradients[0] = np.array([[.0, .0],
84- # [.0, 1.0]])
94+ left_macro_gradients [0 ] = np .array ([[.0 , .0 ],
95+ [.0 , 1.0 ]])
8596left_macro_gradients [1 ] = np .array ([[1.0 , .0 ],
8697 [.0 , .0 ]])
8798left_macro_gradients [2 ] = np .array ([[.0 , .5 ],
95106macro_gradient_fields_list = []
96107for load_case in np .arange (nb_load_cases ):
97108 macro_gradient_fields_list .append (discretization .get_gradient_size_field (name = f'macro_gradient_field_{ load_case } ' ))
98- macro_gradient_fields_list [ - 1 ] = discretization .get_macro_gradient_field (
109+ discretization .get_macro_gradient_field_mugrid (
99110 macro_gradient_ij = macro_gradients [load_case ],
100111 macro_gradient_field_ijqxyz = macro_gradient_fields_list [- 1 ])
101112 # macro_gradient_fields.append( discretization.get_macro_gradient_field(macro_gradients[load_case]))
175186def objective_function_multiple_load_cases (phase_field_1nxyz ):
176187 # print('Objective function:')
177188 # reshape the field
178- phase_field_1nxyz = phase_field_1nxyz .reshape ([1 , 1 , * discretization .nb_of_pixels ])
189+ phase_field_inxyz = discretization .get_scalar_field (name = 'phase_field_inxyz_ofmlc' )
190+ phase_field_inxyz .s = phase_field_1nxyz .reshape ([1 , 1 , * discretization .nb_of_pixels ])
179191
180192 # objective function phase field terms
181193 f_phase_field = topology_optimization .objective_function_phase_field (discretization = discretization ,
182- phase_field_1nxyz = phase_field_1nxyz ,
194+ phase_field_1nxyz = phase_field_inxyz ,
183195 eta = eta ,
184196 double_well_depth = double_well_depth_test )
185197 # sensitivity phase field terms
@@ -353,17 +365,23 @@ def objective_function_multiple_load_cases(phase_field_1nxyz):
353365
354366 # TODO CREATE random field from the same frequenciess all the same time
355367 def apply_filter (phase ):
356- f_field = discretization .fft .fft ( phase )
357- f_field [ 0 , 0 , np . logical_and ( np . abs ( discretization . fft . ifftfreq [ 0 ]) > 8 ,
358- np . abs ( discretization . fft . ifftfreq [ 1 ]) > 8 )] = 0
359- phase = discretization . fft . ifft ( f_field ) * discretization . fft . normalisation
360- phase [ phase > 1 ] = 1
361- phase [ phase < 0 ] = 0
362- return phase
368+ f_field = discretization .fft .fourier_space_field (
369+ unique_name = 'apply_filter_TO' , # name of the field
370+ shape = ( 1 ,))
371+
372+ # f_field = discretization.fft.fft(phase)
373+
374+ discretization . fft . fft ( phase , f_field )
363375
376+ f_field .s [0 , 0 , np .logical_and (np .abs (discretization .fft .ifftfreq [0 ]) > 8 ,
377+ np .abs (discretization .fft .ifftfreq [1 ]) > 8 )] = 0
378+ discretization .fft .ifft (f_field , phase )
379+ phase .s *= discretization .fft .normalisation
380+ phase .s [phase .s > 1 ] = 1
381+ phase .s [phase .s < 0 ] = 0
364382
365383 # phase = np.random.random(discretization.get_scalar_sized_field().shape)
366- phase_field_0 . s = apply_filter (phase_field_0 . s )
384+ apply_filter (phase_field_0 )
367385
368386 if MPI .COMM_WORLD .size == 1 :
369387 print ('rank' f'{ MPI .COMM_WORLD .rank :6} phase=' f'' )
@@ -375,15 +393,15 @@ def apply_filter(phase):
375393
376394 plt .show ()
377395
378- #phase_field_00 = np.copy(phase_field_0.s)
396+ # phase_field_00 = np.copy(phase_field_0.s)
379397 # my_sensitivity_pixel(phase_field_0).reshape([1, 1, *number_of_pixels])
380398
381399 test_init_phase_field = discretization .get_scalar_field (name = 'test_init_phase_field' )
382- test_init_phase_field .s = phase_field_0
400+ test_init_phase_field .s = phase_field_0 . s
383401 print ('Init objective function FE = {}' .format (
384- objective_function_multiple_load_cases (test_init_phase_field .s )[0 ]))
402+ objective_function_multiple_load_cases (test_init_phase_field .s . reshape ( - 1 ) )[0 ]))
385403 # print('Init objective function pixel = {}'.format(my_objective_function_pixel(phase_field_00)))
386- phase_field_0 = phase_field_0 . s . reshape ( - 1 ) # b
404+ # phase_field_0 = # b
387405
388406 if run_lbfg :
389407
@@ -414,7 +432,7 @@ def my_callback(result_norms):
414432
415433
416434 xopt_FE_MPI = Optimization .l_bfgs (fun = objective_function_multiple_load_cases ,
417- x = phase_field_0 ,
435+ x = phase_field_0 . s . reshape ( - 1 ) ,
418436 jac = True ,
419437 maxcor = 20 ,
420438 gtol = 1e-5 ,
0 commit comments