Beispiel #1
0
 /// removes data by name
 void clear( const std::string& name)
 {
   remove_component(name);
   // anything to be deallocated?
 }
Real VolumeIntegral::integrate(const Field& field, const std::vector< Handle<Entities> >& entities)
{
  Real local_integral = 0.;
  boost_foreach( const Handle<Entities>& patch, entities )
  {
    if( patch->element_type().dimensionality() != patch->element_type().dimension() )
      throw SetupError( FromHere(), "Cannot compute Volume integral of surface element");

    if( is_not_null(m_quadrature) )
      remove_component("quadrature");
    m_quadrature = create_component<Quadrature>("quadrature",
        "cf3.mesh.gausslegendre."+GeoShape::Convert::instance().to_str(patch->element_type().shape())+"P"+common::to_str(m_order));

    /// Common part for every element of this patch
    const Space& space = field.space(*patch);
    const Uint nb_elems = space.size();
    const Uint nb_nodes_per_elem = space.shape_function().nb_nodes();
    const Uint nb_qdr_pts = m_quadrature->nb_nodes();
    const Uint nb_vars = field.row_size();

    RealMatrix qdr_pt_values( nb_qdr_pts, nb_vars );
    RealMatrix interpolate( nb_qdr_pts, nb_nodes_per_elem );
    RealMatrix field_pt_values( nb_nodes_per_elem, nb_vars );
    RealMatrix elem_coords;

    patch->geometry_space().allocate_coordinates(elem_coords);

    for( Uint qn=0; qn<nb_qdr_pts; ++qn)
    {
      interpolate.row(qn) = space.shape_function().value( m_quadrature->local_coordinates().row(qn) );
    }

    /// Loop over every element of this patch
    for (Uint e=0; e<nb_elems; ++e)
    {
      if( ! patch->is_ghost(e) )
      {
        patch->geometry_space().put_coordinates(elem_coords,e);

        // interpolate
        for (Uint n=0; n<nb_nodes_per_elem; ++n)
        {
          const Uint p = space.connectivity()[e][n];
          for (Uint v=0; v<nb_vars; ++v)
          {
            field_pt_values(n,v) = field[p][v];
          }
        }
        qdr_pt_values = interpolate * field_pt_values;

        // integrate
        for( Uint qn=0; qn<nb_qdr_pts; ++qn)
        {
          const Real Jdet = patch->element_type().jacobian_determinant( m_quadrature->local_coordinates().row(qn), elem_coords );
          local_integral += Jdet * m_quadrature->weights()[qn] * qdr_pt_values(qn,0);
        }
      }
    }
  }
  Real global_integral;
  PE::Comm::instance().all_reduce(PE::plus(), &local_integral, 1, &global_integral);
  return global_integral;
}
static gboolean press_callback(GtkWidget* widget,GdkEventButton* event,gpointer data)
{
	double mx=event->x;
	double my=event->y;
	double width=gtk_widget_get_allocated_width(widget);
	double height=gtk_widget_get_allocated_height(widget);
	double spacing=MIN((width-2*gutter)/grid.width,(height-2*gutter)/grid.height);
	mx-=width/2.0;
	my-=height/2.0;
	mx=mx/spacing;
	my=my/spacing;
	mx+=grid.width/2.0;
	my+=grid.height/2.0;
	int ia,ib;
	double da,db;
	int i;
	ia=0;ib=0;
	da=db=grid.width+grid.height;
	for(i=0;i<grid.map.vcount;i++){
		double x=grid.map.vertices[i].id%(grid.width+1);
		double y=(int)(grid.map.vertices[i].id/(grid.width+1));
		double d=sqrt((x-mx)*(x-mx)+(y-my)*(y-my));
		if(d<da){
			db=da;
			ib=ia;
			da=d;
			ia=i;
		}else if(d<db){
			db=d;
			ib=i;
		}
	}
	int A=MIN(grid.map.vertices[ia].id,grid.map.vertices[ib].id);
	int B=MAX(grid.map.vertices[ia].id,grid.map.vertices[ib].id);

	if(draw_state==PLACE_WIRE){
		Component c;
		c.type=WIRE;
		c.A=A;
		c.B=B;
		add_component(c);
	}
	if(draw_state==PLACE_RESISTOR){
		Component c;
		c.type=RESISTOR;
		c.A=A;
		c.B=B;
		c.data=calloc(1,sizeof(double));
		*(double*)c.data=10;
		add_component(c);
	}
	if(draw_state==PLACE_BATTERY){
		Component c;
		c.type=BATTERY;
		c.A=A;
		c.B=B;
		c.data=calloc(1,sizeof(double));
		*(double*)c.data=5;
		add_component(c);
	}if(draw_state==DELETE){
		for(i=0;i<grid.map.ccount;i++){
			if((grid.map.components[i].A==A)&&(grid.map.components[i].B==B)){
				remove_component(i);
				break;
			}
		}
	}if(draw_state==EDIT){
		for(i=0;i<grid.map.ccount;i++){
			if((grid.map.components[i].A==A)&&(grid.map.components[i].B==B)){
				edit_dialog(grid.map.components+i);
				break;
			}
		}
	}
	calculate();
	//gtk_widget_queue_draw_area(widget,0,0,width,height);
	gtk_widget_queue_draw(widget);
	return TRUE;
}