17 int i0=cells(icell,0);
18 int i1=cells(icell,1);
19 int i2=cells(icell,2);
22 double V00= points(i1,0)- points(i0,0);
23 double V01= points(i2,0)- points(i0,0);
25 double V10= points(i1,1)- points(i0,1);
26 double V11= points(i2,1)- points(i0,1);
29 double det=V00*V11 - V01*V10;
41 int i0=cells(icell,0);
42 int i1=cells(icell,1);
43 int i2=cells(icell,2);
46 double V00= points(i1,0)- points(i0,0);
47 double V01= points(i2,0)- points(i0,0);
49 double V10= points(i1,1)- points(i0,1);
50 double V11= points(i2,1)- points(i0,1);
53 double det=V00*V11 - V01*V10;
57 SLocal(0,0)= fac * ( ( V10-V11 )*( V10-V11 )+( V01-V00 )*( V01-V00 ) );
58 SLocal(0,1)= fac * ( ( V10-V11 )* V11 - ( V01-V00 )*V01 );
59 SLocal(0,2)= fac * ( -( V10-V11 )* V10 + ( V01-V00 )*V00 );
61 SLocal(1,1)= fac * ( V11*V11 + V01*V01 );
62 SLocal(1,2)= fac * ( -V11*V10 - V01*V00 );
64 SLocal(2,2)= fac * ( V10*V10+ V00*V00 );
66 SLocal(1,0)=SLocal(0,1);
67 SLocal(2,0)=SLocal(0,2);
68 SLocal(2,1)=SLocal(1,2);
100 double third=1.0/3.0;
104 for (
int icell=0; icell<ncells; icell++)
109 double klocal=(kappa(cells(icell,0))+kappa(cells(icell,1))+kappa(cells(icell,2)))/3.0;
111 for (
int i=0;i<=ndim;i++)
112 for (
int j=0;j<=ndim;j++)
114 Rhs(cells(icell,i))+=vol*MLocal0(i,j)*source(cells(icell,j));
115 SGlobal(cells(icell,i),cells(icell,j))+=klocal*SLocal(i,j);
125 for (
int ibface=0; ibface<nbfaces; ibface++)
128 int ireg=bfaceregions(ibface);
129 int i0=bfaces(ibface,0);
130 int i1=bfaces(ibface,1);
136 SGlobal(i0,i0)+=bcfac(ireg);
137 Rhs(i0)+=bcfac(ireg)*bcval(ireg);
139 SGlobal(i1,i1)+=bcfac(ireg);
140 Rhs(i1)+=bcfac(ireg)*bcval(ireg);
143 else if (bcfac(ireg)>0.0)
146 double dx= points(bfaces(ibface,1),0)-points(bfaces(ibface,0),0);
147 double dy= points(bfaces(ibface,1),1)-points(bfaces(ibface,0),1);
148 double h=sqrt(dx*dx+dy*dy);
150 SGlobal(i0,i0)+=h*bcfac(ireg)/3.0;
151 SGlobal(i0,i1)+=h*bcfac(ireg)/6.0;
153 SGlobal(i1,i0)+=h*bcfac(ireg)/6.0;
154 SGlobal(i1,i1)+=h*bcfac(ireg)/3.0;
156 Rhs(i0)+=0.5*h*bcval(ireg);
157 Rhs(i1)+=0.5*h*bcval(ireg);
184 double tauinv=1.0/tau;
202 for (
int icell=0; icell<ncells; icell++)
205 double klocal=(kappa(cells(icell,0))+kappa(cells(icell,1))+kappa(cells(icell,2)))/3.0;
208 double KLocal=(kappa(cells(icell,0))+kappa(cells(icell,1))+kappa(cells(icell,2)))/3.0;
212 for (
int i=0;i<=ndim;i++)
213 for (
int j=0;j<=ndim;j++)
215 SGlobal(cells(icell,i),cells(icell,j))+=theta*KLocal*SLocal(i,j)+ tauinv*vol*MLocal(i,j);
217 Rhs(cells(icell,i))+=((theta-1)*KLocal*SLocal(i,j)+tauinv*vol*MLocal(i,j))*
218 OldSol(cells(icell,j))+vol*MLocal(i,j)*source(cells(icell,j));
227 for (
int ibface=0; ibface<nbfaces; ibface++)
230 int ireg=bfaceregions(ibface);
231 int i0=bfaces(ibface,0);
232 int i1=bfaces(ibface,1);
238 SGlobal(i0,i0)+=bcfac(ireg);
239 Rhs(i0)+=bcfac(ireg)*bcval(ireg);
241 SGlobal(i1,i1)+=bcfac(ireg);
242 Rhs(i1)+=bcfac(ireg)*bcval(ireg);
244 else if (bcfac(ireg)>0.0)
247 double dx= points(bfaces(ibface,1),0)-points(bfaces(ibface,0),0);
248 double dy= points(bfaces(ibface,1),1)-points(bfaces(ibface,0),1);
249 double h=sqrt(dx*dx+dy*dy);
251 int i0=bfaces(ibface,0);
252 int i1=bfaces(ibface,1);
254 SGlobal(i0,i0)+=theta*h*bcfac(ireg)/3.0;
255 SGlobal(i0,i1)+=theta*h*bcfac(ireg)/6.0;
257 SGlobal(i1,i0)+=theta*h*bcfac(ireg)/6.0;
258 SGlobal(i1,i1)+=theta*h*bcfac(ireg)/3.0;
260 Rhs(i0)+=OldSol(i0)*(1.0-theta)*h*bcfac(ireg)/3.0;
261 Rhs(i0)+=OldSol(i1)*(1.0-theta)*h*bcfac(ireg)/6.0;
262 Rhs(i1)+=OldSol(i0)*(1.0-theta)*h*bcfac(ireg)/6.0;
263 Rhs(i1)+=OldSol(i1)*(1.0-theta)*h*bcfac(ireg)/3.0;
265 Rhs(i0)+=0.5*h*bcval(ireg);
266 Rhs(i0)+=0.5*h*bcval(ireg);
290 for (
int icell=0; icell<ncells; icell++)
295 for (
int i=0;i<=ndim;i++)
296 for (
int j=0;j<=ndim;j++)
297 norm+=u(cells(icell,i))*u(cells(icell,j))*vol*MLocal(i,j);
315 for (
int icell=0; icell<ncells; icell++)
319 for (
int i=0;i<=ndim;i++)
320 for (
int j=0;j<=ndim;j++)
321 norm+=u(cells(icell,i))*u(cells(icell,j))*SLocal(i,j);
const int ncells() const
Return number of cells.
Sparse matrix class using CRS storage scheme.
const int nbfaces() const
Return number of boundary faces.
void compute_local_stiffness_matrix(const int icell, const numcxx::DArray2 &points, const numcxx::IArray2 &cells, numcxx::DArray2 &SLocal, double &vol)
const TArray2< int > & get_bfaces() const
Get array of point indices describing boundary faces.
Header for simple grid data class.
void flush()
Re-create the internal data structure in order to accomodated all newly created elements.
const TArray2< double > & get_points() const
Get array of point coordinates.
void assemble_heat_problem(const numcxx::SimpleGrid &Grid, const numcxx::DArray1 &BCfac, const numcxx::DArray1 &BCval, const numcxx::DArray1 &Source, const numcxx::DArray1 &Kappa, numcxx::DSparseMatrix &SGlobal, numcxx::DArray1 &Rhs)
Main header of the library.
const TArray1< int > & get_bfaceregions() const
Get array of boundary markers.
double h1norm(const numcxx::SimpleGrid &grid, const numcxx::DArray1 &u)
const double Dirichlet
BC value marking Dirichlet boundary condition.
void assemble_transient_heat_problem(const numcxx::SimpleGrid &grid, const numcxx::DArray1 &bcfac, const numcxx::DArray1 &bcval, const numcxx::DArray1 &source, const numcxx::DArray1 &kappa, double tau, double theta, bool lump, numcxx::DArray1 &OldSol, numcxx::DSparseMatrix &SGlobal, numcxx::DArray1 &Rhs)
One dimensional array class.
Class containing data for simple grid data structure.
void compute_cell_volume(const int icell, const numcxx::DArray2 &points, const numcxx::IArray2 &cells, double &vol)
Two-dimensional array class.
const int npoints() const
Return number of points.
A::value_type norm(const A &a)
Euklidean norm of array or expression.
const TArray2< int > & get_cells() const
Get array of point indices describing cells.
double l2norm(const numcxx::SimpleGrid &grid, const numcxx::DArray1 &u)
const int spacedim() const
Return dimension of space.