Skip to content

Commit 081a17e

Browse files
working model
1 parent 473bf61 commit 081a17e

1 file changed

Lines changed: 78 additions & 10 deletions

File tree

festim_model.py

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
11
import festim as F
22
import openmc2dolfinx
3+
from festim.helpers import nmm_interpolate
4+
import dolfinx
5+
from dolfinx.io import gmshio, XDMFFile
6+
from mpi4py import MPI
37

4-
reader = openmc2dolfinx.StructuredGridReader("out.vtk")
5-
# t_production = reader.create_dolfinx_function("mean")
8+
from create_mesh import gmsh, mesh_comm, model_rank
69

10+
irradiation_time = 10 # s
11+
neutron_rate = 1e8 # n/s
12+
percm3_to_perm3 = 1e6
713

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
1021

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
1124

12-
from create_mesh import gmsh, mesh_comm, model_rank
1325

1426
mesh, ct, ft = gmshio.model_to_mesh(gmsh.model, comm=mesh_comm, rank=model_rank)
1527

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)
1743

1844

1945
with XDMFFile(MPI.COMM_WORLD, "mt.xdmf", "w") as xdmf:
@@ -24,12 +50,44 @@
2450
xdmf.write_mesh(mesh)
2551
xdmf.write_meshtags(ft, mesh.geometry)
2652

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+
2785

2886
model = F.HydrogenTransportProblem()
2987
model.volume_meshtags = ct
3088
model.facet_meshtags = ft
3189

32-
salt = F.Material(D_0=100, E_D=0)
90+
salt = F.Material(D_0=0.5, E_D=0)
3391

3492
top_surface = F.SurfaceSubdomain(id=1)
3593
volume = F.VolumeSubdomain(id=1, material=salt)
@@ -44,13 +102,23 @@
44102
F.FixedConcentrationBC(subdomain=top_surface, value=0.0, species=T)
45103
]
46104

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+
]
48110

49111
model.temperature = 650.0
50112

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)
52114

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+
)
54122

55123
model.exports = [
56124
F.VTXSpeciesExport(filename="tritium_conc.bp", field=T),

0 commit comments

Comments
 (0)