Hi @ngeneva
I fixed the data in my CSV file and using the CustomValidatorPlotter fixed my previous error. However, now I am getting a new error message:
`> error: <__main__.CustomValidatorPlotter object at 0x7f249738d4c0>.__call__ raised an exception: __call__() takes 3 positional arguments but 4 were given`
This is my code after importing all the necessary libraries:
class PFR_equation2D(PDE):
name = "PFR_equation2D"
def __init__(self):
# z coordinate
x = Symbol("x")
#time
t = Symbol("t")
temp = Symbol("temp")
temp = 273
input_variables = {"x": x, "t": t}
c = Function("c")(*input_variables)
Temp = Function("Temp")(*input_variables)
#write equation and store it in the class by adding it to the dictionary of equation
self.equations = {}
self.equations["PFR_equation_c"] = c.diff(t,1) - 0.01*(c.diff(x,2)) + 0.5*(c.diff(x)) + 1.0*(c**2)
arrh_exp = 4.68*math.exp(-806/((600-273)*temp+273)) #rate constant calculated using arrhenius expression at T=273degC. At Tmax, plot didn't change
self.equations["PFR_equation_T"] = Temp.diff(t,1) - 0.01*(Temp.diff(x,2)) + 0.5*(Temp.diff(x)) - 2.45*arrh_exp*(c**2)
class CustomValidatorPlotter(ValidatorPlotter):
def __call__(self, invar, outvar):
ndim = len(invar)
extent, outvar = self._interpolate_2D(100, invar, outvar)
a = np.linspace(0, 1, 100)
b = np.linspace(0, 4, 100)
dims = list(invar.keys())
fs = []
for k in outvar:
f = plt.figure(figsize=(5, 4), dpi=100)
plt.pcolor(a, b, outvar[k].T, vmax=1.0, vmin=0.0) # origin="lower", extent=extent)
plt.xlabel(dims[0])
plt.ylabel(dims[1])
plt.colorbar()
plt.title(k)
plt.tight_layout()
fs.append((f, k))
@modulus.main(config_path="conf", config_name="config")
def run(cfg: ModulusConfig) -> None:
pfr = PFR_equation2D()
pfr_net = instantiate_arch(
input_keys=[Key("x"), Key("t")],
output_keys=[Key("c"), Key("Temp")],
cfg=cfg.arch.fully_connected,
)
nodes = pfr.make_nodes() + [pfr_net.make_node(name="pfr_network")]
x, t = Symbol("x"), Symbol("t")
time_range = {t : (0,4)}
geo = Line1D(0, 1)
#make domain
domain = Domain()
#initial condition
IC = PointwiseInteriorConstraint(
nodes=nodes,
geometry=geo,
outvar={"c": 0, "Temp":0},
batch_size=cfg.batch_size.IC,
parameterization={t: 0.0}
)
domain.add_constraint(IC, "IC")
#boundary condition for both PDEs
BC = PointwiseBoundaryConstraint(
nodes=nodes,
geometry=geo,
outvar={"c": 1},
batch_size=cfg.batch_size.BC,
criteria=Eq(x, 0),
parameterization=time_range
)
domain.add_constraint(BC, "BC")
#boundary condition 2 for both PDEs
BC2 = PointwiseBoundaryConstraint(
nodes=nodes,
geometry=geo,
outvar={"c__x": 0,"Temp__x": 0,},
batch_size=cfg.batch_size.BC2,
criteria=Eq(x, 1),
parameterization=time_range
)
domain.add_constraint(BC2, "BC2")
#interior for PDE 1
interior = PointwiseInteriorConstraint(
nodes=nodes,
geometry=geo,
outvar={"PFR_equation_c": 0},
batch_size=cfg.batch_size.interior,
parameterization=time_range
)
domain.add_constraint(interior, "interior")
#interior for PDE 2
interior2 = PointwiseInteriorConstraint(
nodes=nodes,
geometry=geo,
outvar={"PFR_equation_T": 0},
batch_size=cfg.batch_size.interior,
parameterization=time_range
)
domain.add_constraint(interior2, "interior2")
x = np.linspace(0, 1, 100)
t = np.linspace(0, 4, 100)
X, T = np.meshgrid(x, t)
X = np.expand_dims(X.flatten(), axis=-1)
T = np.expand_dims(T.flatten(), axis=-1)
invar_numpy = {"x": X, "t": T}
grid_inference = PointwiseInferencer(
nodes=nodes,
invar=invar_numpy,
output_names=["c","Temp"],
batch_size=128,
plotter=InferencerPlotter(),
)
domain.add_inferencer(grid_inference, "inf_data")
#add validation data
#need to create CSV files for inputs too, even though they don't need validation,
mapping = {"Concentration":"c", "Temperature": "Temp", "z-axis": "x", "time":"t"}
val_data = csv_to_dict(to_absolute_path("Val_data.csv"),mapping)
val_invar_numpy = {
key: value for key, value in val_data.items() if key in ["x", "t"]
}
val_outvar_numpy = {
key: value for key, value in val_data.items() if key in ["c", "Temp"]
}
validator = PointwiseValidator(
nodes=nodes,
invar=val_invar_numpy,
true_outvar=val_outvar_numpy,
batch_size=128,
plotter=CustomValidatorPlotter(),
)
domain.add_validator(validator, "val_data")
#create solver
slv = Solver(cfg, domain)
slv.solve()
if __name__ == "__main__":
run()
I tried doing two separate mappings for c and Temp, but that didn’t solve the problem. As you can see from the PDE equations I defined at the top of my code, the second equation relies on three variables and is linked to the other PDE. I believe I am almost close to the solution, but I am having problems fixing the error message