Example #1
0
quads = quads[:, 1:]

for i in range(len(fields)):
    field3 = zeros((simu.domain.nodes.n, 3))
    field3[:, 0:2] = fields[i]
    fields[i] = field3
    # dir_sol = zeros(g.shape[0])
    # remove = eq['dir_positions']
    # g = my_solver.build_solution(dir_sol, g, remove, True)
    # field2 =  zeros((simu.domain.nodes.n,3))
    # field2[:,0:2] = g
    # g_sol = field2
    write_vtk(
        filename + str(i) + ".vtk",
        "MyTitle",
        "UNSTRUCTURED_GRID",
        simu.domain.nodes.coords,
        quads,
        ["VECTORS", ["sol"], [fields[i]]],
    )

# Analitic solution

a = 2
b = 4
k = []
for m in range(1, 6):
    for n in range(1, 6):
        k.append((m * pi / a) ** 2 + (n * pi / b) ** 2)
print k
Example #2
0
simu.domain.read_regions_file(reg_filename)

inter = Interpreter()
eq = inter.build_static_EM_eq(simu)
g = eq['sol_vec']

my_solver = Solver()
fields = my_solver.solve_stationary(simu, eq)
quads = my_solver.substract_1(simu.domain.elements.quads.el_set)
quads = quads[:,1:]

field3 =  zeros((simu.domain.nodes.n,3))
field3[:,0:2] = fields
fields = field3

dir_sol = zeros(g.shape[0])
remove = eq['dir_positions']
g = my_solver.build_solution(dir_sol, g, remove, True)
print g
field2 =  zeros((simu.domain.nodes.n,3))
field2[:,0:2] = g
g_sol = field2



write_vtk(filename +'.vtk', 'MyTitle', 'UNSTRUCTURED_GRID' ,simu.domain.nodes.coords,\
               quads, ['VECTORS', ['sol'], [fields]])
write_vtk(filename+'_dirichlet' +'.vtk', 'MyTitle', 'UNSTRUCTURED_GRID' ,simu.domain.nodes.coords,\
               quads, ['VECTORS', ['sol'], [g_sol]])

Example #3
0

value, fields = my_solver.solve_spectral(simu, eq)
print len(fields), 'value', value
quads = my_solver.substract_1(simu.domain.elements.quads.el_set)
quads = quads[:,1:]
from numpy import zeros
for i in range(len(fields)):
    field3 =  zeros((simu.domain.nodes.n,3))
    field3[:,0:2] = fields[i]
    fields[i] = field3
    

#dir_sol = zeros(g.shape[0])
#remove = eq['dir_positions']
#g = my_solver.build_solution(dir_sol, g, remove, True)
#field2 =  zeros((simu.domain.nodes.n,3))
#field2[:,0:2] = g
#g_sol = field2
    write_vtk(filename+'_' +str(i)+'.vtk', 'MyTitle', 'UNSTRUCTURED_GRID' ,simu.domain.nodes.coords,\
               quads, ['VECTORS', ['sol'], [fields[i]]])

# Analitic solution
from numpy import pi
a = 2; b = 4
k=[]
for m in range(1,6):
    for n in range(1,6):
        k.append((m*pi/a)**2 +(n*pi/b)**2)
print 'k', k
Example #4
0
write_solver_input('whole_cylinder.msh',dimension = 2, bc_type = 'Dir', \
parameter = [], eq = 'Harm_Elec', sol_type = 'Stationary',analysis_param \
= ['y', 'y', 4, 4, 20, 20, 2], bc_filename = 'whole_cylinder.bc')  

simu = Simulation()
simu.read_solver_input('whole_cylinder.msh')
simu.domain.read_mesh_file('whole_cylinder.msh', True)

inter = Interpreter()
eq = inter.build_static_EM_eq(simu)
g = eq['sol_vec']
my_solver = Solver()
fields = my_solver.solve_stationary(simu, eq)
quads = my_solver.substract_1(simu.domain.elements.quads.el_set)
quads = quads[:,1:]
from numpy import zeros
field3 =  zeros((simu.domain.nodes.n,3))
field3[:,0:2] = fields
fields = field3


