Beispiel #1
0
//--------------------------------------------------------------
void vehicle::applyBehaviours(vector<vehicle> vehicles, ofVec2f* gradient){

    ofPoint mouse(ofGetMouseX(), ofGetMouseY());
    
    ofPoint separateForce = separate(vehicles);
    ofPoint seekForce = seek(mouse);
    ofPoint border = borders();
    ofPoint slope = slopes(gradient);
    
    separateForce*=2;
    seekForce *= 1;
    border *=3;
    slope *= 2;
    
    applyForce(slope);
    applyForce(border);
    applyForce(separateForce);
    applyForce(seekForce);
}
Beispiel #2
0
void EmptyTrace::PrecomputeBackgroundSlopeForDeriv ( int flow_buffer_index )
{
  // calculate the slope of the background curve at every point
  float *bsPtr = &neg_bg_buffers_slope[flow_buffer_index*imgFrames];
  float *bPtr  = &bg_buffers[flow_buffer_index*imgFrames];

  // expand into frames
  assert (secondsPerFrame > 0.0f);
  assert (imgFrames == (int)timePoints.size());

  int nFrames = (int)( (timePoints[timePoints.size()-1]+.0001)/secondsPerFrame);
  std::vector<float> frameTime(nFrames, 0);
  for (int i=0; i<nFrames; i++)
    frameTime[i] = (i+1.0f)*secondsPerFrame;

  std::vector<float> interpValues(nFrames, 0);
  TimeCompression::Interpolate(&timePoints[0], bPtr, imgFrames, &frameTime[0], &interpValues[0], nFrames);
			  
  //SavitskyGolayComputeSlope ( bsPtr,bPtr,imgFrames );
  std::vector<float> slopes(nFrames, 0);
  SavitskyGolayComputeSlope ( &slopes[0], &interpValues[0], nFrames );
  TimeCompression::Interpolate(&frameTime[0], &slopes[0], nFrames, &timePoints[0], bsPtr, imgFrames);

  /* // jgv
     char s[60000]; int n=0;
     n += sprintf(s, "SavitskyGolayComputeSlope\t%d :", regionIndex);
     for (int pt = 0;pt < imgFrames;pt++)
     n += sprintf(&s[n], "\t%f", bsPtr[pt]);

     n += sprintf(&s[n], "\nOrig Time: ");
     for (int i=0; i< timePoints.size(); i++)
     n += sprintf(&s[n], "\t%f", timePoints[i]);
     n += sprintf(&s[n], "\n\0");
     assert (n<60000);
     fprintf(stdout, "%s", s);
  */
}
Beispiel #3
0
void cxxTitanSimulation::init_piles()
{

    MatProps* matprops_ptr = get_matprops();
    FluxProps* fluxprops_ptr = get_fluxprops();
    TimeProps* timeprops_ptr = get_timeprops();
    StatProps* statprops_ptr = get_statprops();

    ElementsHashTable* HT_Elem_Ptr=get_HT_Elem();
    NodeHashTable* HT_Node_Ptr=get_HT_Node();

    PileProps* pileprops_ptr=get_pileprops();

    unsigned nodes[9][KEYLENGTH], *node_key;
    
    int no_of_buckets = HT_Elem_Ptr->get_no_of_buckets();
    vector<HashEntryLine> &bucket=HT_Elem_Ptr->bucket;
    tivector<Element> &elenode_=HT_Elem_Ptr->elenode_;
    

    PileProps::PileType pile_type= pileprops_ptr->get_default_piletype();

    int i;
    bool allPilesAreElliptical=true;
    for(i=0;i<pileprops_ptr->numpiles;i++)
    {
        if(!(pileprops_ptr->pile_type[i] == PileProps::PARABALOID || pileprops_ptr->pile_type[i] == PileProps::CYLINDER))
            allPilesAreElliptical=false;
    }
    if(pileprops_ptr->numpiles>0)pile_type= pileprops_ptr->pile_type[0];

    if(!adapt)
        H_adapt_to_level(HT_Elem_Ptr, HT_Node_Ptr, matprops_ptr, pileprops_ptr, fluxprops_ptr, timeprops_ptr, REFINE_LEVEL);

    if(allPilesAreElliptical)
    {
        if(adapt)
            initial_H_adapt(HT_Elem_Ptr, HT_Node_Ptr, 0, matprops_ptr, pileprops_ptr, fluxprops_ptr, timeprops_ptr, 4);
    }
    else
    {
        printf("It seems this type of piles have hardcoded coordinates\n");
        assert(0);
        //@ElementsBucketDoubleLoop
        for(int ibuck = 0; ibuck < no_of_buckets; ibuck++)
        {
            for(int ielm = 0; ielm < bucket[ibuck].ndx.size(); ielm++)
            {
                Element *EmTemp = &(elenode_[bucket[ibuck].ndx[ielm]]);
                
                if(EmTemp->adapted_flag() > 0)
                {
                    //put in the pile height right here...
                    double pile_height = 0.0;
                    double radius_sq;
                    switch (pile_type)
                    {

                        case PileProps::PLANE:
                            radius_sq = pow(EmTemp->coord(0) - 76., 2) + pow(EmTemp->coord(1) - 80., 2);
                            if(radius_sq < 35.)
                                pile_height = 10 * (1. - radius_sq / 35.);
                            break;
                        case PileProps::CASITA:
                            radius_sq = pow(EmTemp->coord(0) - 504600., 2) + pow(EmTemp->coord(1) - 1402320., 2);
                            if(radius_sq < 30000.)
                                pile_height = 15 * (1. - radius_sq / 30000.);
                            break;
                        case PileProps::POPO: //popo topo
                            radius_sq = pow(EmTemp->coord(0) - 537758. / matprops_ptr->scale.length, 2)
                                    + pow(EmTemp->coord(1) - 2100910. / matprops_ptr->scale.length, 2);
                            if(radius_sq < (10000. / matprops_ptr->scale.length))
                                pile_height = 1. - radius_sq / (10000. / matprops_ptr->scale.length);
                            break;
                        case PileProps::ID1: // iverson and denlinger experiments I -- as pictured

                            if(EmTemp->coord(0) < 53.345 && EmTemp->coord(0) > 45.265 && EmTemp->coord(1) > -10. && EmTemp->coord(1) < 300.)
                            {
                                if(EmTemp->coord(0) < 51.148)
                                    pile_height = 3.5912 * (1.0 - (51.148 - EmTemp->coord(0)) / 5.8832);
                                else
                                    pile_height = 3.59 * (53.345 - EmTemp->coord(0)) / 2.1967;
                                if(pile_height < 0)
                                    pile_height = 0;
                            }
                            break;
                        case PileProps::ID2: //iverson and denlinger experiments II -- 90 angle with plane
                            if(EmTemp->coord(0) < 53.345 / matprops_ptr->scale.length && EmTemp->coord(0)
                                    > 46.45 / matprops_ptr->scale.length)
                                pile_height = 4.207255
                                        * (1.0 - (53.345 / matprops_ptr->scale.length - EmTemp->coord(0)) / 6.895
                                                * matprops_ptr->scale.length);
                            break;
                        default:
                            printf("Danger no recognized pile type defined in init_piles.C\n");
                            assert(0);
                    }
                    EmTemp->put_height(pile_height);

                }
            }
        }
    } //end "#if defined PARABALOID || defined CYLINDER"
    move_data(numprocs, myid, HT_Elem_Ptr, HT_Node_Ptr, timeprops_ptr);
    
    //update temporary arrays of elements/nodes pointers
    HT_Node_Ptr->flushNodeTable();
    HT_Elem_Ptr->flushElemTable();
    HT_Elem_Ptr->updateLocalElements();
    HT_Elem_Ptr->updateNeighboursIndexes();
    
    slopes(HT_Elem_Ptr, HT_Node_Ptr, matprops_ptr);
    
    /* initial calculation of actual volume on the map */

    double realvolume = 0.0, depositedvol = 0.0, forcebed = 0.0, meanslope = 0.0;
    double epsilon[DIMENSION];
    for(i=0;i<DIMENSION;i++)
        epsilon[i]=matprops_ptr->scale.epsilon;
    
    //@ElementsBucketDoubleLoop
    for(int ibuck = 0; ibuck < no_of_buckets; ibuck++)
    {
        for(int ielm = 0; ielm < bucket[ibuck].ndx.size(); ielm++)
        {
            Element* Curr_El  = &(elenode_[bucket[ibuck].ndx[ielm]]);
            if(Curr_El->adapted_flag() > 0)
            { //if this is a refined element don't involve!!!
                double dvol = Curr_El->dx(0) * Curr_El->dx(1) * Curr_El->state_vars(0);
                realvolume += dvol;
                Curr_El->set_kactxy(epsilon);

                Curr_El->calc_stop_crit(matprops_ptr,integrator);
                if(Curr_El->stoppedflags() == 2)
                    depositedvol += dvol;

                double resolution = 0, xslope = 0, yslope = 0;
                Get_max_resolution(&resolution);
                Get_slope(resolution, Curr_El->coord(0) * matprops_ptr->scale.length,
                          Curr_El->coord(1) * matprops_ptr->scale.length, xslope, yslope);
                double slope = sqrt(xslope * xslope + yslope * yslope);

                forcebed += dvol * 9.8 / sqrt(1.0 + slope * slope)
                        * tan(matprops_ptr->bedfrict[Curr_El->material()]);

            }
        }
    }
    
    double tempin[3], tempout[3];
    tempin[0] = realvolume;
    tempin[1] = forcebed;
    tempin[2] = depositedvol;
#ifdef USE_MPI
    MPI_Reduce(tempin, tempout, 3, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
#else //USE_MPI
    for(int i9=0;i9<3;++i9)tempout[i9]=tempin[i9];
#endif //USE_MPI
    
    statprops_ptr->realvolume = tempout[0] * (matprops_ptr->scale.height) * (matprops_ptr->scale.length) * (matprops_ptr->scale.length);
    statprops_ptr->outflowvol = 0.0;
    statprops_ptr->erodedvol = 0.0;
    statprops_ptr->depositedvol = tempout[2] * (matprops_ptr->scale.height) * (matprops_ptr->scale.length)
                              * (matprops_ptr->scale.length);
    
    statprops_ptr->forceint = 0.0;
    statprops_ptr->forcebed = tempout[1] / tempout[0];
    
    return;
}
Beispiel #4
0
UnifiedModel* ModelParametersLWPR::toUnifiedModel(void) const
{
  if (lwpr_object_->nIn()!=1)
  {
    //cout << "Warning: Can only call toUnifiedModel() when input dim of LWPR is 1" << endl;
    return NULL;
  }
  if (lwpr_object_->model.nOut!=1)
  {
    //cout << "Warning: Can only call toUnifiedModel() when output dim of LWPR is 1" << endl;
    return NULL;
  }
  
  int i_in = 0;
  int i_out = 0;

  int n_basis_functions = lwpr_object_->model.sub[i_out].numRFS;
  VectorXd centers(n_basis_functions);
  VectorXd widths(n_basis_functions);
  VectorXd offsets(n_basis_functions);
  VectorXd slopes(n_basis_functions);
  
  vector<double> tmp;
  
  for (int iRF = 0; iRF < lwpr_object_->model.sub[i_out].numRFS; iRF++)
  {
    LWPR_ReceptiveFieldObject rf = lwpr_object_->getRF(i_out,iRF);
    
    tmp = rf.center();
    centers[iRF] = tmp[i_in];
    
    offsets[iRF] = rf.beta0();
    
    tmp = rf.slope();
    slopes[iRF] = tmp[i_in];
    tmp = rf.beta();

    vector<vector<double> > D = rf.D();
    widths[iRF] = sqrt(1.0/D[i_in][i_in]);
    
  }

  
  vector<double> norm_out = lwpr_object_->normOut();
  vector<double> norm_in = lwpr_object_->normIn();
  //cout << "  centers=" << centers.transpose() << endl;
  //cout << "  widths=" << widths.transpose() << endl;
  //cout << "  offsets=" << offsets.transpose() << endl;
  //cout << "  slopes=" << slopes.transpose() << endl;
  //cout << "  norm_out[i_out]=" << norm_out[i_out] << endl;
  //cout << "  norm_in[i_in]=" << norm_out[i_in] << endl;

  offsets /= norm_out[i_out];
  slopes /= norm_out[i_out];
  centers /= norm_in[i_in];
  widths /= norm_in[i_in];
  
  //cout << "  centers=" << centers.transpose() << endl;
  //cout << "  widths=" << widths.transpose() << endl;
  //cout << "  offsets=" << offsets.transpose() << endl;
  //cout << "  slopes=" << slopes.transpose() << endl;

  //bool asymmetric_kernels=false;
  bool normalized_basis_functions=true;
  bool lines_pivot_at_max_activation=true;

  return new UnifiedModel(centers,widths,slopes,offsets,
                                    normalized_basis_functions, lines_pivot_at_max_activation);
}
Beispiel #5
0
void step(HashTable* El_Table, HashTable* NodeTable, int myid, int nump, MatProps* matprops_ptr,
    TimeProps* timeprops_ptr, PileProps *pileprops_ptr, FluxProps *fluxprops,
    StatProps* statprops_ptr, int* order_flag, OutLine* outline_ptr, DISCHARGE* discharge,
    int adaptflag) {
	/*
	 * PREDICTOR-CORRECTED based on Davis' Simplified Godunov Method
	 */

	/* pass off proc data here (really only need state_vars for off-proc neighbors) */
	move_data(nump, myid, El_Table, NodeTable, timeprops_ptr);

	slopes(El_Table, NodeTable, matprops_ptr, 0);

	// get coefficients, eigenvalues, hmax and calculate the time step
	double dt = get_coef_and_eigen(El_Table, NodeTable, matprops_ptr, fluxprops, timeprops_ptr, 0);
	// here we store the required data (solution and functional sensitivity) for the 0 time step

	timeprops_ptr->incrtime(&dt); //also reduces dt if necessary

	// assign influxes and then if any new sources are activating in
	// current time step refine and re-mark cells
	adapt_fluxsrc_region(El_Table, NodeTable, matprops_ptr, pileprops_ptr, fluxprops, timeprops_ptr,
	    dt, myid, adaptflag);

	int i;
	HashEntryPtr* buck = El_Table->getbucketptr();
	HashEntryPtr currentPtr;
	Element* Curr_El;

	double dt2 = .5 * dt; // dt2 is set as dt/2 !

	/*
	 *  predictor step
	 */
	int j, k, counter;
	double tiny = GEOFLOW_TINY;
	double flux_src_coef = 0;

#ifdef SECOND_ORDER
	//-------------------go through all the elements of the subdomain and
	//-------------------calculate the state variables at time .5*delta_t
	/* mdj 2007-04 */
	int IF_STOPPED;
	double curr_time,influx[3],*d_uvec; //VxVy[2];
	double VxVy[2];
	Node* nd;
#pragma omp parallel for                                                \
  private(currentPtr,Curr_El,IF_STOPPED,influx,j,k,curr_time,flux_src_coef,VxVy)
	for(i=0; i<El_Table->get_no_of_buckets(); i++)
	if(*(buck+i))
	{
		currentPtr = *(buck+i);
		while(currentPtr) {

			Curr_El=(Element*)(currentPtr->value);

			influx[3];
			influx[0]=*(Curr_El->get_influx()+0);
			influx[1]=*(Curr_El->get_influx()+1);
			influx[2]=*(Curr_El->get_influx()+2);

			if(!(influx[0]>=0.0)) {
				printf("negative influx=%g\n",influx[0]);
				assert(0);
			}

			if(Curr_El->get_adapted_flag()>0) {

				d_uvec = Curr_El->get_d_state_vars();
				nd = (Node*) NodeTable->lookup(Curr_El->pass_key());

				// -- calc contribution of flux source
				flux_src_coef=0;
				curr_time=(timeprops_ptr->time)*(timeprops_ptr->TIME_SCALE);

				//VxVy[2];
				if(*(Curr_El->get_state_vars()+0)>GEOFLOW_TINY) {
					VxVy[0]=*(Curr_El->get_state_vars()+1)/ *(Curr_El->get_state_vars()+0);
					VxVy[1]=*(Curr_El->get_state_vars()+2)/ *(Curr_El->get_state_vars()+0);
				}
				else
				VxVy[0]=VxVy[1]=0.0;

#ifdef STOPCRIT_CHANGE_SOURCE
				IF_STOPPED=Curr_El->get_stoppedflags();
#else
				IF_STOPPED=!(!(Curr_El->get_stoppedflags()));
#endif

				predict_(Curr_El->get_state_vars(), d_uvec, (d_uvec+NUM_STATE_VARS),
						Curr_El->get_prev_state_vars(), &tiny,
						Curr_El->get_kactxy(), &dt2, Curr_El->get_gravity(),
						Curr_El->get_curvature(),
						&(matprops_ptr->bedfrict[Curr_El->get_material()]),
						&(matprops_ptr->intfrict),
						Curr_El->get_d_gravity(), &(matprops_ptr->frict_tiny),
						order_flag, VxVy,
						&IF_STOPPED,influx);

				/* apply bc's */
#ifdef APPLY_BC
				for(j=0;j<4;j++)
				if(*(Curr_El->get_neigh_proc()+j) == INIT)   // this is a boundary!
				for(k=0;k<NUM_STATE_VARS;k++)
				*(Curr_El->get_state_vars()+k) = 0;
#endif
			}
			currentPtr=currentPtr->next;
		}
	}
	/* finished predictor step */
	/* really only need to share dudx, state_vars, and kactxy */
	move_data(nump, myid, El_Table, NodeTable,timeprops_ptr);

	/* calculate the slopes for the new (half-time step) state variables */
	slopes(El_Table, NodeTable, matprops_ptr);
#endif  //SECOND_ORDER

	/* really only need to share dudx, state_vars, and kactxy */
	move_data(nump, myid, El_Table, NodeTable, timeprops_ptr);

	/* calculate kact/pass */
	double dt_not_used = get_coef_and_eigen(El_Table, NodeTable, matprops_ptr, fluxprops,
	    timeprops_ptr, 1);

	/*
	 * calculate edge states
	 */
	double outflow = 0.0; //shouldn't need the =0.0 assignment but just being cautious.
	//printf("step: before calc_edge_states\n"); fflush(stdout);

	calc_edge_states<Element>(El_Table, NodeTable, matprops_ptr, timeprops_ptr, myid, order_flag,
	    &outflow);
	outflow *= dt;

	/*
	 * corrector step and b.c.s
	 */

	//for comparison of magnitudes of forces in slumping piles
	double forceint = 0.0, elemforceint;
	double forcebed = 0.0, elemforcebed;
	double eroded = 0.0, elemeroded;
	double deposited = 0.0, elemdeposited;
	double realvolume = 0.0;

	buck = El_Table->getbucketptr();

	// mdj 2007-04 this loop has pretty much defeated me - there is
	//             a dependency in the Element class that causes incorrect
	//             results
	//

	for (i = 0; i < El_Table->get_no_of_buckets(); i++)
		if (*(buck + i)) {
			HashEntryPtr currentPtr = *(buck + i);
			while (currentPtr) {
				Element* Curr_El = (Element*) (currentPtr->value);
				if (Curr_El->get_adapted_flag() > 0) { //if this is a refined element don't involve!!!

					double *dxy = Curr_El->get_dx();
					// if calculations are first-order, predict is never called
					// ... so we need to update prev_states
//					void *Curr_El_out = (void *) Curr_El;
					//I believe it's because we need correct function be a friend function of node class, but we do not want to add element header to node.h
					if (*order_flag == 1)
						Curr_El->update_prev_state_vars();

					//if (*(Curr_El->pass_key())==2151461179 && *(Curr_El->pass_key()+1)==330382099 /*&& timeprops->iter == 9 */)
					//  cout<<"step is cheking the element"<<endl;

					correct(NodeTable, El_Table, dt, matprops_ptr, fluxprops, timeprops_ptr, Curr_El,
					    &elemforceint, &elemforcebed, &elemeroded, &elemdeposited);

					forceint += fabs(elemforceint);
					forcebed += fabs(elemforcebed);
					realvolume += dxy[0] * dxy[1] * *(Curr_El->get_state_vars());
					eroded += elemeroded;
					deposited += elemdeposited;

					double *coord = Curr_El->get_coord();
					//update the record of maximum pileheight in the area covered by this element
					double hheight = *(Curr_El->get_state_vars());

//					int ind = Curr_El->get_sol_rec_ind();
//					jacobian = solHyst->at(ind);

#ifdef MAX_DEPTH_MAP
					double pfheight[6];
					outline_ptr->update(coord[0] - 0.5 * dxy[0], coord[0] + 0.5 * dxy[0],
					    coord[1] - 0.5 * dxy[1], coord[1] + 0.5 * dxy[1], hheight, pfheight);
#endif

//#ifdef APPLY_BC
//					for (j = 0; j < 4; j++)
//						if (*(Curr_El->get_neigh_proc() + j) == INIT) // this is a boundary!
//							for (k = 0; k < NUM_STATE_VARS; k++)
//								*(Curr_El->get_state_vars() + k) = 0;
//#endif

				}
				currentPtr = currentPtr->next;
			}
		}

	//update the orientation of the "dryline" (divides partially wetted cells
	//into wet and dry parts solely based on which neighbors currently have
	//pileheight greater than GEOFLOW_TINY
	for (i = 0; i < El_Table->get_no_of_buckets(); i++) {
		HashEntryPtr currentPtr = *(buck + i);
		while (currentPtr) {
			Element* Curr_El = (Element*) (currentPtr->value);
			currentPtr = currentPtr->next;
			if (Curr_El->get_adapted_flag() > 0) //if this is a refined element don't involve!!!
				Curr_El->calc_wet_dry_orient(El_Table);
		}
	}

	/* finished corrector step */
	calc_stats(El_Table, NodeTable, myid, matprops_ptr, timeprops_ptr, statprops_ptr, discharge, dt);

//	double tempin[6], tempout[6];
//	tempin[0] = outflow;    //volume that flew out the boundaries this iteration
//	tempin[1] = eroded;     //volume that was eroded this iteration
//	tempin[2] = deposited;  //volume that is currently deposited
//	tempin[3] = realvolume; //"actual" volume within boundaries
//	tempin[4] = forceint;   //internal friction force
//	tempin[5] = forcebed;   //bed friction force
//
//	MPI_Reduce(tempin, tempout, 6, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
//
//	statprops_ptr->outflowvol += tempout[0] * (matprops_ptr->HEIGHT_SCALE)
//	    * (matprops_ptr->LENGTH_SCALE) * (matprops_ptr->LENGTH_SCALE);
//	statprops_ptr->erodedvol += tempout[1] * (matprops_ptr->HEIGHT_SCALE)
//	    * (matprops_ptr->LENGTH_SCALE) * (matprops_ptr->LENGTH_SCALE);
//	statprops_ptr->depositedvol = tempout[2] * (matprops_ptr->HEIGHT_SCALE)
//	    * (matprops_ptr->LENGTH_SCALE) * (matprops_ptr->LENGTH_SCALE);
//	statprops_ptr->realvolume = tempout[3] * (matprops_ptr->HEIGHT_SCALE)
//	    * (matprops_ptr->LENGTH_SCALE) * (matprops_ptr->LENGTH_SCALE);
//
//	statprops_ptr->forceint = tempout[4] / tempout[3] * matprops_ptr->GRAVITY_SCALE;
//	statprops_ptr->forcebed = tempout[5] / tempout[3] * matprops_ptr->GRAVITY_SCALE;

	//calc_volume(El_Table, myid, matprops_ptr, timeprops_ptr, dt, v_star, nz_star);

	return;
}
Beispiel #6
0
	static window_regression_stats *get_window_regression_stats(
	 const grid<pixel_t> &red, const grid<pixel_t> &nir, size_t size,
	 bool force)
	{
		size_t output_block = 100;
		size_t row_count = (red.height() / size);
		IF_NORMAL(std::cout << row_count << " rows" << std::endl);
		size_t window_count = (red.width() / size) * row_count;
		array<numeric_t> slopes(window_count);
		array<numeric_t> intercepts(window_count);
		array<numeric_t> r2s(window_count);
		array<bool> goodness(window_count);
		numeric_t *slopes_ptr = slopes.data();
		numeric_t *intercepts_ptr = intercepts.data();
		numeric_t *r2s_ptr = r2s.data();
		bool *ptr_goodness = goodness.data();
		size_t good_count = 0;
		rect<size_t> subr = {0, 0, size, size};
		for (subr.y = 0; subr.y + size <= red.height() && subr.y +
		 size <= nir.height(); subr.y += size) {
			for (subr.x = 0; subr.x + size <= red.width() &&
			 subr.x + size <= nir.width(); subr.x += size) {
				const grid<pixel_t> red_sub(
				 const_cast<grid<pixel_t>*>(&red), subr);
				const grid<pixel_t> nir_sub(
				 const_cast<grid<pixel_t>*>(&nir), subr);
				if (force || is_good_data(red_sub, nir_sub)) {
					linear_regression *reg =
					 stats_find_linear_regression(red_sub,
					 nir_sub);
					*slopes_ptr = reg->eq.slope;
					*intercepts_ptr = reg->eq.intercept;
					*r2s_ptr = reg->r2;
					*ptr_goodness = true;
					good_count++;
					delete reg;
				} else {
					IF_VERBOSE(std::cout << "Bad sector: ");
					IF_VERBOSE(std::cout << "(" << subr.x);
					IF_VERBOSE(std::cout << ", " << subr.y);
					IF_VERBOSE(std::cout << ") ");
					*ptr_goodness = false;
				}
				slopes_ptr++;
				intercepts_ptr++;
				r2s_ptr++;
				ptr_goodness++;
			}
			if ((subr.y / size) % output_block == 0) {
				IF_NORMAL(std::cout << "\ranalyzing rows "
				 "starting at " << (subr.y / size) << "...");
				IF_NORMAL(std::cout.flush());
			}
		}
		IF_NORMAL(std::cout << std::endl);
		// okay, we have slope data, now find statistics
		window_regression_stats *stats = new window_regression_stats;
		// first, filter out the bad ones
		IF_VERBOSE(std::cout << "Found " << good_count);
		IF_VERBOSE(std::cout << " good sectors out of ");
		IF_VERBOSE(std::cout << window_count << std::endl);
		array<numeric_t> good_slope_data(good_count);
		array<numeric_t> good_intercept_data(good_count);
		array<numeric_t> good_r2_data(good_count);
		size_t good_data_cur = 0;
		for (size_t i = 0; i < window_count; i++) {
			if (goodness[i]) {
				good_slope_data[good_data_cur] = slopes[i];
				good_intercept_data[good_data_cur] =
				 intercepts[i];
				good_r2_data[good_data_cur] = r2s[i];
				good_data_cur++;
			}
		}
		stats->slope_mean = numeric_mean(good_slope_data);
		stats->slope_stddev = numeric_stddev(good_slope_data);
		stats->intercept_mean = numeric_mean(good_intercept_data);
		stats->intercept_stddev = numeric_stddev(good_intercept_data);
		stats->r2_mean = numeric_mean(good_r2_data);
		stats->r2_stddev = numeric_stddev(good_r2_data);
		stats->window_size = size;
		return stats;
	}
Beispiel #7
0
void step(HashTable* El_Table, HashTable* NodeTable, int myid, int nump,
	  MatProps* matprops_ptr, TimeProps* timeprops_ptr, 
	  PileProps *pileprops_ptr, FluxProps *fluxprops, 
	  StatProps* statprops_ptr, int* order_flag, 
	  OutLine* outline_ptr, DISCHARGE* discharge, int adaptflag)
{
  /* 
   * PREDICTOR-CORRECTED based on Davis' Simplified Godunov Method 
   */

  /* pass off proc data here (really only need state_vars for off-proc neighbors) */
  move_data(nump, myid, El_Table, NodeTable,timeprops_ptr);

  slopes(El_Table, NodeTable, matprops_ptr);

  // get coefficients, eigenvalues, hmax and calculate the time step 
  double dt = get_coef_and_eigen(El_Table, NodeTable, matprops_ptr, 
				 fluxprops, timeprops_ptr,0);

  timeprops_ptr->incrtime(&dt); //also reduces dt if necessary

  // assign influxes and then if any new sources are activating in 
  // current time step refine and re-mark cells 
  adapt_fluxsrc_region(El_Table,NodeTable,matprops_ptr,pileprops_ptr,fluxprops,
		       timeprops_ptr,dt,myid,adaptflag);

  int i;

  HashEntryPtr* buck = El_Table->getbucketptr();
  HashEntryPtr currentPtr;
  Element* Curr_El;

  double dt2 = .5*dt; // dt2 is set as dt/2 !
  // printf("dt for explicit is ...%f \n", dt);

  /*
   *  predictor step
   */
  int j,k, counter;
  double tiny = GEOFLOW_TINY,phi;
  double flux_src_coef=0;

  // printf("the number of elements are ...........%d\n", num_nonzero_elem(El_Table));
#ifdef SECOND_ORDER
  //-------------------go through all the elements of the subdomain and  
  //-------------------calculate the state variables at time .5*delta_t
  /* mdj 2007-04 */
  int IF_STOPPED;
  double curr_time,influx[3],*d_uvec,*lap_phi; //VxVy[2];
  double VxVy[2];
  Node* nd;
#pragma omp parallel for                                                \
  private(currentPtr,Curr_El,IF_STOPPED,influx,j,k,curr_time,flux_src_coef,VxVy)
  for(i=0; i<El_Table->get_no_of_buckets(); i++)
    if(*(buck+i))
      {
	currentPtr = *(buck+i);
	while(currentPtr){

	  Curr_El=(Element*)(currentPtr->value);

	  influx[3];
	  influx[0]=*(Curr_El->get_influx()+0);
	  influx[1]=*(Curr_El->get_influx()+1);
	  influx[2]=*(Curr_El->get_influx()+2);

	  if(!(influx[0]>=0.0)){
	    printf("negative influx=%g\n",influx[0]);
	    assert(0);
	  }


	  if(Curr_El->get_adapted_flag()>0){
	    lap_phi=Curr_El->get_lap_phi();
	    d_uvec = Curr_El->get_d_state_vars();
	    nd = (Node*) NodeTable->lookup(Curr_El->pass_key());

	    // -- calc contribution of flux source
	    flux_src_coef=0;
	    curr_time=(timeprops_ptr->time)*(timeprops_ptr->TIME_SCALE);

	    //VxVy[2]; 
	    if(*(Curr_El->get_state_vars())<0/*GEOFLOW_TINY*/) {
	      VxVy[0]=*(Curr_El->get_state_vars()+2)/ *(Curr_El->get_state_vars()+1);
	      VxVy[1]=*(Curr_El->get_state_vars()+3)/ *(Curr_El->get_state_vars()+1);
	    }
	    else
	      VxVy[0]=VxVy[1]=0.0;

#ifdef STOPCRIT_CHANGE_SOURCE
	    IF_STOPPED=Curr_El->get_stoppedflags();
#else
	    IF_STOPPED=!(!(Curr_El->get_stoppedflags()));
#endif

	    predict_(Curr_El->get_state_vars(), d_uvec, (d_uvec+NUM_STATE_VARS),lap_phi,
		     Curr_El->get_prev_state_vars(), &tiny, 
		     Curr_El->get_kactxy(), &dt2, Curr_El->get_gravity(), 
		     Curr_El->get_curvature(),
		     &(matprops_ptr->bedfrict[Curr_El->get_material()]), 
		     &(matprops_ptr->intfrict),
		     Curr_El->get_d_gravity(), &(matprops_ptr->frict_tiny), 
		     order_flag, VxVy, 
		     &IF_STOPPED,influx);

	    /* apply bc's */
#ifdef APPLY_BC
	    for(j=0;j<4;j++)
	      if(*(Curr_El->get_neigh_proc()+j) == INIT)   // this is a boundary!
		for(k=1;k<NUM_STATE_VARS;k++)
		  *(Curr_El->get_state_vars()+k) = 0;
#endif
	  }
	  currentPtr=currentPtr->next;      	    
	}
      }
  /* finished predictor step */
  /* really only need to share dudx, state_vars, and kactxy */
  move_data(nump, myid, El_Table, NodeTable,timeprops_ptr);

  /* calculate the slopes for the new (half-time step) state variables */
  slopes(El_Table, NodeTable, matprops_ptr);
#endif  //SECOND_ORDER

	/* really only need to share dudx, state_vars, and kactxy */
  move_data(nump, myid, El_Table, NodeTable,timeprops_ptr);

  /* calculate kact/pass */
  double dt_not_used = get_coef_and_eigen(El_Table, NodeTable, matprops_ptr,
					  fluxprops, timeprops_ptr, 1);

  /*
   * calculate edge states
   */
  double outflow=0.0;  //shouldn't need the =0.0 assignment but just being cautious.
  //printf("step: before calc_edge_states\n"); fflush(stdout);
  calc_edge_states(El_Table,NodeTable,matprops_ptr,timeprops_ptr,myid,order_flag,&outflow);
	
  //printf("the outflow in step after calc_edge ..............%f\n",outflow);
  outflow*=dt;
  //printf("the dt in step ...............%f\n",dt);
  //printf("the outflow in step ...............%f\n",outflow);

 MapNames mapnames;
  char *b,*c,*d;
  char a[5]="abs";// ,b[5],c[5],d[5];
  b=c=d=a;
  int ce=0;

  mapnames.assign(a, b, c,d, ce);

  if (/*timeprops_ptr->iter%50==4||*/timeprops_ptr->iter==1){
    int tt=timeprops_ptr->iter;
    //for(int ii=0;ii<1000;ii++){

      initialization( NodeTable, El_Table, dt, matprops_ptr,fluxprops, timeprops_ptr);
      meshplotter(El_Table, NodeTable,matprops_ptr,timeprops_ptr,&mapnames,ce);
      //timeprops_ptr->iter++;
      //}
      //timeprops_ptr->iter=tt;
  }


  /*
   * corrector step and b.c.s
   */

  //for comparison of magnitudes of forces in slumping piles
  double forceint=0.0, elemforceint;
  double forcebed=0.0, elemforcebed;
  double eroded=0.0, elemeroded;
  double deposited=0.0, elemdeposited;
  double realvolume=0.0;



  for(i=0; i<El_Table->get_no_of_buckets(); i++)
    if(*(buck+i))
      {
	HashEntryPtr currentPtr = *(buck+i);
	while(currentPtr)
	  {
	    Element* Curr_El=(Element*)(currentPtr->value);
	    if(Curr_El->get_adapted_flag()>0) { //if this is a refined element don't involve!!!

	      double *dxy=Curr_El->get_dx();
	      // if calculations are first-order, predict is never called
	      // ... so we need to update prev_states
	      // double phi=*(Curr_El->get_state_vars())+*(Curr_El->get_state_vars()+4);

	      if ( *order_flag == 1 )
		Curr_El->update_prev_state_vars();

	      void *Curr_El_out= (void *) Curr_El;

	      correct(NodeTable, El_Table, dt, matprops_ptr,
		      fluxprops, timeprops_ptr,
		      Curr_El_out,
		      &elemforceint,&elemforcebed,
		      &elemeroded,&elemdeposited);

	      for(int kk=0;kk<6;kk++) 
		if (isnan(*(Curr_El->get_state_vars()+kk)))
		  printf("Hello this is the NAN");
	      forceint+=fabs(elemforceint);
	      forcebed+=fabs(elemforcebed);
	      realvolume+=dxy[0]*dxy[1]**(Curr_El->get_state_vars()+1);
	      eroded+=elemeroded;
	      deposited+=elemdeposited;

	      double *coord=Curr_El->get_coord();	      
	      //update the record of maximum pileheight in the area covered by this element
	      double hheight=*(Curr_El->get_state_vars()+1);
	      if(hheight>0 && hheight<0);


#ifdef MAX_DEPTH_MAP
	      double pfheight[6];
	      outline_ptr->update(coord[0]-0.5*dxy[0],coord[0]+0.5*dxy[0],
				  coord[1]-0.5*dxy[1],coord[1]+0.5*dxy[1],
				  hheight,pfheight);      
#endif

#ifdef APPLY_BC
	      for(j=0;j<4;j++)
		if(*(Curr_El->get_neigh_proc()+j) == INIT)   // this is a boundary!
		  for(k=1;k<NUM_STATE_VARS;k++)
		    *(Curr_El->get_state_vars()+k) = 0;
#endif
	    }
	    currentPtr=currentPtr->next;      	    
	  }
      }

//  for(i=0; i<El_Table->get_no_of_buckets(); i++) {
//    if(*(buck+i))
//      {
//  	HashEntryPtr currentPtr = *(buck+i);
//  	while(currentPtr)
//  	  {
//  	    Element* Curr_El=(Element*)(currentPtr->value);
//  	    if(Curr_El->get_adapted_flag()>0
//	       )//&& ((timeprops_ptr->iter%5==4)))//||(timeprops_ptr->iter%5==2)))
//  	      { //if this is a refined element don't involve!!!
//  		//if (*(Curr_El->get_state_vars()+1)>1e-3)
//		//{					
//		phi = *(Curr_El->get_state_vars());
//		if(phi>1) phi=1;
//		if(phi<0) phi=0;
		//}
  		//else 
		//phi=0;
	//	*(Curr_El->get_state_vars())=phi;
		//  		Curr_El->update_phase1(phi);
//  	      } 
//  	    currentPtr=currentPtr->next;      	    
//  	  }
//      }
//  }

  //update the orientation of the "dryline" (divides partially wetted cells
  //into wet and dry parts solely based on which neighbors currently have 
  //pileheight greater than GEOFLOW_TINY
  //for(i=0; i<El_Table->get_no_of_buckets(); i++) 
  // {
  //     HashEntryPtr currentPtr = *(buck+i);
  //    while(currentPtr) 
//	{
//	  Element* Curr_El=(Element*)(currentPtr->value);
//	  currentPtr=currentPtr->next;      	    
//	  if(Curr_El->get_adapted_flag()>0) //if this is a refined element don't involve!!!
//	    Curr_El->calc_wet_dry_orient(El_Table);
//	}
  //  }

  /* finished corrector step */
  calc_stats(El_Table, NodeTable, myid, matprops_ptr, timeprops_ptr, 
	     statprops_ptr, discharge, dt);

  double tempin[6], tempout[6];
  tempin[0]=outflow;    //volume that flew out the boundaries this iteration
  tempin[1]=eroded;     //volume that was eroded this iteration
  tempin[2]=deposited;  //volume that is currently deposited
  tempin[3]=realvolume; //"actual" volume within boundaries
  tempin[4]=forceint;   //internal friction force
  tempin[5]=forcebed;   //bed friction force

  MPI_Reduce(tempin,tempout,6,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);

  statprops_ptr->outflowvol+=tempout[0]*(matprops_ptr->HEIGHT_SCALE)*
    (matprops_ptr->LENGTH_SCALE)*(matprops_ptr->LENGTH_SCALE);
  statprops_ptr->erodedvol+=tempout[1]*(matprops_ptr->HEIGHT_SCALE)*
    (matprops_ptr->LENGTH_SCALE)*(matprops_ptr->LENGTH_SCALE);
  statprops_ptr->depositedvol=tempout[2]*(matprops_ptr->HEIGHT_SCALE)*
    (matprops_ptr->LENGTH_SCALE)*(matprops_ptr->LENGTH_SCALE);
  statprops_ptr->realvolume=tempout[3]*(matprops_ptr->HEIGHT_SCALE)*
    (matprops_ptr->LENGTH_SCALE)*(matprops_ptr->LENGTH_SCALE);

  statprops_ptr->forceint=tempout[4]/tempout[3]*matprops_ptr->GRAVITY_SCALE;
  statprops_ptr->forcebed=tempout[5]/tempout[3]*matprops_ptr->GRAVITY_SCALE;

  return;
}
Beispiel #8
0
void init_piles(HashTable* HT_Elem_Ptr, HashTable* HT_Node_Ptr, 
		int myid, int numprocs, int adaptflag,
		MatProps* matprops, TimeProps* timeprops_ptr, 
		MapNames* mapnames, PileProps* pileprops, 
		FluxProps *fluxprops, StatProps* statprops) { 

	unsigned nodes[9][KEYLENGTH], *node_key;
	int num_buckets=HT_Elem_Ptr->get_no_of_buckets();

	if(!adaptflag)
		H_adapt_to_level(HT_Elem_Ptr,HT_Node_Ptr,matprops,pileprops,
				fluxprops,timeprops_ptr,REFINE_LEVEL);
#if defined PARABALOID || defined CYLINDER 
	if(adaptflag)
		initial_H_adapt(HT_Elem_Ptr, HT_Node_Ptr, 0, matprops, 
				pileprops,fluxprops,timeprops_ptr,4); 
#else
	for(int ibucket=0; ibucket<num_buckets; ibucket++)
	{
		HashEntry *entryp = *(HT_Elem_Ptr->getbucketptr() + ibucket);
		//check every element in bucket
		while(entryp){	
			Element *EmTemp = (Element*)entryp->value;
			assert(EmTemp);
			if(EmTemp->get_adapted_flag()>0)
			{
				//put in the pile height right here...
				double* ndcoord = EmTemp->get_coord();
				double pile_height=0.0;
				double radius_sq;
				EmTemp->put_height(pileheight);
			} 
			entryp = entryp->next;
		}
	}
#endif //end "#if defined PARABALOID || defined CYLINDER"


	move_data(numprocs, myid, HT_Elem_Ptr, HT_Node_Ptr,timeprops_ptr);
	slopes(HT_Elem_Ptr, HT_Node_Ptr, matprops);

	/* initial calculation of actual volume on the map */

	double realvolume=0.0, depositedvol=0.0, forcebed=0.0, meanslope=0.0;
	double epsilon[2]={matprops->epsilon, matprops->epsilon};

	HashEntryPtr* buck = HT_Elem_Ptr->getbucketptr();
	for(int ibucket=0; ibucket<HT_Elem_Ptr->get_no_of_buckets(); ibucket++)
		if(*(buck+ibucket)) {

			HashEntryPtr currentPtr = *(buck+ibucket);
			while(currentPtr) {

				Element* Curr_El=(Element*)(currentPtr->value);
				assert(Curr_El);

				if(Curr_El->get_adapted_flag()>0) { //if this is a refined element don't involve!!!
					double *dxy=Curr_El->get_dx();
					double dvol=dxy[0]*dxy[1]**(Curr_El->get_state_vars()+1);
					realvolume+=dvol;

					Curr_El->put_kactxy(epsilon);
					Curr_El->calc_stop_crit(matprops);
					if (Curr_El->get_stoppedflags()==2)
						depositedvol += dvol;

					double resolution=0, xslope=0, yslope=0;
					Get_max_resolution(&resolution);
					Get_slope(resolution,
							*((Curr_El->get_coord()))*matprops->LENGTH_SCALE,
							*((Curr_El->get_coord())+1)*matprops->LENGTH_SCALE,
							&xslope,&yslope);
					double slope=sqrt(xslope*xslope+yslope*yslope); 

					forcebed+=dvol*9.8/sqrt(1.0+slope*slope)*
						tan(matprops->bedfrict[Curr_El->get_material()]);
Curr_El->level_set(HT_Elem_Ptr);

				}
				currentPtr=currentPtr->next;      	    
			}
		}

//=========================================================================================================================

 for(int ibucket=0; ibucket<HT_Elem_Ptr->get_no_of_buckets(); ibucket++)
                if(*(buck+ibucket)) {

                        HashEntryPtr currentPtr = *(buck+ibucket);
                        while(currentPtr) {

                                Element* Curr_El=(Element*)(currentPtr->value);
                                assert(Curr_El);

                                if(Curr_El->get_adapted_flag()>0) { 
if(*( Curr_El->get_state_vars()+5)==3) *(Curr_El->get_state_vars())=0.0;//to make zero phi on the boundary 
                                }
                                currentPtr=currentPtr->next;
                        }
                }

	double tempin[3], tempout[3];
	tempin[0]=realvolume;
	tempin[1]=forcebed;
	tempin[2]=depositedvol;

	MPI_Reduce(tempin,tempout,3,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);

	statprops->realvolume=tempout[0]*(matprops->HEIGHT_SCALE)
		*(matprops->LENGTH_SCALE)*(matprops->LENGTH_SCALE);
	statprops->outflowvol=0.0;
	statprops->erodedvol=0.0;
	statprops->depositedvol=tempout[2]*(matprops->HEIGHT_SCALE)
		*(matprops->LENGTH_SCALE)*(matprops->LENGTH_SCALE);

	statprops->forceint=0.0;
	statprops->forcebed=tempout[1]/tempout[0];
	return;
}