Exemplo n.º 1
0
    int NextPBin(int *penv)
    {
        double nChanged, nDied, nMitosed, nRemaining, nGone,
				nMigrationTo, MigrationPool,
     	    	nMutated, nMutatedTo, MutationPool, nConverted, nConvertedTo, ConversionPool,temp;
        int    iindex, jindex, AlteringEvent = false, anychanges;
        int    envnowl;
		unsigned int icelltype, getcelltype();
       	extern int get_dest_gap();
		extern void sort_lookuptable();
		void Gomp_UpdateTime();
       
		if (!ContinDrugRuleActive) /* Only check for an enviroment change if a BB rule isn't in effect */
			envnowl = getenvir( t );
		else
			envnowl = *penv;
		
		if (PendingEnvChange)
			CheckEnv( t, &envnowl );


		if ((KineticsModel == IsGompertz) && (t > UpdateTime)) {
			Gomp_UpdateTime(envnowl);
    		UpdateTime += UPDATEGAP*delta_t;
    	}

	   	anychanges = false;
    	pre_ntypes = active_ntypes;
   
	 for ( iindex= 1; iindex < MaxLookUp; iindex++ )
    	      nDescOfItype(iindex) = 0.0; /* set  matrix zero */
	 for ( iindex = 1; iindex <= pre_ntypes; iindex++ )
       {
          nChanged = nMutated = nDied = nMitosed = 0.0;
          if ( CN[iindex]>= 1.0 )
          {
             /* the number of cells that are mutated, died or devided */

            temp = EventProb(SomeEventProb,iindex,envnowl);
			nChanged= grand_b_n( CN[iindex],temp);
   

     		nRemaining = nChanged;
     		if ( nRemaining <= 0.0) goto NEXTCELLTYPE;
     
            anychanges = true;
            /* number of "itype" cells which died */
			temp = EventProb(GoneProb,iindex,envnowl);


            nGone = grand_b_n( nChanged,temp);

     		nDied = grand_b_n( nGone, CondProbDeath(iindex,envnowl));
     		
			nConverted = nGone - nDied;
     		ConversionPool = nConverted; 
			
			for ( jindex = 0; jindex < LookUp[iindex].ParaPr->NumOfCo; jindex++ )
     		{ 
    		   if ( ConversionPool <= 0.0)
     			 break;
    			 icelltype=getcelltype(iindex,jindex,envnowl,G0T);
    		   	 AlteringEvent = TRUE;
                 temp=CondCoTo(iindex,jindex,envnowl);
     			 nConvertedTo = grand_b_n( ConversionPool,temp);
     			 if ( nConvertedTo > 0.0 )
     			 {
					if ( (Class[0].class_type==1 ) && (labs((long) (LookUp[iindex].LookUpId-icelltype)))>= Tblength ) {
						/* A cell has converted from the ith to jth type */                        
     					if ((*OrganFunc)(iindex,icelltype,nConvertedTo,envnowl) ==False)
							return False;
					} 
					else { /* if not "organ" */
						if ( create_para_struct(icelltype,SIM) == False )
    						return False;
    					nDescOfItype(change_index) += nConvertedTo;
					}
    			
			   		if ( ConversionPool > nConvertedTo )
     					   ConversionPool = ConversionPool - nConvertedTo;
     				else
     					   ConversionPool = 0.0;
				}/* if nConverted > 0 */
     		} /* end of for loop */

			MigrationPool = ConversionPool;
			
			if ( MigrationPool > 0.0) {
				for ( jindex = 0; jindex < LookUp[iindex].ParaPr->NumOfMig; jindex++ )
     			{ 
    			  	 AlteringEvent = TRUE;
					 temp = CondMigTo(iindex,jindex,envnowl);
					 nMigrationTo = grand_b_n(	MigrationPool,temp);
					 if (nMigrationTo > 0.0 )
     				 {
						icelltype=getcelltype(iindex,jindex,envnowl,MIG);
    					if ( create_para_struct(icelltype,SIM)== False )
    						return False;
						nDescOfItype(change_index) += nMigrationTo;
     					
    					if ( MigrationPool > nMigrationTo )
     					   MigrationPool = MigrationPool - nMigrationTo;
     					else
     					   MigrationPool = 0.0;
						if ( MigrationPool  <= 0.0)
     						 break;
     			  }
     			}
			}
    		
    		nDescOfItype(iindex) -= nGone; 
     		nRemaining =  nChanged - nGone;
     		if ( nRemaining <= 0.0) goto NEXTCELLTYPE;
     
			temp = EventProb(MuProb,iindex,envnowl);
     		nMutated = grand_b_n( nRemaining, temp);
     		MutationPool = nMutated;                  /* number of cells mutated */
     		for ( jindex = 0; jindex < LookUp[iindex].ParaPr->NumOfMu; jindex++ )
     		{ 
    		   if ( MutationPool <= 0.0)
     			 break;
    			 icelltype=getcelltype(iindex,jindex,envnowl,MUTATION);
    			 AlteringEvent = TRUE;
    			 temp=CondMuTo(iindex,jindex,envnowl);
     			 nMutatedTo = grand_b_n( MutationPool,temp);
     			 if ( nMutatedTo > 0.0 )
     			 { /* A cell has mutated from the ith to jth type */   
					 if ( create_para_struct(icelltype,SIM) == False)
    						return False ;

    				 nDescOfItype(change_index) += nMutatedTo;
     								 
					 if ( MutationPool > nMutatedTo )
     					   MutationPool = MutationPool - nMutatedTo;
     				 else
     					   MutationPool = 0.0;
					 } /* if ( nMutatedTo > 0.0 ) */
     		}    /* end of for loop */     

     		nRemaining =  nChanged - nGone - nMutated;
     		if ( nRemaining <= 0.0) goto NEXTCELLTYPE;
    		
    		nDescOfItype(iindex) += nRemaining;  /* number of cells which divided */
    
     	  }
    	  NEXTCELLTYPE:  ; /* Skip to the next cell type.*/
      }
      if ( anychanges ){
     	  /* A change occurred in at least one cell (any type) */
     	  for ( iindex = 1 ; iindex <= active_ntypes; iindex++ ){
			if (Update_CN_NGomp(iindex,envnowl)== false )
				return false;
		}

		if ( (AlteringEvent == TRUE) && (verbos > 3) )
     		  eprint( "Note: at least one cell was altered (mutated or converted)\n" );
      }
  
#ifdef SORT   
	if ( pre_ntypes < active_ntypes)
		sort_lookuptable(pre_ntypes+1,active_ntypes,SIM);
#endif
   
      *penv=envnowl;
	  nowenv = envnowl;
      return True;
     }
