Skip to content

Commit

Permalink
Merge pull request #4 from cmgcds/inverse_problems
Browse files Browse the repository at this point in the history
Added examples for solving inverse problems using FastVPINNs.
  • Loading branch information
thivinanandh authored Apr 24, 2024
2 parents bd8fa89 + 32f1f2e commit 3d84a48
Show file tree
Hide file tree
Showing 11 changed files with 4,546 additions and 1 deletion.
92 changes: 92 additions & 0 deletions examples/inverse_problems_2d/cd2d/cd2d_inverse_circle_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Example file for the poisson problem
# Path: examples/poisson.py
# file contains the exact solution, rhs and boundary conditions for the poisson problem
# Actual Solution : sin(X) * cos(Y) * exp(-1.0 * eps * (X**2 + Y**2))
import numpy as np
import tensorflow as tf




def left_boundary(x, y):
"""
This function will return the boundary value for given component of a boundary
"""
val = np.ones_like(x) * 0.0
return val

def right_boundary(x, y):
"""
This function will return the boundary value for given component of a boundary
"""
val = np.ones_like(x) * 0.0
return val

def top_boundary(x, y):
"""
This function will return the boundary value for given component of a boundary
"""
val = np.ones_like(x) * 0.0
return val

def bottom_boundary(x, y):
"""
This function will return the boundary value for given component of a boundary
"""
val = np.ones_like(x) * 0.0
return val

def rhs(x, y):
"""
This function will return the value of the rhs at a given point
"""

# return -y * np.sin(x * y) * np.tanh(8 * x * y) + 8 * y * np.cos(x * y) / np.cosh(8 * x * y)**2 + 10 * (x**2 + y**2) * \
# (16 * np.sin(x * y) / np.cosh(8 * x * y)**2 + np.cos(x * y) * np.tanh(8 * x * y) + 128 * np.cos(x * y) * np.tanh(8 * x * y) / np.cosh(8 * x * y)**2) * np.sin(x) * np.cos(y)


return 10.0 * np.ones_like(x)


def exact_solution(x, y):
"""
This function will return the exact solution at a given point
"""

val = np.ones_like(x) * 0.0

return val

def get_boundary_function_dict():
"""
This function will return a dictionary of boundary functions
"""
return {1000: bottom_boundary, 1001: right_boundary, 1002: top_boundary, 1003: left_boundary}

def get_bound_cond_dict():
"""
This function will return a dictionary of boundary conditions
"""
return {1000: "dirichlet", 1001: "dirichlet", 1002: "dirichlet", 1003: "dirichlet"}

def get_bilinear_params_dict():
"""
This function will return a dictionary of bilinear parameters
"""

eps = 0.1 # will not be used in the loss function, as it will be replaced by the predicted value of NN
b1 = 1
b2 = 0
c = 0.0

return {"eps": eps, "b_x": b1, "b_y": b2, "c": c}



def get_inverse_params_actual_dict(x, y):
"""
This function will return a dictionary of inverse parameters
"""
# Initial Guess
eps = 0.5 * (np.sin(x) + np.cos(y))
return {"eps": eps}
2,252 changes: 2,252 additions & 0 deletions examples/inverse_problems_2d/cd2d/circle_quad.mesh

Large diffs are not rendered by default.

1,090 changes: 1,090 additions & 0 deletions examples/inverse_problems_2d/cd2d/fem_output_circle2.csv

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions examples/inverse_problems_2d/cd2d/input_inverse_domain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# input file for inverse problems (domain)
experimentation:
output_path: "output/inverse/circle_1"

geometry:
mesh_generation_method: "external"
internal_mesh_params:
x_min: 0
x_max: 1
y_min: 0
y_max: 1
n_cells_x: 20
n_cells_y: 20
n_boundary_points: 1500
n_test_points_x: 100
n_test_points_y: 100

mesh_type: "quadrilateral"
external_mesh_params:
mesh_file_name: "circle_quad.mesh" # should be a .mesh file
boundary_refinement_level: 2
boundary_sampling_method: "uniform" # "uniform" or "lhs"

fe:
fe_order: 3
fe_type: "jacobi" #"parmoon", "legendre" and "legendre".
quad_order: 5
quad_type: "gauss-jacobi" # "gauss-jacobi, gauss-legendre, gauss-lobatto"

pde:
beta: 10
model:
model_architecture: [2, 30,30,30, 2] # output is made as 2 to accomodate the inverse param in the output
activation: "tanh"
use_attention: False
epochs: 50000
dtype: "float32"
set_memory_growth: True
learning_rate:
initial_learning_rate: 0.003
use_lr_scheduler: False
decay_steps: 1000
decay_rate: 0.98
staircase: True

logging:
update_progress_bar: 100
update_console_output: 5000
update_solution_images: 5000

inverse:
num_sensor_points: 500

sensor_data_file: "fem_output_circle2.csv"

wandb:
use_wandb: True
project_name: "New_Inverse_Complex_updated"
wandb_run_prefix: "Test_Gear"
entity: "starslab-iisc"

additional:
run_by: "Divij"
System: "23"

Loading

0 comments on commit 3d84a48

Please sign in to comment.