예제 #1
0
/*! Compute Y matrix of bond wire.
 */
matrix bondwire::calcMatrixY (const nr_double_t f) {
  nr_double_t Lw;
  L = 0;

  switch (model) {
  case MIRROR:
    L = Lmirror ();
    R = resistance (f);
    break;
  case FREESPACE:
    L = Lfreespace (f);
    R = resistance (f);
    break;
  default:
    break;
  }

  Lw = L * 2 * M_PI * f;

  /* build Y-parameter matrix */
  nr_complex_t yL = 1.0 / rect (R, Lw);

  matrix Y (2);
  Y.set (NODE_1, NODE_1, +yL);
  Y.set (NODE_1, NODE_2, -yL);
  Y.set (NODE_2, NODE_1, -yL);
  Y.set (NODE_2, NODE_2, +yL);
  return Y;
}
예제 #2
0
double action_t::calculate_tick_damage()
{
  tick_dmg = resisted_dmg = blocked_dmg = 0;

  if ( base_td == 0 ) base_td = base_td_init;

  if ( base_td == 0 ) return 0;

  tick_dmg  = base_td + total_power() * tick_power_mod;
  tick_dmg *= total_td_multiplier();

  double init_tick_dmg = tick_dmg;

  if ( result == RESULT_CRIT )
  {
    tick_dmg *= 1.0 + total_crit_bonus();
  }

  if ( ! binary )
  {
    resisted_dmg = resistance() * tick_dmg;
    tick_dmg -= resisted_dmg;
  }

  if ( sim -> debug )
  {
    log_t::output( sim, "%s dmg for %s: td=%.0f i_td=%.0f b_td=%.0f mod=%.2f power=%.0f b_mult=%.2f p_mult=%.2f t_mult=%.2f",
                   player -> name(), name(), tick_dmg, init_tick_dmg, base_td, tick_power_mod,
                   total_power(), base_multiplier * base_td_multiplier, player_multiplier, target_multiplier );
  }

  return tick_dmg;
}
예제 #3
0
int Ground(int stgnum, Agent_status *agent, node_t *trees,int auto_or_mamual,Girl *Girl_status){
    int count = 0;
    if(agent->END_FLAG == 0)
    {
        Gravity(stgnum,agent,trees,auto_or_mamual,Girl_status);
        agent->Jumpflag = 0;
        control(stgnum,agent,trees,auto_or_mamual,Girl_status);

        if(count > 10)
            {
                resistance(agent);
                count = 0;
            }
        count++;

        /*
          if((agent->X >= Girl_status->X))
          {
          END(1,stgnum,trees,auto_or_mamual,agent);
          return 0;
          }
        */


        //    if (agent->END_FLAG != 1)
        //    {
        //            usleep(20000);
        Ground(stgnum,agent,trees,auto_or_mamual,Girl_status);
        //    }
    }
    return 0;
}
예제 #4
0
파일: sc_spell.cpp 프로젝트: coleb/Raid-Sim
void spell_t::calculate_result()
{
  int delta_level = target -> level - player -> level;

  direct_dmg = 0;
  result = RESULT_NONE;

  if ( ! harmful || ! may_hit ) return;

  if ( ( result == RESULT_NONE ) && may_miss )
  {
    if ( rng[ RESULT_MISS ] -> roll( miss_chance( delta_level ) ) )
    {
      result = RESULT_MISS;
    }
  }

  if ( ( result == RESULT_NONE ) && may_resist && binary )
  {
    if ( rng[ RESULT_RESIST ] -> roll( resistance() ) )
    {
      result = RESULT_RESIST;
    }
  }

  if ( result == RESULT_NONE )
  {
    result = RESULT_HIT;

    if ( may_crit )
    {
      if ( rng[ RESULT_CRIT ] -> roll( crit_chance( delta_level ) ) )
      {
        result = RESULT_CRIT;
      }
    }
  }

  if ( sim -> debug ) log_t::output( sim, "%s result for %s is %s", player -> name(), name(), util_t::result_type_string( result ) );
}
예제 #5
0
/*! DC model initialization.
 *! DC model of a bondwire is a resistance.
 */