Exemplo n.º 2
0
void write_vtkFile_debug(const char *szProblem,
		int    timeStepNumber,
		double xlength,
		double ylength,
		double zlength,
		int    imax,
		int    jmax,
		int    kmax,
		double dx,
		double dy,
		double dz,
		double ***U,
		double ***V,
		double ***W,
		double ***P,
		int ***Flag) {

	int i,j,k;
	double uVel,vVel,wVel;
	char szFileName[80];
	FILE *fp=NULL;
	//sprintf( szFileName, "simulation/%s.%i_debug.vtk", szProblem, timeStepNumber );
	sprintf( szFileName, "/media/norbert/940CB6150CB5F27A/Documents/simulation/%s.%i_debug.vtk", szProblem, timeStepNumber );

	fp = fopen( szFileName, "w");
	if( fp == NULL )
	{
		char szBuff[80];
		sprintf( szBuff, "Failed to open %s", szFileName );
		ERROR( szBuff );
		return;
	}

	write_vtkHeader_debug(fp, imax, jmax, kmax, dx, dy, dz);
	write_vtkPointCoordinates_debug(fp, imax, jmax, kmax, dx, dy, dz);


	fprintf(fp,"POINT_DATA %i \n", (imax+3)*(jmax+3)*(kmax+3) );

	fprintf(fp,"\n");
	fprintf(fp, "VECTORS velocity float\n");
	for(k = -1; k < kmax+2; k++) {
		for(j = -1; j < jmax+2; j++) {
			for(i = -1; i < imax+2; i++) {
				if(i >= 0 && j >= 0 && k >= 0 && i < imax+1 && j < jmax+1 && k < kmax+1){
					uVel = getValidValue((U[i][j][k] + U[i][j+1][k] + U[i][j][k+1] + U[i][j+1][k+1]) * 0.25);
					vVel = getValidValue((V[i][j][k] + V[i+1][j][k] + V[i][j][k+1] + V[i+1][j][k+1]) * 0.25);
					wVel = getValidValue((W[i][j][k] + W[i+1][j][k] + W[i][j+1][k] + W[i+1][j+1][k]) * 0.25);
					fprintf(fp, "%f %f %f\n",uVel,vVel,wVel);
				}
				else{
					fprintf(fp, "0 0 0\n");
				}
			}
		}
	}

	fprintf(fp,"\n");
	fprintf(fp,"CELL_DATA %i \n", ((imax+2)*(jmax+2)*(kmax+2)) );
	fprintf(fp, "SCALARS pressure float 1 \n");
	fprintf(fp, "LOOKUP_TABLE default \n");
	for(k = 0; k < kmax+2; k++) {
		for(j = 0; j < jmax+2; j++) {
			for(i = 0; i < imax+2; i++) {
				fprintf(fp, "%f\n",getValidValue(P[i][j][k]));
			}
		}
	}


	fprintf(fp,"\n");
	fprintf(fp, "SCALARS flag short 1 \n");
	fprintf(fp, "LOOKUP_TABLE default \n");

	for(k = 0; k < kmax+2; k++) {
		for(j = 0; j < jmax+2; j++) {
			for(i = 0; i < imax+2; i++) {
				fprintf(fp, "%d\n",getcelltype(Flag[i][j][k]));
			}
		}
	}

	if( fclose(fp) )
	{
		char szBuff[80];
		sprintf( szBuff, "Failed to close %s", szFileName );
		ERROR( szBuff );
	}
}