dir_sol = zeros(g.shape[0])
remove = eq['dir_positions']
g = my_solver.build_solution(dir_sol, g, remove, True)
field2 =  zeros((simu.domain.nodes.n,3))
field2[:,0:2] = g
g_sol = field2

write_vtk('whole_cylinder'+'.vtk', 'MyTitle', 'UNSTRUCTURED_GRID' ,simu.domain.nodes.coords,\
               quads, ['VECTORS', ['sol'], [fields]])
Example #5
0
#! /usr/bin/python
"""
Created on Tue Feb 12 09:51:01 2013

@author: santiago
"""

from Classes import *
from Interpreter import *
from Solver import *
from utils import substract_1  
from write import write_vtk

simulation = Simulation()
simulation.read_solver_input('square.msh')
simulation.domain.read_mesh_file('square.msh')
simulation.domain.read_bc_file('square.bc')

interpreter = Interpreter()
equation = interpreter.build_QM_dirichlet_eq(simulation)

solver = Solver()
solution = solver.solve_spectral(simulation, equation)

nodes_coords = simulation.domain.nodes.coords
triangles = simulation.domain.elements.triangles.el_set
triangles = substract_1(triangles)
triangles = triangles[:, 1:]

write_vtk('square_from_OOP.vtk','this shit','',nodes_coords,\
            triangles,['SCALARS',['solution'],[solution[1]]])
quads = quads[:,1:]
from numpy import zeros
field3 =  zeros((simu.domain.nodes.n,3))
field3[:,0:2] = fields
fields = field3


dir_sol = zeros(g.shape[0])
remove = eq['dir_positions']
g = my_solver.build_solution(dir_sol, g, remove, True)
print g
field2 =  zeros((simu.domain.nodes.n,3))
field2[:,0:2] = g
g_sol = field2
from numpy import sqrt
expr_x = '12*x/sqrt(x**2+y**2)**3-12*(x-4)/sqrt((x-4)**2+y**2)**3'
expr_y = '12*y/sqrt(x**2+y**2)**3-12*y/sqrt((x-4)**2+y**2)**3'
for i in range(g_sol.shape[0]/2):
    if i not in remove:
        x = simu.domain.nodes.coords[i, 0]
        y = simu.domain.nodes.coords[i, 1]
        x_value = eval(expr_x)
        y_value = eval(expr_y)
        g_sol[i,0] = x_value
        g_sol[i,1] = y_value

write_vtk('cylinder2_finer'+'.vtk', 'MyTitle', 'UNSTRUCTURED_GRID' ,simu.domain.nodes.coords,\
               quads, ['VECTORS', ['sol'], [fields]])
write_vtk('cylinder2_analy_finer'+'.vtk', 'MyTitle', 'UNSTRUCTURED_GRID' ,simu.domain.nodes.coords,\
               quads, ['VECTORS', ['sol'], [g_sol]])
Example #7
0
from write import write_vtk, write_solver_input 

filename = 'unit_cell_1-02_two_reg'
write_solver_input(filename +'.msh',dimension = 2, bc_type = 'Bloch', \
parameter = [], eq = 'EM', sol_type = 'Stationary',analysis_param \
= ['y', 'y', 15, 15, 11, 11, 5], bc_filename = filename +'.bc')  

simu = Simulation()
simu.read_solver_input(filename +'.msh')
simu.domain.read_mesh_file(filename +'.msh',simu)

inter = Interpreter(vectorial = True)
eq = inter.build_EM_bloch_eq(simu)
my_solver = Solver()
k_mesh, energy = my_solver.solve_bloch(simu, eq)


from numpy import zeros, sqrt, around
nodes =  zeros((k_mesh[0].shape[0],3))
nodes[:,0:2] = k_mesh[0]
triangles = k_mesh[1]