void bondwire::initDC (void) {
  nr_double_t g;

  getProperties ();

  /* for non-zero resistances usual MNA entries */
  if (rho != 0.0) {
    g = 1.0 / resistance (0);
    setVoltageSources (0);
    allocMatrixMNA ();
    setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
    setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
  }
  /* for zero resistances create a zero voltage source */
  else {
    setVoltageSources (1);
    setInternalVoltageSource (1);
    allocMatrixMNA ();
    clearY ();
    voltageSource (VSRC_1, NODE_1, NODE_2);
  }
}
예제 #6
0
void  convertunits()
/*
**--------------------------------------------------------------
**  Input:   none
**  Output:  none
**  Purpose: converts units of input data
**--------------------------------------------------------------
*/
{
   int   i,j,k;
   double ucf;        /* Unit conversion factor */
   Pdemand demand;   /* Pointer to demand record */

/* Convert nodal elevations & initial WQ */
/* (WQ source units are converted in QUALITY.C */
   for (i=1; i<=Nnodes; i++)
   {
      Node[i].El /= Ucf[ELEV];
      Node[i].C0 /= Ucf[QUALITY];
   }

/* Convert demands */
   for (i=1; i<=Njuncs; i++)
   {
       for (demand = Node[i].D; demand != NULL; demand = demand->next)
          demand->Base /= Ucf[DEMAND];
   }

/* Convert emitter discharge coeffs. to head loss coeff. */
   ucf = pow(Ucf[FLOW],Qexp)/Ucf[PRESSURE];
   for (i=1; i<=Njuncs; i++)
     if (Node[i].Ke > 0.0) Node[i].Ke = ucf/pow(Node[i].Ke,Qexp);

/* Initialize tank variables (convert tank levels to elevations) */
   for (j=1; j<=Ntanks; j++)
   {
      i = Tank[j].Node;
      Tank[j].H0 = Node[i].El + Tank[j].H0/Ucf[ELEV];
      Tank[j].Hmin = Node[i].El + Tank[j].Hmin/Ucf[ELEV];
      Tank[j].Hmax = Node[i].El + Tank[j].Hmax/Ucf[ELEV];
      Tank[j].A = PI*SQR(Tank[j].A/Ucf[ELEV])/4.0;
      Tank[j].V0 /= Ucf[VOLUME];
      Tank[j].Vmin /= Ucf[VOLUME];
      Tank[j].Vmax /= Ucf[VOLUME];
      Tank[j].Kb /= SECperDAY;
      Tank[j].V = Tank[j].V0;
      Tank[j].C = Node[i].C0;
      Tank[j].V1max *= Tank[j].Vmax;
   }

/* Convert WQ option concentration units */
   Climit /= Ucf[QUALITY];
   Ctol   /= Ucf[QUALITY];

/* Convert global reaction coeffs. */
   Kbulk /= SECperDAY;
   Kwall /= SECperDAY;

/* Convert units of link parameters */
   for (k=1; k<=Nlinks; k++)
   {
      if (Link[k].Type <= PIPE)
      {
      /* Convert pipe parameter units:                         */
      /*    - for Darcy-Weisbach formula, convert roughness    */
      /*      from millifeet (or mm) to ft (or m)              */
      /*    - for US units, convert diameter from inches to ft */
         if (Formflag  == DW) Link[k].Kc /= (1000.0*Ucf[ELEV]);
         Link[k].Diam /= Ucf[DIAM];
         Link[k].Len /= Ucf[LENGTH];

      /* Convert minor loss coeff. from V^2/2g basis to Q^2 basis */
         Link[k].Km = 0.02517*Link[k].Km/SQR(Link[k].Diam)/SQR(Link[k].Diam);
      
      /* Convert units on reaction coeffs. */
         Link[k].Kb /= SECperDAY;
         Link[k].Kw /= SECperDAY;
      }

      else if (Link[k].Type == PUMP )
      {
      /* Convert units for pump curve parameters */
         i = PUMPINDEX(k);
         if (Pump[i].Ptype == CONST_HP)
         {
         /* For constant hp pump, convert kw to hp */
            if (Unitsflag == SI) Pump[i].R /= Ucf[POWER];
         }
         else
         {
         /* For power curve pumps, convert     */
         /* shutoff head and flow coefficient  */
            if (Pump[i].Ptype == POWER_FUNC)
            {
               Pump[i].H0 /= Ucf[HEAD];
               Pump[i].R  *= (pow(Ucf[FLOW],Pump[i].N)/Ucf[HEAD]);
            }
         /* Convert flow range & max. head units */
            Pump[i].Q0   /= Ucf[FLOW];
            Pump[i].Qmax /= Ucf[FLOW];
            Pump[i].Hmax /= Ucf[HEAD];
         }
      }

      else
      {
      /* For flow control valves, convert flow setting    */
      /* while for other valves convert pressure setting  */
         Link[k].Diam /= Ucf[DIAM];
         Link[k].Km = 0.02517*Link[k].Km/SQR(Link[k].Diam)/SQR(Link[k].Diam);      
         if (Link[k].Kc != MISSING) switch (Link[k].Type)
         {
            case FCV: Link[k].Kc /= Ucf[FLOW]; break;
            case PRV:
            case PSV:
            case PBV: Link[k].Kc /= Ucf[PRESSURE]; break;
         }
      }

   /* Compute flow resistances */
      resistance(k);
   }

/* Convert units on control settings */
   for (i=1; i<=Ncontrols; i++)
   {
      if ( (k = Control[i].Link) == 0) continue;
      if ( (j = Control[i].Node) > 0)
      {
      /* j = index of controlling node, and if           */
      /* j > Njuncs, then control is based on tank level */
      /* otherwise control is based on nodal pressure    */
         if (j > Njuncs)
              Control[i].Grade = Node[j].El + Control[i].Grade/Ucf[ELEV];
         else Control[i].Grade = Node[j].El + Control[i].Grade/Ucf[PRESSURE];
      }

      /* Convert units on valve settings */
      if (Control[i].Setting != MISSING) switch (Link[k].Type)
      {
         case PRV:
         case PSV:
         case PBV:
            Control[i].Setting /= Ucf[PRESSURE];
            break;
         case FCV:
            Control[i].Setting /= Ucf[FLOW];
      }
   }
}                       /*  End of convertunits  */
예제 #7
0
파일: otownlnk.cpp 프로젝트: mecirt/7k2
//------- Begin of function Town::setup_link ---------//
//
void Town::setup_link()
{
	//-----------------------------------------------------------------------------//
	// check the connected firms location and structure if ai_link_checked is true
	//-----------------------------------------------------------------------------//

	if(ai_town)
		ai_link_checked = 0;

	//----- build town-to-firm link relationship -------//

	int   firmRecno;
	Firm* firmPtr;
	FirmInfo* firmInfo;

	linked_firm_count = 0;

	for( firmRecno=firm_array.size() ; firmRecno>0 ; firmRecno-- )
	{
		if( firm_array.is_deleted(firmRecno) )
			continue;

		firmPtr  = firm_array[firmRecno];
		firmInfo = firm_res[firmPtr->firm_id];

		if( !firmInfo->is_linkable_to_town )
			continue;

		//----- only linkable if the firm and the town belong to the same nation or the firm can influence a foreign town, i.e. Camp, Fort and Fryhtan Lair,

		if( nation_recno==0 )
		{
			//--- independent towns can linked to work firms and markets ---//

			if( !firmPtr->cast_to_FirmWork() && !firmPtr->cast_to_FirmMarket()
				 && !firmPtr->cast_to_FirmCamp() )
			{
				continue;
			}
		}
		else
		{
			//--- nation towns can only linked to own firms or camps -------//

			if( firmPtr->nation_recno != nation_recno && !firmPtr->cast_to_FirmCamp() )
				continue;
		}

		//---------- check if the firm is close enough to this firm -------//

		if( m.points_distance( firmPtr->center_x, firmPtr->center_y, center_x, center_y )
			 > world.effective_distance(firmPtr->firm_id, 0) )
		{
			continue;
		}

		//------ check if both are on the same terrain type ------//

		if( (world.get_loc(firmPtr->loc_x1, firmPtr->loc_y1)->is_plateau()==1)
			 != (world.get_loc(loc_x1, loc_y1)->is_plateau()==1) )
		{
			continue;
		}

		//----- if the firm requires same race -------//

		if( !firm_res.is_linkable_to_town(firmPtr->firm_id, firmPtr->race_id, race_id) )
			continue;

		//------- determine default link flag -------//

		int defaultLinkStatus = LINK_EE;

		if( nation_recno==0 )		// if this is an independent town
		{
			if( firmPtr->nation_recno==0 || resistance(firmPtr->nation_recno) > INDEPENDENT_LINK_RESISTANCE )
				defaultLinkStatus = LINK_DD;
		}

		//-------- add the link now -------//

		if( linked_firm_count < MAX_LINKED_FIRM_TOWN )
		{
			err_when( linked_firm_count>0 && linked_firm_array[linked_firm_count-1] == firmRecno );		// BUGHERE - check double linking error

			linked_firm_array[linked_firm_count] = firmRecno;
			linked_firm_enable_array[linked_firm_count] = defaultLinkStatus;

			linked_firm_count++;
		}
		else
		{
			err_here();
		}

		if( firmPtr->linked_town_count < MAX_LINKED_TOWN_TOWN )
		{
			firmPtr->linked_town_array[firmPtr->linked_town_count] = town_recno;
			firmPtr->linked_town_enable_array[firmPtr->linked_town_count] = defaultLinkStatus;

			firmPtr->linked_town_count++;

			if(firmPtr->is_ai)
				firmPtr->ai_link_checked = 0;
		}
		else
		{
			err_here();
		}
	}

	//----- build town-to-town link relationship -------//

	linked_town_count = 0;

	int   townRecno;
	Town* townPtr;

	for( townRecno=town_array.size() ; townRecno>0 ; townRecno-- )
	{
		if( town_array.is_deleted(townRecno) || townRecno==town_recno )
			continue;

		townPtr = town_array[townRecno];

		//----- if the firm requires same race -------//

		if( race_id != townPtr->race_id )
			continue;

		//------ check if the town is close enough to this firm -------//

		if( m.points_distance( townPtr->center_x, townPtr->center_y,
			 center_x, center_y ) > world.effective_distance(0, 0) )
		{
			continue;
		}

		//------ check if both are on the same terrain type ------//

		if( (world.get_loc(townPtr->loc_x1, townPtr->loc_y1)->is_plateau()==1)
			 != (world.get_loc(loc_x1, loc_y1)->is_plateau()==1) )
		{
			continue;
		}

		//-------- link this town -------//

		if( linked_town_count < MAX_LINKED_TOWN_TOWN )
		{
			linked_town_array[linked_town_count] = townRecno;
			linked_town_enable_array[linked_town_count] = LINK_EE;

			linked_town_count++;
		}
		else
		{
			err_here();
		}

		//-------- link the other town  -------//

		if( townPtr->linked_town_count < MAX_LINKED_TOWN_TOWN )
		{
			townPtr->linked_town_array[townPtr->linked_town_count] = town_recno;
			townPtr->linked_town_enable_array[townPtr->linked_town_count] = LINK_EE;

			townPtr->linked_town_count++;

			if(townPtr->ai_town)
				townPtr->ai_link_checked = 0;
		}
		else
		{
			err_here();
		}
	}
}
예제 #8
0
double action_t::calculate_direct_damage()
{
  direct_dmg = resisted_dmg = blocked_dmg = 0;

  double base_direct_dmg = sim -> range( base_dd_min, base_dd_max );

  if ( base_direct_dmg == 0 ) return 0;
  
  direct_dmg  = base_direct_dmg + base_dd_adder + player_dd_adder + target_dd_adder;
  if ( weapon_multiplier > 0 )
  {
    // x% weapon damage + Y
    // e.g. Obliterate, Shred, Backstab
    direct_dmg += calculate_weapon_damage();
    direct_dmg *= weapon_multiplier;
    
    // OH penalty
    if ( weapon && weapon -> slot == SLOT_OFF_HAND )
      direct_dmg *= 0.5;
  }
  direct_dmg += direct_power_mod * total_power();
  direct_dmg *= total_dd_multiplier();

  double init_direct_dmg = direct_dmg;

  if ( result == RESULT_GLANCE )
  {
    double delta_skill = ( sim -> target -> level - player -> level ) * 5.0;

    if ( delta_skill < 0.0 )
      delta_skill = 0.0;

    double max_glance = 1.3 - 0.03 * delta_skill;

    if ( max_glance > 0.99 ) 
      max_glance = 0.99;
    else if ( max_glance < 0.2 )
      max_glance = 0.20;

    double min_glance = 1.4 - 0.05 * delta_skill;

    if ( min_glance > 0.91 )
      min_glance = 0.91;
    else if ( min_glance < 0.01 )
      min_glance = 0.01;

    if ( min_glance > max_glance )
    {
      double temp = min_glance;
      min_glance = max_glance;
      max_glance = temp;
    }

    direct_dmg *= sim -> range( min_glance, max_glance ); // 0.75 against +3 targets.
  }
  else if ( result == RESULT_CRIT )
  {
    direct_dmg *= 1.0 + total_crit_bonus();
  }

  if ( ! binary )
  {
    resisted_dmg = resistance() * direct_dmg;
    direct_dmg -= resisted_dmg;
  }

  if ( result == RESULT_BLOCK )
  {
    blocked_dmg = sim -> target -> block_value;
    direct_dmg -= blocked_dmg;
    if ( direct_dmg < 0 ) direct_dmg = 0;
  }

  if ( sim -> debug )
  {
    log_t::output( sim, "%s dmg for %s: dd=%.0f i_dd=%.0f b_dd=%.0f mod=%.2f power=%.0f b_mult=%.2f p_mult=%.2f t_mult=%.2f",
                   player -> name(), name(), direct_dmg, init_direct_dmg, base_direct_dmg, direct_power_mod,
                   total_power(), base_multiplier * base_dd_multiplier, player_multiplier, target_multiplier );
  }

  return direct_dmg;
}
예제 #9
0
// solve vegetation model
void modifiedVegetationModel::solve(volVectorField& U, volScalarField& T, volScalarField& w)
{
    // solve radiation within vegetation
    radiation();

    const double p_ = 101325;

    // Magnitude of velocity
    volScalarField magU("magU", mag(U));

    // Bounding velocity
    bound(magU, UMin_);

    // solve aerodynamic, stomatal resistance
    volScalarField new_Tl("new_Tl", Tl_);

    // info
    Info << "    max leaf temp tl=" << max(T.internalField())
         << "k, iteration i=0" << endl;

    scalar maxError, maxRelError;
    int i;

    // solve leaf temperature, iteratively.
    int maxIter = 500;
    for (i=1; i<=maxIter; i++)
    {
        // Solve aerodynamc, stomatal resistance
        resistance(magU, T, w, new_Tl);

        forAll(LAD_, cellI)
        {
            if (LAD_[cellI] > 10*SMALL)
            {
                // Initial leaf temperature
                if (i==1)
                    Tl_[cellI];// = T[cellI];//*0. + 300.;//T[cellI];

                // Calculate saturated density, specific humidity
                rhosat_[cellI] = calc_rhosat(Tl_[cellI]);
                evsat_[cellI] = calc_evsat(Tl_[cellI]);
                wsat_[cellI] = 0.621945*(evsat_[cellI]/(p_-evsat_[cellI])); // ASHRAE 1, eq.23

                // Calculate transpiration rate]);
                E_[cellI] = nEvapSides_.value()*LAD_[cellI]*rhoa_.value()*(wsat_[cellI]-w[cellI])/(ra_[cellI]+rs_[cellI]);
                //E_[cellI] = 0.0; // No evapotranspiration

                // Calculate latent heat flux
                Ql_[cellI] = lambda_.value()*E_[cellI];

                // Calculate new leaf temperature
                new_Tl[cellI] = T[cellI] + (Rn_[cellI] - Ql_[cellI])*(ra_[cellI]/(2.0*rhoa_.value()*cpa_.value()*LAD_[cellI]));

            }
        }

        // info
        Info << "    max leaf temp tl=" << gMax(new_Tl.internalField())
             << " K, iteration i="   << i << endl;

        // Check rel. L-infinity error
        maxError = gMax(mag(new_Tl.internalField()-Tl_.internalField()));
        maxRelError = maxError/gMax(mag(new_Tl.internalField()));

        // update leaf temp.
        forAll(Tl_, cellI)
            Tl_[cellI] = 0.5*Tl_[cellI]+0.5*new_Tl[cellI];

         // convergence check
         if (maxRelError < 1e-8)
             break;
    }
    Tl_.correctBoundaryConditions();

    // Iteration info
    Info << "Vegetation model:  Solving for Tl, Final residual = " << maxError
         << ", Final relative residual = " << maxRelError
         << ", No Iterations " << i << endl;

    Info << "temperature parameters: max Tl = " << gMax(Tl_)
         << ", min T = " << gMin(T) << ", max T = " << gMax(T) << endl;

    Info << "resistances: max rs = " << gMax(rs_)
         << ", max ra = " << gMax(ra_) << endl;

    // Final: Solve aerodynamc, stomatal resistance
    resistance(magU, T, w, Tl_);

    // Final: Update sensible and latent heat flux
    forAll(LAD_, cellI)
    {
        if (LAD_[cellI] > 10*SMALL)
        {
            // Calculate saturated density, specific humidity
            rhosat_[cellI] = calc_rhosat(Tl_[cellI]);
            evsat_[cellI] = calc_evsat(Tl_[cellI]);
            wsat_[cellI] = 0.621945*(evsat_[cellI]/(p_-evsat_[cellI])); // ASHRAE 1, eq.23

            // Calculate transpiration rate
            E_[cellI] = nEvapSides_.value()*LAD_[cellI]*rhoa_.value()*(wsat_[cellI]-w[cellI])/(ra_[cellI]+rs_[cellI]); // todo: implement switch for double or single side

            // Calculate latent heat flux
            Ql_[cellI] = lambda_.value()*E_[cellI];

            // Calculate sensible heat flux
            Qs_[cellI] = 2.0*rhoa_.value()*cpa_.value()*LAD_[cellI]*(Tl_[cellI]-T[cellI])/ra_[cellI];
        }
    }
    rhosat_.correctBoundaryConditions();
    wsat_.correctBoundaryConditions();
    E_.correctBoundaryConditions();
    Ql_.correctBoundaryConditions();
    Qs_.correctBoundaryConditions();


}