/* interpolate a quarter (half a window)
 *
 * ibuf buffer of ilen length is swept at rate speed.
 * result put in output buffer obuf of size olen.
 */
static void interpolation(
  pitch_t pitch,
  st_sample_t *ibuf, int ilen, 
  PITCH_FLOAT * out, int olen,
  PITCH_FLOAT rate) /* signed */
{
    register int i, size;
    register PITCH_FLOAT index;

    size = pitch->step; /* size == olen? */

    if (rate>0) /* sweep forwards */
    {
        for (index=ZERO, i=0; i<olen; i++, index+=rate)
        {
            register int ifl = (int) index; /* FLOOR */
            register PITCH_FLOAT frac = index - ifl;

            if (pitch->interopt==PITCH_INTERPOLE_LIN)
                out[i] = lin((PITCH_FLOAT) ibuf[ifl], 
                             (PITCH_FLOAT) ibuf[ifl+1],
                             frac);
            else
                out[i] = cub((PITCH_FLOAT) ibuf[ifl-1], 
                             (PITCH_FLOAT) ibuf[ifl], 
                             (PITCH_FLOAT) ibuf[ifl+1], 
                             (PITCH_FLOAT) ibuf[ifl+2],
                             frac);
        }
    }
    else /* rate < 0, sweep backwards */
    {
        for (index=ilen-1, i=olen-1; i>=0; i--, index+=rate)
        {
            register int ifl = (int) index; /* FLOOR */
            register PITCH_FLOAT frac = index - ifl;

            if (pitch->interopt==PITCH_INTERPOLE_LIN)
                out[i] = lin((PITCH_FLOAT) ibuf[ifl], 
                             (PITCH_FLOAT) ibuf[ifl+1],
                             frac);
            else
                out[i] = cub((PITCH_FLOAT) ibuf[ifl-1], 
                             (PITCH_FLOAT) ibuf[ifl], 
                             (PITCH_FLOAT) ibuf[ifl+1], 
                             (PITCH_FLOAT) ibuf[ifl+2],
                             frac);
        }
    }
}
示例#2
0
bool compare_files(std::string layout_file, std::string schematic_file) {
  std::ifstream sin(schematic_file.c_str());
  std::ifstream lin(layout_file.c_str());

  std::vector<layout_rectangle> rects;
  std::vector<layout_pin> pins;
  parse_layout(rects, pins, lin);

  schematic_database reference_schematic;
  parse_schematic_database(reference_schematic, sin);

  layout_database layout;
  populate_layout_database(layout, rects);

  connectivity_database connectivity;
  populate_connectivity_database(connectivity, pins, layout);

  schematic_database schematic;
  std::vector<device>& devices = schematic.devices;
  for(std::size_t i = 0; i < pins.size(); ++i) {
    devices.push_back(device());
    devices.back().type = "PIN";
    devices.back().terminals.push_back(pins[i].net);
  }
  extract_devices(devices, connectivity, layout);
  extract_netlist(schematic.nets, devices);

  return compare_schematics(reference_schematic, schematic);
}
rndf::PerimeterPoint* REPerimeterPoint::create(rndf::Perimeter* p, double utm_x, double utm_y, const string& utm_zone) {
  if (!p) {return NULL;}

  unsigned int index;

  if (elem_) {
    if (elem_->perimeter() == p) {
      if (elem_->index() < p->numPerimeterPoints() - 1) {
        rndf::PerimeterPoint* p1 = p->perimeterPoint(elem_->index());
        rndf::PerimeterPoint* p2 = p->perimeterPoint(elem_->index() + 1);
        Line_2 lin(Point_2(p1->utmX(), p1->utmY()), Point_2(p2->utmX(), p2->utmY()));
        Point_2 p = lin.projection(Point_2(utm_x, utm_y));
        utm_x = p.x();
        utm_y = p.y();
      }
    }

    index = elem_->index() + 1;
  }
  else {
    index = p->numPerimeterPoints();
  }

  double lat, lon;
  utmToLatLong(utm_x, utm_y, utm_zone, &lat, &lon);
  elem_ = rn_->addPerimeterPoint(p, lat, lon, index);

  return elem_;
}
示例#4
0
int main(){
	int n,choose;

	while(1){
    scanf("%d %d",&choose,&n);
	switch(choose){
    case 0:return;

    case 1:
        lin(n);
        break;
    case 2:
        even(n+1);
        break;
    case 3:
        odd(n);
        break;
    default: printf("error");
	}
	}




return;
}
示例#5
0
文件: psycho.cpp 项目: cutun/kazoo
History & History::get (Vector<float> & past)
{
  ASSERT_SIZE(past, size_out());

  past.zero();
  m_spline_weights.zero();

  for (Frame * f = m_frames; f; f = f->next) {
    float i = log_time(f->time);

    LinearInterpolate lin(i, m_length);
    m_spline_weights[lin.i0] += lin.w0;
    m_spline_weights[lin.i1] += lin.w1;

    float scale = 1.0 / f->num_terms();
    Vector<float> past0 = past.block(m_size, lin.i0);
    Vector<float> past1 = past.block(m_size, lin.i1);
    if (lin.w0 > 0) multiply_add(lin.w0 * scale, f->data, past0);
    if (lin.w1 > 0) multiply_add(lin.w1 * scale, f->data, past1);
  }

  for (size_t i = 0; i < m_length; ++i) {
    Vector<float> past_i = past.block(m_size, i);
    if (m_spline_weights[i] > 0) {
      float normalize_factor = 1.0 / m_spline_weights[i];
      LOG1("normalize_factor = " << normalize_factor);
      for (size_t j = 0; j < m_size; ++j) {
        past_i[j] *= normalize_factor;
      }
    }
  }

  return * this;
}
示例#6
0
void FGFDMExec::DoLinearization(int mode)
{
  double saved_time;
  if (Constructing) return;
  saved_time = sim_time;
  FGLinearization lin(this,mode);
  Setsim_time(saved_time);
}
示例#7
0
void tet_basis::proj2d_bdry(FLT *lin1, FLT *f1, int stride) {
	Array<FLT,2> wk0(gpy,3+em);
   const int be2 = em+3, be3 = 2*em+3;
   const int lgpx = gpx, lgpy = gpy, lnmodx = nmodx;  
   int sign;
   FLT lcl0;
#ifdef BZ_DEBUG
   Array<FLT,1> lin(lin1, shape(3+3*em+fm), neverDeleteData);
   Array<FLT,2> f(f1, shape(gpx,stride), neverDeleteData);
#endif

   /* DETERMINE U VALUES, GRAD U VALUES
      AT COLLOCATION POINTS
      SUM HAT(U) FOR DU/DX AND DU/DY
   */

   /* PART I - sum u*g_mn for each n, s_j   */
  	for(int j = 0; j < lgpy; ++j ) {
     
		/* VERTEX 1 */
		wk0(j,0) = lin(0)*gy(j,1);

		/* VERTEX 2, EDGE 3 */
		sign = 1;
		lcl0 = lin(1)*gy(j,2);
		for(int i = 0; i < em; ++i){
			lcl0 += sign*lin(be3+i)*gy(j,3+em+i);	
			sign*=-1;
		}
		wk0(j,1) = lcl0;

		/* VERTEX 3, EDGE 2 */
		lcl0 = lin(2)*gy(j,2);
		for(int i = 0; i < em; ++i){
			lcl0 += lin(be2+i)*gy(j,3+em+i);
		}
		wk0(j,2) = lcl0;
		
		/* EDGE 1 */		
		for(int p = 3; p < em+3; ++p){
			wk0(j,p)=lin(p)*gy(j,p);	
	
		}
	}		
		
	/* SUM OVER N AT EACH I,J POINT   */  
	for (int i = 0; i < lgpx; ++i ) {
		for (int j = 0; j < lgpy; ++j) {
			lcl0 = wk0(j,0)*gx(i,0);
			for(int n = 1; n < lnmodx; ++n ) {     
				lcl0 += wk0(j,n)*gx(i,n);
			}
			f(i,j)  = lcl0;
		}
	}
	
   return;
}
示例#8
0
void tet_basis::proj2d_bdry_leg(FLT *lin1, FLT *f1, int stride) {
   const int ltm = 3+3*em;
   FLT lcl0;
#ifdef BZ_DEBUG
   Array<FLT,1> lin(lin1, shape(3+3*em+fm), neverDeleteData);
   Array<FLT,2> f(f1, shape(gpx,stride), neverDeleteData);
#endif
   
   /* INTERIOR */
	for(int i = 1; i < em; ++i) {
		for(int j = 1; j < em+1-i; ++j) {	
			lcl0 = 0.0;
			for(int m = 0; m < ltm; ++m)
				lcl0 += lin(m)*lgrnge2d(m,i,j);
			f(i,j) = lcl0;
		}
	}
   
   return;
}
示例#9
0
 Real value( const ROL::Vector<Real> &x, Real &tol ) {
   Teuchos::RCP<const std::vector<Real> > ex
     = Teuchos::dyn_cast<const ROL::StdVector<Real> >(x).getVector();
   Real quad(0), lin(0);
   std::vector<Real> p = ROL::ParametrizedObjective<Real>::getParameter();
   unsigned size = static_cast<unsigned>(ex->size());
   for ( unsigned i = 0; i < size; i++ ) {
     quad += (*ex)[i]*(*ex)[i]; 
     lin  += (*ex)[i]*p[i+1];
   }
   return std::exp(p[0])*quad + lin + p[size+1];
 }
