Skip to content

Commit

Permalink
Se cambio el orden al poner las condicion incial
Browse files Browse the repository at this point in the history
  • Loading branch information
ZibraMax committed Jun 5, 2023
1 parent eeed10b commit eae1bb8
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Examples/Mesh_tests/Example17.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"nodes": [[0.0], [0.0025], [0.005], [0.0075], [0.01], [0.0125], [0.015], [0.0175], [0.02], [0.0225], [0.025], [0.0275], [0.03], [0.0325], [0.035], [0.0375], [0.04], [0.0425], [0.045], [0.0475], [0.05], [0.0525], [0.055], [0.0575], [0.06], [0.0625], [0.065], [0.0675], [0.07], [0.0725], [0.075], [0.0775], [0.08], [0.0825], [0.085], [0.08750000000000001], [0.09], [0.0925], [0.095], [0.0975], [0.1]], "dictionary": [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40]], "types": ["L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V"], "regions": [], "ebc": [], "nbc": [[-1, 0.0025]], "nvn": 1, "ngdl": 41, "holes": [], "fillets": [], "solutions": [{"info": {"solver-type": "lineal"}, "U": [[100.0], [97.91805186007046], [95.91201024898662], [93.97992091286525], [92.11990164095512], [90.3301404320172], [88.60889372910171], [86.95448472100266], [85.36530170873505], [83.83979653544331], [82.37648307821142], [80.97393580030561], [79.63078836243908], [78.34573229170593], [77.11751570688772], [75.94494209889062], [74.82686916512526], [73.76220769669366], [72.74992051729927], [71.78902147284623], [70.87857447074373], [70.01769256797951], [69.20553710707401], [68.44131689907357], [67.72428745278678], [67.05375024951294], [66.4290520625562], [65.84958432086252], [65.31478251615945], [64.82412565302106], [64.37713574132252], [63.9733773305897], [63.612457085790226], [63.29402340415274], [63.01776607264106], [62.78341596574956], [62.59074478332543], [62.4395648281622], [62.32972882314817], [62.26112976779136], [62.23370083398135]]}], "properties": {"verbose": false, "name": "", "problem": "Heat1D", "A": [5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06], "P": [0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012], "ku": [385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385], "beta": [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25], "Ta": 20, "q": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "duration": 1.421224, "description": "FEM problem using the 1D Heat transfer formulation.,DOF: 41,Elements: 40,Solver: lineal,EBC: 1,NBC: 1"}}
{"nodes": [[0.0], [0.0025], [0.005], [0.0075], [0.01], [0.0125], [0.015], [0.0175], [0.02], [0.0225], [0.025], [0.0275], [0.03], [0.0325], [0.035], [0.0375], [0.04], [0.0425], [0.045], [0.0475], [0.05], [0.0525], [0.055], [0.0575], [0.06], [0.0625], [0.065], [0.0675], [0.07], [0.0725], [0.075], [0.0775], [0.08], [0.0825], [0.085], [0.08750000000000001], [0.09], [0.0925], [0.095], [0.0975], [0.1]], "dictionary": [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40]], "types": ["L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V", "L1V"], "regions": [], "ebc": [], "nbc": [[-1, 0.0025]], "nvn": 1, "ngdl": 41, "holes": [], "fillets": [], "solutions": [{"info": {"solver-type": "lineal"}, "U": [[100.0], [97.91805186007046], [95.91201024898662], [93.97992091286525], [92.11990164095512], [90.3301404320172], [88.60889372910171], [86.95448472100266], [85.36530170873505], [83.83979653544331], [82.37648307821142], [80.97393580030561], [79.63078836243908], [78.34573229170593], [77.11751570688772], [75.94494209889062], [74.82686916512526], [73.76220769669366], [72.74992051729927], [71.78902147284623], [70.87857447074373], [70.01769256797951], [69.20553710707401], [68.44131689907357], [67.72428745278678], [67.05375024951294], [66.4290520625562], [65.84958432086252], [65.31478251615945], [64.82412565302106], [64.37713574132252], [63.9733773305897], [63.612457085790226], [63.29402340415274], [63.01776607264106], [62.78341596574956], [62.59074478332543], [62.4395648281622], [62.32972882314817], [62.26112976779136], [62.23370083398135]]}], "properties": {"verbose": false, "name": "", "problem": "Heat1D", "A": [5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06, 5e-06], "P": [0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012, 0.012], "ku": [385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385], "beta": [25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25], "Ta": 20, "q": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "duration": 3.100282, "description": "FEM problem using the 1D Heat transfer formulation.,DOF: 41,Elements: 40,Solver: lineal,EBC: 1,NBC: 1"}}
2 changes: 1 addition & 1 deletion Examples/Mesh_tests/Example51.json

Large diffs are not rendered by default.

87 changes: 74 additions & 13 deletions Examples/example51.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,80 @@
if __name__ == '__main__':
from FEM.Geometry import Lineal
from FEM.Heat1D import Heat1DTransient
import matplotlib.pyplot as plt
L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

L = 0.1
A = 0.001*0.005
P = 2*(0.005+0.001)
k = 385
beta = 25
Ta = 20
T0 = 100
n = 1
geometria = Lineal(L, n, 2)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.5)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
O.postProcess(node=-1)

n = 40
L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 1
geometria = Lineal(L, n, 2)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.0)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
O.postProcess(node=-1, ax=plt.gca())
plt.gca().get_lines()[-1].set_color("yellow")

