Exemplo n.º 1
0
/*!
  Rectangular submatrix support for @a objR.

  @par Revision history:
  - 26.04.2001, c
  - 05.03.2003, adopted from rcfem2
  - 31.03.2003
*/
int32 fmfr_sumLevelsMulF( FMField *objR, FMField *objA, float64 *val )
{
  int32 il, ir, ic, ii;
  float64 *pa, *pr;

#ifdef DEBUG_FMF
  if ((objR->nRow != objA->nRow) || (objR->nCol != objA->nCol)
      || (objR->nLev != 1)) {
    errput( ErrHead "ERR_BadMatch (%d == %d, %d == %d, %d == 1)\n",
	    objR->nRow, objA->nRow, objR->nCol, objA->nCol, objR->nLev );
  }
#endif

/*    output( "%d %d\n", objR->offset, objR->nColFull ); */
  pr = objR->val + objR->offset;
  for (ir = 0; ir < objR->nRow; ir++) {
    for (ic = 0; ic < objR->nCol; ic++) {
      pr[ic] = 0.0;
    }
    pr += objR->nColFull;
  }
  for (il = 0; il < objA->nLev; il++) {
    pr = objR->val + objR->offset;
    pa = objA->val + objA->nCol * objA->nRow * il;
    ii = 0;
    for (ir = 0; ir < objR->nRow; ir++) {
      for (ic = 0; ic < objR->nCol; ic++, ii++) {
	pr[ic] += pa[ii] * val[il];
      }
      pr += objR->nColFull;
    }
  }

  return( RET_OK );
}
Exemplo n.º 2
0
// `incident` must be preallocated - use mesh_count_incident().
int32 mesh_get_incident(Mesh *mesh,
                        MeshConnectivity *incident, int32 dim,
                        Indices *entities, int32 dent)
{
  int32 ret = RET_OK;
  uint32 ii;
  int32 D = mesh->topology->max_dim;
  MeshEntityIterator it0[1], it1[1];
  MeshConnectivity *conn = mesh->topology->conn[IJ(D, dent, dim)];

  if (!conn->num) {
    errput("connectivity %d -> %d is not avaliable!\n", dent, dim);
    ERR_CheckGo(ret);
  }

  ii = 0;
  incident->offsets[0] = 0;
  for (mei_init_sub(it0, mesh, entities, dent); mei_go(it0); mei_next(it0)) {
    for (mei_init_conn(it1, it0->entity, dim); mei_go(it1); mei_next(it1)) {
      incident->indices[ii++] = it1->entity->ii;
    }
    incident->offsets[it0->it + 1] = incident->offsets[it0->it] + it1->it_end;
  }

 end_label:
  return(ret);
}
Exemplo n.º 3
0
int32 geme_invar2( float64 *invar, FMField *mtx )
{
  int32 il, dim;
  float64 *j;

  dim = mtx->nRow;
  for (il = 0; il < mtx->nLev; il++) {
    j = mtx->val + dim*dim*il;
    switch (dim) {
    case 1: /* no sense in 1D */
      invar[il] = 0.0;
      break;
    case 2: /* plain strain */
      invar[il] = j[0]*j[3] + j[0] + j[3] - j[1]*j[1];
      break;
    case 3:
      invar[il] = j[0]*j[4] + j[0]*j[8] + j[4]*j[8]
	- j[1]*j[1] - j[2]*j[2] - j[5]*j[5];
      break;
    default:
      errput( ErrHead "ERR_Switch\n" );
    }
  }
  return( RET_OK );
}
Exemplo n.º 4
0
/*!
  @par Revision history:
  - 09.02.2001, c
  - 06.03.2003, adopted from rcfem2
*/
int32 geme_det3x3( float64 *det, FMField *mtx )
{
  int32 il, dim;
  float64 *j;

  dim = mtx->nRow;
  for (il = 0; il < mtx->nLev; il++) {
    j = mtx->val + dim*dim*il;
    switch (dim) {
    case 1:
      det[il] = j[0];
      break;
    case 2:
      det[il] = j[0] * j[3] - j[1] * j[2];
      break;
    case 3:
      det[il] = j[0]*j[4]*j[8] + j[3]*j[7]*j[2] + j[1]*j[5]*j[6]
	- j[2]*j[4]*j[6] - j[5]*j[7]*j[0] - j[1]*j[3]*j[8];
      break;
    default:
      errput( ErrHead "ERR_Switch\n" );
    }
  }
  return( RET_OK );
}
Exemplo n.º 5
0
/*!
  objR = val * objA^T.
  Can be used instead of transposition.

  @par Revision history:
  - 24.04.2001, c
  - 05.03.2003, adopted from rcfem2
  - 07.04.2003
*/
int32 fmf_mulATF( FMField *objR, FMField *objA, float64 *val )
{
  int32 ir, ic, il;
  int32 wa;
  float64 *pr, *pa;

#ifdef DEBUG_FMF
  if ((objR->nRow != objA->nCol) || (objR->nCol != objA->nRow)
      || (objR->nLev != objA->nLev)) {
    errput( ErrHead "ERR_BadMatch: (%d %d %d) == (%d %d %d)^T * (?, 1)\n",
	    objR->nLev, objR->nRow, objR->nCol,
	    objA->nLev, objA->nRow, objA->nCol );
  }
#endif

  wa = objA->nCol;
  for (il = 0; il < (objR->nLev); il++) {
    pr = objR->val + objR->nCol * objR->nRow * il;
    pa = objA->val + objA->nCol * objA->nRow * il;
    for (ir = 0; ir < objR->nRow; ir++) {
      for (ic = 0; ic < objR->nCol; ic++) {
	pr[ic] = pa[wa*ic+ir] * val[il];
      }
      pr += objR->nCol;
    }
  }

  return( RET_OK );
}
Exemplo n.º 6
0
/*!
  @par Revision history:
  - 04.12.2003, c
*/
int32 fmfr_print( FMField *obj, FILE *file, int32 mode )
{
  int32 i, j, il;

  if (mode == 0) {
    fprintf( file, "%d %d %d %d %d\n", obj->nLev, obj->nRow, obj->nCol,
	     obj->offset, obj->nColFull );
    for (il = 0; il < obj->nLev; il++) {
      fprintf( file, "%d\n", il );
      for (i = 0; i < obj->nRow; i++) {
	for (j = 0; j < obj->nCol; j++) {
	  fprintf( file, " %.12e",
		   obj->val[obj->offset+obj->nColFull*(obj->nRow*il+i)+j] );
	}
	fprintf( file, "\n" );
      }
    }
  } else if (mode == 1) {
    fmf_print( obj, file, mode );
  } else {
    errput( ErrHead "ERR_Switch!\n" );
  }

  return( RET_OK );
}
Exemplo n.º 7
0
/*!
  @par Revision history:
  - 06.02.2001, c
  - 14.11.2001
  - 05.03.2003, adopted from rcfem2
  - 18.03.2003
  - 08.04.2003
*/
int32 fmf_print( FMField *obj, FILE *file, int32 mode )
{
  int32 i, j, il;

  if (mode == 0) {
    fprintf( file, "%d %d %d\n", obj->nLev, obj->nRow, obj->nCol );
    for (il = 0; il < obj->nLev; il++) {
      fprintf( file, "%d\n", il );
      for (i = 0; i < obj->nRow; i++) {
	for (j = 0; j < obj->nCol; j++) {
/* 	  fprintf( file, " %.12e", obj->val[obj->nCol*(obj->nRow*il+i)+j] ); */
	  fprintf( file, " %.6e", obj->val[obj->nCol*(obj->nRow*il+i)+j] );
	}
	fprintf( file, "\n" );
      }
    }
  } else if (mode == 1) {
    fprintf( file, "nCell: %d nLev: %d nRow: %d nCol: %d\n",
	     obj->nCell, obj->nLev, obj->nRow, obj->nCol );
    fprintf( file, "offset: %d nColFull: %d nAlloc: %d cellSize %d\n",
	     obj->offset, obj->nColFull, obj->nAlloc, obj->cellSize );
  } else {
    errput( ErrHead "ERR_Switch!\n" );
  }

  return( RET_OK );
}
Exemplo n.º 8
0
/*!
  @par Revision history:
  - 04.04.2003, c
  - 07.04.2003
  - 20.01.2004
*/
int32 fmfr_copy( FMField *objR, FMField *objA )
{
  int32 il, ir, ic;
  int32 wa, wr, ha, hr;
  float64 *pa, *pr;
#ifdef DEBUG_FMF
  if ((objR->nRow != objA->nRow) || (objR->nCol != objA->nCol)
      || (objR->nLev != objA->nLev)) {
    errput( ErrHead "ERR_BadMatch: (%d %d %d) = (%d %d %d)\n",
	    objR->nLev, objR->nRow, objR->nCol,
	    objA->nLev, objA->nRow, objA->nCol );
  }
#endif
  wa = objA->nCol;
  wr = objR->nColFull;
  ha = objA->nRow;
  hr = objR->nRow;
  for (il = 0; il < objR->nLev; il++) {
    pr = objR->val + objR->offset + wr * hr * il;
    pa = objA->val + wa * ha * il;
    for (ir = 0; ir < ha; ir++) {
      for (ic = 0; ic < wa; ic++) {
	pr[wr*ir+ic] = pa[wa*ir+ic];
      }
    }
  }

  return( RET_OK );
}
Exemplo n.º 9
0
/*!
  @par Revision history:
  - 22.04.2001, c
  - 17.09.2001
  - 20.01.2004, adopted from rcfem2
*/
int32 fmf_gMtx2VecDLU3x3( FMField *objR, FMField *objA )
{
  int32 i, il;
  static int32 order[][9] = {{0, 0, 0, 0, 0, 0, 0, 0, 0},
			     {0, 3, 2, 1, 0, 0, 0, 0, 0},
			     {0, 4, 8, 3, 6, 7, 1, 2, 5}};
  int32 *pord;
  float64 *pr, *pa;

#ifdef DEBUG_FMF
  if ((objR->nRow != (objA->nRow * objA->nCol)) || (objR->nLev != objA->nLev)
    || (objR->nCol != 1) || (objA->nRow > 3) || (objA->nCol != objA->nRow)) {
    errput( ErrHead "ERR_BadMatch: (%d %d %d) <-> (%d %d %d)\n",
	    objR->nLev, objR->nRow, objR->nCol,
	    objA->nLev, objA->nRow, objA->nCol );
  }
#endif

  pord = order[objA->nRow-1];

  for (il = 0; il < objR->nLev; il++) {
    pr = objR->val + objR->nCol * objR->nRow * il;
    pa = objA->val + objA->nCol * objA->nRow * il;
    for (i = 0; i < (objR->nRow); i++) {
      pr[i] = pa[pord[i]];
    }
  }

  return( RET_OK );
}
Exemplo n.º 10
0
/*!
  @par Revision history:
  - 13.11.2001, c
  - 06.03.2003, adopted from rcfem2
*/
int32 geme_tensor2vectorS3( FMField *vec, FMField *mtx )
{
  int32 il, dim;
  float64 *pmtx, *pvec;
  
  dim = mtx->nRow;
  for (il = 0; il < mtx->nLev; il++) {
    pvec = FMF_PtrLevel( vec, il );
    pmtx = FMF_PtrLevel( mtx, il );
    switch (dim) {
    case 1:
      pvec[0] = pmtx[0];
      break;
    case 2:
      pvec[0] = pmtx[0];
      pvec[1] = pmtx[3];
      pvec[2] = pmtx[1];
      break;
    case 3:
      pvec[0] = pmtx[0];
      pvec[1] = pmtx[4];
      pvec[2] = pmtx[8];
      pvec[3] = pmtx[1];
      pvec[4] = pmtx[2];
      pvec[5] = pmtx[5];
      break;
    default:
      errput( ErrHead "ERR_Switch\n" );
    }
  }

  return( RET_OK );
}
Exemplo n.º 11
0
/*!
  @par Revision history:
  - 18.10.2001, c
  - 05.03.2003, adopted from rcfem2
*/
int32 fmfc_copyAmulF( FMField *objR, FMField *objA, float64 *val )
{
  int32 i, il, ic;
  float64 *pr, *pa;

#ifdef DEBUG_FMF
  if ((objR->nRow != objA->nRow) || (objR->nCol != objA->nCol)
      || (objR->nLev != objA->nLev) || (objR->nCell != objA->nCell)) {
    errput( ErrHead "ERR_BadMatch\n" );
  }
#endif

  pr = objR->val0;
  pa = objA->val0;
  for (ic = 0; ic < objR->nCell; ic++) {
    for (il = 0; il < (objR->nLev); il++) {
      for (i = 0; i < (objR->nRow * objR->nCol); i++) {
	pr[i] = pa[i] * val[il];
      }
      pr += objR->nCol * objR->nRow;
      pa += objA->nCol * objA->nRow;
    }
    val += objR->nLev;
  }

  return( RET_OK );
}
Exemplo n.º 12
0
/*!
  @a objA^T.

  @par Revision history:
  - 23.05.2005, c
*/
int32 fmf_sumLevelsTMulF( FMField *objR, FMField *objA, float64 *val )
{
  int32 il, ir, ic, wr, wc;
  float64 *pa, *pr;

#ifdef DEBUG_FMF
  if ((objR->nRow != objA->nCol) || (objR->nCol != objA->nRow)
      || (objR->nLev != 1)) {
    errput( ErrHead "ERR_BadMatch (%d == %d, %d == %d, %d == 1)\n",
	    objR->nRow, objA->nCol, objR->nCol, objA->nRow, objR->nLev );
  }
#endif

  wr = objR->nCol;
  pr = objR->val;
  wc = objA->nCol;

  fmf_fillC( objR, 0.0 );
  for (il = 0; il < objA->nLev; il++) {
    pa = objA->val + objA->nCol * objA->nRow * il;
    for (ir = 0; ir < objR->nRow; ir++) {
      for (ic = 0; ic < objR->nCol; ic++) {
	pr[wr*ir+ic] += pa[wc*ic+ir] * val[il];
      }
    }
  }

  return( RET_OK );
}
Exemplo n.º 13
0
/*!
  objR = objA^T * objB^T

  @par Revision history:
  - 06.02.2001, c
  - 05.03.2003, adopted from rcfem2
*/
int32 fmf_mulATBT_nn( FMField *objR, FMField *objA, FMField *objB )
{
  int32 i, j, k, il, wr, wa, wb;
  float64 *pr, *pa, *pb;

#ifdef DEBUG_FMF
  if ((objR->nRow != objA->nCol) || (objR->nCol != objB->nRow)
      || (objA->nRow != objB->nCol)
      || (objR->nLev != objA->nLev) || (objR->nLev != objB->nLev)) {
    errput( ErrHead "ERR_BadMatch: (%d %d %d) = (%d %d %d)^T * (%d %d %d)^T\n",
	    objR->nLev, objR->nRow, objR->nCol,
	    objA->nLev, objA->nRow, objA->nCol,
	    objB->nLev, objB->nRow, objB->nCol );
  }
#endif

  wr = objR->nCol;
  wa = objA->nCol;
  wb = objB->nCol;
  for (il = 0; il < objR->nLev; il++) {
    pr = objR->val + objR->nCol * objR->nRow * il;
    pa = objA->val + objA->nCol * objA->nRow * il;
    pb = objB->val + objB->nCol * objB->nRow * il;
    for (i = 0; i < objR->nRow; i++) {
      for (j = 0; j < objR->nCol; j++) {
	pr[wr*i+j] = 0.0;
	for (k = 0; k < objA->nRow; k++) {
	  pr[wr*i+j] += pa[wa*k+i] * pb[wb*j+k];
	}
      }
    }
  }
  return( RET_OK );
}
Exemplo n.º 14
0
/*!
  objR = objA + objB

  @par Revision history:
  - 06.02.2001, c
  - 05.03.2003, adopted from rcfem2
*/
int32 fmf_addAB_nn( FMField *objR, FMField *objA, FMField *objB )
{
  int32 i;

#ifdef DEBUG_FMF
  if ((objR->nRow != objA->nRow) || (objR->nCol != objB->nCol)
      || (objA->nRow != objB->nRow)
      || (objR->nLev != objA->nLev) || (objR->nLev != objB->nLev)) {
    errput( ErrHead "ERR_BadMatch: (%d %d %d) = (%d %d %d) + (%d %d %d)\n",
	    objR->nLev, objR->nRow, objR->nCol,
	    objA->nLev, objA->nRow, objA->nCol,
	    objB->nLev, objB->nRow, objB->nCol );
  }
#endif

  for (i = 0; i < objR->nLev * objR->nRow * objR->nCol; i++) {
//      if (debug == 1) {
//        printf( "%d %p %p %p %d %f %f\n",
//  	      objR->nLev * objR->nRow * objR->nCol,
//  	      this, a, b, i, objA->val[i], objB->val[i] );
//        debug = 0;
//      }
    
    objR->val[i] = objA->val[i] + objB->val[i];
  }
  return( RET_OK );
}
Exemplo n.º 15
0
/*!
  @par Revision history:
  - 15.07.2002, c
  - 26.07.2002
  - 05.03.2003, adopted from rcfem2
  - 18.03.2003
*/
int32 fmfc_save( FMField *obj, const char *fileName, int32 mode )
{
  int32 ii;
  FILE *file;

  if ((file = fopen( fileName, "w" )) == 0) {
    errput( ErrHead "ERR_FileOpen\n" );
  }

  if (mode == 0) {
    FMF_SetFirst( obj );
    for (ii = 0; ii < obj->nCell; ii++) {
      fmf_print( obj, file, 0 );
      FMF_SetCellNext( obj );
    }
  } else if (mode == 1) {
    fprintf( file, "%d\n", obj->nAlloc );
    for (ii = 0; ii < obj->nAlloc; ii++) {
      fprintf( file, "%d %.12e\n", ii, obj->val0[ii] );
    }
  }

  fclose( file );

  return( RET_OK );
}
Exemplo n.º 16
0
/*!
  @par Revision history:
  - 23.05.2005, c
  - 25.05.2005
*/
int32 fmf_addAmulF( FMField *objR, FMField *objA, float64 *val )
{
  int32 ii, il;
  float64 *pr, *pa;

#ifdef DEBUG_FMF
  if ((objR->nRow != objA->nRow) || (objR->nCol != objA->nCol)
      || (objR->nLev != objA->nLev)) {
    errput( ErrHead "ERR_BadMatch: (%d %d %d) = (%d %d %d) * C\n",
	    objR->nLev, objR->nRow, objR->nCol,
	    objA->nLev, objA->nRow, objA->nCol );
  }
#endif

  pr = objR->val;
  pa = objA->val;
  for (il = 0; il < (objR->nLev); il++) {
    for (ii = 0; ii < (objR->nRow * objR->nCol); ii++) {
      pr[ii] += pa[ii] * val[il];
    }
    pr += objR->nCol * objR->nRow;
    pa += objA->nCol * objA->nRow;
  }

  return( RET_OK );
}
Exemplo n.º 17
0
/*!
  @a in is a vector (dim, 1).

  @par Revision history:
  - 06.09.2006, c
*/
int32 bf_actt_c1( FMField *out, FMField *bf, FMField *in )
{
  int32 iqp, ir, ic, nEP, nQP, dim;
  float64 *pout, *pbf, *pin;

  nEP = bf->nCol;
  nQP = bf->nLev;
  dim = in->nRow;

#ifdef DEBUG_FMF
  if ((out->nRow != dim * nEP) || (out->nCol != 1) || (out->nLev != in->nLev)
      || (out->nLev != bf->nLev) || (in->nRow != dim) || (in->nCol != 1)) {
    errput( ErrHead "ERR_BadMatch: (%d %d %d), (%d %d %d), (%d %d %d)\n",
	    out->nLev, out->nRow, out->nCol,
	    bf->nLev, bf->nRow, bf->nCol,
	    in->nLev, in->nRow, in->nCol );
  }
#endif

  for (iqp = 0; iqp < nQP; iqp++) {
    pbf = FMF_PtrLevel( bf, iqp );
    pout = FMF_PtrLevel( out, iqp );
    pin = FMF_PtrLevel( in, iqp );

    for (ic = 0; ic < dim; ic++ ) {
      for (ir = 0; ir < nEP; ir++) {
	pout[nEP*ic+ir] = pbf[ir] * pin[ic];
      }
    }
  }

  return( RET_OK );
}
Exemplo n.º 18
0
/*!
  @par Revision history:
  - 06.02.2001, c
  - 17.10.2001
  - 05.03.2003, adopted from rcfem2
*/
int32 fmf_copy( FMField *objR, FMField *objA )
{
  if (objR->cellSize != objA->cellSize) {
    errput( ErrHead "ERR_BadMatch\n" );
  }
  memcpy( objR->val, objA->val, objA->cellSize * sizeof( float64 ) );

  return( RET_OK );
}
Exemplo n.º 19
0
/*!
  @fn int32 form_sdcc_actOpGT_VS3( FMField *diff, FMField *vec, FMField *gc )

  @f$(G_{SD})^T@f$ operation (i.e. divergence of columns of a tensor)
  used on a symmetric tensor (symmetric vector storage - e.g. stress vector).

  @par Revision history:
  - 30.04.2001, c
  - 03.10.2001
  - 06.06.2002
  - 17.03.2003, adopted from rcfem2
*/
int32 form_sdcc_actOpGT_VS3( FMField *diff, FMField *gc, FMField *vec )
{
  int32 iqp, iep, nEP, nQP;
  float64 *pdiff1, *pdiff2, *pdiff3, *pvec, *pg1, *pg2, *pg3;

  nEP = gc->nCol;
  nQP = gc->nLev;

  switch (gc->nRow) {
  case 3:
    for (iqp = 0; iqp < nQP; iqp++) {
      pdiff1 = FMF_PtrLevel( diff, iqp );
      pdiff2 = pdiff1 + nEP;
      pdiff3 = pdiff2 + nEP;
      pvec = FMF_PtrLevel( vec, iqp );
      pg1 = FMF_PtrLevel( gc, iqp );
      pg2 = pg1 + nEP;
      pg3 = pg2 + nEP;
      for (iep = 0; iep < nEP; iep++) {
	pdiff1[iep]
	  = pg1[iep] * pvec[0]
	  + pg2[iep] * pvec[3]
	  + pg3[iep] * pvec[4];
	pdiff2[iep]
	  = pg1[iep] * pvec[3]
	  + pg2[iep] * pvec[1]
	  + pg3[iep] * pvec[5];
	pdiff3[iep]
	  = pg1[iep] * pvec[4]
	  + pg2[iep] * pvec[5]
	  + pg3[iep] * pvec[2];
      }
    }
    break;
  case 2:
    for (iqp = 0; iqp < nQP; iqp++) {
      pdiff1 = FMF_PtrLevel( diff, iqp );
      pdiff2 = pdiff1 + nEP;
      pvec = FMF_PtrLevel( vec, iqp );
      pg1 = FMF_PtrLevel( gc, iqp );
      pg2 = pg1 + nEP;
      for (iep = 0; iep < nEP; iep++) {
	pdiff1[iep]
	  = pg1[iep] * pvec[0]
	  + pg2[iep] * pvec[2];
	pdiff2[iep]
	  = pg1[iep] * pvec[2]
	  + pg2[iep] * pvec[1];
      }
    }
    break;
  default:
    errput( ErrHead "ERR_Switch\n" );
  }

  return( RET_OK );
}
Exemplo n.º 20
0
Arquivo: mesh.c Projeto: clazaro/sfepy
// `local_ids` must be preallocated to same size as `entities`.
int32 mesh_get_local_ids(Mesh *mesh, Indices *local_ids,
                         Indices *entities, int32 dent,
                         MeshConnectivity *incident, int32 dim)
{
  int32 ret = RET_OK;
  uint32 ii, iind, ic, found;
  uint32 D = mesh->topology->max_dim;
  MeshEntity entity[1];
  MeshEntityIterator it1[1];
  MeshConnectivity *conn = mesh->topology->conn[IJ(D, dim, dent)];

  if (!conn->num) {
    errput("connectivity %d -> %d is not avaliable!\n", dim, dent);
    ERR_CheckGo(ret);
  }

  entity->mesh = mesh;
  entity->dim = dim;

  ii = 0;
  for (iind = 0; iind < incident->num; iind++) {
    for (ic = incident->offsets[iind]; ic < incident->offsets[iind+1]; ic++) {
      entity->ii = incident->indices[ic];
      // printf("%d: ? %d in %d\n", iind, entities->indices[iind], entity->ii);
      found = 0;
      for (mei_init_conn(it1, entity, dent); mei_go(it1); mei_next(it1)) {
        if (entities->indices[iind] == it1->entity->ii) {
          local_ids->indices[ii++] = it1->it;
          // printf("%d -> %d\n", ii, it1->it);
          found = 1;
          break; // Degenerate cases - 1. occurrence is returned.
        }
      }
      if (!found) {
        errput("entity (%d, %d) not found in entity (%d, %d)!\n",
               entities->indices[iind], dent, entity->ii, dim);
        ERR_CheckGo(ret);
      }
    }
  }

 end_label:
  return(ret);
}
Exemplo n.º 21
0
int32 geme_invert4x4( FMField *mtxI, FMField *mtx )
{
  int32 ii, il;
  float64 det, buf[16];
  float64 *pm, *pi;

  for (il = 0; il < mtx->nLev; il++) {
    pm = FMF_PtrLevel( mtx, il );
    pi = FMF_PtrLevel( mtxI, il );

    buf[0] = pm[5]*pm[10]*pm[15] - pm[5]*pm[11]*pm[14] - pm[9]*pm[6]*pm[15]
      + pm[9]*pm[7]*pm[14] + pm[13]*pm[6]*pm[11] - pm[13]*pm[7]*pm[10];
    buf[4] = -pm[4]*pm[10]*pm[15] + pm[4]*pm[11]*pm[14] + pm[8]*pm[6]*pm[15]
      - pm[8]*pm[7]*pm[14] - pm[12]*pm[6]*pm[11] + pm[12]*pm[7]*pm[10];
    buf[8] = pm[4]*pm[9]*pm[15] - pm[4]*pm[11]*pm[13] - pm[8]*pm[5]*pm[15]
      + pm[8]*pm[7]*pm[13] + pm[12]*pm[5]*pm[11] - pm[12]*pm[7]*pm[9];
    buf[12] = -pm[4]*pm[9]*pm[14] + pm[4]*pm[10]*pm[13] + pm[8]*pm[5]*pm[14]
      - pm[8]*pm[6]*pm[13] - pm[12]*pm[5]*pm[10] + pm[12]*pm[6]*pm[9];
    buf[1] = -pm[1]*pm[10]*pm[15] + pm[1]*pm[11]*pm[14] + pm[9]*pm[2]*pm[15]
      - pm[9]*pm[3]*pm[14] - pm[13]*pm[2]*pm[11] + pm[13]*pm[3]*pm[10];
    buf[5] = pm[0]*pm[10]*pm[15] - pm[0]*pm[11]*pm[14] - pm[8]*pm[2]*pm[15]
      + pm[8]*pm[3]*pm[14] + pm[12]*pm[2]*pm[11] - pm[12]*pm[3]*pm[10];
    buf[9] = -pm[0]*pm[9]*pm[15] + pm[0]*pm[11]*pm[13] + pm[8]*pm[1]*pm[15]
      - pm[8]*pm[3]*pm[13] - pm[12]*pm[1]*pm[11] + pm[12]*pm[3]*pm[9];
    buf[13] = pm[0]*pm[9]*pm[14] - pm[0]*pm[10]*pm[13] - pm[8]*pm[1]*pm[14]
      + pm[8]*pm[2]*pm[13] + pm[12]*pm[1]*pm[10] - pm[12]*pm[2]*pm[9];
    buf[2] = pm[1]*pm[6]*pm[15] - pm[1]*pm[7]*pm[14] - pm[5]*pm[2]*pm[15]
      + pm[5]*pm[3]*pm[14] + pm[13]*pm[2]*pm[7] - pm[13]*pm[3]*pm[6];
    buf[6] = -pm[0]*pm[6]*pm[15] + pm[0]*pm[7]*pm[14] + pm[4]*pm[2]*pm[15]
      - pm[4]*pm[3]*pm[14] - pm[12]*pm[2]*pm[7] + pm[12]*pm[3]*pm[6];
    buf[10] = pm[0]*pm[5]*pm[15] - pm[0]*pm[7]*pm[13] - pm[4]*pm[1]*pm[15]
      + pm[4]*pm[3]*pm[13] + pm[12]*pm[1]*pm[7] - pm[12]*pm[3]*pm[5];
    buf[14] = -pm[0]*pm[5]*pm[14] + pm[0]*pm[6]*pm[13] + pm[4]*pm[1]*pm[14]
      - pm[4]*pm[2]*pm[13] - pm[12]*pm[1]*pm[6] + pm[12]*pm[2]*pm[5];
    buf[3] = -pm[1]*pm[6]*pm[11] + pm[1]*pm[7]*pm[10] + pm[5]*pm[2]*pm[11]
      - pm[5]*pm[3]*pm[10] - pm[9]*pm[2]*pm[7] + pm[9]*pm[3]*pm[6];
    buf[7] = pm[0]*pm[6]*pm[11] - pm[0]*pm[7]*pm[10] - pm[4]*pm[2]*pm[11]
      + pm[4]*pm[3]*pm[10] + pm[8]*pm[2]*pm[7] - pm[8]*pm[3]*pm[6];
    buf[11] = -pm[0]*pm[5]*pm[11] + pm[0]*pm[7]*pm[9] + pm[4]*pm[1]*pm[11]
      - pm[4]*pm[3]*pm[9] - pm[8]*pm[1]*pm[7] + pm[8]*pm[3]*pm[5];
    buf[15] = pm[0]*pm[5]*pm[10] - pm[0]*pm[6]*pm[9] - pm[4]*pm[1]*pm[10]
      + pm[4]*pm[2]*pm[9] + pm[8]*pm[1]*pm[6] - pm[8]*pm[2]*pm[5];

    det = pm[0]*buf[0] + pm[1]*buf[4] + pm[2]*buf[8] + pm[3]*buf[12];
    if (fabs(det) == 1e-16) {
      errput("singular matrix!\n");
    }
    det = 1.0 / det;

    for (ii = 0; ii < 16; ii++) {
      pi[ii] = buf[ii] * det;
    }
  }

  return( RET_OK );
}
Exemplo n.º 22
0
Arquivo: mesh.c Projeto: clazaro/sfepy
int32 mesh_transpose(Mesh *mesh, int32 d1, int32 d2)
{
  int32 ret = RET_OK;
  uint32 n_incident;
  uint32 ii;
  uint32 *nd2 = 0;
  uint32 D = mesh->topology->max_dim;
  MeshEntityIterator it2[1], it1[1];
  MeshConnectivity *c12 = 0; // d1 -> d2 - to compute

  debprintf("transpose %d -> %d\n", d1, d2);

  if (d1 >= d2) {
    errput("d1 must be smaller than d2 in mesh_transpose()!\n");
    ERR_CheckGo(ret);
  }

  c12 = mesh->topology->conn[IJ(D, d1, d2)];

  // Count entities of d2 -> d1.
  conn_alloc(c12, mesh->topology->num[d1], 0);
  ERR_CheckGo(ret);
  nd2 = c12->offsets + 1;

  for (mei_init(it2, mesh, d2); mei_go(it2); mei_next(it2)) {
    for (mei_init_conn(it1, it2->entity, d1); mei_go(it1); mei_next(it1)) {
      nd2[it1->entity->ii]++;
    }
  }

  // c12->offsets now contains counts - make a cumsum to get offsets.
  for (ii = 1; ii < c12->num + 1; ii++) {
    c12->offsets[ii] += c12->offsets[ii-1];
  }

  n_incident = c12->offsets[c12->num];
  debprintf("transpose n_incident (%d -> %d): %d\n", d1, d2, n_incident);

  // Fill in the indices.
  conn_alloc(c12, 0, n_incident);
  ERR_CheckGo(ret);
  for (ii = 0; ii < c12->n_incident; ii++) {
    c12->indices[ii] = UINT32_None; // "not set" value.
  }

  for (mei_init(it2, mesh, d2); mei_go(it2); mei_next(it2)) {
    for (mei_init_conn(it1, it2->entity, d1); mei_go(it1); mei_next(it1)) {
      conn_set_to_free(c12, it1->entity->ii, it2->entity->ii);
      ERR_CheckGo(ret);
    }
  }

 end_label:
  return(ret);
}
Exemplo n.º 23
0
/*!
  Prints memory usage statistics.
  @par Revision history:
  - 17.02.2005, from rcfem2
  - 06.10.2005
*/
int32 mem_print(FILE *file, int32 mode)
{
  size_t cnt = 0;
  size_t hsize = sizeof(AllocSpaceAlign);
  AllocSpace *head = al_head;
  char *p;

  mode = 0;
  fprintf(file, "allocated memory: %zu records, usage: %zu, max: %zu\n",
          al_frags, al_curUsage, al_maxUsage);
  if (head == 0) {
    goto end_label_ok;
  }

  while (head) {
    p = (char *) head;
    fprintf(file, "  %s, %s, %s, %d: size: %zu, ptr: %p\n",
            head->dirName, head->fileName, head->funName, head->lineNo,
            head->size, p + hsize);
    cnt++;
    if (cnt > al_frags) {
      errput("damaged allocation record (overrun)!\n");
      ERR_GotoEnd(1);
    }
    head = head->next;
  }
  if (cnt < al_frags) {
    errput("damaged allocation record (underrun)!\n");
    ERR_GotoEnd(1);
  }

 end_label_ok:
  fprintf(file, "done.\n");

  return(RET_OK);

 end_label:
  if (ERR_Chk) {
    errput(ErrHead "error exit!\n");
  }
  return(RET_Fail);
}
Exemplo n.º 24
0
/*!
  @par Revision history:
  - 17.02.2005, from rcfem2
*/
void *mem_alloc_mem(size_t size, int lineNo, char *funName,
                    char *fileName, char *dirName)
{
  char *p;
  size_t hsize = sizeof(AllocSpaceAlign);
  size_t tsize, aux;

  if (size == 0) {
    errput("%s, %s, %s, %d: zero allocation!\n",
           dirName, fileName, funName, lineNo);
    ERR_GotoEnd(1);
  }

  aux = size % sizeof(float64);
  size += (aux) ? sizeof(float64) - aux : 0;
  tsize = size + hsize + sizeof(float64);
  if ((p = (char *) PyMem_Malloc(tsize)) == 0) {
    errput("%s, %s, %s, %d: error allocating %zu bytes (current: %zu).\n",
           dirName, fileName, funName, lineNo, size, al_curUsage);
    ERR_GotoEnd(1);
  }
  p += hsize;

  mem_list_new(p, size, al_head, lineNo, funName, fileName, dirName);

  al_curUsage += size;
  if (al_curUsage > al_maxUsage) {
    al_maxUsage = al_curUsage;
  }
  al_frags++;

  memset(p, 0, size);

  return((void *) p);

 end_label:
  if (ERR_Chk) {
    errput(ErrHead "error exit!\n");
  }

  return(0);
}
Exemplo n.º 25
0
/*!
  @par Revision history:
  - 06.02.2001, c
  - 17.10.2001
  - 05.03.2003, adopted from rcfem2
*/
int32 fmf_copy( FMField *objR, FMField *objA )
{
  if (objR->cellSize != objA->cellSize) {
    errput(ErrHead "ERR_BadMatch: (%d %d %d) = (%d %d %d)\n",
           objR->nLev, objR->nRow, objR->nCol,
           objA->nLev, objA->nRow, objA->nCol);
  }
  memcpy( objR->val, objA->val, objA->cellSize * sizeof( float64 ) );

  return( RET_OK );
}
Exemplo n.º 26
0
/*!
  @par Revision history:
  - 28.11.2005, c
  - 30.05.2007
*/
int32 laplace_act_gt_m( FMField *out, FMField *gc, FMField *mtx )
{
  int32 iqp, iep, ii, nEP, nQP, nCol;
  float64 *pout, *pmtx, *pg1, *pg2, *pg3;

  nEP = gc->nCol;
  nQP = gc->nLev;
  nCol = mtx->nCol;

  switch (gc->nRow) {
  case 3:
    for (iqp = 0; iqp < nQP; iqp++) {
      pg1 = FMF_PtrLevel( gc, iqp );
      pg2 = pg1 + nEP;
      pg3 = pg2 + nEP;
      
      pmtx = FMF_PtrLevel( mtx, iqp );
      for (iep = 0; iep < nEP; iep++) {
	pout = FMF_PtrLevel( out, iqp ) + nCol * iep;
	for (ii = 0; ii < nCol; ii++) {
	  pout[ii]
	    = pg1[iep] * pmtx[0*nCol+ii]
	    + pg2[iep] * pmtx[1*nCol+ii]
	    + pg3[iep] * pmtx[2*nCol+ii];
	}
      }
    }
    break;

  case 2:
    for (iqp = 0; iqp < nQP; iqp++) {
      pg1 = FMF_PtrLevel( gc, iqp );
      pg2 = pg1 + nEP;
      
      pmtx = FMF_PtrLevel( mtx, iqp );
      for (iep = 0; iep < nEP; iep++) {
	pout = FMF_PtrLevel( out, iqp ) + nCol * iep;
	for (ii = 0; ii < nCol; ii++) {
	  pout[ii]
	    = pg1[iep] * pmtx[0*nCol+ii]
	    + pg2[iep] * pmtx[1*nCol+ii];
	}
      }
    }
    break;

  default:
    errput( ErrHead "ERR_Switch\n" );
    return( RET_Fail );
  }

  return( RET_OK );
}
Exemplo n.º 27
0
/*!
  @par Revision history:
  - 09.01.2006, c
  - 10.01.2006
*/
int32 vg_getElementDiameters( VolumeGeometry *obj, FMField *out,
			      int32 *edges, int32 edges_nRow, int32 edges_nCol,
			      float64 *coorIn, int32 nNod, int32 dim,
			      int32 *conn, int32 nEl, int32 nEP,
			      int32 *elList, int32 elList_nRow,
			      int32 mode )
{
  int32 ii, ie, id, iel, nd;
  float64 val0 = 0.0, val1 = 0.0, vv, aux = 0.0, exponent;

  if ((mode < 0) && (mode > 2)) {
    errput( ErrHead "ERR_Switch\n" );
    return( RET_Fail );
  }

/*   output( "%d %d %d %d %d %d %d\n", */
/* 	  edges_nRow, edges_nCol, nNod, dim, nEl, nEP, elList_nRow ); */

  nd = obj->bfGM->nRow; // Can be <> dim.
  exponent = 1.0 / ((float64) dim);
  for (ii = 0; ii < elList_nRow; ii++) {
    iel = elList[ii];
    FMF_SetCell( out, ii );

    if ((mode == 0) || (mode == 2)) {
      val0 = 0.0;
      for (ie = 0; ie < edges_nRow; ie++) {
	vv = 0.0;
	for (id = 0; id < nd; id++) {
	  aux = coorIn[dim*conn[nEP*iel+edges[2*ie+1]]+id]
	    - coorIn[dim*conn[nEP*iel+edges[2*ie+0]]+id];
/* 	  output( "%d %d %d %d %f %f %f\n", ii, iel, ie, id, aux, */
/* 		  coorIn[dim*conn[nEP*iel+edges[2*ie+1]]+id], */
/* 		  coorIn[dim*conn[nEP*iel+edges[2*ie+0]]+id] ); */
/* 	  sys_pause(); */
	  vv += aux * aux;
	}
/* 	output("%f\n", sqrt(vv)); */
	val0 = Max( val0, vv );
	out->val[0] = val0;
      }
    }
    if ((mode == 1) || (mode == 2)) {
      FMF_SetCell( obj->volume, iel );
      val1 = pow( 0.16 * obj->volume->val[0], exponent );
      out->val[0] = val1;
    }
    if (mode == 2) {
      out->val[0] = Max( val0, val1 );
    }
  }
  return( RET_OK );
}
Exemplo n.º 28
0
/*!
  @par Revision history:
  - 18.12.2003, c
*/
int32 geme_eig3x3( float64 *out, FMField *mtx )
{
  int32 il, dim;
  float64 *j, *val;

  dim = mtx->nRow;
  for (il = 0; il < mtx->nLev; il++) {
    j = mtx->val + dim*dim*il;
    val = out + dim*il;
    switch (dim) {
    case 1:
      val[0] = j[0];
      break;
    case 2: {
      // See Numerical Recipes.
      float64 b, c, q;

      b = -j[0] - j[2];
      c = j[0] * j[2] - j[1] * j[3];
      q = - 0.5 * (b + Sgn(b) * sqrt( b * b - 4.0 * c ));

      val[0] = q;
      val[1] = c / q;
    } break;
    case 3: {
      // See Numerical Recipes.
      float64 a, b, c, q, r, t;

      a = -(j[0] + j[4] + j[8]);
      b = j[0] * j[4] + j[0] * j[8] + j[4] * j[8]
	- j[3] * j[1] - j[6] * j[2] - j[7] * j[5]; 
      c = j[0] * j[5] * j[7] + j[4] * j[6] * j[2] + j[8] * j[1] * j[3]
	- j[6] * j[1] * j[5] - j[0] * j[4] * j[8] - j[3] * j[2] * j[7];

      q = (a * a - 3.0 * b) / 9.0;
      r = (2.0 * a * a * a - 9.0 * a * b + 27.0 * c) / 54.0;

      if (((q * q * q) - (r * r)) > MachEps) {
	t = acos( r / sqrt( q * q * q ) );
      } else {
	t = Pi;
      }
/*       output( "%e %e %e\n", r * r, q * q * q, t ); */
      val[0] = -2.0 * sqrt( q ) * cos( (t) / 3.0 ) - a / 3.0;
      val[1] = -2.0 * sqrt( q ) * cos( (t+2.0*Pi) / 3.0 ) - a / 3.0;
      val[2] = -2.0 * sqrt( q ) * cos( (t-2.0*Pi) / 3.0 ) - a / 3.0;
    } break;
    default:
      errput( ErrHead "ERR_Switch\n" );
    }
  }
  return( RET_OK );
}
Exemplo n.º 29
0
/*!
  @par Revision history:
  - 06.02.2001, c
  - 30.04.2001
  - 27.05.2001
  - 06.03.2003, adopted from rcfem2
*/
int32 fmf_free( FMField *obj )
{
  if (obj == 0) return( RET_OK );

  if (obj->nAlloc >= 0) {
    free_mem( obj->val0 );
  } else {
    errput( ErrHead "FMField was pretended\n" );
  }

  return( RET_OK );
}
Exemplo n.º 30
0
/*!
  @par Revision history:
  - 17.10.2001, c
  - 05.03.2003, adopted from rcfem2
*/
int32 fmfc_copy( FMField *objR, FMField *objA )
{
  // Cannot use nAlloc because of pretended FMFields...
  if ((objR->nCell * objR->nLev * objR->nRow * objR->nCol)
      != (objA->nCell * objA->nLev * objA->nRow * objA->nCol)) {
    errput( ErrHead "ERR_BadMatch\n" );
  }
  memcpy( objR->val0, objA->val0,
	  objA->nCell * objA->nLev * objA->nRow * objA->nCol
	  * sizeof( float64 ) );

  return( RET_OK );
}