def CalculateRecoveryErrors(self, time): error_mat_deriv = 0. max_error_mat_deriv = - float('inf') error_laplacian = 0. max_error_laplacian = - float('inf') total_volume = 0. mat_deriv_average = Vector(3) laplacian_average = Vector(3) for k in range(3): mat_deriv_average[k] = 0.0 laplacian_average[k] = 0.0 norm_mat_deriv_average = 0. norm_laplacian_average = 0. module_mat_deriv = 0. module_laplacian = 0. fluid_model_part = self.all_model_parts.Get('FluidPart') for i_node, node in enumerate(fluid_model_part.Nodes): calc_mat_deriv = [0.] * 3 calc_laplacian = [0.] * 3 mat_deriv= Vector(3) laplacian= Vector(3) coor= Vector(3) coor[0]=node.X coor[1]=node.Y coor[2]=node.Z self.flow_field.CalculateMaterialAcceleration(time, coor, mat_deriv, 0) self.flow_field.CalculateLaplacian(time, coor, laplacian, 0) calc_mat_deriv[0] = node.GetSolutionStepValue(MATERIAL_ACCELERATION_X) calc_mat_deriv[1] = node.GetSolutionStepValue(MATERIAL_ACCELERATION_Y) calc_mat_deriv[2] = node.GetSolutionStepValue(MATERIAL_ACCELERATION_Z) calc_laplacian[0] = node.GetSolutionStepValue(VELOCITY_LAPLACIAN_X) calc_laplacian[1] = node.GetSolutionStepValue(VELOCITY_LAPLACIAN_Y) calc_laplacian[2] = node.GetSolutionStepValue(VELOCITY_LAPLACIAN_Z) module_mat_deriv += math.sqrt(calc_mat_deriv[0] ** 2 + calc_mat_deriv[1] ** 2 + calc_mat_deriv[2] ** 2) module_laplacian += math.sqrt(calc_laplacian[0] ** 2 + calc_laplacian[1] ** 2 + calc_laplacian[2] ** 2) #module_mat_deriv = max(math.sqrt(mat_deriv[0] ** 2 + mat_deriv[1] ** 2 + mat_deriv[2] ** 2), 1e-8) #module_laplacian = max(math.sqrt(laplacian[0] ** 2 + laplacian[1] ** 2 + laplacian[2] ** 2), 1e-8) #laplacian[0] = 14 #laplacian[1] = 2 #laplacian[2] = 0 #nodal_volume = node.GetSolutionStepValue(NODAL_AREA) #total_volume += nodal_volume current_error = SDP.NormOfDifference(calc_mat_deriv, mat_deriv) error_mat_deriv += current_error max_error_mat_deriv = max(max_error_mat_deriv, current_error) current_error = SDP.NormOfDifference(calc_laplacian, laplacian) error_laplacian += current_error max_error_laplacian = max(max_error_laplacian, current_error) diff_mat_deriv = [calc_mat_deriv[i] - mat_deriv[i] for i in range(len(calc_mat_deriv))] diff_laplacian = [calc_laplacian[i] - laplacian[i] for i in range(len(calc_laplacian))] #mat_deriv_averager.SDP.Norm(diff_mat_deriv) #laplacian_averager.SDP.Norm(diff_laplacian) #for k in range(3): #mat_deriv_average[k] += mat_deriv[k] #laplacian_average[k] += laplacian[k] norm_mat_deriv_average += SDP.Norm(mat_deriv) norm_laplacian_average += SDP.Norm(laplacian) node.SetSolutionStepValue(VELOCITY_LAPLACIAN_RATE_X, calc_mat_deriv[0] - mat_deriv[0]) node.SetSolutionStepValue(VELOCITY_LAPLACIAN_RATE_Y, calc_mat_deriv[1] - mat_deriv[1]) node.SetSolutionStepValue(VELOCITY_LAPLACIAN_RATE_Z, calc_mat_deriv[2] - mat_deriv[2]) #node.SetSolutionStepValue(MATERIAL_ACCELERATION_X, mat_deriv[0]) #node.SetSolutionStepValue(MATERIAL_ACCELERATION_Y, mat_deriv[1]) #node.SetSolutionStepValue(MATERIAL_ACCELERATION_Z, mat_deriv[2]) node.SetSolutionStepValue(VELOCITY_LAPLACIAN_X, calc_laplacian[0] - laplacian[0]) node.SetSolutionStepValue(VELOCITY_LAPLACIAN_Y, calc_laplacian[1] - laplacian[1]) node.SetSolutionStepValue(VELOCITY_LAPLACIAN_Z, calc_laplacian[2] - laplacian[2]) #node.SetSolutionStepValue(VELOCITY_LAPLACIAN_X, calc_laplacian_0) #node.SetSolutionStepValue(VELOCITY_LAPLACIAN_Y, calc_laplacian_1) #node.SetSolutionStepValue(VELOCITY_LAPLACIAN_Z, calc_laplacian_2) #node.SetSolutionStepValue(VELOCITY_LAPLACIAN_X, laplacian[0]) #node.SetSolutionStepValue(VELOCITY_LAPLACIAN_Y, laplacian[1]) #node.SetSolutionStepValue(VELOCITY_LAPLACIAN_Z, laplacian[2]) module_mat_deriv /= len(fluid_model_part.Nodes) module_laplacian /= len(fluid_model_part.Nodes) SDP.MultiplyNodalVariableByFactor(fluid_model_part, VELOCITY_LAPLACIAN_RATE, 1.0 / module_mat_deriv) SDP.MultiplyNodalVariableByFactor(fluid_model_part, VELOCITY_LAPLACIAN, 1.0 / module_laplacian) if norm_mat_deriv_average > 0. and norm_laplacian_average > 0: self.current_mat_deriv_errors[0] = error_mat_deriv / norm_mat_deriv_average self.current_mat_deriv_errors[1] = max_error_mat_deriv / norm_mat_deriv_average * len(fluid_model_part.Nodes) self.current_laplacian_errors[0] = error_laplacian / norm_laplacian_average self.current_laplacian_errors[1] = max_error_laplacian / norm_laplacian_average * len(fluid_model_part.Nodes) self.mat_deriv_errors.append(self.current_mat_deriv_errors) self.laplacian_errors.append(self.current_laplacian_errors) #print('mat_deriv: min, max, avg, ', mat_deriv_averager.GetCurrentData()) #print('laplacian: min, max, avg, ', laplacian_averager.GetCurrentData()) print('rel_error_mat_deriv', error_mat_deriv / norm_mat_deriv_average) print('rel_error_laplacian', error_laplacian / norm_laplacian_average)
error_laplacian += current_error max_error_laplacian = max(max_error_laplacian, current_error) diff_mat_deriv = [ calc_mat_deriv[i] - mat_deriv[i] for i in range(len(calc_mat_deriv)) ] diff_laplacian = [ calc_laplacian[i] - laplacian[i] for i in range(len(calc_laplacian)) ] #mat_deriv_averager.swim_proc.Norm(diff_mat_deriv) #laplacian_averager.swim_proc.Norm(diff_laplacian) #for k in range(3): #mat_deriv_average[k] += mat_deriv[k] #laplacian_average[k] += laplacian[k] norm_mat_deriv_average += swim_proc.Norm(mat_deriv) norm_laplacian_average += swim_proc.Norm(laplacian) node.SetSolutionStepValue(MATERIAL_ACCELERATION_X, calc_mat_deriv[0] - mat_deriv[0]) node.SetSolutionStepValue(MATERIAL_ACCELERATION_Y, calc_mat_deriv[1] - mat_deriv[1]) node.SetSolutionStepValue(MATERIAL_ACCELERATION_Z, calc_mat_deriv[2] - mat_deriv[2]) #node.SetSolutionStepValue(MATERIAL_ACCELERATION_X, mat_deriv[0]) #node.SetSolutionStepValue(MATERIAL_ACCELERATION_Y, mat_deriv[1]) #node.SetSolutionStepValue(MATERIAL_ACCELERATION_Z, mat_deriv[2]) node.SetSolutionStepValue(VELOCITY_LAPLACIAN_X, calc_laplacian[0] - laplacian[0]) node.SetSolutionStepValue(VELOCITY_LAPLACIAN_Y,