L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 2
geometria = Lineal(L, n, 1)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.5)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
O.postProcess(node=-1, ax=plt.gca())
plt.gca().get_lines()[-1].set_color("red")

L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 2
geometria = Lineal(L, n, 1)
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=True)
O.cbe = [[0, T0]]
O.cbe = [[-1, 0]]
O.solve(t0=0, tf=10, steps=100)
O.exportJSON("Examples/Mesh_tests/Example51.json")
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.0)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
O.postProcess(node=-1, ax=plt.gca())
plt.gca().get_lines()[-1].set_color("blue")
# O.exportJSON("Examples/Mesh_tests/Example51.json")
plt.xlim([0, 2.5])
plt.ylim([0, 1.5])
plt.legend(["1 O2, a=0.5", "1 O2, a=0.0", "2 O1, a=0.5", "2 O2, a=0.0"])
plt.grid()
plt.show()
165 changes: 165 additions & 0 deletions Examples/example52.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
if __name__ == '__main__':
from FEM.Geometry import Lineal
from FEM.Heat1D import Heat1DTransient
import matplotlib.pyplot as plt
L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 1
geometria = Lineal(L, n, 1)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.0)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
X, U1L0 = O.postProcess(node=-1)

L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 1
geometria = Lineal(L, n, 1)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(1.0)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
X, U1L1 = O.postProcess(node=-1, ax=plt.gca())
plt.gca().get_lines()[-1].set_color("yellow")

L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 1
geometria = Lineal(L, n, 1)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.5)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
X, U1L0_5 = O.postProcess(node=-1, ax=plt.gca())
plt.gca().get_lines()[-1].set_color("red")

L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 2
geometria = Lineal(L, n, 1)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.5)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
X, U2L0_5 = O.postProcess(node=-1, ax=plt.gca())
plt.gca().get_lines()[-1].set_color("blue")
# O.exportJSON("Examples/Mesh_tests/Example51.json")

L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 4
geometria = Lineal(L, n, 1)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.5)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
X, U4L0_5 = O.postProcess(node=-1, ax=plt.gca())

L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 8
geometria = Lineal(L, n, 1)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.5)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
X, U8L0_5 = O.postProcess(node=-1, ax=plt.gca())

L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 1
geometria = Lineal(L, n, 2)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.5)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
X, U1Q0_5 = O.postProcess(node=-1, ax=plt.gca())

L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 2
geometria = Lineal(L, n, 2)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.5)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
X, U2Q0_5 = O.postProcess(node=-1, ax=plt.gca())

L = 1
A = 1
P = 1
k = 1
beta = 0
Ta = 0
T0 = 0

n = 4
geometria = Lineal(L, n, 2)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(1.0)
O.set_alpha(0.5)
O.solve(t0=0, tf=6, steps=50, dt=0.05, plot=False)
X, U4Q0_5 = O.postProcess(node=-1, ax=plt.gca())

import numpy as np
SOLUTIONS = np.array([U1L0, U1L1, U1L0_5, U2L0_5, U4L0_5,
U8L0_5, U1Q0_5, U2Q0_5, U4Q0_5]).T
np.savetxt("temperaturas_transient.csv", SOLUTIONS[0], delimiter=",", fmt="%s")
22 changes: 22 additions & 0 deletions Examples/example53.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if __name__ == '__main__':
from FEM.Geometry import Lineal
from FEM.Heat1D import Heat1DTransient
import matplotlib.pyplot as plt
L = 0.1
A = 0.001*0.005
P = 2*(0.005+0.001)
k = 385
beta = 25
Ta = 20
T0 = 100
# TODO hay algo mal

n = 30
geometria = Lineal(L, n, 2)
geometria.cbe = [[0, T0]]
O = Heat1DTransient(geometria, A, P, k, beta, Ta, verbose=False)
O.set_initial_condition(0.0)
O.set_alpha(0.5)
O.solve(t0=0, tf=10, steps=400, plot=False)
O.postProcess()
plt.show()
9 changes: 2 additions & 7 deletions src/FEM/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,24 +303,21 @@ def __init__(self, geometry: Geometry, solver: Solver = None, verbose: bool = Fa
# Initial condition for all gdls in domain
self.u0: list[float] = [0.0]*self.ngdl

self.apply_initial_condition()

def set_initial_condition(self, ic: Union[list[float], Callable[[], float], float]) -> None:
if isinstance(ic, float):
self.u0 = [ic]*self.ngdl
elif isinstance(ic, Callable):
self.u0 = ic(self.geometry.gdls)
elif isinstance(ic, list):
self.u0 = ic
self.apply_initial_condition()

def apply_initial_condition(self):
def apply_initial_condition(self, t0, dt):
self.U[:, 0] = self.u0
for i in self.cbe:
self.U[int(i[0]), 0] = i[1]
self.solver.solutions.append(self.U.copy())
self.solver.solutions_info.append(
{'solver-type': self.solver.type, "time": "Initial time", "dt": "Not defined"})
{'solver-type': self.solver.type, "time": t0, "dt": dt})
self.solver.setSolution(-1, True)

def ensembling(self) -> None:
Expand Down Expand Up @@ -392,8 +389,6 @@ def set_initial_condition(self, u0: Union[list[float], Callable[[], float], floa
elif isinstance(ddu0, list):
self.ddu0 = ddu0

self.apply_initial_condition()

def apply_initial_condition(self):
self.U[:, 0] = self.u0
self.dU[:, 0] = self.du0
Expand Down
Loading

0 comments on commit eae1bb8

Please sign in to comment.