![]() |
![]() |
![]() |
This code is developed to solve 2-D transient (time dependent) heat transfer problems. We use here an alternative to the presentation of the previous demo code. More specifically, we show how to perform all important phases of a time dependent finite element code.
#include "OFELI.h" #include "Therm.h" using namespace OFELI; |
IPF data("ttd2 - 1.1",argv[1]);
double max_time = data.getMaxTime();
double deltat = data.getTimeStep();
int save_flag = data.getSave();
int verbose = data.getVerbose();
|
IOField pf(data.getPlotFile(),OUT); |
Mesh ms(data.getMeshFile()); SkSMatrix<double> A(ms); Vect<double> b(ms.getNbDOF()), u(ms.getNbDOF()); |
Prescription pr(ms,data.getDataFile()); pr.get(INITIAL_FIELD,u); |
Vect<double> bc(ms.getNbDOF()), body_f(ms.getNbDOF()), bound_f(ms.getNbDOF()); int nb_step = int(max_time/deltat); |
double time = 0;
for (int step=1; step<=nb_step; step++) {
time += deltat;
b = 0;
|
pr.get(BOUNDARY_CONDITION,bc,time);
pr.get(SOURCE,body_f,time);
pr.get(FLUX,bound_f,time);
|
Element *el;
MeshElementLoop(ms,el) {
|
DC2DT3 eq(el,u,time);
eq.LCapacity(double(1./deltat));
eq.Diffusion();
eq.BodyRHS(Vect<double>(el,body_f));
|
if (step==1)
eq.ElementAssembly(A);
b.ElementAssembly(b);
}
|
Side *sd;
MeshSideLoop(ms,sd) {
DC2DT3 eq(sd,u,time);
eq.BoundaryRHS(Vect<double>(el,bound_f));
b.Assembly(sd,eq.b());
}
|
A.Prescribe(ms,b,bc,step-1);
if (step == 1)
A.Factor();
A.Solve(b);
u = b;
|
NodeVect<double> U(ms,u,"Temperature",time);
if (step%save_flag == 0)
pf.put(U);
}
|
saveGnuplot(data.getProject()+"-gpl1.dat",ms); |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<OFELI_File>
<info>
<title>Finite Element Mesh of a beam</title>
<date>January 1, 2010</date>
<author>R. Touzani</author>
</info>
<Project name="proj">
<mesh_file>proj-5x10.m</mesh_file>
<plot_file>proj.pl</plot_file>
<time_step>0.01</time_step>
<max_time>1.0</max_time>
<verbose>0</verbose>
<output>0</output>
<save>1</save>
</Project>
<Prescription>
<BoundaryCondition code="1">-tanh(10)*(exp(t)-1)</BoundaryCondition>
<BoundaryCondition code="2"> tanh(10)*(exp(t)-1)</BoundaryCondition>
<Source>tanh(10*y)*(exp(t)+200*(exp(t)-1)/(cosh(10*y)*cosh(10*y)))</Source>
</Prescription>
</OFELI_File>
|
In summary, this file looks mainly like the one in the previous example. We show here in addition how to prescribe a boundary condition by an algebraic expression. The OFELI library is equipped with the expression parser fparser. We use here the variables x, y, z, and t for space and time variables.
![]() |
![]() |
![]() |