bool 
ChemistryMulti::check (const Scope& scope, const Geometry& geo,
		       const Soil& soil, const SoilWater& soil_water,
		       const SoilHeat& soil_heat, const Chemistry& chemistry,
		       Treelog& msg) const
{ 
  bool ok = true; 
  for (size_t c = 0; c < combine.size (); c++)
    {
      Treelog::Open nest (msg, "Chemistry: '" + combine[c]->objid  + "'");
      if (!combine[c]->check (scope, geo, soil, soil_water, soil_heat,
                              chemistry, msg))
	ok = false;
    }

  // Check for duplicate chemicals.
  std::map<symbol, size_t> found;
  for (size_t i = 0; i < chemicals.size (); i++)
    {
      const symbol type = chemicals[i]->objid;
      std::map<symbol, size_t>::const_iterator f = found.find (type);
      if (f != found.end ())
	{
	  std::ostringstream tmp;
	  tmp << "Chemical '" << type << "' definded in multiple chemistries:";
	  for (size_t j = 0; j < combine.size (); j++)
	    if (combine[j]->know (type))
	      tmp << " '" << combine[j]->objid << "'";
	  msg.error (tmp.str ());
	  ok = false;
	}
      found[type] = i;
    }
  return ok;
}
Beispiel #2
0
  bool has_attribute (const symbol name) const
  { 
    bool missing = false;
    for (size_t i = 0; i < layers.size (); i++)
      if (!layers[i]->horizon->has_attribute (name))
	missing = true;
    for (size_t i = 0; i < zones.size (); i++)
      if (!zones[i]->horizon->has_attribute (name))
	missing = true;
    return !missing;
  }
void 
ChemistryMulti::mass_balance (const Geometry& geo, 
                              const SoilWater& soil_water) const
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->mass_balance (geo, soil_water); 
}
Beispiel #4
0
void ErrorEstimatorImpl::output(std::ostream& os) const
{
    os << "[ErrorEstimator] iterations:" << iterationCount_ <<
        " error:" << error_ << endl;
    for (int i=0; i<(int)massSpreads_.size(); i++)
        os << "  " << *massSpreads_[i] << endl;
}
Beispiel #5
0
const MassSpread* ErrorEstimatorImpl::massSpread(int index) const
{
    if (index < 0 || index >= (int)massSpreads_.size())
        throw out_of_range("[ErrorEstimatorImpl::massSpread] Index out of range.");

    return massSpreads_[index];
}
Beispiel #6
0
    void paintColumns()
	{
	for(size_t i=0;i< columns.size();++i)
	    {

	    }
	}
void 
ChemistryMulti::tick_top (const Units& units, const Geometry& geo, 
                          const Soil& soil, const SoilWater& soil_water, 
                          const SoilHeat& soil_heat, 
                          const double tillage_age /* [d] */,
                          const Surface& surface,
                          const double snow_leak_rate, // [h^-1]
                          const double canopy_cover, // [],
                          const double canopy_leak_rate, // [h^-1]
                          const double litter_cover, // [],
                          const double litter_leak_rate, // [h^-1]
                          const double surface_runoff_rate /* [h^-1] */,
                          const double surface_water /* [mm] */,
                          const double total_rain /* [mm/h] */,
                          const double direct_rain, // [mm/h]
                          const double canopy_drip /* [mm/h] */, 
                          const double h_veg /* [m] */,
                          Chemistry& chemistry, 
                          const double dt, // [h]
                          Treelog& msg) 
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->tick_top (units, geo, soil, soil_water, soil_heat,
                          tillage_age, surface, 
                          snow_leak_rate, canopy_cover, canopy_leak_rate, 
                          litter_cover, litter_leak_rate,
			  surface_runoff_rate, surface_water,
                          total_rain, direct_rain, canopy_drip, h_veg, 
                          chemistry, dt, msg);
}
void 
ChemistryMulti::mix (const Geometry& geo, const Soil& soil, 
                     const SoilWater& soil_water,
                     const double from, const double to, 
                     const double penetration)
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->mix (geo, soil, soil_water, from, to, penetration); 
}
void 
ChemistryMulti::swap (const Geometry& geo,
                      const Soil& soil, const SoilWater& soil_water,
                      const double from, const double middle,
                      const double to)
{ 
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->swap (geo, soil, soil_water, from, middle, to); 
}
void 
ChemistryMulti::sorption_table (const Soil& soil, const size_t cell, 
                                const double Theta, const double start,
                                const double factor, const int intervals,
                                Treelog& msg) const
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->sorption_table (soil, cell, Theta, start, factor, intervals,
                                msg); 
}
Beispiel #11
0
void 
Movement1D::initialize_derived (const Soil& soil,
                                const Groundwater& groundwater,
                                bool has_macropores, Treelog& msg)
{
  TREELOG_MODEL (msg);

  for (size_t i = 0; i < matrix_water.size (); i++)
    matrix_water[i]->has_macropores (has_macropores);
}
void 
ChemistryMulti::tick_source (const Scope& scope, const Geometry& geo,
                             const Soil& soil, const SoilWater& soil_water, 
                             const SoilHeat& soil_heat, 
                             const OrganicMatter& organic, 
                             const Chemistry& chemistry, Treelog& msg)
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->tick_source (scope, geo, soil, soil_water, soil_heat, 
                             organic, chemistry, msg);
}
Beispiel #13
0
 bool has_attribute (const symbol name, Treelog& msg) const
 { 
   bool missing = false;
   for (size_t i = 0; i < layers.size (); i++)
     if (!layers[i]->horizon->has_attribute (name))
       {
         msg.error ("Required attribute '" 
                    + name + "' is missing from the soil horizon '"
                    + layers[i]->horizon->objid + "'");
         missing = true;
       }
   for (size_t i = 0; i < zones.size (); i++)
     if (!zones[i]->horizon->has_attribute (name))
       {
         msg.error ("Required attribute '" 
                    + name + "' is missing from the soil zone '"
                    + zones[i]->horizon->objid + "'");
         missing = true;
       }
   return !missing;
 }
