M-x delete-trailing-whitespace .
This commit is contained in:
70
geometry.c
70
geometry.c
@@ -3,7 +3,7 @@
|
||||
#include "geometry.h"
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
static void
|
||||
static void
|
||||
cross(const double u[3], const double v[3], double w[3])
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
@@ -13,7 +13,7 @@ cross(const double u[3], const double v[3], double w[3])
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
static double
|
||||
static double
|
||||
norm(const double w[3])
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
@@ -23,9 +23,9 @@ norm(const double w[3])
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
void
|
||||
compute_face_geometry(int ndims, double *coords, int nfaces,
|
||||
int *nodepos, int *facenodes, double *fnormals,
|
||||
void
|
||||
compute_face_geometry(int ndims, double *coords, int nfaces,
|
||||
int *nodepos, int *facenodes, double *fnormals,
|
||||
double *fcentroids, double *fareas)
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
@@ -36,7 +36,7 @@ compute_face_geometry(int ndims, double *coords, int nfaces,
|
||||
double u[3];
|
||||
double v[3];
|
||||
double w[3];
|
||||
|
||||
|
||||
int i,k;
|
||||
int node;
|
||||
|
||||
@@ -44,12 +44,12 @@ compute_face_geometry(int ndims, double *coords, int nfaces,
|
||||
double n[3] = {0};
|
||||
const double twothirds = 0.666666666666666666666666666667;
|
||||
for (f=0; f<nfaces; ++f)
|
||||
{
|
||||
{
|
||||
double area = 0.0;
|
||||
for(i=0; i<ndims; ++i) x[i] = 0.0;
|
||||
for(i=0; i<ndims; ++i) n[i] = 0.0;
|
||||
for(i=0; i<ndims; ++i) cface[i] = 0.0;
|
||||
|
||||
for(i=0; i<ndims; ++i) cface[i] = 0.0;
|
||||
|
||||
/* average node */
|
||||
for(k=nodepos[f]; k<nodepos[f+1]; ++k)
|
||||
{
|
||||
@@ -64,7 +64,7 @@ compute_face_geometry(int ndims, double *coords, int nfaces,
|
||||
/* compute first vector u (to the last node in the face) */
|
||||
node = facenodes[nodepos[f+1]-1];
|
||||
for(i=0; i<ndims; ++i) u[i] = coords[3*node+i] - x[i];
|
||||
|
||||
|
||||
|
||||
/* Compute triangular contrib. to face normal and face centroid*/
|
||||
for(k=nodepos[f]; k<nodepos[f+1]; ++k)
|
||||
@@ -74,23 +74,23 @@ compute_face_geometry(int ndims, double *coords, int nfaces,
|
||||
|
||||
cross(u,v,w);
|
||||
double a = 0.5*norm(w);
|
||||
area += a;
|
||||
area += a;
|
||||
if(!(a>0))
|
||||
{
|
||||
fprintf(stderr, "Internal error in compute_face_geometry.");
|
||||
}
|
||||
|
||||
/* face normal */
|
||||
/* face normal */
|
||||
for (i=0; i<ndims; ++i) n[i] += w[i];
|
||||
|
||||
|
||||
/* face centroid */
|
||||
for (i=0; i<ndims; ++i)
|
||||
cface[i] += a*(x[i]+twothirds*0.5*(u[i]+v[i]));
|
||||
|
||||
for (i=0; i<ndims; ++i)
|
||||
cface[i] += a*(x[i]+twothirds*0.5*(u[i]+v[i]));
|
||||
|
||||
/* Store v in u for next iteration */
|
||||
for (i=0; i<ndims; ++i) u[i] = v[i];
|
||||
for (i=0; i<ndims; ++i) u[i] = v[i];
|
||||
}
|
||||
|
||||
|
||||
/* Store face normal and face centroid */
|
||||
for (i=0; i<ndims; ++i)
|
||||
{
|
||||
@@ -104,10 +104,10 @@ compute_face_geometry(int ndims, double *coords, int nfaces,
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
void
|
||||
compute_cell_geometry(int ndims, double *coords, int nfaces,
|
||||
int *nodepos, int *facenodes, double *fcentroids,
|
||||
int ncells, int *facepos, int *cellfaces,
|
||||
void
|
||||
compute_cell_geometry(int ndims, double *coords, int nfaces,
|
||||
int *nodepos, int *facenodes, double *fcentroids,
|
||||
int ncells, int *facepos, int *cellfaces,
|
||||
double *ccentroids, double *cvolumes)
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
@@ -127,10 +127,10 @@ compute_cell_geometry(int ndims, double *coords, int nfaces,
|
||||
double volume = 0.0;
|
||||
for(i=0; i<ndims; ++i) xcell[i] = 0.0;
|
||||
for(i=0; i<ndims; ++i) ccell[i] = 0.0;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Approximate cell center as average of face centroids
|
||||
* Approximate cell center as average of face centroids
|
||||
*/
|
||||
for(f=facepos[c]; f<facepos[c+1]; ++f)
|
||||
{
|
||||
@@ -142,14 +142,14 @@ compute_cell_geometry(int ndims, double *coords, int nfaces,
|
||||
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* For all faces, add tetrahedron's volume and centroid to
|
||||
* 'cvolume' and 'ccentroid'.
|
||||
*/
|
||||
for(f=facepos[c]; f<facepos[c+1]; ++f)
|
||||
{
|
||||
{
|
||||
for(i=0; i<ndims; ++i) x[i] = 0.0;
|
||||
for(i=0; i<ndims; ++i) cface[i] = 0.0;
|
||||
for(i=0; i<ndims; ++i) cface[i] = 0.0;
|
||||
|
||||
face = cellfaces[f];
|
||||
|
||||
@@ -167,14 +167,14 @@ compute_cell_geometry(int ndims, double *coords, int nfaces,
|
||||
/* compute first vector u (to the last node in the face) */
|
||||
node = facenodes[nodepos[face+1]-1];
|
||||
for(i=0; i<ndims; ++i) u[i] = coords[3*node+i] - x[i];
|
||||
|
||||
|
||||
|
||||
/* Compute triangular contributions to face normal and face centroid */
|
||||
for(k=nodepos[face]; k<nodepos[face+1]; ++k)
|
||||
{
|
||||
node = facenodes[k];
|
||||
for (i=0; i<ndims; ++i) v[i] = coords[3*node+i] - x[i];
|
||||
|
||||
|
||||
cross(u,v,w);
|
||||
double tet_volume = 0;
|
||||
for(i=0; i<ndims; ++i) tet_volume += fabs(0.5/3 * w[i]*(x[i]-xcell[i]));
|
||||
@@ -183,17 +183,17 @@ compute_cell_geometry(int ndims, double *coords, int nfaces,
|
||||
volume += tet_volume;
|
||||
|
||||
/* face centroid of triangle */
|
||||
for (i=0; i<ndims; ++i) cface[i] = (x[i]+twothirds*0.5*(u[i]+v[i]));
|
||||
|
||||
for (i=0; i<ndims; ++i) cface[i] = (x[i]+twothirds*0.5*(u[i]+v[i]));
|
||||
|
||||
/* Cell centroid */
|
||||
for (i=0; i<ndims; ++i) ccell[i] += tet_volume * 3/4.0*(cface[i] - xcell[i]);
|
||||
|
||||
|
||||
|
||||
|
||||
/* Store v in u for next iteration */
|
||||
for (i=0; i<ndims; ++i) u[i] = v[i];
|
||||
for (i=0; i<ndims; ++i) u[i] = v[i];
|
||||
}
|
||||
}
|
||||
for (i=0; i<ndims; ++i) ccentroids[3*c+i] = xcell[i] + ccell[i]/volume;
|
||||
cvolumes[c] = volume;
|
||||
cvolumes[c] = volume;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ mexFunction(int nlhs, mxArray *plhs[],
|
||||
mxArray *fn = mxCreateDoubleMatrix(getNumberOfDimensions(G), getNumberOfFaces(G), mxREAL);
|
||||
mxArray *cc = mxCreateDoubleMatrix(getNumberOfDimensions(G), getNumberOfCells(G), mxREAL);
|
||||
mxArray *cv = mxCreateDoubleMatrix(getNumberOfCells(G), 1, mxREAL);
|
||||
|
||||
|
||||
compute_geometry(G, mxGetPr(fa), mxGetPr(fc), mxGetPr(fn), mxGetPr(cc), mxGetPr(cv));
|
||||
|
||||
mxAssert(nlhs==5, "Requires 5 return arguments");
|
||||
|
||||
@@ -207,7 +207,7 @@ mexFunction(int nlhs, mxArray *plhs[],
|
||||
|
||||
for (i = 0; i < nc; i++) { src[i] = 0.0; } /* No sources */
|
||||
for (i = 0; i < ncf_tot; i++) { gflux[i] = 0.0; } /* No gravity */
|
||||
|
||||
|
||||
hybsys_compute_press_flux(nc, nconn, conn, gflux, src, Binv, sys,
|
||||
pi, mxGetPr(plhs[1]), mxGetPr(plhs[0]),
|
||||
work, max_ncf);
|
||||
|
||||
@@ -100,7 +100,7 @@ verify_structural_consistency(int nlhs, int nrhs, const mxArray *prhs[])
|
||||
(mxIsDouble(prhs[3]) || mxIsInt32(prhs[3])) &&
|
||||
(mxGetNumberOfElements(prhs[2]) <
|
||||
mxGetNumberOfElements(prhs[3]));
|
||||
|
||||
|
||||
return grid_ok && rock_ok && conn_ok;
|
||||
}
|
||||
|
||||
@@ -206,20 +206,20 @@ extract_cell_data(const mxArray *G,
|
||||
|
||||
extract_connection_data(M_nconn, M_conn, ncells,
|
||||
nconn, conn, sum_nconn, sum_nconn2);
|
||||
|
||||
|
||||
*max_ncf = 0;
|
||||
|
||||
for(i=0; i<ncells; ++i)
|
||||
{
|
||||
int n = (*ncfaces)[i+1] - (*ncfaces)[i];
|
||||
(*ncfaces)[i] = n;
|
||||
|
||||
|
||||
*max_ncf = MAX(*max_ncf, n);
|
||||
}
|
||||
|
||||
*ccentroids = getCellCentroids(G);
|
||||
*cvolumes = getCellVolumes(G);
|
||||
|
||||
|
||||
return ncells;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ get_conn(const mxArray *M_conn, int *conn)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
static int
|
||||
static int
|
||||
get_number_of_faces(int nc, int *nconn, int *conn)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
@@ -162,12 +162,12 @@ get_number_of_faces(int nc, int *nconn, int *conn)
|
||||
N += nconn[i];
|
||||
}
|
||||
|
||||
int nf=0;
|
||||
int nf=0;
|
||||
for(i=0; i<N; ++i)
|
||||
{
|
||||
nf = MAX(nf, conn[i]+1);
|
||||
}
|
||||
|
||||
|
||||
return nf;
|
||||
}
|
||||
|
||||
@@ -223,18 +223,18 @@ mexFunction(int nlhs, mxArray *plhs[],
|
||||
p1 += nconn[c];
|
||||
p2 += nconn[c] * nconn[c];
|
||||
}
|
||||
|
||||
|
||||
int *conn= mxMalloc(mxGetNumberOfElements(prhs[2])*sizeof *conn);
|
||||
get_conn(prhs[2], conn);
|
||||
|
||||
int nf = get_number_of_faces(nc, nconn, conn);
|
||||
int nf = get_number_of_faces(nc, nconn, conn);
|
||||
struct Sparse A;
|
||||
/* double *b = malloc(nf * sizeof *b); */
|
||||
double *b;
|
||||
hybsys_assemble(nc, nf, nconn, conn, ptr, sys->r, &A, &b);
|
||||
#if 0
|
||||
double *x = malloc(A.n * sizeof *x);
|
||||
|
||||
|
||||
callMWUMFPACK(A.n, A.ia, A.ja, A.sa, b, x);
|
||||
|
||||
int i;for(i=0; i<nf; ++i)mexPrintf("x[%d]=%f\n", i, x[i]);
|
||||
|
||||
30
mrst_api.c
30
mrst_api.c
@@ -33,7 +33,7 @@ extractIntMatrix(const mxArray *a)
|
||||
for (i=0; i<n; ++i)
|
||||
{
|
||||
q[i] = p[i]-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(mxIsDouble(a))
|
||||
{
|
||||
@@ -44,10 +44,10 @@ extractIntMatrix(const mxArray *a)
|
||||
mxAssert ((1 <= p[i]) && (p[i] <= INT_MAX),
|
||||
"Matrix entry exceeds INT_MAX");
|
||||
q[i] = p[i]-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ extractIntMatrixTranspose(const mxArray *a)
|
||||
int *p = extractIntMatrix(a);
|
||||
int M = mxGetM(a);
|
||||
int N = mxGetN(a);
|
||||
|
||||
|
||||
int *q = mxMalloc(M * N * sizeof *q);
|
||||
if (q != NULL)
|
||||
{
|
||||
@@ -100,15 +100,15 @@ extractDoubleMatrixTranspose(const mxArray *a)
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
int
|
||||
int
|
||||
getNumberOfDimensions(const mxArray *G)
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
{
|
||||
return mxGetN(getField(G, "nodes", "coords"));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
void
|
||||
void
|
||||
getLocal2GlobalCellMap(const mxArray *G)
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
@@ -116,7 +116,7 @@ getLocal2GlobalCellMap(const mxArray *G)
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
int
|
||||
int
|
||||
getNumberOfNodes(const mxArray *G)
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
@@ -134,7 +134,7 @@ getNodeCoordinates(const mxArray *G)
|
||||
|
||||
p1 = mxGetField(G , 0, "nodes" );
|
||||
p2 = mxGetField(p1, 0, "coords");
|
||||
|
||||
|
||||
const int n = getNumberOfNodes(G);
|
||||
const int d = getNumberOfDimensions(G);
|
||||
|
||||
@@ -157,7 +157,7 @@ getNodeCoordinates(const mxArray *G)
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
int
|
||||
int
|
||||
getNumberOfFaces(const mxArray *G)
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
@@ -173,7 +173,7 @@ getFaceNodePos(const mxArray *G)
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
int
|
||||
int
|
||||
getNumberOfFaceNodes(const mxArray *G)
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
@@ -198,7 +198,7 @@ getFaceCellNeighbors(const mxArray *G)
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
double *
|
||||
double *
|
||||
getFaceAreas(const mxArray *G)
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
@@ -222,11 +222,11 @@ getFaceCentroids(const mxArray *G)
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
int
|
||||
int
|
||||
getNumberOfCells(const mxArray *G)
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
return mxGetNumberOfElements(getField(G, "cells", "facePos"))-1;
|
||||
return mxGetNumberOfElements(getField(G, "cells", "facePos"))-1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
@@ -240,7 +240,7 @@ int *getCellFacePos(const mxArray *G)
|
||||
int getNumberOfCellFaces(const mxArray *G)
|
||||
/* ------------------------------------------------------------------ */
|
||||
{
|
||||
return mxGetNumberOfElements(getField(G, "cells", "faces"))-1;
|
||||
return mxGetNumberOfElements(getField(G, "cells", "faces"))-1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
Reference in New Issue
Block a user