コード例 #1
0
ファイル: next_number.c プロジェクト: nikai3d/ce-challenges
int main(int argc, char *argv[]) {
	FILE *fp;
	int a;

	if (argc != 2) {
		printf("Usage: %s [FILE]\n", argv[0]);
		return 1;
	}
	fp = fopen(*++argv, "r");
	while (fscanf(fp, "%d", &a) != EOF) {
		int b = a + 9, d = dsig(a);
		while (d != dsig(b))
			b += 9;
		printf("%d\n", b);
	}
	return 0;
}
コード例 #2
0
void calculate(double *photoperiod,
	       double *mean_air_temp,
	       double *daily_precipitation,
	       double *popdens,
	       double *param,
	       double *n0,
	       double *n10,
	       double *n1,
	       double *n2,
	       double *n3,
	       double *n4fj,
	       double *n4f,
	       double *nBS,
	       double *K,
	       double *d4,
	       double *d4s,
	       double *F4,
	       double *egg,
	       double *percent_strong,
	       int    TIME) {
  double par[2];

  if (TIME==-1) {
    (*n0) = param[alpha_dp_egg];
    (*n10) = 0.0;
    (*n1) = param[alpha_0];
    (*n2) = param[alpha_1];
    (*n3) = param[alpha_2];
    (*n4fj) = 0.0;
    (*n4f) = param[alpha_3];
    (*nBS) = 0.0;
    (*K) = 0.0;
    (*d4) = 0.0;
    (*d4s) = 0.0;
    (*F4) = 0.0;
    (*egg) = (*n0) + (*n10) + (*n1);
    (*percent_strong) = 0.0;

    if ((*n10) > 0) incubator_add(&conn10,(*n10),0.0);
    if ((*n1) > 0) incubator_add(&conn1,(*n1),0.0);
    if ((*n2) > 0) incubator_add(&conn2,(*n2),0.0);
    if ((*n3) > 0) incubator_add(&conn3,(*n3),0.0);
    if ((*n4f) > 0) incubator_add(&conn4,(*n4f),0.0);

    return;
  }

  // ---------------------
  // modelDelayAalbopictus
  // ---------------------

  double deltaT = param[alpha_deltaT];

  double Ta = mean_air_temp[TIME];
  
  double Tw = Ta+deltaT;

  // Number of breeding sites
  (*nBS) = param[alpha_BS_pdens]*(*popdens) + param[alpha_BS_dprec]*daily_precipitation[TIME] + param[alpha_BS_nevap]*(*nBS);
  (*K) = param[alpha_BS_nevap]==1.0 ? (*nBS)/(TIME+1.0) : (*nBS)*(param[alpha_BS_nevap]-1.0)/(pow(param[alpha_BS_nevap],(TIME+1))-1.0);

  // Density of the immature stages
  // Assume uniform distribution across all breeding sites
  double n23dens = ((incubator_sum(conn2)+incubator_sum(conn3))/(*K));

  // Fecundity
  double bigF4 = poly(Ta,param[alpha_F4_1],param[alpha_F4_2],param[alpha_F4_3]);
  (*F4) = bigF4;

  double densd = expd(n23dens,param[alpha_n23_surv]);
  // Egg survival (diapausing eggs)
  double p0_Ta  = flin(Ta,param[alpha_p0_1],param[alpha_p0_2]);
  // Egg survival (non-diapausing eggs)
  double p1_Tw = dsig(Tw,param[alpha_p1_1],param[alpha_p1_2],param[alpha_p1_3]);
  // Larval survival
  double p2_Tw = dsig(Tw,param[alpha_p2_1],param[alpha_p2_2],param[alpha_p2_3])*densd;
  // Pupal survival
  double p3_Tw = dsig(Tw,param[alpha_p3_1],param[alpha_p3_2],param[alpha_p3_3])*densd;

  double densdev = fpow(n23dens,param[alpha_n23_1],param[alpha_n23_2]*poly(Tw,param[alpha_n23_3],param[alpha_n23_4],param[alpha_n23_5]));
  // Egg development time
  double d1 = poly(Tw,param[alpha_d1_1],param[alpha_d1_2],param[alpha_d1_3]);
  // Larval development time
  double d2 = poly(Tw,param[alpha_d2_1],param[alpha_d2_2],param[alpha_d2_3])*densdev;
  // Pupal development time
  double d3 = poly(Tw,param[alpha_d3_1],param[alpha_d3_2],param[alpha_d3_3])*densdev;
  // Time to first blood meal
  double alpha_blood = poly(Ta,param[alpha_tbm_1],param[alpha_tbm_2],param[alpha_tbm_3]);
  // Adult lifetime (from emergence)
  double dd4 = dsig2(Ta,param[alpha_d4_1],param[alpha_d4_2],param[alpha_d4_3]);
  double dd4s = gamma_matrix_sd*dd4;
  (*d4) = dd4;
  (*d4s) = dd4s;

  // Update development times and survival proportions
  // of the immature stages and juvenile adults
  //
  // Diapausing eggs
  (*n0) = p0_Ta*(*n0);
  //
  // Normal and tagged eggs
  par[0] = p1_Tw; par[1] = 1.0/max(1.0,d1);
  incubator_update(conn1,update,par);
  incubator_update(conn10,update,par);
  //
  // Larvae
  par[0] = p2_Tw; par[1] = 1.0/max(1.0,d2);
  incubator_update(conn2,update,par);
  //
  // Pupae
  par[0] = p3_Tw; par[1] = 1.0/max(1.0,d3);
  incubator_update(conn3,update,par);
  //
  // Adult females
  incubator_develop_survive(&conn4,-1,0,dd4,dd4s,alpha_blood,n4fj,n4f,0,gamma_mode);
  //
  // Check if it is winter or summer
  char short_days = photoperiod[TIME] < param[alpha_dp_thr];
  char cold_days = Ta < param[alpha_ta_thr];
  //
  // Lay eggs
  (*egg) = bigF4*(*n4f); // Total number of eggs that will be laid that day
  double hatch = 0;
  //
  if (short_days && cold_days) { // DIAPAUSE
    // The fraction of tagged eggs increases linearly
    (*percent_strong) = min(1.0,(*percent_strong)+param[alpha_rate_strong]);
    //
    incubator_add(&conn10,bigF4*(*n4f)*(*percent_strong),0.0); // Tagged eggs
    incubator_add(&conn1,bigF4*(*n4f)*(1.0-(*percent_strong)),0.0); // Normal eggs
    //
  } else { // NO DIAPAUSE
    if (!short_days && !cold_days) { // EXIT FROM DIAPAUSE
      // Prepare diapausing eggs for hatching
      double vn0_n10 = (*n0)*param[alpha_rate_normal];
      (*n0) -= vn0_n10; // Diapausing eggs
      hatch += vn0_n10; // Eggs to hatch
    }
    // Lay normal eggs
    incubator_add(&conn1,bigF4*(*n4f),0.0); // Normal eggs
    //
    (*percent_strong) = 0.0;
  }
  // Develop
  double nn1;
  double nn2;
  double nn3;
  incubator_remove(&conn3,&nn3);
  incubator_remove(&conn2,&nn2); incubator_add(&conn3,nn2,0.0);
  incubator_remove(&conn1,&nn1); hatch += nn1;
  // Harvest developed tagged eggs
  double vn10_hn0;
  incubator_remove(&conn10,&vn10_hn0);
  // Tagged eggs always become diapausing eggs
  (*n0) = (*n0) + vn10_hn0;
  // All eggs, which are ready to hatch, become larvae
  incubator_add(&conn2,hatch,0.0);
  //
  // Update immature stage counts
  (*n3) = incubator_sum(conn3);
  (*n2) = incubator_sum(conn2);
  (*n1) = incubator_sum(conn1) + incubator_sum(conn10);
  //
  // Add newly developed females to adults
  nn3 *= 0.5;
  incubator_add(&conn4,nn3,0.0);
  (*n4f) += nn3;
}
コード例 #3
0
ファイル: ElasticMPM.cpp プロジェクト: pbena/nairn-mpm-fea
// Once stress deformation has been decomposed, finish calculations in the material axis system
// When stress are found, they are rotated back to the global axes (using Rtot and dR)
// Similar, strain increments are rotated back to find work energy (done in global system)
void Elastic::LRElasticConstitutiveLaw(MPMBase *mptr,Matrix3 de,Matrix3 er,Matrix3 Rtot,Matrix3 dR,
									   Matrix3 *Rnmatot,int np,void *properties,ResidualStrains *res) const
{
	// effective strains
	double dvxxeff = de(0,0)-er(0,0);
	double dvyyeff = de(1,1)-er(1,1);
	double dvzzeff = de(2,2)-er(2,2);
	double dgamxy = 2.*de(0,1);
	
    // save initial stresses
	Tensor *sp=mptr->GetStressTensor();
    //Tensor st0=*sp;
	
	// stress increments
	// cast pointer to material-specific data
	ElasticProperties *p = GetElasticPropertiesPointer(properties);
	if(np==THREED_MPM)
	{	double dgamyz = 2.*de(1,2);
		double dgamxz = 2.*de(0,2);
		
		// update sigma = dR signm1 dRT + Rtot dsigma RtotT
		double dsigyz = p->C[3][3]*dgamyz;
		double dsigxz = p->C[4][4]*dgamxz;
		double dsigxy = p->C[5][5]*dgamxy;
		Matrix3 dsig(p->C[0][0]*dvxxeff + p->C[0][1]*dvyyeff + p->C[0][2]*dvzzeff, dsigxy, dsigxz,
					 dsigxy, p->C[1][0]*dvxxeff + p->C[1][1]*dvyyeff + p->C[1][2]*dvzzeff, dsigyz,
					 dsigxz, dsigyz, p->C[2][0]*dvxxeff + p->C[2][1]*dvyyeff + p->C[2][2]*dvzzeff);
		Matrix3 dsigrot = dsig.RMRT(Rtot);
		Matrix3 stn(sp->xx,sp->xy,sp->xz,sp->xy,sp->yy,sp->yz,sp->xz,sp->yz,sp->zz);
		Matrix3 str = stn.RMRT(dR);
		sp->xx = str(0,0) + dsigrot(0,0);
		sp->yy = str(1,1) + dsigrot(1,1);
		sp->zz = str(2,2) + dsigrot(2,2);
		sp->xy = str(0,1) + dsigrot(0,1);
		sp->xz = str(0,2) + dsigrot(0,2);
		sp->yz = str(1,2) + dsigrot(1,2);
		
		// stresses are in global coordinates so need to rotate strain and residual
		// strain to get work energy increment per unit mass (dU/(rho0 V0))
		Matrix3 derot = de.RMRT(Rtot);
		Matrix3 errot = er.RMRT(Rtot);
		mptr->AddWorkEnergyAndResidualEnergy(sp->xx*derot(0,0) + sp->yy*derot(1,1) + sp->zz*derot(2,2)
											  + 2.*(sp->yz*derot(1,2) + sp->xz*derot(0,2) + sp->xy*derot(0,1)),
											 sp->xx*errot(0,0) + sp->yy*errot(1,1) + sp->zz*errot(2,2)
											  + 2.*(sp->yz*errot(1,2) + sp->xz*errot(0,2) + sp->xy*errot(0,1)) );
		//mptr->AddWorkEnergyAndResidualEnergy(0.5*((st0.xx+sp->xx)*derot(0,0) + (st0.yy+sp->yy)*derot(1,1)
		//										  + (st0.zz+sp->zz)*derot(2,2)) + (st0.yz+sp->yz)*derot(1,2)
		//										  + (st0.xz+sp->xz)*derot(0,2) + (st0.xy+sp->xy)*derot(0,1),
		//									 0.5*((st0.xx+sp->xx)*errot(0,0) + (st0.yy+sp->yy)*errot(1,1)
		//										  + (st0.zz+sp->zz)*errot(2,2)) + (st0.yz+sp->yz)*errot(1,2)
		//										  + (st0.xz+sp->xz)*errot(0,2) + (st0.xy+sp->xy)*errot(0,1));
	}
	else
	{	// find stress increment
		// this does xx, yy, and xy only. zz done later if needed
		double dsxx,dsyy;
		if(np==AXISYMMETRIC_MPM)
		{	dsxx = p->C[1][1]*dvxxeff + p->C[1][2]*dvyyeff + p->C[4][1]*dvzzeff ;
			dsyy = p->C[1][2]*dvxxeff + p->C[2][2]*dvyyeff + p->C[4][2]*dvzzeff;
		}
		else
		{	dsxx = p->C[1][1]*dvxxeff + p->C[1][2]*dvyyeff;
			dsyy = p->C[1][2]*dvxxeff + p->C[2][2]*dvyyeff;
		}
		double dsxy = p->C[3][3]*dgamxy;
		
		// update sigma = dR signm1 dRT + Rtot dsigma RtotT
		Matrix3 dsig(dsxx,dsxy,dsxy,dsyy,0.);
		Matrix3 dsigrot = dsig.RMRT(Rtot);
		Matrix3 stn(sp->xx,sp->xy,sp->xy,sp->yy,sp->zz);
		Matrix3 str = stn.RMRT(dR);
		sp->xx = str(0,0) + dsigrot(0,0);
		sp->yy = str(1,1) + dsigrot(1,1);
		sp->xy = str(0,1) + dsigrot(0,1);
		
		// stresses are in global coordinate so need to rotate strain and residual
		// strain to get work energy increment per unit mass (dU/(rho0 V0))
		double ezzr = er(2,2);
		Matrix3 derot = de.RMRT(Rtot);
		Matrix3 errot = er.RMRT(Rtot);
		
		// work and residual strain energy increments and sigma or F in z direction
		double workEnergy = sp->xx*derot(0,0) + sp->yy*derot(1,1) + 2.0*sp->xy*derot(0,1);
		double resEnergy = sp->xx*errot(0,0) + sp->yy*errot(1,1) + 2.*sp->xy*errot(0,1);
		//double workEnergy = 0.5*((st0.xx+sp->xx)*derot(0,0) + (st0.yy+sp->yy)*derot(1,1)) + (st0.xy+sp->xy)*derot(0,1);
		//double resEnergy = 0.5*((st0.xx+sp->xx)*errot(0,0) + (st0.yy+sp->yy)*errot(1,1)) + (st0.xy+sp->xy)*errot(0,1);
		if(np==PLANE_STRAIN_MPM)
		{	// need to add back terms to get from reduced cte to actual cte
			sp->zz += p->C[4][1]*(dvxxeff+p->alpha[5]*ezzr) + p->C[4][2]*(dvyyeff+p->alpha[6]*ezzr) - p->C[4][4]*ezzr;
			
			// extra residual energy increment per unit mass (dU/(rho0 V0)) (by midpoint rule) (nJ/g)
			resEnergy += sp->zz*ezzr;
			//resEnergy += 0.5*(st0.zz+sp->zz)*ezzr;
		}
		else if(np==PLANE_STRESS_MPM)
		{	// zz deformation
			mptr->IncrementDeformationGradientZZ(p->C[4][1]*dvxxeff + p->C[4][2]*dvyyeff + ezzr);
		}
		else
		{	// axisymmetric hoop stress
			sp->zz += p->C[4][1]*dvxxeff + p->C[4][2]*dvyyeff + p->C[4][4]*dvzzeff;
			
			// extra work and residual energy increment per unit mass (dU/(rho0 V0)) (by midpoint rule) (nJ/g)
			workEnergy += sp->zz*de(2,2);
			resEnergy += sp->zz*ezzr;
			//workEnergy += 0.5*(st0.zz+sp->zz)*de(2,2);
			//resEnergy += 0.5*(st0.zz+sp->zz)*ezzr;
		}
		mptr->AddWorkEnergyAndResidualEnergy(workEnergy, resEnergy);
		
	}
    
    // track heat energy
    IncrementHeatEnergy(mptr,res->dT,0.,0.);
}