Ejemplo n.º 1
0
    void RockFromDeck::assignPermeability(Opm::EclipseStateConstPtr eclState,
                                          int number_of_cells,
                                          const int* global_cell,
                                          const int* cartdims,
                                          double perm_threshold)
    {
        const int dim              = 3;
        const int nc = number_of_cells;

        assert(cartdims[0]*cartdims[1]*cartdims[2] > 0);
        static_cast<void>(cartdims); // Squash warning in release mode.

        permeability_.assign(dim * dim * nc, 0.0);

        std::vector<PermComponent> tensor;
        tensor.reserve(6);

        std::array<int,9> kmap;
        PermeabilityKind pkind = fillTensor(eclState, global_cell,
                                            tensor, kmap);
        if (pkind == Invalid) {
            OPM_THROW(std::runtime_error, "Invalid permeability field.");
        }

        assert (! tensor.empty());
        {
            int off = 0;

            for (int c = 0; c < nc; ++c, off += dim*dim) {
                // SharedPermTensor K(dim, dim, &permeability_[off]);
                int kix = 0;

                for (int i = 0; i < dim; ++i) {
                    for (int j = 0; j < dim; ++j, ++kix) {
                        // Clients expect column-major (Fortran) order
                        // in "permeability_" so honour that
                        // requirement despite "tensor" being created
                        // row-major.  Note: The actual numerical
                        // values in the resulting array are the same
                        // in either order when viewed contiguously
                        // because fillTensor() enforces symmetry.
                        permeability_[off + (i + dim*j)] =
                            tensor[kmap[kix]][c];
                    }

                    // K(i,i) = std::max(K(i,i), perm_threshold);
                    double& kii = permeability_[off + i*(dim + 1)];
                    kii = std::max(kii, perm_threshold);
                }

                permfield_valid_[c] = std::vector<unsigned char>::value_type(1);
            }
        }
    }
