Skip to content

Commit

Permalink
modified for mass computation
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal FREY committed Aug 1, 2018
1 parent b1996bd commit 482421c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
26 changes: 0 additions & 26 deletions sources/inout.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
#include "libmesh5.h"


static inline double mass_2d(double *a,double *b,double *c) {
return( ((b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])) / 2.0 );
}


/* read mesh */
int loadMesh(NSst *nsst) {
pMat pm;
Expand Down Expand Up @@ -118,19 +113,6 @@ int loadMesh(NSst *nsst) {
for (k=1; k<=nsst->info.nt; k++) {
pt1 = &nsst->mesh.tria[k];
GmfGetLin(inm,GmfTriangles,&pt1->v[0],&pt1->v[1],&pt1->v[2],&pt1->ref);
/* compute initial mass */
if ( nsst->info.dim == 2 && nsst->sol.nmat ) {
a = &nsst->mesh.point[pt1->v[0]].c[0];
b = &nsst->mesh.point[pt1->v[1]].c[0];
c = &nsst->mesh.point[pt1->v[2]].c[0];
for (i=0; i<nsst->sol.nmat; i++) {
pm = &nsst->sol.mat[i];
if ( pm->ref == pt1->ref ) {
pm->mass += mass_2d(a,b,c);
break;
}
}
}
}
}
/* read mesh tetrahedra */
Expand All @@ -151,14 +133,6 @@ int loadMesh(NSst *nsst) {
if ( nsst->info.nt ) fprintf(stdout,", %d triangles",nsst->info.nti);
if ( nsst->info.ne ) fprintf(stdout,", %d tetrahedra",nsst->info.nei);
fprintf(stdout,"\n");
if ( nsst->sol.nmat > 0 ) {
printf(" mass: ");
for (i=0; i<nsst->sol.nmat; i++) {
pm = &nsst->sol.mat[i];
printf("%g, ",pm->mass);
}
fprintf(stdout,"\n");
}
}

return(1);
Expand Down
2 changes: 1 addition & 1 deletion sources/nstokes.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ int main(int argc,char **argv) {
}

/* packing mesh if needed */
if ( nsst.sol.nmat ) {
if ( nsst.sol.nmat > 0 ) {
ier = nsst.info.dim == 2 ? pack_2d(&nsst) : pack_3d(&nsst);
if ( ier == 0 ) {
if ( nsst.info.verb != '0' ) fprintf(stdout," # Packing error.\n");
Expand Down
35 changes: 31 additions & 4 deletions sources/packing.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "nstokes.h"


static inline double mass_2d(double *a,double *b,double *c) {
return( ((b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])) / 2.0 );
}


/* compactify mesh structure */
int pack_3d(NSst *nsst) {
pTetra pe;
Expand Down Expand Up @@ -184,17 +189,39 @@ int pack_2d(NSst *nsst) {
pTria pt;
pEdge pa;
pPoint ppt;
double nu,rho,w[2];
pMat pm;
double *a,*b,*c,mass,nu,rho,w[2];
int *prm,i,k,nf,id;

/* check if compression needed */
nf = 0;
for (k=1; k<=nsst->info.nti; k++) {
pt = &nsst->mesh.tria[k];
if ( getMat(&nsst->sol,pt->ref,&nu,&rho) ) {
nf++;
for (i=0; i<3; i++) nsst->mesh.point[pt->v[i]].new = pt->v[i];
a = &nsst->mesh.point[pt->v[0]].c[0];
b = &nsst->mesh.point[pt->v[1]].c[0];
c = &nsst->mesh.point[pt->v[2]].c[0];

/* compute mass */
for (i=0; i<nsst->sol.nmat; i++) {
pm = &nsst->sol.mat[i];
if ( pm->ref == pt->ref ) {
pm->mass += mass_2d(a,b,c);
nf++;
/* for renumbering purposes */
for (i=0; i<3; i++) nsst->mesh.point[pt->v[i]].new = pt->v[i];
break;
}
}
}
if ( nsst->info.verb != '0' ) {
fprintf(stdout," mass: ");
mass = 0.0;
for (i=0; i<nsst->sol.nmat; i++) {
pm = &nsst->sol.mat[i];
fprintf(stdout," %g [%d], ",pm->mass,pm->ref);
mass += pm->mass;
}
fprintf(stdout," total: %g\n",mass);
}
if ( nf == nsst->info.nti ) return(-1);

Expand Down

0 comments on commit 482421c

Please sign in to comment.