예제 #1
0
 def AnalyticalSol(self, gridE, probeTime):
     # Source terms
     sol = []
     for initial in self._initialCond:
         if (initial["type"] == "gaussian"):
             for time in probeTime:
                 #return np.exp( - ((x-delay)**2 / (2*spread**2)) )
                 Ereal_right=Solver.movingGaussian(gridE,time, \
                     sp.speed_of_light,initial["peakPosition"],\
                     initial["gaussianAmplitude"]/2, \
                     initial["gaussianSpread"])
                 Ereal_left=Solver.movingGaussian(gridE,time, \
                     -sp.speed_of_light,initial["peakPosition"],\
                     initial["gaussianAmplitude"]/2, \
                     initial["gaussianSpread"])
                 sol.append(Ereal_right + Ereal_left)
         else:
             raise ValueError("Invalid source type: " + initial["type"])
     # plt.plot(gridE,sol[9])
     sol = [
         sol[0]
     ] + sol[:-1]  #Repeat the initial because it is repeated in Solver
     return sol
예제 #2
0
parser = argparse.ArgumentParser(description='Python FDTD 2D')
parser.add_argument('-i', '--input', nargs=1, type=str)
args = parser.parse_args()
if len(sys.argv) == 1:
    parser.print_help()
    sys.exit()

inputFilename = ''.join(args.input).strip()
print("--- Reading file: %s" % (inputFilename))
data = json.load(open(inputFilename))

print('--- Initializing mesh')
mesh = Mesh(data["coordinates"], data["elements"], data["grid"])

print('--- Initializing solver')
solver = Solver(mesh, data["options"], data["probes"], data["sources"],
                data["materials"])

print('--- Solving')
solver.solve(data["options"]["finalTime"])

print('--- Measuring')
measures = Measures(mesh, solver.getProbes(), data["measures"])

print('--- Frecuency analysis')
results_freq = Fourier_trans(measures, solver.getProbes(), data)
print(f"Reflexion coefficient: {results_freq[2][0]}")
print(f"Transmission coefficient: {results_freq[2][1]}")
print(f"Sum of coefficients: {results_freq[2][0] + results_freq[2][1]}")

print('--- Plotting')
view = View(solver.getProbes(),
예제 #3
0
parser = argparse.ArgumentParser(description='Python FDTD 2D')
parser.add_argument('-i', '--input', nargs=1, type=str)
args = parser.parse_args()
if len(sys.argv) == 1:
    parser.print_help()
    sys.exit()

inputFilename = ''.join(args.input).strip()
print("--- Reading file: %s" % (inputFilename))
data = json.load(open(inputFilename))

print('--- Initializing mesh')
mesh = Mesh(data["coordinates"], data["elements"], data["grid"])

print('--- Initializing solver')
solver = Solver(mesh, data["options"], data["probes"], data["sources"])

print('--- Solving')
solver.solve(data["options"]["finalTime"])

print('--- Writing output files')
(folder, file) = os.path.split(inputFilename)
caseName = os.path.splitext(file)[0]
xdmf = Xdmf(basename=caseName, format="XML")
for p in solver.getProbes():
    xdmf.add(p)

open(xdmf.basename + ".xmf", "w+").write(xdmf.tostring().decode('utf-8'))

print('=== Program finished')
예제 #4
0
inputFilename = ''.join(args.input).strip()

print("--- Reading file: %s" % (inputFilename))
data = json.load(open(inputFilename))

print('--- Initializing mesh')
mesh = Mesh(data["coordinates"], data["elements"], data["grid"])
#layer = None
layer = DispersiveMedia(mesh, data["dispersiveLayers"])
#indeces = layer.layerIndices(mesh)
print('--- Initializing solver')
#layer=None
solver = Solver(mesh,
                data["options"],
                data["probes"],
                data["sources"],
                dispLayer=layer)

print('--- Solving')
solver.solve(data["options"]["finalTime"])

print('--- Visualizing')
solNum = solver.getProbes()[0]

#Measure transmittance
transmission = MeasureTransmittance(layer, solNum['time'],
                                    solNum['valuesFree'], solNum['values'])
freq, transCoef = transmission.T()
freq2, reflecCoef = transmission.R()
PlotTransmittance(freq, [transCoef, reflecCoef], labels=['T', 'R'])
예제 #5
0
parser = argparse.ArgumentParser(description='Python FDTD 1D')
parser.add_argument('-i', '--input', nargs=1, type=str)
args = parser.parse_args()
if len(sys.argv) == 1:
    parser.print_help()
    sys.exit()

inputFilename = ''.join(args.input).strip()
print("--- Reading file: %s" % (inputFilename))
data = json.load(open(inputFilename))

print('--- Initializing mesh')
mesh = Mesh(data["coordinates"], data["elements"], data["grid"])

print('--- Initializing solver')
solver = Solver(mesh, data["options"], data["probes"], data["sources"],
                data["initialCond"])

print('--- Solving')
solver.solve(data["options"]["finalTime"])

print('--- Visualizing')
#print(mesh)
#print(solver.getProbes()[0])
solNum = solver.getProbes()[0]
Animator(mesh, solNum)

#%%
print('--- Comparison with analytical solution')
comparison = AnalyticComp(mesh, solNum, data["initialCond"])
solReal = comparison.AnalyticalSol(comparison.gridE, comparison.probeTime)
err = comparison.L2Error(solReal)
예제 #6
0
from fdtd.mesh import Mesh
from fdtd.solver import Solver
from fdtd.viewer import Animator

print("=== Python FDTD 1D")

parser = argparse.ArgumentParser(description='Python FDTD 1D')
parser.add_argument('-i', '--input', nargs=1, type=str)
args = parser.parse_args()
if len(sys.argv) == 1:
    parser.print_help()
    sys.exit()

inputFilename = ''.join(args.input).strip()
print("--- Reading file: %s" % (inputFilename))
data = json.load(open(inputFilename))

print('--- Initializing mesh')
mesh = Mesh(data["coordinates"], data["elements"], data["grid"])

print('--- Initializing solver')
solver = Solver(mesh, data["options"], data["probes"], data["sources"])

print('--- Solving')
solver.solve(data["options"]["finalTime"])

print('--- Visualizing')
Animator(mesh, solver.getProbes()[0])

print('=== Program finished')