void 
ChemistryMulti::initialize (const Scope& scope, 
			    const Geometry& geo,
			    const Soil& soil, 
			    const SoilWater& soil_water,
			    const SoilHeat& soil_heat,
			    const Surface& surface, Treelog& msg)
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->initialize (scope, geo, soil, soil_water, soil_heat, surface, 
                            msg);
}
double 
ChemistryMulti::suggest_dt () const
{
  double dt = 0.0;
  for (size_t c = 0; c < combine.size (); c++)
    {
      const double chem_dt = combine[c]->suggest_dt ();
      if (std::isnormal (chem_dt)
          && (!std::isnormal (dt) || chem_dt < dt))
        dt = chem_dt;
    }
  return dt;
}
void 
ChemistryMulti::tick_soil (const Scope& scope, 
                           const Geometry& geo, const double ponding,
			   const double R_mixing,
			   const Soil& soil, const SoilWater& soil_water,
			   const SoilHeat& soil_heat, Movement& movement,
			   const OrganicMatter& organic_matter,
			   Chemistry& chemistry, 
			   const double dt, Treelog& msg)
{ 
  TREELOG_MODEL (msg);

  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->tick_soil (scope, geo, ponding, R_mixing, 
			   soil, soil_water, soil_heat, movement, 
			   organic_matter, chemistry, dt, msg);
}
Beispiel #17
0
    void loop()
	{
	rows.push_back(new Column);
	rows.back()->label.assign("CHROM");
	rows.push_back(new Column);
	rows.back()->label.assign("POS");
	rows.push_back(new Column);
	rows.back()->label.assign("ID");
	rows.push_back(new Column);
	rows.back()->label.assign("REF");
	rows.push_back(new Column);
	rows.back()->label.assign("ALT");
	for(int i=0;i< samples.size();++i)
	    {
	    Sample* sample=samples.at(i);
	    rows.push_back(new Column);
	    rows.back()->label.assign(sample->name).append(":QUAL");
	    rows.push_back(new Column);
	    rows.back()->label.assign(sample->name).append(":FILTER");
	    rows.push_back(new Column);
	    rows.back()->label.assign(sample->name).append(":INFO");
	    rows.push_back(new Column);
	    rows.back()->label.assign(sample->name).append(":FORMAT");
	    rows.push_back(new Column);
	    rows.back()->label.assign(sample->name).append(":CALL");
	    }


	screen=Screen::startup();
	screen->border();
	screen->refresh();
	for(;;)
	    {
	    int c=screen->getch();
	    switch(c)
		{
		case 'q':
		    {
		    break;
		    }
		case
		}
	    }

	Screen::shutdown();
	}
