Developed by Moeid Heidari and Omar Mohammed
Non homogeneous Heat conduction equation implementation in C++.
Step 2. Expand u(x,t), f(x,t), and P(x) in series of Gn(x). This will convert the nonhomogeneous PDE to a set of simple nonhomogeneous ODEs.
Step 3. We Solve the nonhomogeneous ODEs, use their solutions to reassemble the complete solution for the PDE.
For the current example, our eigenfunctions are Gn(x) = sin(nπx), so we should try
From Eqs. (3) and (4), qn(t) and un(0) have already been determined. Our task is to solve un(t) and express it in
un(0) (the initial condition of un(t)) and qn(t) (the forcing that acts on un(t)).
Plugging Eq. (2) into the original PDE, we have
or,
Equation (5) has the standard solution,
Since un(0) and qn(t) are known from Eqs. (3) and (4), we have the complete solution once the integral in Eq. (6)
is evaluated to obtain un(t) ; u(x,t) can be evaluated by Eq. (2) once un(t) is known.
Thus, the expansion in Eq. (2) is reduced to just two terms,
The final solution:
Where,
Use the Makefile to make the source code
IDIR =include
CC=g++
CFLAGS=-I$(IDIR)
ODIR=obj
LDIR =lib
_DEPS = PDE.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ = pde.o main.o
OBJ = $($(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: main.cpp $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
all: $(OBJ)
$(CC) $(CFLAGS) $(LIBS) src/main.cpp -o main
.PHONY: clean
clean:
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
#use make in the root directory of the project
make
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.