import tensorflow.compat.v1 as tf tf.disable_v2_behavior() import numpy as np pi = np.pi sin = np.sin cos = np.cos exp = np.exp sh = np.shape reshape = np.reshape #%% VarNet import from Domain import Domain1D from ADPDE import ADPDE from UtilityFunc import UF uf = UF() sess = tf.Session() from TF_ELM.base_elm import TF_ELM #%% 1D AD-PDE: closed-form solution u = 1.0 # velocity magnitude D = 0.1 / pi # diffusivity T = 2.0 # maximum time bound tlim = [0, T] # time limits # Domain limits: interval = np.array([-1.0, 1.0]) lim = reshape(interval, [2, 1])
import numpy as np pi = np.pi sin = np.sin cos = np.cos exp = np.exp shape = np.shape reshape = np.reshape from Domain import Domain1D from ContourPlot import ContourPlot from ADPDE import ADPDE from VarNet import VarNet from UtilityFunc import UF uf = UF() import matplotlib.pyplot as plt from IPython import get_ipython get_ipython().run_line_magic('matplotlib', 'inline') #%% PDE input data: u = 1.0 # velocity magnitude D = 0.1 / pi # diffusivity T = 2.0 # maximum simulation time # Initial condition: def IC(x):
""" #%% Modules: import numpy as np shape = np.shape reshape = np.reshape size = np.size import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras import layers from tensorflow.python.client import device_lib from UtilityFunc import UF uf = UF() #%% Data Parallelism (Replicated Training) class TFNN(): """ Class to construct the tensorflow computational graph and models accross devices. Attributes: dim inpDim seqLen depth layerWidth modelId
import numpy as np pi = np.pi sin = np.sin cos = np.cos exp = np.exp shape = np.shape reshape = np.reshape from Domain import Domain1D from ContourPlot import ContourPlot from ADPDE import ADPDE from MOR import MOR from VarNet import VarNet from UtilityFunc import UF uf = UF() import matplotlib.pyplot as plt from IPython import get_ipython get_ipython().run_line_magic('matplotlib', 'inline') #%% PDE input data: u = 1.0 # velocity magnitude T = 2.0 # maximum simulation time def diffFun(x, t=0, D=0.1/pi): """Diffusivity field function.""" return D*np.ones([shape(x)[0], 1]) def IC(x):
functions for a 2D unstructured field which is the solution of the Advection-Diffusion PDE. Different methods are compared in terms of accuracy and speed. To see the results simply run the code in a Python console. For details on the interpolation functions, see the manual at: https://docs.scipy.org/doc/scipy/reference/interpolate.html """ import time import numpy as np import scipy.io as spio from scipy import interpolate from Domain import PolygonDomain2D from ContourPlot import ContourPlot from UtilityFunc import UF uf = UF() import matplotlib.pyplot as plt from IPython import get_ipython get_ipython().run_line_magic('matplotlib', 'inline') #%% Data: mat = spio.loadmat('coord.mat') coord = mat['coord'] # coordinates # Exact concentration field: mat = spio.loadmat('cEx.mat') cEx = mat['cEx'] cEx = cEx.todense()
shape = np.shape reshape = np.reshape sin = np.sin cos = np.cos exp = np.exp pi = np.pi from scipy import special erf = special.erf # error function from Domain import PolygonDomain2D from ContourPlot import ContourPlot from ADPDE import ADPDE from VarNet import VarNet from UtilityFunc import UF uf = UF() import matplotlib.pyplot as plt # from IPython import get_ipython # get_ipython().run_line_magic('matplotlib', 'inline') #%% PDE input data: #lim = np.array([[0, -0.5], [2, 0.5]]) # spatial domain boundaries T = 1.5 # maximum simulation time q = [1., 0.] # velocity magnitude kappa = 1.e-3 # diffusivity c0 = 1.0 # concentration value on x=0, |y|<a a = 0.2 # bounds on the concentration BC nt = 151 # time discretization number for results