Skip to content

Commit

Permalink
Ahora transient heat1D hereda multiple con HEAT 1D y con Parabolic
Browse files Browse the repository at this point in the history
  • Loading branch information
ZibraMax committed Jun 11, 2023
1 parent d5656cb commit ed344b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 59 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": 3.100282, "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.106238, "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/Example53.json

Large diffs are not rendered by default.

73 changes: 16 additions & 57 deletions src/FEM/Heat1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Heat1D(Core):
q (float or list, optional): Internal heat generation rate. If float, all elements will have the same internal heat generation rate coeficient. If list, the i-element will have the i-internal heat generation rate. Defaults to 0.0.
"""

def __init__(self, geometry: Geometry, A: float, P: float, ku: float, beta: float, Ta: float, q: float = 0.0) -> None:
def __init__(self, geometry: Geometry, A: float, P: float, ku: float, beta: float, Ta: float, q: float = 0.0, **kargs) -> None:
"""Creates a 1D Stady state heat problem. Convective border conditions can be applied
The differential equation is:
Expand Down Expand Up @@ -57,14 +57,15 @@ def __init__(self, geometry: Geometry, A: float, P: float, ku: float, beta: floa
self.beta = beta
self.Ta = Ta
self.q = q
Core.__init__(self, geometry)
Core.__init__(self, geometry, **kargs)
self.name = '1D Heat transfer'
self.properties['A'] = self.A
self.properties['P'] = self.P
self.properties['ku'] = self.ku
self.properties['beta'] = self.beta
self.properties['Ta'] = self.Ta
self.properties['q'] = self.q
self.convective_conditions = []

def elementMatrices(self) -> None:
"""Calculate the element matrices using Gauss Legendre quadrature.
Expand Down Expand Up @@ -108,7 +109,7 @@ def defineConvectiveBoderConditions(self, node: int, value: float = 0) -> None:
if act == 0:
break
self.cbn += [[node, value+self.Ta*self.beta[k]*self.A[k]]]
self.K[node, node] += self.beta[k]*self.A[k]
self.convective_conditions.append([node, self.beta[k]*self.A[k]])

def postProcess(self) -> None:
"""Generate graph of solution and solution derivative
Expand All @@ -127,8 +128,16 @@ def postProcess(self) -> None:
ax1.set_title(r'$T(x)$')
plt.show()

def set_convective_conditions(self):
for idx, value in self.convective_conditions:
self.K[idx, idx] += value

def borderConditions(self) -> None:
super().borderConditions()
self.set_convective_conditions()

class Heat1DTransient(CoreParabolic):

class Heat1DTransient(Heat1D, CoreParabolic):
"""Creates a 1D Stady state heat problem. Convective border conditions can be applied
The differential equation is:
Expand Down Expand Up @@ -163,33 +172,12 @@ def __init__(self, geometry: Geometry, A: float, P: float, ku: float, beta: floa
Ta (float): Ambient temperature (also called T∞)
q (float or list, optional): Internal heat generation rate. If float, all elements will have the same internal heat generation rate coeficient. If list, the i-element will have the i-internal heat generation rate. Defaults to 0.0.
"""
Heat1D.__init__(self, geometry=geometry, A=A, P=P, ku=ku,
beta=beta, Ta=Ta, q=q, **kargs)
CoreParabolic.__init__(
self, geometry=geometry, **kargs)

if isinstance(A, float) or isinstance(A, int):
A = [A]*len(geometry.elements)
if isinstance(P, float) or isinstance(P, int):
P = [P]*len(geometry.elements)
if isinstance(ku, float) or isinstance(ku, int):
ku = [ku]*len(geometry.elements)
if isinstance(beta, float) or isinstance(beta, int):
beta = [beta]*len(geometry.elements)
if isinstance(q, float) or isinstance(q, int):
q = [q]*len(geometry.elements)
self.A = A
self.P = P
self.ku = ku
self.beta = beta
self.Ta = Ta
self.q = q
self.name = '1D Heat transfer'
self.properties['A'] = self.A
self.properties['P'] = self.P
self.properties['ku'] = self.ku
self.properties['beta'] = self.beta
self.properties['Ta'] = self.Ta
self.properties['q'] = self.q
self.convective_conditions = []
self.name = '1D transient heat transfer'

def elementMatrices(self) -> None:
"""Calculate the element matrices using Gauss Legendre quadrature.
Expand Down Expand Up @@ -228,35 +216,6 @@ def elementMatrices(self) -> None:
e.Fe = (M1 - a2*Kt)@e.Ue.T + Fttp1
e.Ke = M1 + a1*Ktp1

def defineConvectiveBoderConditions(self, node: int, value: float = 0) -> None:
"""Add a convective border condition. The value is: :math:`kA\\frac{dT}{dx}+\\beta A(T-T_{\infty})=value`
Args:
node (int): Node where the above border condition is applied
value (float, optional): Defined below. Defaults to 0.
"""

near = np.infty
for i, e in enumerate(self.elements):
act = min(abs(self.geometry.gdls[node][0] - e._coords[0]),
abs(self.geometry.gdls[node][0] - e._coords[0]))
if act < near:
near = act
k = i
if act == 0:
break
self.cbn += [[node, value+self.Ta*self.beta[k]*self.A[k]]]
self.convective_conditions.append([node, self.beta[k]*self.A[k]])

def set_convective_conditions(self):
for idx, value in self.convective_conditions:
self.K[idx, idx] += value

def borderConditions(self) -> None:
a = super().borderConditions()
self.set_convective_conditions()
return a

def postProcess(self, node=None, t0=None, tf=None, steps=None, dt=None, ax=None) -> None:
"""Post process the solution and steps
"""
Expand Down

0 comments on commit ed344b2

Please sign in to comment.