void 
ChemistryMulti::deposit (const symbol chem, const double flux, Treelog& msg)
{
  bool found = false;

  for (size_t c = 0; c < combine.size (); c++)
    if (combine[c]->know (chem))
      {
	if (found)
	  msg.error ("Duplicate chemical '" + chem + "' detected");

	Chemical& chemical = combine[c]->find (chem);
        chemical.deposit (flux);
	found = true;
      }
  
  if (found)
    return;

  check_ignore (chem, msg);
}
void 
ChemistryMulti::incorporate (const Geometry& geo,
			     const symbol chem, const double amount,
                             const Volume& volume,
			     Treelog& msg)
{
  bool found = false;

  for (size_t c = 0; c < combine.size (); c++)
    if (combine[c]->know (chem))
      {
	if (found)
	  msg.error ("Duplicate chemical '" + chem + "' detected");

	Chemical& chemical = combine[c]->find (chem);
        chemical.incorporate (geo, amount, volume);
	found = true;
      }
  
  if (found)
    return;

  check_ignore (chem, msg);
}
void
ChemistryMulti::clear ()
{ 
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->clear (); 
}
Beispiel #21
0
void 
Movement1D::tick_water (const Geometry1D& geo,
                        const Soil& soil, const SoilHeat& soil_heat, 
                        Surface& surface, Groundwater& groundwater,
                        const std::vector<double>& S,
                        std::vector<double>& h_old,
                        const std::vector<double>& Theta_old,
                        const std::vector<double>& h_ice,
                        std::vector<double>& h,
                        std::vector<double>& Theta,
                        std::vector<double>& q,
                        std::vector<double>& q_p,
                        const double dt, 
                        Treelog& msg)
{
  const size_t top_edge = 0U;
  const size_t bottom_edge = geo.edge_size () - 1U;

  // Limit for groundwater table.
  size_t last  = soil.size () - 1;

  // Limit for ridging.
  const size_t first = (surface.top_type (geo, 0U) == Surface::soil)
    ? surface.last_cell (geo, 0U) 
    : 0U;
  // Calculate matrix flow next.

  for (size_t m = 0; m < matrix_water.size (); m++)
    {
      water_attempt (m);
      Treelog::Open nest (msg, matrix_water[m]->name);
      try
        {
          matrix_water[m]->tick (msg, geo, soil, soil_heat,
                                 first, surface, top_edge, 
                                 last, groundwater, bottom_edge,
                                 S, h_old, Theta_old, h_ice, h, Theta, 0U, q, 
                                 dt);

          for (size_t i = last + 2; i <= soil.size (); i++)
            {
              q[i] = q[i-1];
              q_p[i] = q_p[i-1];
            }

          // Update surface and groundwater reservoirs.
          surface.accept_top (q[0] * dt, geo, 0U, dt, msg);
          surface.update_pond_average (geo);
          const double q_down = q[soil.size ()] + q_p[soil.size ()];
          groundwater.accept_bottom (q_down * dt, geo, soil.size ());
          if (m > 0)
            msg.debug ("Reserve model succeeded");
          return;
        }
      catch (const char* error)
        {
          msg.debug (std::string ("UZ problem: ") + error);
        }
      catch (const std::string& error)
        {
          msg.debug (std::string ("UZ trouble: ") + error);
        }
      
      water_failure (m);
    }
  throw "Water matrix transport failed"; 
}
Beispiel #22
0
	int main(int argc,char** argv)
	    {
	    const char* exonFile=0;
	    int optind=1;
	    char* faidxfile=NULL;
	    while(optind < argc)
		{
		if(strcmp(argv[optind],"-h")==0)
		    {
		    this->usage(cerr,argc,argv);
		    return(EXIT_FAILURE);
		    }
		else if(strcmp(argv[optind],"-f")==0 && optind+1< argc)
		    {
		    faidxfile = argv[++optind];
		    }
		else if(strcmp(argv[optind],"-g")==0 && optind+1< argc)
		    {
		    exonFile=argv[++optind];
		    }
		else if(strcmp(argv[optind],"--")==0)
		    {
		    ++optind;
		    break;
		    }
		else if(argv[optind][0]=='-')
		    {
		    cerr << "unknown option '" << argv[optind]<< "'" << endl;
		    this->usage(cerr,argc,argv);
		    return EXIT_FAILURE;
		    }
		else
		    {
		    break;
		    }
		++optind;
		}
	    if(faidxfile==0)
		{
		cerr << "no fasta genome defined." << endl;
		this->usage(cerr,argc,argv);
		return EXIT_FAILURE;
		}
	    this->faidx.reset(new IndexedFasta(faidxfile));





	    if(exonFile==0)
		{
		cerr << "no bed for exons defined." << endl;
		this->usage(cerr,argc,argv);
		return EXIT_FAILURE;
		}



	    if(optind==argc)
		{
		cerr << "BAM files missing"<< endl;
		return EXIT_FAILURE;
		}
	    else
		{
		while(optind< argc)
		    {
		    char* bamfile=argv[optind++];
		    WHERE("Open "<< bamfile);
		    BamFile2* bam=new BamFile2(bamfile);
		    this->bamFiles.push_back(bam);
		    bam->open(true);
		    }
		}

	   //open exon file
	    igzstreambuf buf(exonFile);
	    istream in(&buf);
	    this->readExons(in);
	    buf.close();
	    if(exons.empty())
		{
		cerr << "No exon.\n";
		return EXIT_FAILURE;
		}

	    run();
	    for(size_t i=0;i< bamFiles.size();++i)
		{
		bamFiles[i]->close();
		}
	    return EXIT_SUCCESS;
	    }
void 
ChemistryMulti::update_C (const Soil& soil, const SoilWater& soil_water)
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->update_C (soil, soil_water); 
}
void
ChemistryMulti::harvest (const double removed, const double surface)
{
  for (size_t c = 0; c < combine.size (); c++)
    combine[c]->harvest (removed, surface);
}