Skip to content

Commit

Permalink
Saddle point in work [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
niravshah241 committed Oct 24, 2024
1 parent 9b8c484 commit e6b4434
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions demo/saddle_point_dlrbnicsx/dlrbnicsx_saddle_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,3 +772,57 @@ def generate_ann_output_set(problem, reduced_problem, input_set, mode=None):
output_range=reduced_problem.output_range_u,
index=1, verbose=True)
print(f"Error (U): {error_numpy_sigma[i]}")

# Online phase
# Define a parameter
online_mu = np.array([-2.3, 0.47, 0.57, 0.67, 3.4])

# Compute FEM solution
solution_sigma, solution_u = problem_parametric.solve(online_mu)

# Compute RB solution
rb_solution_sigma = \
reduced_problem.reconstruct_solution_sigma(online_nn(reduced_problem,
problem_parametric,
online_mu, model_sigma,
len(reduced_problem._basis_functions_sigma),
input_scaling_range=reduced_problem.input_scaling_range,
output_scaling_range=reduced_problem.output_scaling_range_sigma,
input_range=reduced_problem.input_range,
output_range=reduced_problem.output_range_sigma))

rb_solution_u = \
reduced_problem.reconstruct_solution_u(online_nn(reduced_problem,
problem_parametric,
online_mu, model_u,
len(reduced_problem._basis_functions_u),
input_scaling_range=reduced_problem.input_scaling_range,
output_scaling_range=reduced_problem.output_scaling_range_u,
input_range=reduced_problem.input_range,
output_range=reduced_problem.output_range_u))

solution_sigma_error = dolfinx.fem.Function(problem_parametric._Q)
solution_sigma_error.x.array[:] = abs(solution_sigma.x.array - rb_solution_sigma.x.array)

solution_u_error = dolfinx.fem.Function(problem_parametric._W)
solution_u_error.x.array[:] = abs(solution_u.x.array - rb_solution_u.x.array)

with dolfinx.io.XDMFFile(mesh.comm, "dlrbnicsx_solution/fem_sigma_online_mu.xdmf",
"w") as solution_file:
solution_file.write_mesh(mesh)
solution_file.write_function(solution_sigma)

with dolfinx.io.XDMFFile(mesh.comm, "dlrbnicsx_solution/rb_sigma_online_mu.xdmf",
"w") as solution_file:
solution_file.write_mesh(mesh)
solution_file.write_function(rb_solution_sigma)

with dolfinx.io.XDMFFile(mesh.comm, "dlrbnicsx_solution/fem_u_online_mu.xdmf",
"w") as solution_file:
solution_file.write_mesh(mesh)
solution_file.write_function(solution_u)

with dolfinx.io.XDMFFile(mesh.comm, "dlrbnicsx_solution/rb_u_online_mu.xdmf",
"w") as solution_file:
solution_file.write_mesh(mesh)
solution_file.write_function(rb_solution_u)

0 comments on commit e6b4434

Please sign in to comment.