def setUp(self): self.k = 15.0 self.a = 5.0 self.hcoef = 1.0 self.solver = thermal.FiniteDifferenceImplicitThermalSolver() self.material = materials.ConstantThermalMaterial("Test", self.k, self.a) self.fluid = materials.ConstantFluidMaterial({"Test": self.hcoef}) self.t = 0.2 self.r = 2.0 self.h = 1.0 self.nr = 10 self.nt = 200 self.nz = 2 self.tmax = 1000.0 self.ntime = 10 self.tube = receiver.Tube(self.r, self.t, self.h, self.nr, self.nt, self.nz, 0) self.times = np.linspace(0, self.tmax, self.ntime+1) self.tube.set_times(self.times) self.tube.make_1D(self.tube.h/2, 0) self.ttimes, self.thetas, self.zs = np.meshgrid( self.times, np.linspace(0, 2*np.pi, self.nt + 1)[:-1], np.linspace(0, self.h, self.nz), indexing = 'ij') self.rs = np.linspace(self.r - self.t, self.r, self.nr)
def setUp(self): self.k = 15.0 self.a = 5.0 self.hcoef = 1.0 self.solver = thermal.FiniteDifferenceImplicitThermalSolver() self.material = materials.ConstantThermalMaterial("Test", self.k, self.a) self.fluid = materials.ConstantFluidMaterial({"Test": self.hcoef}) self.t = 0.2 self.r = 2.0 self.h = 1.0 self.nr = 5 self.nt = 10 self.nz = 5 self.tmax = 10.0 self.ntime = 10 self.tube = receiver.Tube(self.r, self.t, self.h, self.nr, self.nt, self.nz, 0) self.times = np.linspace(0, self.tmax, self.ntime+1) self.tube.set_times(self.times) self.T_inner = 100 Tin = receiver.ConvectiveBC(self.r-self.t, self.h, self.nz, self.times, np.ones((self.ntime+1,self.nz))*self.T_inner) self.tube.set_bc(Tin, "inner") Tright = receiver.HeatFluxBC(self.r, self.h, self.nt, self.nz, self.times, np.zeros((self.ntime+1,self.nt,self.nz))) self.tube.set_bc(Tright, "outer")
def setUp(self): self.solver = thermal.FiniteDifferenceImplicitThermalSolver() self.material = materials.ConstantThermalMaterial("Test", 10.0, 5.0) self.fluid = materials.ConstantFluidMaterial({"Test": 7.5}) self.tol = 1e-2 self.atol = 1e-3
def setUp(self): self.problems = [ ManufacturedSolution("1D: no spatial", 1, lambda t, r: t, lambda t, k, alpha, r: k/alpha * (r*0.0+1)), ManufacturedSolution("1D: spatial and time", 1, lambda t, r: np.sin(t)*np.log(r), lambda t, k, alpha, r: k/alpha * np.log(r) * np.cos(t)), ManufacturedSolution("1D: just spatial", 1, lambda t, r: np.sin(r), lambda t, k, alpha, r: k * np.sin(r) - k/r*np.cos(r)), ManufacturedSolution("2D: just time", 2, lambda t, r, th: t, lambda t, k, alpha, r, th: k/alpha * (r*0.0+1)), ManufacturedSolution("2D: just r", 2, lambda t, r, th: np.sin(r), lambda t, k, alpha, r, th: k * np.sin(r) - k/r * np.cos(r)), ManufacturedSolution("2D: just theta", 2, lambda t, r, th: np.cos(th), lambda t, k, alpha, r, th: k * np.cos(th) / r**2.0), ManufacturedSolution("2D: theta and r", 2, lambda t, r, th: np.cos(th) / r, lambda t, k, alpha, r, th: -k*np.cos(th) / r**3.0), ManufacturedSolution("2D: all three", 2, lambda t, r, th: np.log(r) * np.sin(th) / (t+1), lambda t, k, alpha, r, th: k*np.log(r)*np.sin(th)/((t+1)*r**2.0) - k/alpha * np.log(r) * np.sin(th) / (t+1)**2.0), ManufacturedSolution("3D: just t", 3, lambda t, r, th, z: t, lambda t, k, alpha, r, th, z: k/alpha * (r*0.0+1)), ManufacturedSolution("3D: just r", 3, lambda t, r, th, z: np.sin(r), lambda t, k, alpha, r, th, z: k * np.sin(r) - k/r * np.cos(r)), ManufacturedSolution("3D: just theta", 3, lambda t, r, th, z: np.cos(th), lambda t, k, alpha, r, th, z: k * np.cos(th) / r**2.0), ManufacturedSolution("3D: just z", 3, lambda t, r, th, z: np.sin(z), lambda t, k, alpha, r, th, z: k * np.sin(z)), ManufacturedSolution("3D: all spatial", 3, lambda t, r, th, z: z**2.0*np.cos(th)/r, lambda t, k, alpha, r, th, z: -k*np.cos(th)/r*((z/r)**2.0+2)), ManufacturedSolution("3D: everything", 3, lambda t, r, th, z: np.log(r)*np.sin(th)*np.cos(z)/(t+1.0), lambda t, k, alpha, r, th, z: k*np.log(r) * np.sin(th) * np.cos(z) / (t+1) * (1.0 + 1/r**2.0 - 1.0/(alpha*(t+1)))), ] self.solver = thermal.FiniteDifferenceImplicitThermalSolver() self.material = materials.ConstantThermalMaterial("Test", 10.0, 5.0) self.fluid = materials.ConstantFluidMaterial({"Test": 7.5}) self.tol = 1e-2 self.atol = 1e-3
def make_tube(D, period): R = 1.0 t = 0.1 h = 10.0 nr = 10 nt = 20 nz = 10 T0 = 50 tmax = period ntime = 10 T0 = 300 tube = receiver.Tube(R, t, h, nr, nt, nz, T0=T0) if D == 1: tube.make_1D(h / 2, 1) elif D == 2: tube.make_2D(h / 2) times = np.linspace(0, tmax, ntime) tube.set_times(times) Tf_0 = 300 Tf_m = 600 def fluid_T(t): if t < tmax / 2.0: return Tf_0 + (Tf_m - Tf_0) / (tmax / 2.0) * t else: return Tf_m - (Tf_m - Tf_0) / (tmax / 2.0) * (t - tmax / 2.0) ftemps = np.array([fluid_T(t) * np.ones((nz, )) for t in times]) inner_convection = receiver.ConvectiveBC(R - t, h, nz, times, ftemps) tube.set_bc(inner_convection, "inner") hflux = receiver.HeatFluxBC(R, h, nt, nz, times, np.zeros((ntime, nt, nz)) + 2.0) tube.set_bc(hflux, "outer") solver = thermal.FiniteDifferenceImplicitThermalSolver() tmat = materials.ConstantThermalMaterial("dummy", 20.0e-3, 4.8) fmat = materials.ConstantFluidMaterial({"dummy": 8.1e-3}) solver.solve(tube, tmat, fmat) return tube
import numpy as np problem = ManufacturedSolution( "test", 1, lambda t, r: np.sin(r), lambda t, k, alpha, r: k * np.sin(r) - k / r * np.cos(r)) def run_with(solver, material, fluid): """ Run the standard problems with the provided solver and material """ for problem in problems: res = problem.solve(solver, material, fluid) problem.plot_comparison(res) plt.show() if __name__ == "__main__": solver = thermal.FiniteDifferenceImplicitThermalSolver() tmat = materials.ConstantThermalMaterial("Test", 10.0, 5.0) fmat = materials.ConstantFluidMaterial({"Test": 7.5}) if len(sys.argv) == 2: n = int(sys.argv[1]) else: n = 1 for i in range(n): res = problem.solve(solver, tmat, fmat)