for i in range(energy.shape[1]):
    energy[:,i] = sqrt(around(energy[:,i],10))
    
    write_vtk('Bloch_periodic_r-a_1-02_two_reg'+str(i)+'.vtk','this shit','POLYDATA', nodes,\
               triangles, ['SCALARS', ['sol'], [energy[:,i]]])

# from inform import inform
# inform('Iḿ done runing')
print 'Finished.'
Example #8
0
n = shape(nodes)[0]                 #Number of nodes      
bc_lines = elements[1]      # Boundary condition is (bc) lines
triangles = elements[2]

potential = potential_2d('well', nodes, v0 = 2)



write_solver_input(glo_tag +'.msh', parameter = potential, dimension = 2, \
                   bc_type = 'Dir', \
                   sol_type = 'Stationary', eq = 'Schro', \
                   analysis_param = ['y', 'y', 4, 20, 15, 15, 1], \
                   bc_filename = glo_tag+'.bc')

k = read_solver_input(glo_tag +'.msh')
v, solution = schroedinger(glo_tag +'.msh')
triangles = substract_1(triangles)
triangles = triangles[:, 1:]

#k, solution = schroedinger(glo_tag +'.msh')
#z = zeros((k[0].shape[0], 3))
#print k[0].shape, z[:, 0:1].shape
#z[:, 0:2] = k[0]
#nodes = z
#triangles = k[1]
 
print v
write_vtk(glo_tag + '_1.vtk', 'this shit', '', nodes, triangles, \
            ['SCALARS', ['solution'], [solution]])
            
Example #9
0
potential = potential_2d("well", nodes, v0=0)
write_solver_input(
    glo_tag + ".msh",
    parameter=potential,
    dimension=2,
    bc_type="Dir",
    sol_type="Stationary",
    eq="Schro",
    analysis_param=["y", "y", 20, 20, 15, 15, 1],
    bc_filename=glo_tag + ".bc",
)

k = read_solver_input(glo_tag + ".msh")
v, solution = schroedinger(glo_tag + ".msh")
triangles = substract_1(triangles)
triangles = triangles[:, 1:]

# k, solution = schroedinger(glo_tag +'.msh')
# z = zeros((k[0].shape[0], 3))
# print k[0].shape, z[:, 0:1].shape
# z[:, 0:2] = k[0]
# nodes = z
# triangles = k[1]

print v
write_vtk(glo_tag + "_dir.vtk", "this shit", "", nodes, triangles, ["SCALARS", ["solution"], [solution]])
print solution.shape
sol = test_sol(nodes, pi, 3 * pi)
write_vtk(glo_tag + "_sol.vtk", "this shit", "", nodes, triangles, ["SCALARS", ["sol"], [sol]])
Example #10
0
@author: santiago
"""

from Classes import Simulation
from Interpreter import Interpreter
from Solver import Solver
from write import write_vtk, write_solver_input 

write_solver_input('square8_cap.msh',dimension = 2, bc_type = 'Dir', \
parameter = [], eq = 'Harm_Elec', sol_type = 'Stationary',analysis_param \
= ['y', 'y', 4, 4, 20, 20, 2], bc_filename = 'square.bc')  

simu = Simulation()
simu.read_solver_input('square8_cap.msh')
simu.domain.read_mesh_file('square8_cap.msh',simu)

inter = Interpreter()
eq = inter.build_static_EM_eq(simu)
my_solver = Solver()
fields = my_solver.solve_stationary(simu, eq)
quads = my_solver.substract_1(simu.domain.elements.quads.el_set)
quads = quads[:,1:]
from numpy import zeros
field3 =  zeros((simu.domain.nodes.n,3))
field3[:,0:2] = fields
fields = field3

write_vtk('newman_cap'+'.vtk', 'MyTitle', 'UNSTRUCTURED_GRID' ,simu.domain.nodes.coords,\
               quads, ['VECTORS', ['sol'], [fields]])
print 'Finished.'