Ejemplo n.º 1
0
 node_info helper(TreeNode* node, int& max_size) {
     //consider empty tree as valid BST
     if (!node) return node_info(true, 0, 0, 0);
     //leaf node
     if (!node->left && !node->right) {
         max_size = max(1, max_size);
         return node_info(true, node->val, node->val, 1);
     }
     node_info l_info = helper(node->left, max_size);
     node_info r_info = helper(node->right, max_size);
     
     if (!l_info.isBST || !r_info.isBST) return node_info(false, 0, 0, 0);
     
     if (l_info.size > 0 && node->val < l_info.max_val) 
         return node_info(false, 0, 0, 0);
     if (r_info.size > 0 && node->val > r_info.min_val) 
         return node_info(false, 0, 0, 0);
     max_size = max(l_info.size+r_info.size+1, max_size);
     if (l_info.size == 0)
         return node_info(true, node->val, r_info.max_val, l_info.size+r_info.size+1);
     else if (r_info.size == 0)
         return node_info(true, l_info.min_val, node->val, l_info.size+r_info.size+1);
     else
         return node_info(true, l_info.min_val, r_info.max_val, l_info.size+r_info.size+1);
     
 }
Ejemplo n.º 2
0
  graph(double timeout_sec): rpc_server(timeout_sec) {

    rpc_server::add<std::string(std::string) >("get_config", pfi::lang::bind(&Impl::get_config, static_cast<Impl*>(this), pfi::lang::_1));
    rpc_server::add<std::string(std::string) >("create_node", pfi::lang::bind(&Impl::create_node, static_cast<Impl*>(this), pfi::lang::_1));
    rpc_server::add<bool(std::string, std::string) >("remove_node", pfi::lang::bind(&Impl::remove_node, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<bool(std::string, std::string, property) >("update_node", pfi::lang::bind(&Impl::update_node, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2, pfi::lang::_3));
    rpc_server::add<uint64_t(std::string, std::string, edge_info) >("create_edge", pfi::lang::bind(&Impl::create_edge, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2, pfi::lang::_3));
    rpc_server::add<bool(std::string, std::string, uint64_t, edge_info) >("update_edge", pfi::lang::bind(&Impl::update_edge, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2, pfi::lang::_3, pfi::lang::_4));
    rpc_server::add<bool(std::string, std::string, uint64_t) >("remove_edge", pfi::lang::bind(&Impl::remove_edge, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2, pfi::lang::_3));
    rpc_server::add<double(std::string, std::string, int32_t, preset_query) >("get_centrality", pfi::lang::bind(&Impl::get_centrality, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2, pfi::lang::_3, pfi::lang::_4));
    rpc_server::add<bool(std::string, preset_query) >("add_centrality_query", pfi::lang::bind(&Impl::add_centrality_query, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<bool(std::string, preset_query) >("add_shortest_path_query", pfi::lang::bind(&Impl::add_shortest_path_query, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<bool(std::string, preset_query) >("remove_centrality_query", pfi::lang::bind(&Impl::remove_centrality_query, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<bool(std::string, preset_query) >("remove_shortest_path_query", pfi::lang::bind(&Impl::remove_shortest_path_query, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<std::vector<std::string >(std::string, shortest_path_req) >("get_shortest_path", pfi::lang::bind(&Impl::get_shortest_path, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<bool(std::string) >("update_index", pfi::lang::bind(&Impl::update_index, static_cast<Impl*>(this), pfi::lang::_1));
    rpc_server::add<bool(std::string) >("clear", pfi::lang::bind(&Impl::clear, static_cast<Impl*>(this), pfi::lang::_1));
    rpc_server::add<node_info(std::string, std::string) >("get_node", pfi::lang::bind(&Impl::get_node, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<edge_info(std::string, std::string, uint64_t) >("get_edge", pfi::lang::bind(&Impl::get_edge, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2, pfi::lang::_3));
    rpc_server::add<bool(std::string, std::string) >("save", pfi::lang::bind(&Impl::save, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<bool(std::string, std::string) >("load", pfi::lang::bind(&Impl::load, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<std::map<std::string, std::map<std::string, std::string > >(std::string) >("get_status", pfi::lang::bind(&Impl::get_status, static_cast<Impl*>(this), pfi::lang::_1));
    rpc_server::add<bool(std::string, std::string) >("create_node_here", pfi::lang::bind(&Impl::create_node_here, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<bool(std::string, std::string) >("remove_global_node", pfi::lang::bind(&Impl::remove_global_node, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2));
    rpc_server::add<bool(std::string, uint64_t, edge_info) >("create_edge_here", pfi::lang::bind(&Impl::create_edge_here, static_cast<Impl*>(this), pfi::lang::_1, pfi::lang::_2, pfi::lang::_3));
  }
Ejemplo n.º 3
0
void main_routine(){
	// Basic iterations
	if (ITERFLAG == 1){
		for (int iter = 0; iter < ITER_NUM; iter++){
			iterGlobal = iter;
			Cal();
			printf("[INFO] ROUND %02d: CALCULATION DONE\n", iter+1);
			if (ITER_ALGO == 0){
				Norm();
				printf("[INFO] ROUND %02d: NORMALIZATION DONE\n", iter+1);
			}
		}
		matrix_dump();
	} else
		matrix_retrieve();
	
	
	//Compute the matrix of same node pair;
	node_info();

	//The greedy approach of matrix mapping
	matrix_mapping(ITER_NUM, 0);

	//Using the mapped pairs to induce other mapping
	if (PICK_ALGO != 0)
		mapping_induction();
	
}
Ejemplo n.º 4
0
		//-----------------------------------------------------------------------
		const shawn::EventScheduler::EventHandle
			FloodRouting::
			find_sending_jitter_timer( const shawn::Node& owner, const shawn::EventScheduler::EventHandle eh )
			const
			throw()
		{
			const FloodRoutingNodeInfo& rni = node_info(owner);
			FloodRoutingEventHandleSetConstIterator it = rni.sending_jitter_timer().find( eh );
			if( it != rni.sending_jitter_timer().end() )
			{
				return *it;
			}
			return NULL;
		}
Ejemplo n.º 5
0
  static void _recurse_create_bare_tao_tree_info(tao_tree_info_s * tree_info,
						 taoDNode * node)
  {
    tree_info->info.push_back(tao_node_info_s());
    tao_node_info_s & node_info(tree_info->info.back());
    node_info.node = node;
    node_info.joint = node->getJointList();
    node_info.id = node->getID();
    node_info.link_name = "link" + sfl::to_string(node_info.id);
    node_info.joint_name = "joint" + sfl::to_string(node_info.id);
    node_info.limit_lower = std::numeric_limits<double>::min();
    node_info.limit_upper = std::numeric_limits<double>::max();
    for (taoDNode * child(node->getDChild()); child != NULL; child = child->getDSibling()) {
      _recurse_create_bare_tao_tree_info(tree_info, child);
    }
  }
Ejemplo n.º 6
0
		//-----------------------------------------------------------------------
		bool
			FloodRouting::
			message_in_history( const shawn::Node& owner, const shawn::ConstMessageHandle& mh )
			const
			throw()
		{
			const FloodRoutingNodeInfo& rni = node_info(owner);
			FloodRoutingMessageHistoryConstIterator it = rni.message_history().find_history( mh );
			if( it == rni.message_history().end_history() )
			{
				return false;
			}
			else
			{
				return true;
			}
		}
Ejemplo n.º 7
0
ssize_t Master::_add_IO_node(const std::string& node_ip, std::size_t total_memory, int socket)
{
	ssize_t id=0; 
	if(-1 == (id=_get_node_id()))
	{
		return -1;
	}
	if(_registed_IOnodes.end() != _find_by_ip(node_ip))
	{
		return -1;
	}
	_registed_IOnodes.insert(std::make_pair(id, node_info(id, node_ip, total_memory, socket)));
	node_info *node=&(_registed_IOnodes.at(id)); 
	_IOnode_socket.insert(std::make_pair(socket, node)); 
	Server::_add_socket(socket); 
	++_node_number; 
	//int open;
	//Recv(socket, open);
	return id; 
}
Ejemplo n.º 8
0
void DragonView::_CopyTarget( BMessage *msg )
{
	// Try to translate the data.  If we can't manage to translate it, 
	// there's no point in continuing.

	char *translated_mime;
	BMallocIO *data_buffer = _TranslateBitmap( msg, &translated_mime );

	if( data_buffer == NULL ) {
		// Couldn't translate... d'oh!
		msg->SendReply( B_MESSAGE_NOT_UNDERSTOOD, this );
		return;
	}

	const char *type = msg->FindString( "be:types" );
	if( strcmp( type, B_FILE_MIME_TYPE ) ) {
		// It doesn't match B_FILE_MIME_TYPE, so they actually want some
		// data passed in a message... let's give it to them.

		BMessage data_reply( B_MIME_DATA );
		data_reply.AddData( translated_mime, B_MIME_TYPE,
							data_buffer->Buffer(),
							data_buffer->BufferLength() );

		msg->SendReply( &data_reply, this );
	} else {
		// If you're here, it's because the drop target wants us to create a
		// file.
		entry_ref dir_ref;

		if( msg->FindRef( "directory", &dir_ref ) != B_OK ) {
			// Something bad has happened; the message is corrupt or 
			// incomplete.
			msg->SendReply( B_MESSAGE_NOT_UNDERSTOOD, this );

			// Lots of people are against goto in "real" code; this is one
			// of the few good ways to use it... since we're using C++, we
			// could replace this with an exception, and clean up when we
			// catch the exception, but that introduces unecessary overhead
			// here... if we were using exceptions all over the program it
			// would make more sense.
			//
			// See Scott Meyers's More Effective C++ for a discussion about
			// the overhead introduced by exceptions.
			goto cleanup_and_return;
		}

		// See if we can get a BFile in the specified location
		const char *filename = msg->FindString( "name" );

		BDirectory bit_dir;
		if( bit_dir.SetTo( &dir_ref ) != B_OK ) {
			msg->SendReply( B_MESSAGE_NOT_UNDERSTOOD, this );

			goto cleanup_and_return;
		}

		BFile bit_file;
		if( bit_file.SetTo( &bit_dir, filename, 
							B_WRITE_ONLY | B_CREATE_FILE ) != B_OK ) {
			msg->SendReply( B_MESSAGE_NOT_UNDERSTOOD, this );

			goto cleanup_and_return;
		}

		// Write the data...
		ssize_t wrote_bytes = bit_file.Write( data_buffer->Buffer(),
											  data_buffer->BufferLength() );

		if( wrote_bytes != static_cast<ssize_t>( data_buffer->BufferLength() ) ) {
			// Then we didn't write all of the data. 
			msg->SendReply( B_MESSAGE_NOT_UNDERSTOOD, this );

			goto cleanup_and_return;
		}
		
		// We'll also be nice and set the file's MIME type to the type of
		// the translated data.
		BNodeInfo node_info( &bit_file );
		(void)node_info.SetType( translated_mime );
	}

cleanup_and_return:
	delete [] translated_mime;
	delete data_buffer;

	return;
}
Ejemplo n.º 9
0
dtls_dispatch::dtls_dispatch(worker_thread* io)
	: sockets(std::bind(&dtls_dispatch::cleanup_socket, this, std::placeholders::_1), DISPATCH_NONPEER::NUM_NONPEER_FDS, "dispatch"), buflist(-1),
	  vn(new vnet(this, io, timers, buflist)), pinit(new peer_init(this, vn.get(), timers, &buflist)),
	  run_state(RUNNING), natpmp_addr(0)
{
	buflist.set_bufsize(vn->get_tun_mtu()+200); // tun MTU plus [over-]estimate of DTLS overhead
	sockets.emplace_back(INVALID_SOCKET, pvevent::read, std::bind(&vnet::tuntap_socket_event, vn.get(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), dtls_socket(csocket(), sockaddrunion()));
#ifdef WINDOWS
	// set_read_ready_cb must be called after sockets.emplace_back above so that TUNTAP_FD is a valid index, as the callback may be called immediately if data is available
	vn->get_tun().set_read_ready_cb(std::bind(&decltype(sockets)::indicate_read, &sockets, TUNTAP_FD), vn->get_tun_mtu());
#else
	sockets.set_fd(TUNTAP_FD, vn->get_tun().get_fd());
#endif
	sockets.emplace_back(interthread_msg_queue.getSD(), pvevent::read, std::bind(&function_tqueue::pv_execute, &interthread_msg_queue, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), dtls_socket(csocket(), sockaddrunion()));
	csocket icmp4, icmp6;
	try {
		icmp4 = csocket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
		icmp6 = csocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
	} catch(const check_err_exception& e) {
		eout() << "Failed to configure ICMP socket: " << e;
	}
	int icmp4_sd = icmp4.fd(), icmp6_sd = icmp6.fd();
	sockets.emplace_back(icmp4_sd, pvevent::read, std::bind(&dtls_dispatch::icmp_socket_event, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), dtls_socket(std::move(icmp4), sockaddrunion()));
	sockets.emplace_back(icmp6_sd, pvevent::read, std::bind(&dtls_dispatch::icmp6_socket_event, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), dtls_socket(std::move(icmp6), sockaddrunion()));
	// that's it for the nonpeers, now grab sockets for all the local ipaddrs
	peer_socket_event_function = std::bind(&dtls_dispatch::peer_socket_event, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
	std::vector<sockaddrunion> local_addrs(detect_local_addrs(vn->get_tun_ipaddr()));
	// TODO: this concept of always using the same incoming and outgoing local ports for all connections theoretically makes the NAT traversal stuff work pretty well
		// and it means we can use a finite number of sockets for arbitrarily many peers
		// but there are probably going to be some circumstances where binding a new socket on a different port will be in order
	// one example of this is when a connection fails (e.g. hard restart of the daemon or device) and the client tries to reconnect using the same ports, which the peer already has associated with the dead connection
		// the current implementation probably does the right thing eventually (maybe bad packet causes peer to do heartbeat and then fail the dead connection?)
		// and if not then the client will send DHT CONNECT which should do the same (induce peer to do heartbeat and fail dead connection)
		// but that's a lot of timeouts and maybes for something that could be avoided by binding a new socket on a random port
			// so could do that for the pre-DHT connection for reconnect-after-failure or reconnects during grace period
	// there are also likely to be situations where the NAT misbehaves in various ways, especially if two nodes behind the same NAT choose the same ports
		// although in that case the NAPT detection should mostly sort it out in theory (at least for incoming port; still needs to be implemented for outgoing port)
	// TODO: figure out what to do if we can't bind the appropriate port on one or more addrs
		// part of the problem is that this sometimes happens normally, e.g. OS (especially stupid Windows) gives useless addrs that don't work but the real addrs are fine
		// but this could also happen if some other program has the port on one or more addrs, or the port is privileged and we don't have privs, etc.
	for(sockaddrunion& su : local_addrs) {
		su.set_ip_port(htons(snow::conf[snow::DTLS_OUTGOING_PORT]));
		try {
			create_socket(su, dtls_socket::PERSISTENT);
		} catch(const e_check_sock_err &e) {
			eout() << "Could not create create UDP socket: " << e;
		}
		if(su.s.sa_family == AF_INET)
			su.set_ip_port(htons(snow::conf[snow::DTLS_BIND_PORT]));
		else
			su.set_ip_port(htons(snow::conf[snow::DTLS_BIND6_PORT]));
		try {
			create_socket(su, dtls_socket::PERSISTENT);
			local_interface_addrs.push_back(su.get_ip_union());
		} catch(const e_check_sock_err &e) {
			eout() << "Could not create create UDP socket: " << e;
		}
	}
	if(local_addrs.size() > 0) {
		std::vector<ip_info> infos;
		for(auto& addr : local_addrs)
			infos.emplace_back(ip_info(addr));
		dout() << "local node info: " << pinit->local_hashkey().key_string() << "," << node_info(infos, htons(snow::conf[snow::DTLS_OUTGOING_PORT]));
	}
	query_natpmpupnp();
}
Ejemplo n.º 10
0
void 
extract_nodal_eb_vec(double sol_vec[], int var_no, int ktype, int matIndex,
		     int eb_index, double nodal_vec[], Exo_DB *exo, 
		     int timeDerivative, double time)

  /******************************************************************************
   *
   * extract_nodal_eb_vec:
   *
   *      This function extracts the a particular nodal variable specified
   *  by the program arguments and loads it up into a global vector.
   *  This routine only operates on one element block.
   *
   * This function puts the nodal values of the selected variable
   * into a global solution vector which contains all the mesh nodes,
   * and interpolates the mid-side and centroid values of 
   * all variables with Q1 interpolation on a
   * 9-NODE mesh and interpolates to find their values at the mid-side
   * nodes and at the centroid
   *
   *  Input
   * --------
   *  sol_vec[] = Current global solution vector
   *  var_no    = Variable type to be extracted
   *  ktype     = sub_var number of the variable type to be extracted
   *  matIndex  = material index of the variable to be extracted.
   *             -1 : extract the nonspecific variable
   *             -2 : extract the first variable with var_no no
   *                  matter what material index.
   *  exo       = Exodus database structure
   *  timeDerivative = Are we extracting a time derivative? if so,
   *              then this is true. If not, false.
   *
   * Output
   * -------
   *  nodal_vec[] = nodal vector which receives the value
   *                of the extracted vector. (length number
   *                of nodes)
   *********************************************************************************/
{
  int mn, e_start, e_end, ielem, ielem_type, ip_total, num_local_nodes;
  int ielem_dim, iconnect_ptr, i, I, index;
  int ileft, Ileft, iright, Iright, midside;
  int lastSpeciesSum, iDof, j;
  MATRL_PROP_STRUCT *matrl;
  double rho;
#ifdef DEBUG_HKM
  int nunks, interpType;
#endif

  /*
   * Find out the material number, mn, from the element block index
   */
  mn = Matilda[eb_index];
  matrl = mp_glob[mn];

  /* 
   * Assign local pointer pd to appropriate material
   */
  pd = pd_glob[mn];

  /*
   *  Check for the existence of a special case for the sum of
   *  the last species constraint condition
   */
  lastSpeciesSum = FALSE;
  if (var_no == MASS_FRACTION) {
    if (matrl->Num_Species_Eqn < matrl->Num_Species) {
      if (ktype == matrl->Num_Species - 1) lastSpeciesSum = TRUE;
    }
  }

  /*
   *  Found out the beginning element number and ending element number
   *  from the element block index
   */
  e_start =  exo->eb_ptr[eb_index];
  e_end   =  exo->eb_ptr[eb_index+1];

  /*
   *  Loop over elements in the element block
   */
  for (ielem = e_start; ielem < e_end; ielem++) {

    /*
     *  Get the element type for this element -> Isn't this the
     *  same for all elements in the element block?
     *  
     */
    ielem_type      = Elem_Type(exo, ielem);

    /*
     *  Get the total number of quadrature points
     */
    ip_total        = elem_info(NQUAD, ielem_type); 

    /*
     *  Get the dimensionality of the elements in the element block
     */
    ielem_dim       = elem_info(NDIM, ielem_type);

    /*
     * Number of local nodes in the element
     */
    num_local_nodes = elem_info(NNODES, ielem_type);

    /*
     *  find ptr to beginning of this element's connectivity list 
     *
     */
    iconnect_ptr = Proc_Connect_Ptr[ielem]; 

    /* 
     * First, place the known nodal variable values for this
     * particular variable and type into the nodal vector.
     *
     * This will zero out the midside node for conjugate problems
     * at the interface between material.
     * It needs to be fixed! -RRR
     *
     *  The field variable is zero where it is not defined
     */

    for (i = 0; i < num_local_nodes; i++) {
      I = Proc_Elem_Connect[iconnect_ptr + i];
      iDof = 0;
      /*
       * HKM -> Special compatibility section
       */
#ifdef DEBUG_HKM
      interpType = pd_glob[mn]->i[var_no];
      nunks = node_info(i, ielem_type, var_no, I);
      if (nunks > 1) {
	if (interpType == I_P0 || interpType == I_P1) {
	} else {
	  if (((exo->eb_id[eb_index] + 1) % 2) == 0) {
	    iDof = 0;
	  } else {
	    iDof = 1;
	  }
	}
      }
#endif
      if (lastSpeciesSum) {
	index = Index_Solution(I, var_no, 0, iDof, matIndex);
	if (index != -1) {
	  nodal_vec[I] = 0.0;
	  for (j = 0; j < matrl->Num_Species_Eqn; j++) {
	    index = Index_Solution(I, var_no, j, iDof, matIndex);
	    nodal_vec[I] -= sol_vec[index];
	  }
	  switch (matrl->Species_Var_Type) {
	  case SPECIES_CONCENTRATION:
	      if (matrl->DensityModel == DENSITY_CONSTANT_LAST_CONC) {
		nodal_vec[I] = matrl->u_density[0];
	      } else {
		rho = calc_concentration(matrl, FALSE, NULL);
		nodal_vec[I] += rho;
	      }
	      break;
	  case SPECIES_DENSITY:
	      rho = calc_density(matrl, FALSE, NULL, time);
	      nodal_vec[I] += rho;
	      break;
	  default:
	      if (!timeDerivative) {
		nodal_vec[I] += 1.0;
	      }
	      break;
	  }
	}
      } else {
	index = Index_Solution(I, var_no, ktype, iDof, matIndex);
	if (index != -1) {
	  nodal_vec[I] = sol_vec[index];
	} 
      }
    }

    /*
     * Rich's famous patch up for lesserly interpolated variables.
     * Promote quadrilateral Q1 variables to Q2 status, 8 node serendipity
     * at least, and 9-node biquadratic at best.
     */
    /* RRR notes a problem here in 3D. 
     *     Should add check for TRIQUAD_QUAD elem type */

    midside = 0;  
    if (((pd->i[var_no] == I_Q1)   ||
         (pd->i[var_no] == I_Q1_G)   ||
	 (pd->i[var_no] == I_Q1_GP)   ||
	 (pd->i[var_no] == I_Q1_GN)   ||
         (pd->i[var_no] == I_Q1_XV)   ||
         (pd->i[var_no] == I_Q1_XG)   ||
         (pd->i[var_no] == I_Q1_HV)   ||
         (pd->i[var_no] == I_Q1_HG)   ||
         (pd->i[var_no] == I_Q1_HVG)   ||
	 (pd->i[var_no] == I_Q1_D) ||
	 (pd->i[var_no] == I_SP)      )
	&& ((ielem_type == S_BIQUAD_QUAD)  ||
	    (ielem_type == BIQUAD_QUAD)         )) {
      midside = 1;
    }
  
    if (midside) {
      /* now interpolate Q1 variables onto 9-node mesh if needed */
      for (i = 4; i < 8; i++) {
	I = Proc_Elem_Connect[iconnect_ptr + i]; 
	/* 
	 * Double check to insure there really are no dofs here.
	 */
	if (Index_Solution(I, var_no, ktype, 0, matIndex) == -1) {
	  /* 
	   * make node lie halfway between adjacent nodes 
	   * cf. PATRAN local numbering scheme for element.
	   */
	  ileft = i - 4;
	  Ileft = Proc_Elem_Connect[iconnect_ptr + ileft];
	  iright = i - 3;
	  if (iright == 4) iright = 0;
	  Iright = Proc_Elem_Connect[iconnect_ptr + iright];
	  nodal_vec[I] = 
	      0.5 * (nodal_vec[Ileft] + nodal_vec[Iright]);
#if 0
          if ((pd->i[var_no] == I_Q1_HV)   ||
              (pd->i[var_no] == I_Q1_HG)   ||
              (pd->i[var_no] == I_Q1_HVG)) nodal_vec[I] = -1.;
#endif
	}
      }
      /*
       *  Only interpolate centroid in  BIQUAD_QUAD
       */
      if (ielem_type == BIQUAD_QUAD) {
	I = Proc_Elem_Connect[iconnect_ptr + 8];
	nodal_vec[I] = 0.0; 
	if ( (Index_Solution(I, var_no, ktype, 0, matIndex) == -1) ||
             /* for P0 jumps, overwrite jump with interpolant */
             (pd->i[var_no] == I_Q1_HV ||
              pd->i[var_no] == I_Q1_HG ||
              pd->i[var_no] == I_Q1_HVG) ) {
	  for (ileft = 0; ileft < 4; ileft++) {
	    Ileft = Proc_Elem_Connect[iconnect_ptr + ileft];
	    nodal_vec[I] += 0.25 * nodal_vec[Ileft];
	  }
#if 0
          if ((pd->i[var_no] == I_Q1_HV)   ||
              (pd->i[var_no] == I_Q1_HG)   ||
              (pd->i[var_no] == I_Q1_HVG)) nodal_vec[I] = -1.;
#endif
	}     
      }
    } /* END if (midside) */
  } /* END for (ielem = e_start; ielem < e_end; ielem++) */
  return;
}
Ejemplo n.º 11
0
void PecoApp::CreateScript(BMessage *msg) {
	entry_ref	directory;
	const char	*name;
	msg->FindRef("directory", &directory);
	msg->FindString("name", &name);
	
	BPath path(&directory);
	path.Append(name);
	
	BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);

	// Initiate
	fWindow->Lock();
	fStatusBar->SetMaxValue(fList->CountItems());
	BTextControl* 	pfadView = (BTextControl *)fWindow->FindView("pfadView");
	BString			Pfad(pfadView->Text());
	fWindow->Unlock();

	FileListItem	*ListItem;
	BString			AlterName, NeuerName;
	BString			output = 
					"#!/bin/sh\n"
					"\n"
					"# This script was created with PecoRename by Werner Freytag.\n"
					"# Visit http://www.pecora.de/pecorename for details!\n\n"
					"alert \"This script will rename files.\n\n"
					"Do you really want to continue?\" \"Yes\" \"No\"\n\n"
					"if [ $? -ne 0 ]\n"
					"then\n"
					"	exit 0\n"
					"fi\n\n";
	
	for (int32 i = 0; (ListItem = (FileListItem *)fListView->ItemAt(i)) != NULL; i++ ) {
		fWindow->Lock();
		fStatusBar->Update(1);
		fWindow->Unlock();
		if (ListItem->fNewName.String() != "" ) {
			AlterName = Pfad; AlterName.Append("/").Append(ListItem->fName);
			AlterName.Replace("\"", "\\\"", AlterName.Length());
			NeuerName = Pfad; NeuerName.Append("/").Append(ListItem->fNewName);
			NeuerName.Replace("\"", "\\\"", NeuerName.Length());
			output << "mv \"" << AlterName.String() << "\" \"" << NeuerName.String() << "\"\n";
		}
	}
	
	file.Write(output.String(), output.Length());
	
	mode_t	perms;
	
	file.GetPermissions(&perms);
	file.SetPermissions(perms | S_IXUSR | S_IXGRP | S_IXOTH );
	
	BNode		node(file);
	BNodeInfo	node_info(&node);
	node_info.SetType("text/plain");
	
	fWindow->Lock();
	fStatusBar->Reset(STATUS_STATUS);
	fWindow->Unlock();

}