Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 44 additions & 27 deletions Flat_Mesh_Ref.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting Mesh_Ref.py\n"
]
}
],
"source": [
"%%writefile Mesh_Ref.py \n",
"\n",
"import bempp.api, numpy as np\n",
"from math import pi\n",
"import os\n",
"from Grid_Maker import *\n",
"\n",
"\n",
"# Se crea una función que entrega la información de los archivos\n",
"# .vert y .face en formato np.array\n",
"\n",
"def text_to_list(mol_name , suffix , txt_format , info_type=float):\n",
" '''\n",
" Rutine which builds lists from text files that contain the vert and face info\n",
Expand All @@ -23,6 +30,8 @@
" txt_format : file format\n",
" info_type : float or int\n",
" '''\n",
" path = os.path.join('Molecule',mol_name)\n",
" \n",
" list_txt = open( os.path.join(path , mol_name +suffix + txt_format) ).read().split('\\n')\n",
"\n",
" listing = np.empty((0,3))\n",
Expand Down Expand Up @@ -73,7 +82,7 @@
" \n",
" return v_centered , new_face_array.astype(int) , new_vert_array\n",
"\n",
"def mesh_flat_refinement(faces,face_array,vert_array , suffix , dens):\n",
"def mesh_flat_refinement(mol_name,faces,face_array,vert_array , suffix , dens):\n",
" '''\n",
" This function builds the msh file for the specified faces.\n",
" faces : Faces arrays to be remeshed\n",
Expand All @@ -98,7 +107,34 @@
" for i in random_faces:\n",
" refined_faces = np.vstack( (refined_faces , face_array[i]))\n",
" \n",
" return refined_faces"
" return refined_faces\n",
"\n",
"def mesh_ref(mol_name , refined_faces , input_file_suffix , output_file_suffixx , starting_density):\n",
" '''\n",
" Global function that refines the mesh.\n",
" mol_name : Abreviated name of the molecule\n",
" refined_faces : np.array((N,3)) which contains faces with respective verts positions to be refined.\n",
" input_file_suffix : Suffix of the starting file\n",
" output_file_suffix : Suffix of the outputfile\n",
" starting_density : Starting density (For an easy handling of files)\n",
" '''\n",
" mol_name = 'methanol'\n",
" path = os.path.join('Molecule',mol_name)\n",
"\n",
" starting_density = 2.0\n",
"\n",
" suffix = ''\n",
"\n",
" # Information is imported\n",
" face_array = text_to_list(mol_name , input_file_suffix , '.face' , info_type=int )\n",
" vert_array = text_to_list(mol_name , input_file_suffix , '.vert' , info_type=float)\n",
"\n",
"\n",
" #refined_faces = random_face_list(50 , face_array) \n",
"\n",
" mesh_flat_refinement(mol_name , refined_faces,face_array,vert_array, output_file_suffixx , dens = starting_density)\n",
" \n",
" return None"
]
},
{
Expand Down Expand Up @@ -267,26 +303,7 @@
]
}
],
"source": [
"# Let's define main variables\n",
"mol_name = 'methanol'\n",
"path = os.path.join('Molecule',mol_name)\n",
"\n",
"starting_density = 2.0\n",
"\n",
"suffix = ''\n",
"\n",
"# Se importa la información \n",
"suf = '_'+str(starting_density)+ suffix\n",
"face_array = text_to_list(mol_name , suf , '.face' , info_type=int )\n",
"vert_array = text_to_list(mol_name , suf , '.vert' , info_type=float)\n",
"\n",
"suffix = '-1'\n",
"\n",
"refined_faces = random_face_list(50 , face_array) \n",
"# refined_faces should be changed for the faces containing a certain error criteria!\n",
"mesh_flat_refinement(refined_faces,face_array,vert_array, suffix , dens = starting_density)"
]
"source": []
},
{
"cell_type": "code",
Expand Down