|
1 | 1 | import festim as F |
2 | 2 | import openmc2dolfinx |
| 3 | +from festim.helpers import nmm_interpolate |
| 4 | +import dolfinx |
| 5 | +from dolfinx.io import gmshio, XDMFFile |
| 6 | +from mpi4py import MPI |
3 | 7 |
|
4 | | -reader = openmc2dolfinx.StructuredGridReader("out.vtk") |
5 | | -# t_production = reader.create_dolfinx_function("mean") |
| 8 | +from create_mesh import gmsh, mesh_comm, model_rank |
6 | 9 |
|
| 10 | +irradiation_time = 10 # s |
| 11 | +neutron_rate = 1e8 # n/s |
| 12 | +percm3_to_perm3 = 1e6 |
7 | 13 |
|
8 | | -from dolfinx.io import gmshio, XDMFFile |
9 | | -from mpi4py import MPI |
| 14 | +# Read OpenMC tally results |
| 15 | +reader = openmc2dolfinx.StructuredGridReader("out.vtk") |
| 16 | +t_production = reader.create_dolfinx_function("mean") |
| 17 | +mesh_source = t_production.function_space.mesh |
| 18 | +mesh_source.geometry.x[:] *= 1e-2 # cm to m |
| 19 | +mesh_source.geometry.x[:, 1] += -0.027 |
| 20 | +mesh_source.geometry.x[:, 2] += -0.45 |
10 | 21 |
|
| 22 | +t_production.x.array[:] *= neutron_rate # T/n/cm3 to T/s/cm3 |
| 23 | +t_production.x.array[:] *= percm3_to_perm3 # T/s/cm3 to T/s/m3 |
11 | 24 |
|
12 | | -from create_mesh import gmsh, mesh_comm, model_rank |
13 | 25 |
|
14 | 26 | mesh, ct, ft = gmshio.model_to_mesh(gmsh.model, comm=mesh_comm, rank=model_rank) |
15 | 27 |
|
16 | | -mesh.geometry.x[:,] |
| 28 | +mesh.geometry.x[:] *= 1e-3 # mm to m |
| 29 | + |
| 30 | +# rotate 90 degrees around x axis (switch y and z) |
| 31 | +y_values = mesh.geometry.x[:, 1].copy() |
| 32 | +z_values = mesh.geometry.x[:, 2].copy() |
| 33 | +mesh.geometry.x[:, 1] = z_values |
| 34 | +mesh.geometry.x[:, 2] = y_values |
| 35 | + |
| 36 | + |
| 37 | +V = dolfinx.fem.functionspace(mesh, ("CG", 1)) |
| 38 | +t_production_on_wedge = dolfinx.fem.Function(V) |
| 39 | +t_production_on_wedge.name = "T production" |
| 40 | + |
| 41 | + |
| 42 | +nmm_interpolate(t_production_on_wedge, t_production) |
17 | 43 |
|
18 | 44 |
|
19 | 45 | with XDMFFile(MPI.COMM_WORLD, "mt.xdmf", "w") as xdmf: |
|
24 | 50 | xdmf.write_mesh(mesh) |
25 | 51 | xdmf.write_meshtags(ft, mesh.geometry) |
26 | 52 |
|
| 53 | +with XDMFFile(MPI.COMM_WORLD, "t_production.xdmf", "w") as xdmf: |
| 54 | + xdmf.write_mesh(mesh) |
| 55 | + xdmf.write_function(t_production_on_wedge) |
| 56 | + |
| 57 | + |
| 58 | +# NOTE need to override these methods in ParticleSource until a |
| 59 | +# new version of festim is released |
| 60 | +class ValueFromOpenMC(F.Value): |
| 61 | + explicit_time_dependent = True |
| 62 | + temperature_dependent = False |
| 63 | + |
| 64 | + def update(self, t): |
| 65 | + if t < irradiation_time: |
| 66 | + return |
| 67 | + else: |
| 68 | + self.fenics_object.x.array[:] = 0.0 |
| 69 | + |
| 70 | + |
| 71 | +# NOTE need to overrid this because ParticleSource won't accept a F.Value as value |
| 72 | +# need to fix in FESTIM |
| 73 | +class SourceFromOpenMC(F.ParticleSource): |
| 74 | + @property |
| 75 | + def value(self): |
| 76 | + return self._value |
| 77 | + |
| 78 | + @value.setter |
| 79 | + def value(self, value): |
| 80 | + if isinstance(value, F.Value): |
| 81 | + self._value = value |
| 82 | + else: |
| 83 | + self._value = F.Value(value) |
| 84 | + |
27 | 85 |
|
28 | 86 | model = F.HydrogenTransportProblem() |
29 | 87 | model.volume_meshtags = ct |
30 | 88 | model.facet_meshtags = ft |
31 | 89 |
|
32 | | -salt = F.Material(D_0=100, E_D=0) |
| 90 | +salt = F.Material(D_0=0.5, E_D=0) |
33 | 91 |
|
34 | 92 | top_surface = F.SurfaceSubdomain(id=1) |
35 | 93 | volume = F.VolumeSubdomain(id=1, material=salt) |
|
44 | 102 | F.FixedConcentrationBC(subdomain=top_surface, value=0.0, species=T) |
45 | 103 | ] |
46 | 104 |
|
47 | | -model.sources = [F.ParticleSource(value=1, volume=volume, species=T)] |
| 105 | +model.sources = [ |
| 106 | + SourceFromOpenMC( |
| 107 | + value=ValueFromOpenMC(t_production_on_wedge), volume=volume, species=T |
| 108 | + ) |
| 109 | +] |
48 | 110 |
|
49 | 111 | model.temperature = 650.0 |
50 | 112 |
|
51 | | -model.settings = F.Settings(atol=1e0, rtol=1e-10, transient=True, final_time=10) |
| 113 | +model.settings = F.Settings(atol=1e-10, rtol=1e-10, final_time=100) |
52 | 114 |
|
53 | | -model.settings.stepsize = 1 |
| 115 | +model.settings.stepsize = F.Stepsize( |
| 116 | + 0.1, |
| 117 | + growth_factor=1.1, |
| 118 | + cutback_factor=0.9, |
| 119 | + target_nb_iterations=4, |
| 120 | + milestones=[irradiation_time], |
| 121 | +) |
54 | 122 |
|
55 | 123 | model.exports = [ |
56 | 124 | F.VTXSpeciesExport(filename="tritium_conc.bp", field=T), |
|
0 commit comments