1D Case - Figure 9#
Comparison of the displacement and strain solutions computed on r-adapted mesh with the analytical reference. The trajectory maps of the mesh nodes are also shown.
The computation is performed using both the trapezoidal rule and the Gauss quadrature rule.
#%% Libraries import
# import HiDeNN library
import sys
# sys.path.append("../neurom/")
from neurom.HiDeNN_PDE import MeshNN, NeuROM, MeshNN_2D, MeshNN_1D
# Import pre-processing functions
import neurom.src.Pre_processing as pre
# Import torch librairies
import torch
import torch.nn as nn
# Import Training funcitons
from neurom.src.Training import Training_1D_FEM_LBFGS
#Import post processing libraries
import neurom.Post.Plots as Pplot
import time
import os
import torch._dynamo as dynamo
mps_device = torch.device("mps")
from importlib import reload # Python 3.4+
import tomllib
import numpy as numpy
import argparse
* Executing job in Configuration/config_2D.toml
* WARNING: could not load tikzplotlib
# Load default configuration file (defines dimension, domain, boundary conditions, number of training iterations etc.)
Default_config_file = 'Configurations/config_1D.toml'
with open(Default_config_file, mode="rb") as f:
config = tomllib.load(f)
# Experiment setting: mesh with 14 nodes, Trapezoidal rule and Gauss quadrature, r-adaptive mesh
mesh_resolution = 14
quadrature_points = 5
training_points = 30
integration_method = ["Trapezoidal", "Gaussian_quad"]
config["interpolation"]["np"] = mesh_resolution
config["postprocess"]["Show_Trajectories"] = "True"
config["solver"]["FrozenMesh"] = False
for m in range(len(integration_method)):
config["solver"]["IntegralMethod"] = integration_method[m]
if config["solver"]["IntegralMethod"] == "Gaussian_quad":
config["interpolation"]["n_integr_points"] = quadrature_points
elif config["solver"]["IntegralMethod"] == "Trapezoidal":
config["training"]["Points_per_element"] = training_points
# Load parameters
if config["interpolation"]["dimension"] == 1:
Mat = pre.Material( flag_lame = True, # If True should input lmbda and mu instead of E and nu
coef1 = config["material"]["E"], # Young Modulus
coef2 = config["geometry"]["A"] # Section area of the 1D bar
)
elif config["interpolation"]["dimension"] == 2:
try:
Mat = pre.Material( flag_lame = False, # If True should input lmbda and mu instead of E and nu
coef1 = config["material"]["E"], # Young Modulus
coef2 = config["material"]["nu"] # Poisson's ratio
)
except:
Mat = pre.Material( flag_lame = True, # If True should input lmbda and mu instead of E and nu
coef1 = config["material"]["lmbda"], # First Lame's coef
coef2 = config["material"]["mu"] # Second Lame's coef
)
MaxElemSize = pre.ElementSize(
dimension = config["interpolation"]["dimension"],
L = config["geometry"]["L"],
order = config["interpolation"]["order"],
np = config["interpolation"]["np"],
)
Excluded = []
Mesh_object = pre.Mesh(
config["geometry"]["Name"], # Create the mesh object
MaxElemSize,
config["interpolation"]["order"],
config["interpolation"]["dimension"]
)
Mesh_object.AddBorders(config["Borders"]["Borders"])
Mesh_object.AddBCs( # Include Boundary physical domains infos (BCs+volume)
config["geometry"]["Volume_element"],
Excluded,
config["DirichletDictionryList"]
)
Mesh_object.MeshGeo() # Mesh the .geo file if .msh does not exist
Mesh_object.ReadMesh()
print(config["solver"]["IntegralMethod"])
print()
# Vtk file not necessary if not using reference element implementation
if config["solver"]["IntegralMethod"] == "Gaussian_quad":
Mesh_object.ExportMeshVtk1D()
# Build the assembly weight matrix if needed
if config["interpolation"]["dimension"] ==1 and config["solver"]["IntegralMethod"] == "Trapezoidal":
Mesh_object.AssemblyMatrix()
if int(Mesh_object.dim) != int(Mesh_object.dimension):
raise ValueError("The dimension of the provided geometry does not match the job dimension")
if config["solver"]["TrainingStrategy"]=="Integral":
match config["solver"]["IntegralMethod"]:
case "Gaussian_quad":
Model_FEM = MeshNN_1D(Mesh_object, config["interpolation"]["n_integr_points"])
case "Trapezoidal":
Model_FEM = MeshNN(Mesh_object)
if config["solver"]["TrainingStrategy"]=="Mixed":
if config["solver"]["IntegralMethod"] == "Gaussian_quad":
Model_FEM = MeshNN_1D(Mesh_object, config["interpolation"]["n_integr_points"])
Model_test = MeshNN_1D(Mesh_object, config["interpolation"]["n_integr_points"])
Model_test.Freeze_Mesh()
# Default setting
Model_FEM.Freeze_Mesh()
Model_FEM.UnFreeze_FEM()
if not config["solver"]["FrozenMesh"]:
Model_FEM.UnFreeze_Mesh()
if config["solver"]["TrainingStrategy"]=="Mixed":
Model_FEM = Training_1D_FEM_LBFGS(Model_FEM, config, Mat, Model_test)
else:
Model_FEM = Training_1D_FEM_LBFGS(Model_FEM, config, Mat)
Pplot.Plot_Eval_1d(Model_FEM,config,Mat, model_du = [], tikz_plot=False)
_ _ ____ ___ __ __
| \ | | ___ _ _| _ \ / _ \| \/ |
| \| |/ _ \ | | | |_) | | | | |\/| |
| |\ | __/ |_| | _ <| |_| | | | |
|_| \_|\___|\__,_|_| \_\ ___/|_| |_|
2024.09.18
************ MESH READING COMPLETE ************
* Dimension of the problem: 1D
* Elements type: 2-node bar
* Number of Dofs: 14
Trapezoidal
epoch = 1
loss = -0.021347197932854396
loss_decrease = 1.0213471979328543
epoch = 2
loss = -0.02555727475284746
loss_decrease = 0.19721917758178212
epoch = 3
loss = -0.025557329919214736
loss_decrease = 2.1585387256617715e-06
epoch = 4
loss = -0.025557330481908426
loss_decrease = 2.2016920078594975e-08
epoch = 5
loss = -0.02555733065305093
loss_decrease = 6.69641545967761e-09
epoch = 6
loss = -0.025557330653051553
loss_decrease = 2.4435276900762727e-14
epoch = 7
loss = -0.025557330669466444
loss_decrease = 6.422771807903825e-10
epoch = 8
loss = -0.025557330669467082
loss_decrease = 2.497828303806942e-14
* Final training loss: -2.5557e-02
/Users/skardova/Dropbox/Lungs/HiDeNN_1D/hidenn_1d/neurom/Post/Plots.py:478: SyntaxWarning: invalid escape sequence '\%'
title_error = r'$\frac{\Vert u_{exact} - u_{ROM}\Vert}{\Vert u_{exact}\Vert}$ = '+error_scientific_notation+ '$\%$'+' Discrete: '+error_scientific_notation_discrete+ '$\%$'
/Users/skardova/Dropbox/Lungs/HiDeNN_1D/hidenn_1d/neurom/Post/Plots.py:478: SyntaxWarning: invalid escape sequence '\%'
title_error = r'$\frac{\Vert u_{exact} - u_{ROM}\Vert}{\Vert u_{exact}\Vert}$ = '+error_scientific_notation+ '$\%$'+' Discrete: '+error_scientific_notation_discrete+ '$\%$'
/Users/skardova/Dropbox/Lungs/HiDeNN_1D/hidenn_1d/neurom/Post/Plots.py:515: SyntaxWarning: invalid escape sequence '\%'
title_error = r'$\frac{\Vert u_{exact} - u_{ROM}\Vert}{\Vert u_{exact}\Vert}$ = '+error_scientific_notation+ '$\%$'
/Users/skardova/Dropbox/Lungs/HiDeNN_1D/hidenn_1d/neurom/Post/Plots.py:643: SyntaxWarning: invalid escape sequence '\%'
title_error = r'$\frac{\Vert u_{exact} - u_{ROM}\Vert}{\Vert u_{exact}\Vert}$ = ' + error_scientific_notation + '$\%$'
/Users/skardova/Dropbox/Lungs/HiDeNN_1D/hidenn_1d/neurom/Post/Plots.py:769: SyntaxWarning: invalid escape sequence '\m'
plt.plot(loss[0],color='#F39C12', label = "$\mathrm{Loss_{PDE}}$")
/Users/skardova/Dropbox/Lungs/HiDeNN_1D/hidenn_1d/neurom/Post/Plots.py:770: SyntaxWarning: invalid escape sequence '\m'
plt.plot(loss[1],color='#741B47', label = "$\mathrm{Loss_{Constitutive}}$")
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[3], line 103
101 Model_FEM = Training_1D_FEM_LBFGS(Model_FEM, config, Mat, Model_test)
102 else:
--> 103 Model_FEM = Training_1D_FEM_LBFGS(Model_FEM, config, Mat)
105 Pplot.Plot_Eval_1d(Model_FEM,config,Mat, model_du = [], tikz_plot=False)
File ~/Dropbox/Lungs/HiDeNN_1D/hidenn_1d/neurom/src/Training.py:2078, in Training_1D_FEM_LBFGS(model, config, Mat, model_test)
2076 # Pplot.Plot_Compare_Loss2l2norm(error,[],'Loss_Comaprison')
2077 if Show_trajectories:
-> 2078 Pplot.PlotTrajectories(Coord_trajectories,'Trajectories',Show_trajectories)
2080 return model
File ~/Dropbox/Lungs/HiDeNN_1D/hidenn_1d/neurom/Post/Plots.py:109, in PlotTrajectories(Coord_trajectories, name, show)
107 plt.ylabel(r'$x_i\left(\underline{x}\right)$')
108 plt.savefig('Results/'+name+'.pdf', transparent=True)
--> 109 tikzplotlib.save('Results/'+name+'.tikz', axis_height='6.5cm', axis_width='9cm')
110 if show:
111 plt.show()
NameError: name 'tikzplotlib' is not defined