Ejemplo n.º 2
0
void Rock<dim>::assignPermeability(Opm::DeckConstPtr deck,
                                   const std::vector<int>& global_cell,
                                   double perm_threshold)
{
    Opm::EclipseGridInspector insp(deck);
    std::array<int, 3> dims = insp.gridSize();
    int num_global_cells = dims[0]*dims[1]*dims[2];
    assert (num_global_cells > 0);

    permeability_.assign(dim * dim * global_cell.size(), 0.0);

    std::vector<const std::vector<double>*> tensor;
    tensor.reserve(10);

    const std::vector<double> zero(num_global_cells, 0.0);
    tensor.push_back(&zero);

    static_assert(dim == 3, "");
    std::array<int,9> kmap;
    permeability_kind_ = fillTensor(deck, tensor, kmap);

    // Assign permeability values only if such values are
    // given in the input deck represented by 'deck'.  In
    // other words: Don't set any (arbitrary) default values.
    // It is infinitely better to experience a reproducible
    // crash than subtle errors resulting from a (poorly
    // chosen) default value...
    //
    if (tensor.size() > 1) {
        const int nc  = global_cell.size();
        int       off = 0;

        for (int c = 0; c < nc; ++c, off += dim*dim) {
            SharedPermTensor K(dim, dim, &permeability_[off]);
            int       kix  = 0;
            const int glob = global_cell[c];

            for (int i = 0; i < dim; ++i) {
                for (int j = 0; j < dim; ++j, ++kix) {
                    K(i,j) = (*tensor[kmap[kix]])[glob];
                }
                K(i,i) = std::max(K(i,i), perm_threshold);
            }

            permfield_valid_[c] = std::vector<unsigned char>::value_type(1);
        }
    }
}
Ejemplo n.º 3
0
Archivo: moaSq.c Proyecto: mhelal/mmDST
int main (int argc, char ** argv) {
  long seqNum, i, k  = 0;
 
  char * * sequences = NULL;
  long * seqLen = NULL;
  char * * * algnseq = NULL;
  long * aSeqLen = NULL;
  int alignmentsNo=0;
  MOA_rec * msaAlgn = NULL;
 
  int stype = 0;
  long currentScore, currentCell = 0;
  long prevScore, prevCell = 0;
  Mode = Sequential;
  processArguments(argc, argv, &seqNum, &sequences, &seqLen, &stype);
  prevNow = NULL;
  prevNow = (struct tm *) mmalloc (sizeof(struct tm));
  currNow = getTime();
  prevNow->tm_hour = currNow->tm_hour;
  prevNow->tm_isdst = currNow->tm_isdst;
  prevNow->tm_mday = currNow->tm_mday;
  prevNow->tm_min = currNow->tm_min;
  prevNow->tm_mon = currNow->tm_mon;
  prevNow->tm_sec = currNow->tm_sec;
  prevNow->tm_wday = currNow->tm_wday;
  prevNow->tm_yday = currNow->tm_yday;
  prevNow->tm_year = currNow->tm_year;
    

  
  /* A. Crteate MOA Alignment Tensor */
  /*msaAlgn = (MOA_rec *) mmalloc(sizeof(MOA_rec));*/
  createMOAStruct (&msaAlgn);
  
  createMOA(seqLen /* shape*/, seqNum /* dimension*/, msaAlgn /* MOA structure*/,0,0);
  if (pdebug == 1)
    mprintf(outputfilename, "MOA dimn %d, elm ub %d\n", 2, msaAlgn->dimn, msaAlgn->elements_ub); 
  /* B. Fill the Tensor */
 
  if (AlignmentType == Global) 
    initTensor (msaAlgn, stype);
  fillTensor (sequences, msaAlgn, stype);
  if (pdebug == 1) 
    printMOA(msaAlgn);

  /* C. trace back */
  aSeqLen = (long *)   mmalloc (sizeof(long));
  aSeqLen[0] = 0;
  prevCell = -1;
  algnseq = (char * * *) mmalloc(sizeof(char * *));
  algnseq[0] = (char * *) mmalloc (seqNum * sizeof(char *));    
  if (AlignmentType == Global) { /* if Global Alignment */
    /*PrintPrevChains(msaAlgn);
    // Get Max Cell on Last Border as Current Cell */
    alignmentsNo = 0;
    currentScore = getMaxOnLastBorder (msaAlgn, &currentCell);
    traceBack (seqNum, sequences, seqLen, msaAlgn, stype, &algnseq, &aSeqLen, &alignmentsNo, &currentCell, &currentScore, 0);
  }
  else { /* if Local Alignment */
    alignmentsNo = -1;
    for (k = 0;k<maxAlignmentsNumber;k++) {
      if (k == 0)
	currentScore = MOA_max(msaAlgn, 0, 0, &currentCell);
      else {
	currentScore = MOA_max(msaAlgn, 1, currentScore, &currentCell);
      }
      if ((prevCell != currentCell) && (currentScore > 0)){
	alignmentsNo ++;
	algnseq = (char * * *) realloc (algnseq, (alignmentsNo + 1) * sizeof(char * *));
     if (algnseq == NULL) {
		mprintf(outputfilename, "Could not reallocate memory for Aligned Sequence Set %d!\n", 1, alignmentsNo + 1);
		return -1;
      }
	algnseq[alignmentsNo] = (char * *) mmalloc (seqNum * sizeof(char *));
	aSeqLen = (long *)  realloc (aSeqLen, (alignmentsNo + 1) * sizeof(long));
     if (aSeqLen == NULL) {
		mprintf(outputfilename, "Could not reallocate memory for Aligned Sequence Length %d!\n", 1, alignmentsNo + 1);
		return -1;
      }
	traceBack_loc (seqNum, sequences, seqLen, msaAlgn, stype, &algnseq, &aSeqLen, &alignmentsNo, &currentCell, &currentScore, 0);
	}
	prevCell = currentCell;
	prevScore = currentScore;
    }
  }

  /* D. Print the resulting Alignemnts */
  PrintASeq (seqNum, sequences, seqLen, &algnseq, aSeqLen, alignmentsNo+1) ;

  /* Free all Memory Allocations & Exit. */
  deleteMOA (msaAlgn);
  if (sequences != NULL) {
    for (i=0;i<seqNum;i++) {
      if (sequences[i] != NULL) 
        free(sequences[i]);
	}
    free(sequences);
  }
  if (algnseq != NULL) {
    for (k=0;k<=alignmentsNo;k++) {
	  if (algnseq[k] != NULL) {
        for (i=0;i<seqNum;i++) {
          if (algnseq[k][i] != NULL)
	        free(algnseq[k][i]);
        }
        free(algnseq[k]);
	  }
    }
    free(algnseq);
  }
  if (seqLen != NULL)
    free(seqLen);
  if (aSeqLen != NULL)
    free(aSeqLen);
  if (prevNow != NULL)
    free(prevNow);

  return 0;

}