From 8c269ce4787428a68921fcd7a11610e9cd33bd39 Mon Sep 17 00:00:00 2001 From: Ramm Date: Sat, 25 May 2019 18:18:19 -0400 Subject: [PATCH] Add files via upload Fixed some bugs. All files might be rebuilt in order to simplify the code and make it more general --- Flat_Mesh_Ref.ipynb | 71 ++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/Flat_Mesh_Ref.ipynb b/Flat_Mesh_Ref.ipynb index 4da81ed..216a98b 100644 --- a/Flat_Mesh_Ref.ipynb +++ b/Flat_Mesh_Ref.ipynb @@ -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", @@ -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", @@ -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", @@ -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" ] }, { @@ -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",