Skip to content

Commit

Permalink
Updated Domain inverse
Browse files Browse the repository at this point in the history
- USA Problem with forward problem and inverse problem
  • Loading branch information
thivinanandh committed Aug 2, 2024
1 parent e4f0f9a commit a6c5d15
Show file tree
Hide file tree
Showing 5 changed files with 7,452 additions and 3,050 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def usa_boundary(x, y):
"""
This function will return the boundary value for given component of a boundary
"""
val = 20 * np.exp(-0.1 * y) * np.cos(x)
# val = 20 * np.exp(-0.1 * y) * np.cos(x)
val = np.exp(-0.1 * y) * np.cos(x)

return val


Expand All @@ -22,15 +24,25 @@ def rhs(x, y):
# 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 (196.0 - 396.0 * np.sin(x) ** 2) * np.exp(-0.2 * y)
# return (196.0 - 396.0 * np.sin(x) ** 2) * np.exp(-0.2 * y)

return (
(
-0.1 * x * np.sin(x * y) * np.cos(x)
- y * np.sin(x) * np.sin(x * y)
+ 1.99 * np.cos(x) * np.cos(x * y)
)
* np.exp(-0.1 * y)
* np.sin(x)
)


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

val = 20 * np.exp(-0.1 * y) * np.cos(x)
val = np.exp(-0.1 * y) * np.cos(x)

return val

Expand Down Expand Up @@ -67,5 +79,5 @@ def get_inverse_params_actual_dict(x, y):
This function will return a dictionary of inverse parameters
"""
# Initial Guess
eps = 10 * np.exp(-0.1 * y) * np.cos(x)
eps = np.sin(x) * np.cos(x * y)
return {"eps": eps}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# input file for inverse problems (domain)
experimentation:
output_path: "output/usa"
output_path: "output/usa_2"

geometry:
mesh_generation_method: "external"
Expand All @@ -22,18 +22,18 @@ geometry:
boundary_sampling_method: "uniform" # "uniform"

fe:
fe_order: 5
fe_order: 4
fe_type: "jacobi" #"jacobi"
quad_order: 5
quad_type: "gauss-jacobi" # "gauss-jacobi,

pde:
beta: 10
model:
model_architecture: [2, 30,30,30,30, 2] # output is made as 2 to accomodate the inverse param in the output
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: 100000
epochs: 20000
dtype: "float32"
set_memory_growth: True
learning_rate:
Expand Down
35 changes: 32 additions & 3 deletions examples/inverse_problems_2d/domain_inverse_cd2d/USA/rhs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"x, y, u, eps = sp.symbols('x y u eps')\n",
"\n",
"# Define the function\n",
"u = 20 * sp.exp (-0.1 * y) * sp.cos (x)\n",
"eps = 10 * sp.cos(x) * sp.exp(-0.1 * y)\n",
"u = sp.exp (-0.1 * y) * sp.cos (x)\n",
"eps = sp.cos(x*y) * sp.sin(x)\n",
"# compute the gradients\n",
"u_x = sp.diff(u, x)\n",
"u_y = sp.diff(u, y)\n",
Expand All @@ -38,7 +38,36 @@
"import inspect\n",
"\n",
"# obtain the source code of the function\n",
"print(inspect.getsource(f_func))\n"
"source_code = inspect.getsource(f_func)\n",
"\n",
"# create a dictionary \n",
"\n",
"replace_dict = {\"exp\": \"np.exp\", \"cos\": \"np.cos\", \"sin\": \"np.sin\", \"sqrt\": \"np.sqrt\", \"log\": \"np.log\"}\n",
"\n",
"# replace the keys with the values in the source code\n",
"for key, value in replace_dict.items():\n",
" source_code = source_code.replace(key, value)\n",
"\n",
"# print the source code\n",
"print(source_code)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = np.linspace(-1, 1, 100)\n",
"y = np.linspace(-1, 1, 100)\n",
"\n",
"X, Y = np.meshgrid(x, y)\n",
"\n",
"U = np.cos(X*Y) * np.sin(X)\n",
"\n",
"plt.contourf(X, Y, U)\n",
"plt.colorbar()\n",
"plt.show()"
]
},
{
Expand Down
Loading

0 comments on commit a6c5d15

Please sign in to comment.