39 int j_evaluation, j_parameter;
41 if (
verbose > 0) std::cout <<
"Hello from finite_difference_Jacobian from proc " << mpi_rank_world << std::endl;
46 MPI_Bcast(&data,1,MPI_INT,0,mpi_comm_group_leaders);
54 MPI_Bcast(state_vector_copy,
N_parameters, MPI_DOUBLE, 0, mpi_comm_group_leaders);
63 double* perturbed_state_vector =
new double[
N_parameters];
64 double* residual_functions =
new double[N_terms * N_evaluations];
65 double* state_vectors =
new double[
N_parameters * N_evaluations];
67 memset(base_case_residual_function, 0, N_terms*
sizeof(
double));
68 memset(residual_functions, 0, N_terms * N_evaluations*
sizeof(
double));
71 for (j_evaluation = 1; j_evaluation <= N_evaluations; j_evaluation++) {
72 memcpy(perturbed_state_vector, state_vector_copy,
N_parameters*
sizeof(
double));
73 if (j_evaluation == 1) {
85 if (proc0_world && (
verbose > 0)) {
86 std::cout <<
"Here comes state_vectors:" << std::endl;
87 for(j_parameter=0; j_parameter<
N_parameters; j_parameter++) {
88 for(j_evaluation=0; j_evaluation<N_evaluations; j_evaluation++) {
89 std::cout << std::setw(25) << std::setprecision(15) << state_vectors[j_evaluation*
N_parameters + j_parameter];
91 std::cout << std::endl;
96 bool* failures =
new bool[N_evaluations];
102 memcpy(base_case_residual_function, residual_functions, N_terms*
sizeof(
double));
104 for (j_parameter=0; j_parameter<
N_parameters; j_parameter++) {
105 for (
int j_term=0; j_term<N_terms; j_term++) {
106 Jacobian[j_parameter*N_terms+j_term] = (residual_functions[(j_parameter+1)*N_terms+j_term] - residual_functions[(j_parameter+1+
N_parameters)*N_terms+j_term])
112 for (j_parameter=0; j_parameter<
N_parameters; j_parameter++) {
113 for (
int j_term=0; j_term<N_terms; j_term++) {
114 Jacobian[j_parameter*N_terms+j_term] = (residual_functions[(j_parameter+1)*N_terms+j_term] - base_case_residual_function[j_term]) /
finite_difference_step_size;
120 delete[] perturbed_state_vector;
121 delete[] residual_functions;
122 delete[] state_vectors;
123 delete[] state_vector_copy;
125 if (proc0_world && (
verbose > 0)) {
126 std::cout <<
"Here comes finite-difference Jacobian:" << std::endl;
127 for (
int j_term=0; j_term<N_terms; j_term++) {
128 for (j_parameter=0; j_parameter<
N_parameters; j_parameter++) {
129 std::cout << std::setw(25) << std::setprecision(15) << Jacobian[j_parameter*N_terms+j_term];
131 std::cout << std::endl;