def Predict(self):
        for i, data_entry in enumerate(self.settings["data_list"]):
            solver = self.solvers[data_entry["solver"]]
            data_name = data_entry["data_name"]
            cs_tools.ImportArrayFromSolver(solver, data_name,
                                           self.data_arrays_prediction[i], 0)
            cs_tools.ImportArrayFromSolver(solver, data_name,
                                           self.data_arrays_aux[i], 1)

            self.data_arrays_prediction[i] = 2 * self.data_arrays_prediction[
                i] - self.data_arrays_aux[i]

        self._UpdateData(self.data_arrays_prediction)
    def Predict(self):
        for i, data_entry in enumerate(self.settings["data_list"]):
            solver = self.solvers[data_entry["solver"]]
            data_name = data_entry["data_name"]
            deriv_data_name = data_entry["derivative_data_name"]
            cs_tools.ImportArrayFromSolver(solver, deriv_data_name,
                                           self.derivative_data_arrays[i], 1)
            cs_tools.ImportArrayFromSolver(solver, data_name,
                                           self.data_arrays[i], 1)

            self.data_arrays[i] += solver.GetDeltaTime(
            ) * self.derivative_data_arrays[i]

        self._UpdateData(self.data_arrays)
    def IsConverged(self):
        convergence_list = []
        for i, data_entry in enumerate(self.settings["data_list"]):
            solver = self.solvers[data_entry["solver"]]
            data_name = data_entry["data_name"]
            cs_tools.ImportArrayFromSolver(solver, data_name, self.new_data)

            residual = self.new_data - self.old_data[i]
            res_norm = la.norm(residual)
            norm_new_data = la.norm(self.new_data)
            if norm_new_data < 1e-15:
                norm_new_data = 1.0 # to avoid division by zero
            abs_norm = res_norm / np.sqrt(residual.size)
            rel_norm = res_norm / norm_new_data
            convergence_list.append(abs_norm < self.abs_tolerances[i] or rel_norm < self.rel_tolerances[i])
            if self.echo_level > 1:
                info_msg  = 'Convergence for "'+bold(data_entry["data_name"])+'": '
                if convergence_list[i]:
                    info_msg += green("ACHIEVED")
                else:
                    info_msg += red("NOT ACHIEVED")
                classprint(self.lvl, self._Name(), info_msg)
            if self.echo_level > 2:
                info_msg  = bold("abs_norm")+" = " + str(abs_norm) + " | "
                info_msg += bold("abs_tol")+" = " + str(self.abs_tolerances[i])
                info_msg += " || "+bold("rel_norm")+" = " + str(rel_norm) + " | "
                info_msg += bold("rel_tol") +" = " + str(self.rel_tolerances[i])
                classprint(self.lvl, self._Name(), info_msg)

        return min(convergence_list) # return false if any of them did not converge!
    def FinalizeSolutionStep(self):
        for i, data_entry in enumerate(self.settings["data_list"]):
            solver = self.solvers[data_entry["solver"]]
            data_name = data_entry["data_name"]
            cs_tools.ImportArrayFromSolver(solver, data_name,
                                           self.data_arrays_aux[i], 0)

            self.data_arrays_prediction[i] = self.beta * self.data_arrays_aux[
                i] + (1 - self.beta) * self.data_arrays_prediction[i]

        self._UpdateData(self.data_arrays_prediction)
    def InitializeNonLinearIteration(self):
        # Saving the previous data for the computation of the residual
        # and the computation of the solution update
        self.data_sizes = [
        ]  # saving the sizes of the data to later split them again
        size_counter = 0
        for i, data_entry in enumerate(self.settings["data_list"]):
            solver = self.solvers[data_entry["solver"]]
            data_name = data_entry["data_name"]
            cs_tools.ImportArrayFromSolver(solver, data_name, self.arrays[i])

            size_counter += self.arrays[i].size
            self.data_sizes.append(size_counter)

        self.combined_prev_data = np.concatenate(self.arrays)
Ejemplo n.º 6
0
    def ImportData(self, data_settings, from_client):
        data_name = data_settings["data_name"]
        io_settings = data_settings["io_settings"]
        data_array = np.array([])
        cs_tools.ImportArrayFromSolver(from_client, data_name, data_array)

        sdof_solver = self.solvers[self.solver_name]
        sdof_data_settings = sdof_solver.GetDataDefinition(
            data_settings["data_name"])

        value = sum(data_array)

        if "io_options" in io_settings:
            if "swap_sign" in io_settings["io_options"]:
                value *= -1.0

        data_identifier = sdof_data_settings["data_identifier"]
        sdof_solver.SetData(data_identifier, value)
    def ComputeUpdate(self):
        for i, data_entry in enumerate(self.settings["data_list"]):
            solver = self.solvers[data_entry["solver"]]
            data_name = data_entry["data_name"]
            cs_tools.ImportArrayFromSolver(solver, data_name, self.arrays[i])

        combined_residuals = np.concatenate(
            self.arrays) - self.combined_prev_data

        combined_new_data = self.combined_prev_data + self._ComputeUpdate(
            combined_residuals, self.combined_prev_data)

        updated_data = np.split(combined_new_data, self.data_sizes)

        for data_entry, data_update in zip(self.settings["data_list"],
                                           updated_data):
            solver = self.solvers[data_entry["solver"]]
            data_name = data_entry["data_name"]
            cs_tools.ExportArrayToSolver(solver, data_name, data_update)
 def InitializeNonLinearIteration(self):
     # Saving the previous data (at beginning of iteration) for the computation of the residual
     for i, data_entry in enumerate(self.settings["data_list"]):
         solver = self.solvers[data_entry["solver"]]
         data_name = data_entry["data_name"]
         cs_tools.ImportArrayFromSolver(solver, data_name, self.old_data[i])