Beispiel #1
0
                                      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)
        swim_proc.MultiplyNodalVariableByFactor(fluid_model_part,
                                                MATERIAL_ACCELERATION,
                                                1.0 / module_mat_deriv)
        swim_proc.MultiplyNodalVariableByFactor(fluid_model_part,
                                                VELOCITY_LAPLACIAN,
                                                1.0 / module_laplacian)

        if norm_mat_deriv_average > 0. and norm_laplacian_average > 0:
            current_mat_deriv_errors[
                0] = error_mat_deriv / norm_mat_deriv_average
            current_mat_deriv_errors[
                1] = max_error_mat_deriv / norm_mat_deriv_average * len(
                    fluid_model_part.Nodes)
            current_laplacian_errors[
                0] = error_laplacian / norm_laplacian_average
            current_laplacian_errors[
                1] = max_error_laplacian / norm_laplacian_average * len(
Beispiel #2
0
    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)
    def CalculateRecoveryErrors(self, time):
        L2_norm_mat_deriv = 0.
        L2_norm_mat_deriv_error = 0.
        L2_norm_laplacian = 0.
        L2_norm_laplacian_error = 0.
        max_mat_deriv_error = 0.
        max_laplacian_error = 0.
        total_volume = 0.

        calc_mat_deriv = np.zeros(3)
        calc_laplacian = np.zeros(3)
        mat_deriv = Vector(3)
        laplacian = Vector(3)

        for node in self.fluid_model_part.Nodes:
            nodal_volume = node.GetSolutionStepValue(NODAL_AREA)
            total_volume += nodal_volume
            coor = Vector([node.X, node.Y, node.Z])

            self.flow_field.CalculateConvectiveDerivative(
                0., coor, mat_deriv, 0)
            self.flow_field.CalculateLaplacian(0., coor, laplacian, 0)
            calc_mat_deriv = node.GetSolutionStepValue(MATERIAL_ACCELERATION)
            calc_laplacian = node.GetSolutionStepValue(VELOCITY_LAPLACIAN)

            module_mat_deriv_squared = sum(x**2 for x in mat_deriv)
            module_laplacian_squared = sum(x**2 for x in laplacian)
            L2_norm_mat_deriv += module_mat_deriv_squared * nodal_volume
            L2_norm_laplacian += module_laplacian_squared * nodal_volume
            diff_mat_deriv = calc_mat_deriv - mat_deriv
            diff_laplacian = calc_laplacian - laplacian
            node.SetSolutionStepValue(VECTORIAL_ERROR,
                                      Vector(list(diff_mat_deriv)))
            node.SetSolutionStepValue(VECTORIAL_ERROR_1,
                                      Vector(list(diff_laplacian)))
            module_mat_deriv_error_squared = sum(x**2 for x in diff_mat_deriv)
            module_laplacian_error_squared = sum(x**2 for x in diff_laplacian)
            L2_norm_mat_deriv_error += module_mat_deriv_error_squared * nodal_volume
            L2_norm_laplacian_error += module_laplacian_error_squared * nodal_volume
            max_mat_deriv_error = max(max_mat_deriv_error,
                                      module_mat_deriv_error_squared)
            max_laplacian_error = max(max_laplacian_error,
                                      module_laplacian_error_squared)

        L2_norm_mat_deriv **= 0.5
        L2_norm_mat_deriv /= total_volume**0.5
        L2_norm_mat_deriv_error **= 0.5
        L2_norm_mat_deriv_error /= total_volume**0.5
        L2_norm_laplacian **= 0.5
        L2_norm_laplacian /= total_volume**0.5
        L2_norm_laplacian_error **= 0.5
        L2_norm_laplacian_error /= total_volume**0.5
        max_mat_deriv_error **= 0.5
        max_laplacian_error **= 0.5

        if L2_norm_mat_deriv > 0 and L2_norm_laplacian > 0:
            SDP.MultiplyNodalVariableByFactor(self.fluid_model_part,
                                              VECTORIAL_ERROR,
                                              1.0 / L2_norm_mat_deriv)
            SDP.MultiplyNodalVariableByFactor(self.fluid_model_part,
                                              VECTORIAL_ERROR_1,
                                              1.0 / L2_norm_laplacian)
            self.current_mat_deriv_errors[
                0] = L2_norm_mat_deriv_error / L2_norm_mat_deriv
            self.current_mat_deriv_errors[
                1] = max_mat_deriv_error / L2_norm_mat_deriv
            self.current_laplacian_errors[
                0] = L2_norm_laplacian_error / L2_norm_laplacian
            self.current_laplacian_errors[
                1] = max_laplacian_error / L2_norm_laplacian
            self.mat_deriv_errors.append(self.current_mat_deriv_errors)
            self.laplacian_errors.append(self.current_laplacian_errors)

            text_width = 40
            print('\n' + '-.' * text_width)
            print('L2 error for the material derivative'.ljust(text_width),
                  self.current_mat_deriv_errors[0])
            print('max error for the material derivative'.ljust(text_width),
                  self.current_mat_deriv_errors[1])
            print('L2 error for the laplacian'.ljust(text_width),
                  self.current_laplacian_errors[0])
            print('max error for the laplacian'.ljust(text_width),
                  self.current_laplacian_errors[1])
            print('-.' * text_width + '\n')