示例#10
0
文件: PolyDlg.cpp 项目: pvaut/Z-Flux
Vector3D CPolyDlg::GetCnrVector( CString cnrstr )
{
	//Extract 3D coordinates from vertex string.  String is assumed to be:
	//	"[cnrnum] [v.x] [v.y] [v.z] R G B"

	istrstream lin( cnrstr.GetBuffer( cnrstr.GetLength() ) ) ;

	//extract & discard corner number if necessary
	if( GetNumTokens( cnrstr ) > 6 )
	{
		int cnrnum ;
		lin >> cnrnum ;
	}
示例#11
0
void		clean_space(char *str)
{
	int	i;
	int	y;

	y = -1;
	while (str[++y])
		if (str[y] == SEPARATOR_CHAR)
		{
			i = y;
			while (--i >= 0 && (str[i] == ' '
				|| str[i] == '	' || str[i] == SEPARATOR_CHAR))
				if (str[i] == SEPARATOR_CHAR)
					error_exit(ft_strjoin("Syntax Error, Bad separator on line:"
						, ft_itoa(lin(1))), EINVAL);
				else
					str[i] = SEPARATOR_CHAR;
			clean_space2(str, &y);
			if (!str[i])
				error_exit(ft_strjoin("Syntax Error, Bad separator on line:"
					, ft_itoa(lin(1))), EINVAL);
		}
}
示例#12
0
static void	clean_space2(char *str, int *y)
{
	int	i;

	i = *y;
	while (str[++i] && (str[i] == ' '
		|| str[i] == '	' || str[i] == SEPARATOR_CHAR))
		if (str[i] == SEPARATOR_CHAR)
			error_exit(ft_strjoin("Syntax Error, Bad separator on line:"
				, ft_itoa(lin(1))), EINVAL);
		else
			str[i] = SEPARATOR_CHAR;
	*y = i;
}
示例#13
0
文件: Test_all.cpp 项目: eriser/CSL
void test_panning_sin() {
	Sine vox(330);
	MulOp mul(vox, 0.2);
	LineSegment lin(6, -1, 1);		// L-to-R sweep over 6 sec
	Panner pan(mul, lin);
	logMsg("playing panning sin 1...");
	run_test(pan, 6.0);
	logMsg("panning sin done.");
	Sine pos(0.5);			// LFO panning
	Panner pan2(mul, pos);
	logMsg("playing panning sin 2...");
	run_test(pan2, 5.0);
	logMsg("panning sin done.");
}
示例#14
0
文件: flock.cpp 项目: cutun/kazoo
void TempoFlockViewer::plot_beat ()
{
  const size_t I = synth().size();
  const size_t X = Rectangle::width();
  const size_t Y = Rectangle::height();

  const float * restrict mass = synth().get_mass();
  const float * restrict phase_x = synth().get_phase_x();
  const float * restrict phase_y = synth().get_phase_y();

  const complex r_part = exp_2_pi_i(0 / 3.0f);
  const complex g_part = exp_2_pi_i(1 / 3.0f);
  const complex b_part = exp_2_pi_i(2 / 3.0f);

  float * restrict red = m_image.red;
  float * restrict green = m_image.green;
  float * restrict blue = m_image.blue;

  //const float * restrict acuity = synth().get_acuity();
  //const float acuity1 = synth().max_acuity();
  const float * restrict duration = synth().get_duration();
  const float duration0 = synth().min_duration();

  if (m_image_mutex.try_lock()) {
    if (m_rhythm_mutex.try_lock()) {

      for (size_t i = 0; i < I; ++i) {
        complex phase(phase_x[i], phase_y[i]);

        float x = wrap(arg(phase) / (2 * M_PI) + 0.5f);
        //float y = synth().acuity_cdf(acuity[i], acuity1);
        float y = synth().duration_cdf(duration[i], duration0);

        float m = min(mass[i], 1.0f);
        float r = m;
        float g = sqr(m);
        float b = 1;

        BilinearInterpolate lin(x * X, X, y * Y, Y);

        lin.imax(red, r);
        lin.imax(green, g);
        lin.imax(blue, b);
      }
      m_rhythm_mutex.unlock();
    }
    m_image_mutex.unlock();
  }
}
示例#15
0
文件: Axis.cpp 项目: PerryZh/idyntree
    SpatialAcc Axis::getRotationSpatialAcc(const double d2theta) const
    {
        SpatialAcc ret;

        Eigen::Map<Eigen::Vector3d> lin(ret.getLinearVec3().data());
        Eigen::Map<Eigen::Vector3d> ang(ret.getAngularVec3().data());

        Eigen::Map<const Eigen::Vector3d> dir(direction.data());
        Eigen::Map<const Eigen::Vector3d> orig(origin.data());

        lin = d2theta*(orig.cross(dir));
        ang = dir*d2theta;

        return ret;
    }
示例#16
0
int main() {
  // for a simple second test
  // let's just output in a csv our kernels over 2D surfaces
  CovMat<2> eye;
  eye << 1, 0, 
    0, 1;
  
  FeatVec<2> mean;
  mean << 2, 2;

  const std::vector<double> std_params = {1.0, 1.0, 1.0};
  const std::vector<double> lin_params = {-2.0, 1.0, 1.0};
  
  KernExpression<2> se(se_generator<2>(std_params), mean, eye);
  KernExpression<2> per(per_generator<2>(std_params), mean, eye);
  KernExpression<2> lin(lin_generator<2>(lin_params), mean, eye);
  KernExpression<2> rq(rq_generator<2>(std_params), mean, eye);
  
  auto& se_x_per = se * per;
  auto& se_x_lin = se * lin;
  auto& per_x_lin = per * lin;
  auto& per_p_lin = per + lin;
  auto& se_p_per = se + per;

  std::ofstream se_dump("../../data-plots/se.csv");
  std::ofstream per_dump("../../data-plots/per.csv");
  std::ofstream lin_dump("../../data-plots/lin.csv");
  std::ofstream rq_dump("../../data-plots/rq.csv");
  std::ofstream se_x_per_dump("../../data-plots/se_x_per.csv");
  std::ofstream se_x_lin_dump("../../data-plots/se_x_lin.csv");
  std::ofstream per_x_lin_dump("../../data-plots/per_x_lin.csv");
  std::ofstream per_p_lin_dump("../../data-plots/per_p_lin.csv");
  std::ofstream se_p_per_dump("../../data-plots/se_p_per.csv");

    
  test_2d_expression(se, se_dump, 100, 4);
  test_2d_expression(per, per_dump, 100, 4);
  test_2d_expression(lin, lin_dump, 100, 4);
  test_2d_expression(rq, rq_dump, 100, 4);
  test_2d_expression(se_x_per, se_x_per_dump, 100, 4);
  test_2d_expression(se_x_lin, se_x_lin_dump, 100, 4);
  test_2d_expression(se_p_per, se_p_per_dump, 100, 4);
  test_2d_expression(per_x_lin, per_x_lin_dump, 100, 4);
  test_2d_expression(per_p_lin, per_p_lin_dump, 100, 4);

  return 0;
}
示例#17
0
int main() { 
	size_t sizeRows = 0;
	size_t sizeColumns = 0; 
	std::vector<float> inputMatrix; 
	std::vector<float> inputVector; 
	std::vector<float> answer; 

	readLinearEquations(inputMatrix, inputVector, sizeRows, sizeColumns);  	
 
	Matrix a(inputMatrix, sizeRows, sizeColumns);
	LinearVector b(inputVector);
	SystemLinearEquations lin(a, b);
	lin.JacodMethod();
	answer = lin.getAnswer();

	printAnswer(answer);
} 
示例#18
0
文件: F2xqE.c 项目: jkeuffer/pari
static GEN
gen_Z2x_Dixon(GEN F, GEN V, long N, void *E, GEN lin(void *E, GEN F, GEN d, long N), GEN invl(void *E, GEN d))
{
  pari_sp av = avma;
  long N2, M;
  GEN VN2, V2, VM, bil;
  ulong q = 1UL<<N;
  if (N == 1) return invl(E, V);
  V = Flx_red(V, q);
  N2 = (N + 1)>>1; M = N - N2;
  F = FlxT_red(F, q);
  VN2 = gen_Z2x_Dixon(F, V, N2, E, lin, invl);
  bil = lin(E, F, VN2, N);
  V2 = Z2x_rshift(Flx_sub(V, bil, q), N2);
  VM = gen_Z2x_Dixon(F, V2, M, E, lin, invl);
  return gerepileupto(av, Flx_add(VN2, Flx_Fl_mul(VM, 1UL<<N2, q), q));
}
示例#19
0
int main()
{
    Segment_2 seg(Point_2(0,0), Point_2(1,1));
    Line_2 lin(1,-1,0);

    // with C++11 support
    // auto result = intersection(seg, lin);
    // without C++11
    CGAL::cpp11::result_of<Intersect_2(Segment_2, Line_2)>::type
    result = intersection(seg, lin);
    if (result) {
        boost::apply_visitor(Intersection_visitor(), *result);
    } else {
        // no intersection
    }

    return 0;
}
示例#20
0
文件: flock.cpp 项目: cutun/kazoo
void PitchFlockViewer::plot_bend ()
{
  const size_t I = synth().size;
  const size_t X = Rectangle::width();
  const size_t Y = Rectangle::height();

  const float * restrict power = get_power();
  const float * restrict energy = get_energy();
  const float * restrict bend = synth().get_bend();
  float * restrict red = m_bend_image.red;
  float * restrict green = m_bend_image.green;
  float * restrict blue = m_bend_image.blue;

  float energy_gain = m_energy_gain.update(max(get_energy()));
  float power_gain = m_power_gain.update(max(get_power()));
  float bend_variance = norm_squared(synth().get_bend()) / I;
  float bend_gain = m_bend_gain.update(bend_variance);
  float min_freq = min(synth().get_freq());
  float max_freq = max(synth().get_freq());
  float pitch_scale = 1 / log(max_freq / min_freq);

  if (m_image_mutex.try_lock()) {

    for (size_t i = 0; i < I; ++i) {

      float m = energy_gain * energy[i];
      float e = power_gain * power[i];

      float b = atanf(0.5f * bend_gain * bend[i]) / M_PI + 0.5f;
      float p = static_cast<float>(i) / I + pitch_scale * log(1 + bend[i]);

      BilinearInterpolate lin(b * X, X, p * Y, Y);

      lin.imax(red, e);
      lin.imax(green, m);
      lin.imax(blue, 1);
    }

    m_image_mutex.unlock();
  }
}
示例#21
0
文件: F2xqE.c 项目: jkeuffer/pari
static GEN
gen_Z2X_Dixon(GEN F, GEN V, long N, void *E,
                     GEN lin(void *E, GEN F, GEN d, long N),
                     GEN lins(void *E, GEN F, GEN d, long N),
                     GEN invls(void *E, GEN d))
{
  pari_sp av = avma;
  long n, m;
  GEN Xn, Xm, FXn, Vm;
  if (N<BITS_IN_LONG)
  {
    ulong q = 1UL<<N;
    return Flx_to_ZX(gen_Z2x_Dixon(ZXT_to_FlxT(F,q), ZX_to_Flx(V,q),N,E,lins,invls));
  }
  V = ZX_remi2n(V, N);
  n = (N + 1)>>1; m = N - n;
  F = ZXT_remi2n(F, N);
  Xn = gen_Z2X_Dixon(F, V, n, E, lin, lins, invls);
  FXn = lin(E, F, Xn, N);
  Vm = ZX_shifti(ZX_sub(V, FXn), -n);
  Xm = gen_Z2X_Dixon(F, Vm, m, E, lin, lins, invls);
  return gerepileupto(av, ZX_remi2n(ZX_add(Xn, ZX_shifti(Xm, n)), N));
}
示例#22
0
文件: flock.cpp 项目: cutun/kazoo
void PitchFlockViewer::plot_pca_4d ()
{
  float timescale = FLOCK_PCA_TIMESCALE_SEC * DEFAULT_AUDIO_FRAMERATE;
  float dt = 1 / timescale;

  m_pca.add_sample(synth().get_beat(), dt);

  const size_t I = synth().size;
  const size_t X = Rectangle::width();
  const size_t Y = Rectangle::height();

  float * restrict select_x = m_select_x;
  float * restrict select_y = m_select_y1;

  float pca_gain = sqrtf(I) / 8;
  const float * restrict energy = get_energy();
  const float * restrict pca_w = m_pca.component(0);
  const float * restrict pca_x = m_pca.component(1);
  const float * restrict pca_y = m_pca.component(2);
  const float * restrict pca_z = m_pca.component(3);
  const float * restrict pca_u = m_pca.component(4);
  const float * restrict pca_v = m_pca.component(5);

  const float ru = 1.0f;
  const float bu = cos(2 * M_PI / 3);
  const float bv = sin(2 * M_PI / 3);
  const float gu = cos(-2 * M_PI / 3);
  const float gv = sin(-2 * M_PI / 3);

  float * restrict energy_image = m_energy_image;
  float * restrict red = m_pca_image.red;
  float * restrict green = m_pca_image.green;
  float * restrict blue = m_pca_image.blue;

  const LinAlg::Orientation4D angle = m_angle4;

  if (m_image_mutex.try_lock()) {

    for (size_t i = 0; i < I; ++i) {
      float m = energy[i];
      float wxyz[4] = {pca_w[i], pca_x[i], pca_y[i], pca_z[i]};
      float u = pca_u[i] * pca_gain;
      float v = pca_v[i] * pca_gain;

      float uv_scale = 1 / (1 + sqrt(max(1e-20f, sqr(u) + sqr(v))));
      u *= uv_scale;
      v *= uv_scale;

      float r = sqr((1 + ru * u) / 2);
      float g = sqr((1 + gu * u + gv * v) / 2);
      float b = sqr((1 + bu * u + bv * v) / 2);

      float x = pca_gain * angle.coord_dot(0, wxyz);
      float y = pca_gain * angle.coord_dot(1, wxyz);

      float x_01 = select_x[i] = (1 + x) / 2;
      float y_01 = select_y[i] = (1 + y) / 2;

      BilinearInterpolate lin(x_01 * X, X, y_01 * Y, Y);
      lin.imax(energy_image, m);
      lin.imax(red, r);
      lin.imax(green, g);
      lin.imax(blue, b);
    }

    m_image_mutex.unlock();
  }
}
示例#23
0
文件: flock.cpp 项目: cutun/kazoo
void PitchFlockViewer::plot_pca_freq ()
{
  float timescale = FLOCK_PCA_TIMESCALE_SEC * DEFAULT_AUDIO_FRAMERATE;
  float dt = 1 / timescale;

  m_pca.add_sample(synth().get_beat(), dt);

  const size_t I = synth().size;
  const size_t X = Rectangle::width();
  const size_t Y = Rectangle::height();

  float * restrict select_x = m_select_x;
  float * restrict select_y1 = m_select_y1;
  float * restrict select_y2 = m_select_y2;

  float pca_gain = sqrtf(I) / 8;
  float dx_gain = sqrtf(I) / synth().num_tones();
  const float * restrict energy = get_energy();
  const float * restrict pca_y = m_pca.component(0);
  const float * restrict pca_z = m_pca.component(1);
  const float * restrict pca_u = m_pca.component(2);
  const float * restrict pca_v = m_pca.component(3);
  const float * restrict pca_dx = m_pca.component(4);

  const float ru = 1.0f;
  const float bu = cos(2 * M_PI / 3);
  const float bv = sin(2 * M_PI / 3);
  const float gu = cos(-2 * M_PI / 3);
  const float gv = sin(-2 * M_PI / 3);

  float * restrict energy_image = m_energy_image;
  float * restrict red = m_pca_image.red;
  float * restrict green = m_pca_image.green;
  float * restrict blue = m_pca_image.blue;

  const LinAlg::Orientation3D angle = m_angle3;
  const float skew = 1.0f / 20;

  if (m_image_mutex.try_lock()) {

    for (size_t i = 0; i < I; ++i) {
      float m = energy[i];
      float xyz[3] = {
        1 - (i + 0.5f) / I * 2 + pca_dx[i] * dx_gain,
        pca_y[i] * pca_gain,
        pca_z[i] * pca_gain
      };
      float u = pca_u[i] * pca_gain;
      float v = pca_v[i] * pca_gain;

      float uv_scale = 1 / (1 + sqrt(max(1e-20f, sqr(u) + sqr(v))));
      u *= uv_scale;
      v *= uv_scale;

      float r = sqr((1 + ru * u) / 2);
      float g = sqr((1 + gu * u + gv * v) / 2);
      float b = sqr((1 + bu * u + bv * v) / 2);

      float x = angle.coord_dot(0, xyz);
      float y = angle.coord_dot(1, xyz);
      float z = angle.coord_dot(2, xyz);

      float y1 = y - skew * z;
      float y2 = y + skew * z;

      float x_01 = select_x[i] = (1 + x) / 2;
      float y1_01 = select_y1[i] = (1 + y1) / 4;
      float y2_01 = select_y2[i] = (1 + y2 + 2) / 4;

      BilinearInterpolate lin(x_01 * X, X, y1_01 * Y, Y);
      lin.imax(energy_image, m);
      lin.imax(red, r);
      lin.imax(green, g);
      lin.imax(blue, b);

      lin.y(y2_01 * Y, Y);
      lin.imax(energy_image, m);
      lin.imax(red, r);
      lin.imax(green, g);
      lin.imax(blue, b);
    }

    m_image_mutex.unlock();
  }
}
示例#24
0
文件: flock.cpp 项目: cutun/kazoo
void FlockViewer::plot_pitch ()
{
  const size_t I = harmony().size;
  const size_t X = Rectangle::width();
  const size_t Y = Rectangle::height();

  const float * restrict selection = m_selection;

  float pca_gain = sqrtf(I) / 8;
  const float * restrict pca_x = m_pca.component(0);
  const float * restrict pca_y = m_pca.component(1);
  const float * restrict pca_z = m_pca.component(2);
  const float * restrict pca_u = m_pca.component(3);
  const float * restrict pca_v = m_pca.component(4);

  const float ru = 1.0f;
  const float bu = cos(2 * M_PI / 3);
  const float bv = sin(2 * M_PI / 3);
  const float gu = cos(-2 * M_PI / 3);
  const float gv = sin(-2 * M_PI / 3);

  float * restrict red = m_image.red;
  float * restrict green = m_image.green;
  float * restrict blue = m_image.blue;
  float * restrict select_x = m_select_x;
  float * restrict select_y = m_select_y;

  const LinAlg::Orientation3D angle = m_angle3;

  if (m_image_mutex.try_lock()) {

    for (size_t i = 0; i < I; ++i) {
      float xyz[3] = {
        pca_x[i] * pca_gain,
        pca_y[i] * pca_gain,
        pca_z[i] * pca_gain
      };
      float u = pca_u[i] * pca_gain;
      float v = pca_v[i] * pca_gain;

      float uv_scale = 1 / (1 + sqrt(max(1e-20f, sqr(u) + sqr(v))));
      u *= uv_scale;
      v *= uv_scale;

      float s = selection[i];
      float r = max(s, sqr((1 + ru * u) / 2));
      float g = max(s, sqr((1 + gu * u + gv * v) / 2));
      float b = max(s, sqr((1 + bu * u + bv * v) / 2));

      float x = angle.coord_dot(0, xyz);
      float y = angle.coord_dot(1, xyz);

      float x_01 = select_x[i] = (1 + x) / 2;
      float y_01 = select_y[i] = (1 + y) / 2;

      BilinearInterpolate lin(x_01 * X, X, y_01 * Y, Y);
      lin.imax(red, r);
      lin.imax(green, g);
      lin.imax(blue, b);
    }

    m_image_mutex.unlock();
  }
}
示例#25
0
文件: main.c 项目: DSG888/SibSUTIS
int main()
{
	lin();
	par();
	return 0;
}
/*----------------------------------------------------------------------*
 |  finalize construction of this interface                             |
 *----------------------------------------------------------------------*/
bool MOERTEL::Interface::Complete()
{ 
  if (IsComplete())
  {
    if (OutLevel()>0)
      std::cout << "MOERTEL: ***WRN*** MOERTEL::Interface::InterfaceComplete:\n"
           << "MOERTEL: ***WRN*** InterfaceComplete() was called before, do nothing\n"
           << "MOERTEL: ***WRN*** file/line: " << __FILE__ << "/" << __LINE__ << "\n";
    return true;
  }
  
  //-------------------------------------------------------------------
  // check for NULL entries in maps
  bool ok = true;
  for (int i=0; i<2; ++i)
  {
	std::map<int,Teuchos::RCP<MOERTEL::Node> >::const_iterator curr;
    for (curr=node_[i].begin(); curr!=node_[i].end(); ++curr)
    {
      if (curr->second == Teuchos::null)
      {
        std::cout << "***ERR*** MOERTEL::Interface::Complete:\n"
             << "***ERR*** Interface # " << Id_ << ":\n"
             << "***ERR*** found NULL entry in map of nodes\n"
             << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n";
        ok = false;
      }
    }
  }
  for (int i=0; i<2; ++i)
  {
	std::map<int,Teuchos::RCP<MOERTEL::Segment> >::const_iterator curr;
    for (curr=seg_[i].begin(); curr!=seg_[i].end(); ++curr)
    {
      if (curr->second == Teuchos::null)
      {
        std::cout << "***ERR*** MOERTEL::Interface::Complete:\n"
             << "***ERR*** Interface # " << Id_ << ":\n"
             << "***ERR*** found NULL entry in map of segments\n"
             << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n";
        ok = false;
      }
    }
  }
  int lok = ok;
  int gok = 1;
  gcomm_.MinAll(&lok,&gok,1);  
  if (!gok) return false;
  
  //-------------------------------------------------------------------
  // check whether all nodes for segments are present
  // (take in account that node might be on different processor)
  // this test is expensive and does not scale. It is therefore only performed
  // when user requests a high output level
#if 1
  if (OutLevel()>9)
  {
    for (int proc=0; proc<gcomm_.NumProc(); ++proc)
    {
      for (int side=0; side<2; ++side)
      {
        // create length of list of all nodes adjacent to segments on proc
        int sendsize =  0;
        if (proc==gcomm_.MyPID())
        {
		  std::map<int,Teuchos::RCP<MOERTEL::Segment> >::const_iterator curr;
          for (curr=seg_[side].begin(); curr!=seg_[side].end(); ++curr)
            sendsize += curr->second->Nnode();
        }
        gcomm_.Broadcast(&sendsize,1,proc);
        
        // create list of all nodes adjacent to segments on proc
		std::vector<int> ids(sendsize);
        if (proc==gcomm_.MyPID())
        {
		  std::map<int,Teuchos::RCP<MOERTEL::Segment> >::const_iterator curr;
          int counter=0;
          for (curr=seg_[side].begin(); curr!=seg_[side].end(); ++curr)
          {
            const int* segids = curr->second->NodeIds();
            for (int i=0; i<curr->second->Nnode(); ++i)
              ids[counter++] = segids[i];
          }
        }
        gcomm_.Broadcast(&ids[0],sendsize,proc);
        
        // check on all processors for nodes in ids
		std::vector<int> foundit(sendsize);
		std::vector<int> gfoundit(sendsize);
        for (int i=0; i<sendsize; ++i) 
        {
          foundit[i] = 0;
          if (node_[side].find(ids[i]) != node_[side].end()) 
            foundit[i] = 1;
        }
        gcomm_.MaxAll(&foundit[0],&gfoundit[0],sendsize);
        for (int i=0; i<sendsize; ++i)
        {
          if (gfoundit[i]!=1)
          {
            if (gcomm_.MyPID()==proc)
            std::cout << "***ERR*** MOERTEL::Interface::Complete:\n"
                 << "***ERR*** cannot find segment's node # " << ids[i] << "\n"
                 << "***ERR*** in map of all nodes on all procs\n"
                 << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n";
            ids.clear();
            foundit.clear();
            gfoundit.clear();
            gcomm_.Barrier();
            return false;
          }
        }
        
        // tidy up
        ids.clear();
        foundit.clear();
        gfoundit.clear();
      } // for (int size=0; side<2; ++side)
    } // for (int proc=0; proc<gcomm_.NumProc(); ++proc)
  }
#endif  
  //-------------------------------------------------------------------
  // find all procs that have business on this interface (own nodes/segments)
  // build a Epetra_comm that contains only those procs
  // this intra-communicator will be used to handle most stuff on this 
  // interface so the interface will not block all other procs
  {
#ifdef EPETRA_MPI
	std::vector<int> lin(gcomm_.NumProc());
	std::vector<int> gin(gcomm_.NumProc());
    for (int i=0; i<gcomm_.NumProc(); ++i) lin[i] = 0;
    
    // check ownership of any segments
    for (int i=0; i<2; ++i)
      if (seg_[i].size() != 0)
      {
        lin[gcomm_.MyPID()] = 1;
        break;
      }
    // check ownership of any nodes
    for (int i=0; i<2; ++i)
      if (node_[i].size() != 0)
      {
        lin[gcomm_.MyPID()] = 1;
        break;
      }
    gcomm_.MaxAll(&lin[0],&gin[0],gcomm_.NumProc());
    lin.clear();
    
    // typecast the Epetra_Comm to Epetra_MpiComm
    Epetra_MpiComm* epetrampicomm = dynamic_cast<Epetra_MpiComm*>(&gcomm_);
    if (!epetrampicomm)
    {
	  std::stringstream oss;
			oss << "***ERR*** MOERTEL::Interface::Complete:\n"
           << "***ERR*** Interface " << Id() << ": Epetra_Comm is not an Epetra_MpiComm\n"
           << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n";
      throw ReportError(oss);
    }

    // split the communicator into participating and none-participating procs
    int color;
    int key = gcomm_.MyPID();
    // I am taking part in the new comm if I have any ownership 
    if (gin[gcomm_.MyPID()]) 
      color = 0; 
    // I am not taking part in the new comm
    else                    
      color = MPI_UNDEFINED;
      
    // tidy up
    gin.clear();

    // create the local communicator   
    MPI_Comm  mpi_global_comm = epetrampicomm->GetMpiComm();
    MPI_Comm* mpi_local_comm  = new MPI_Comm();
    MPI_Comm_split(mpi_global_comm,color,key,mpi_local_comm);

    // create the new Epetra_MpiComm
    if (*mpi_local_comm == MPI_COMM_NULL)
      lcomm_ = Teuchos::null;
    else
      lcomm_ = Teuchos::rcp(new Epetra_MpiComm(*mpi_local_comm)); // FIXME: who destroys the MPI_Comm inside?

#if 0
    // test this stuff on the mpi level
    int grank,lrank;
    MPI_Comm_rank(mpi_global_comm,&grank);
    if (*mpi_local_comm != MPI_COMM_NULL)
      MPI_Comm_rank(*mpi_local_comm,&lrank);
    else
      lrank = -1;
    for (int proc=0; proc<gcomm_.NumProc(); ++proc)
    {
      if (proc==gcomm_.MyPID())
      std::cout << "using mpi    comms: I am global rank " << grank << " and local rank " << lrank << std::endl;
      gcomm_.Barrier();
    }
    // test this stuff on the epetra level
    if (lComm())
      for (int proc=0; proc<lcomm_->NumProc(); ++proc)
      {
        if (proc==lcomm_->MyPID())
        std::cout << "using epetra comms: I am global rank " << gcomm_.MyPID() << " and local rank " << lcomm_->MyPID() << std::endl;
        lcomm_->Barrier();
      }
    gcomm_.Barrier();
#endif


    
#else  // the easy serial case
    Epetra_SerialComm* serialcomm = dynamic_cast<Epetra_SerialComm*>(&gcomm_);
    if (!serialcomm)
    {
	  std::stringstream oss;
			oss << "***ERR*** MOERTEL::Interface::Complete:\n"
           << "***ERR*** Interface " << Id() << ": Epetra_Comm is not an Epetra_SerialComm\n"
           << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n";
      throw ReportError(oss);
    }
    lcomm_ = Teuchos::rcp(new Epetra_SerialComm(*serialcomm));
#endif // end of #ifdef PARALLEL    
  }
  
  //-------------------------------------------------------------------
  // create a map of all nodes to there PID (process id)
  if (lComm())
    for (int proc=0; proc<lcomm_->NumProc(); ++proc)
    {
      int lnnodes = 0;
      if (proc==lcomm_->MyPID())
        lnnodes = node_[0].size() + node_[1].size();
      lcomm_->Broadcast(&lnnodes,1,proc);
	  std::vector<int> ids(lnnodes);
      if (proc==lcomm_->MyPID())
      {
		std::map<int,Teuchos::RCP<MOERTEL::Node> >::const_iterator curr;
        int counter=0;
        for (int side=0; side<2; ++side)
          for (curr=node_[side].begin(); curr!=node_[side].end(); ++curr)
            ids[counter++] = curr->first;
      }
      lcomm_->Broadcast(&ids[0],lnnodes,proc);
      for (int i=0; i<lnnodes; ++i)
        nodePID_.insert(std::pair<int,int>(ids[i],proc));
      ids.clear();
    }
  
  //-------------------------------------------------------------------
  // create a map of all segments to there PID (process id)
  if (lComm())
    for (int proc=0; proc<lcomm_->NumProc(); ++proc)
    {
      int lnsegs = 0;
      if (proc==lcomm_->MyPID())
        lnsegs = seg_[0].size() + seg_[1].size();
      lcomm_->Broadcast(&lnsegs,1,proc);
	  std::vector<int> ids(lnsegs);
      if (proc==lcomm_->MyPID())
      {
		std::map<int,Teuchos::RCP<MOERTEL::Segment> >::const_iterator curr;
        int counter=0;
        for (int side=0; side<2; ++side)
          for (curr=seg_[side].begin(); curr!=seg_[side].end(); ++curr)
            ids[counter++] = curr->first;
      }
      lcomm_->Broadcast(&ids[0],lnsegs,proc);
      for (int i=0; i<lnsegs; ++i)
        segPID_.insert(std::pair<int,int>(ids[i],proc));
      ids.clear();
    }
  
  //-------------------------------------------------------------------
  // set isComplete_ flag
  // we set it here already as we will be using some methods that require it
  // from now on
  isComplete_ = true;
  
  //-------------------------------------------------------------------
  // make the nodes know there adjacent segments
  // find max number of nodes to a segment
  if (lComm())
  {
    int lmaxnnode = 0;
    int gmaxnnode = 0;
    for (int side=0; side<2; ++side)
    {
	  std::map<int,Teuchos::RCP<MOERTEL::Segment> >::const_iterator scurr;
      for (scurr=seg_[side].begin(); scurr!=seg_[side].end(); ++scurr)
        if (lmaxnnode < scurr->second->Nnode())
          lmaxnnode = scurr->second->Nnode();
    }
    lcomm_->MaxAll(&lmaxnnode,&gmaxnnode,1);
    
    // loop all procs and broadcast their adjacency
    for (int proc=0; proc<lcomm_->NumProc(); ++proc)
    {
      // local number of segments
      int lnseg = 0;
      if (proc==lcomm_->MyPID())
        lnseg = seg_[0].size() + seg_[1].size();
      lcomm_->Broadcast(&lnseg,1,proc);
      
      // allocate vector to hold adjacency
      int offset = gmaxnnode+2;
      int size   = lnseg*offset;
	  std::vector<int> adj(size);
      
      // proc fills adjacency vector adj and broadcasts
      if (proc==lcomm_->MyPID())
      {
        int count = 0;
        for (int side=0; side<2; ++side)
        {
		  std::map<int,Teuchos::RCP<MOERTEL::Segment> >::const_iterator scurr;
          for (scurr=seg_[side].begin(); scurr!=seg_[side].end(); ++scurr)
          {
			Teuchos::RCP<MOERTEL::Segment> seg = scurr->second;
            adj[count]   = seg->Id();
            adj[count+1] = seg->Nnode();
            const int* ids = seg->NodeIds();
            for (int i=0; i<seg->Nnode(); ++i)
              adj[count+2+i] = ids[i];
            count += offset;
          }
        }
      }
      lcomm_->Broadcast(&adj[0],size,proc);
      
      // all procs read adj and add segment to the nodes they own
      int count = 0;
      for (int i=0; i<lnseg; ++i)
      {
        int segid = adj[count];
        int nnode = adj[count+1];
        for (int j=0; j<nnode; ++j)
        {
          int nid = adj[count+2+j];
          if (lcomm_->MyPID() == NodePID(nid))
          {
            // I own this node, so set the segment segid in it
			Teuchos::RCP<MOERTEL::Node> node = GetNodeViewLocal(nid);
            if (node == Teuchos::null)
            {
				std::stringstream oss;
					oss << "***ERR*** MOERTEL::Interface::Complete:\n"
						<< "***ERR*** cannot find node " << nid << "\n"
                   << "***ERR*** in map of all nodes on this proc\n"
                   << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n";
				throw ReportError(oss);
            }
            node->AddSegment(segid);
          }
          else
            continue;
        }
        count += offset;
      }
      adj.clear();
    } // for (int proc=0; proc<lcomm_->NumProc(); ++proc)
  } // if (lComm())
  
  //-------------------------------------------------------------------
  // build redundant segments and nodes
  if (lComm())
  {
    int ok = 0;
    ok += RedundantSegments(0);  
    ok += RedundantSegments(1);  
    ok += RedundantNodes(0);
    ok += RedundantNodes(1);
    if (ok != 4)
    {
		std::stringstream oss;
			oss << "***ERR*** MOERTEL::Interface::Complete:\n"
           << "***ERR*** building of redundant information failed\n"
           << "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n";
		throw ReportError(oss);
    }
  }

  //-------------------------------------------------------------------
  // make topology segments <-> nodes for each side
  if (lComm())
    BuildNodeSegmentTopology(); 

  //-------------------------------------------------------------------
  // delete distributed nodes and segments
  for (int i=0; i<2; ++i)
  {
    seg_[i].clear();
    node_[i].clear();
  }


  //-------------------------------------------------------------------
  // we are done
  // note that there might not be any functions on the interface yet
  // they still have to be set
  
  return ok;
}
示例#27
0
double DeltaGibbs(int g,double *Delta,int Q,int G,const int *S,double c2,
		  const double *tau2R,const double *b,const double *r,
		  const double *sigma2,const double *phi,
		  const int *psi,const double *x,
		  const int *delta,const double *nu,Random &ran,int draw) {
  double pot = 0.0;

  //
  // compute prior covariance matrix
  //

  int dim = 0;
  std::vector<int> on(Q,0);
  int q;
  for (q = 0; q < Q; q++) {
    int kqg = qg2index(q,g,Q,G);
    if (delta[kqg] == 1) {
      on[q] = 1;
      dim++;
    }
  }

  if (dim > 0) {
    std::vector<std::vector<double> > var;
    makeSigma(g,G,var,on,Q,c2,tau2R,b,sigma2,r);

    //
    // define prior mean
    //

    std::vector<double> Mean(dim,0.0);
    std::vector<double> meanPrior(Mean);

    //
    // compute extra linear and quadratic terms
    //

    std::vector<double> mean(dim,0.0);

    std::vector<double> lin(dim,0.0);
    std::vector<double> quad(dim,0.0);
    int s;
    int k = 0;
    for (q = 0; q < Q; q++) {
      if (on[q] == 1) {
	int kqg = qg2index(q,g,Q,G);
	double var0 = sigma2[kqg] * phi[kqg];
	double var1 = sigma2[kqg] / phi[kqg];
	int s;
	for (s = 0; s < S[q]; s++)
	  {
	    int ksq = sq2index(s,q,S,Q);
	    double variance = psi[ksq] == 0 ? var0 : var1;
	    quad[k] += 1.0 / variance;
	    int xIndex = sqg2index(s,q,g,S,Q,G);
	    lin[k] += (2.0 * psi[ksq] - 1.0) * (x[xIndex] - nu[kqg]) / variance;
	  }
	k++;
      }
    }

    //
    // Update parameters based on available observations
    //

    std::vector<std::vector<double> > varInv;
    double detPrior = inverse(var,varInv);
    std::vector<std::vector<double> > covInvPrior(varInv);
    for (k = 0; k < dim; k++) {
      Mean[k] += lin[k];
      varInv[k][k] += quad[k];
    }
    double detPosterior = 1.0 / inverse(varInv,var);
    matrixMult(var,Mean,mean);

    //
    // Draw new values
    //

    std::vector<double> vv(dim,0.0);
    if (draw == 1)
      vv = ran.MultiGaussian(var,mean);
    else {
      k = 0;
      for (q = 0; q < Q; q++) {
	if (on[q] == 1) {
	  int kqg = qg2index(q,g,Q,G);
	  vv[k] = Delta[kqg];
	  k++;
	}
      }
    }

    pot += ran.PotentialMultiGaussian(var,mean,vv);

    if (draw == 1) {
      k = 0;
      for (q = 0; q < Q; q++) {
	if (on[q] == 1) {
	  int kqg = qg2index(q,g,Q,G);
	  Delta[kqg] = vv[k];
	  k++;
	}
      }
    }
  }

  return pot;
}
示例#28
0
double nuGibbs(double *nu,int Q,int G,const int *S,double gamma2,
	       const double *tau2Rho,const double *a,const double *rho,
	       const double *sigma2,const double *phi,
	       const int *psi,const double *x,
	       const int *delta,const double *Delta,Random &ran,int draw) {
  double pot = 0.0;

  int g;
  for (g = 0; g < G; g++) {
    //
    // compute prior covariance matrix
    //

    std::vector<std::vector<double> > var;
    makeSigma(g,G,var,Q,gamma2,tau2Rho,a,sigma2,rho);

    //
    // define prior mean
    //

    std::vector<double> Mean(Q,0.0);

    //
    // compute extra linear and quadratic terms
    //

    std::vector<double> lin(Q,0.0);
    std::vector<double> quad(Q,0.0);
    int s;
    int q;
    for (q = 0; q < Q; q++) {
      int kqg = qg2index(q,g,Q,G);
      double var0 = sigma2[kqg] * phi[kqg];
      double var1 = sigma2[kqg] / phi[kqg];
      for (s = 0; s < S[q]; s++) {
	int ksq = sq2index(s,q,S,Q);
	double variance = psi[ksq] == 0 ? var0 : var1;
	quad[q] += 1.0 / variance;
	int ksqg = sqg2index(s,q,g,S,Q,G);
	lin[q] += (x[ksqg] - delta[kqg] * (2.0 * psi[ksq] - 1.0) *
		   Delta[kqg]) / variance;
      }
    }

    //
    // Update parameters based on available observations
    //

    std::vector<std::vector<double> > varInv;
    double detPrior = inverse(var,varInv);

    for (q = 0; q < Q; q++) {
      varInv[q][q] += quad[q];
      Mean[q] += lin[q];
    }

    double detPosterior = 1.0 /inverse(varInv,var);
    std::vector<double> mean(Q,0.0);
    matrixMult(var,Mean,mean);

    //
    // Draw new values
    //

    std::vector<double> vv(Q,0.0);

    if (draw == 1)
      vv = ran.MultiGaussian(var,mean);
    else {
      for (q = 0; q < Q; q++) {
	int kqg = qg2index(q,g,Q,G);
	vv[q] = nu[kqg];
      }
    }

    pot += ran.PotentialMultiGaussian(var,mean,vv);

    if (draw == 1) {
      for (q = 0; q < Q; q++) {
	int kqg = qg2index(q,g,Q,G);
	nu[kqg] = vv[q];
      }
    }
  }

  return pot;
}
示例#29
0
int main(int argc, char* argv[])
{
  // Load the mesh.
  MeshSharedPtr u_mesh(new Mesh), v_mesh(new Mesh);
  MeshReaderH2DXML mloader;
  mloader.load("domain.xml", u_mesh);
  u_mesh->refine_all_elements();
  
  v_mesh->copy(u_mesh);
  v_mesh->refine_towards_boundary("Bdy", INIT_REF_BDY);

  // Define right-hand sides.
  CustomRightHandSide1* g1 = new CustomRightHandSide1(K, D_u, SIGMA);
  CustomRightHandSide2* g2 = new CustomRightHandSide2(K, D_v);

  // Initialize the weak formulation.
  CustomWeakForm wf(g1, g2);

  // Initialize boundary conditions
  DefaultEssentialBCConst<double> bc_u("Bdy", 0.0);
  EssentialBCs<double> bcs_u(&bc_u);
  DefaultEssentialBCConst<double> bc_v("Bdy", 0.0);
  EssentialBCs<double> bcs_v(&bc_v);

  // Create H1 spaces with default shapeset for both displacement components.
  SpaceSharedPtr<double> u_space(new H1Space<double>(u_mesh, &bcs_u, P_INIT_U));
  SpaceSharedPtr<double> v_space(new H1Space<double>(v_mesh, &bcs_v, P_INIT_V));
  Hermes::vector<SpaceSharedPtr<double> > spaces(u_space, v_space);
  NewtonSolver<double> newton(&wf, spaces);

  MeshFunctionSharedPtr<double> u_sln(new Solution<double>());
  MeshFunctionSharedPtr<double> u_sln1(new Solution<double>());
  MeshFunctionSharedPtr<double> v_sln(new Solution<double>());
  MeshFunctionSharedPtr<double> v_sln1(new Solution<double>());
  Hermes::vector<MeshFunctionSharedPtr<double> > slns(u_sln, v_sln);
  Hermes::vector<MeshFunctionSharedPtr<double> > slns1(u_sln1, v_sln1);

  newton.solve();
  Solution<double>::vector_to_solutions(newton.get_sln_vector(), spaces, slns);
  
  u_sln1->copy(u_sln);
  v_sln1->copy(v_sln);
  
  u_sln->free();
  v_sln->free();
  
  u_sln->copy(u_sln1);
  v_sln->copy(v_sln1);

  newton.solve(slns);
  Solution<double>::vector_to_solutions(newton.get_sln_vector(), spaces, slns1);

  Linearizer lin(FileExport);
  lin.process_solution(u_sln);
  lin.process_solution(u_sln1);
  lin.process_solution(v_sln1);
  lin.process_solution(u_sln1);
  lin.process_solution(u_sln1);
  lin.process_solution(v_sln1);

  return 0;
}
示例#30
0
void winfo::release_permanent(void)
{
	QString fname,cclname;
	QByteArray sdat;
	
	if(client == NULL)
		return;

	if(qcbox[7]->isChecked())  // class only 
	{
		cclname = client->get_clientname();
	}
	else
	{
		cclname = res_name;
		cclname += ',';
		cclname += res_class;
	}
	
	if(defaults::cfdir.isNull())
	{
		release_temporary();
		return;
	}
	
	fname = defaults::cfdir;
	fname += "/appdefaults";

	QFile apfile(fname);
	QList<QString> lns;
	
	if(apfile.open(QIODevice::ReadOnly))
	{
		QTextStream lin(&apfile);
		while(! lin.atEnd())
		{
			QString cln = lin.readLine(1024);

			if(cln.indexOf(cclname) != 0)
				lns.append(cln);
		}
		apfile.close();
	}

	if(! apfile.open(QIODevice::WriteOnly))
	{
		sdat = fname.toAscii();
		perror(sdat.data());
		release_temporary();
		return;
	}
	
	for(int i=0; i < lns.size(); i++)
	{
		sdat = lns.at(i).toAscii();
		sdat += '\n';
		apfile.write(sdat.data(), sdat.length());
	}	
	
	int i;
	bool ref=FALSE;
	static const char *qcs[] = { "Sticky","WindowListSkip","SmallFrame","NoResize","NoTile","NoKey","NoScreen" };
	QString ostr;
	
	for(i=0; i < 7; i++)
	{
		if(qcbox[i]->isChecked())
		{
			if(! ref)
			{
				ostr = cclname;
				ostr += ' ';
				ref = TRUE;
			}
			else
				ostr = ',';

			ostr += qcs[i];
			sdat = ostr.toAscii();
			apfile.write(sdat.data(), sdat.length());
		}
	}
	if(ref)
		apfile.write("\n", 1);

	apfile.close();	

	int tl = (client->get_pflags() & (WindowManager::NoTile|WindowManager::Sticky));
	WindowManager::read_cprops();

	if(WindowManager::is_tileddesk())
	{
		if(tl && ! (client->get_pflags() & (WindowManager::NoTile|WindowManager::Sticky)))
		{
			WindowManager::tile_order(client);
		}
		else if(! tl && (client->get_pflags() & (WindowManager::NoTile|WindowManager::Sticky)))
		{
			WindowManager::tile_order(WindowManager::tmaxclient);
			client->raise();
		}
	}	
	release_cancel();
}