Hello, I write this code to create multiple heat source.
import numpy as np
from sympy import Symbol, exp, pi
import torch
import sys
import modulus.sym
from modulus.sym.hydra import ModulusConfig, instantiate_arch
from modulus.sym.solver import Solver
from modulus.sym.domain import Domain
from modulus.sym.geometry.primitives_2d import Rectangle
from modulus.sym.domain.constraint import (
PointwiseBoundaryConstraint,
PointwiseInteriorConstraint,
)
from modulus.sym.eq.pdes.diffusion import Diffusion
from modulus.sym.domain.validator import PointwiseValidator
from modulus.sym.key import Key
from modulus.sym.models.fully_connected import FullyConnectedArch
@modulus.sym.main(config_path="/content/", config_name="config_heat.yaml")
def run(cfg: ModulusConfig) -> None:
# symbols
x, y, t_symbol = Symbol("x"), Symbol("y"), Symbol("t")
# parameters
sigma = 0.1
init_temp = 37
t_max = 10
# heat source centers
centers = [
(-0.8, 0.8),
(-0.8, -0.8),
(0.8, 0.8),
(0.8, -0.8)
]
# heat_source
heat_source_expr = sum(
(1 / (2 * pi * sigma**2)) * exp(-((x - xi) ** 2 + (y - yi) ** 2) / (2 * sigma ** 2)) for xi, yi in centers)
# diffusion equation with heat source
diffusion_eq = Diffusion(T="T", D=0.1, Q=heat_source_expr, dim=2, time=True)
# neural network
heat_net = instantiate_arch(
input_keys=[Key("x"), Key("y"), Key("t")],
output_keys=[Key("T")],
cfg=cfg.arch.fully_connected)
# create nodes
nodes = diffusion_eq.make_nodes() + [heat_net.make_node(name="heat_network")]
# geometry and domain
geo = Rectangle((-1.0, -1.0), (1.0, 1.0))
domain = Domain()
time_range = {t_symbol: (0, T_MAX)}
# IC
IC = PointwiseInteriorConstraint(
nodes=nodes,
geometry=geo,
outvar={"T": init_temp}, # init temp, 37
batch_size=cfg.batch_size.IC,
parameterization={t_symbol: 0.0} # t=0
)
domain.add_constraint(IC, "IC")
# BC
BC = PointwiseBoundaryConstraint(
nodes=nodes,
geometry=geo,
outvar={"T": init_temp}, # boundary temp, 37
batch_size=cfg.batch_size.BC,
parameterization=time_range, # includes all time
)
domain.add_constraint(BC, "BC")
# interior constraint enforcing PDE residuals
interior = PointwiseInteriorConstraint(
nodes=nodes,
geometry=geo,
outvar={"diffusion_T": 0}, # Enforce PDE residuals
batch_size=cfg.batch_size.interior,
parameterization=time_range
)
domain.add_constraint(interior, "interior")
# solver
slv = Solver(cfg, domain)
slv.solve()
if __name__ == "__main__":
if 'google.colab' in sys.modules or 'ipykernel' in sys.modules:
sys.argv = sys.argv[:1]
run()
In this code, I defined my initial and boundary conditions as 37 Degree. I have used Gaussian 2D as heat source and I defined 4 different centers.
And I get this result. I hope it helps for your case.