/* == Sliding boundary conditions == * * It is common to require a Dirichlet boundary condition where the displacement/position in one dimension * is fixed, but the displacement/position in the others are free. This can be easily done when * collecting the new locations for the fixed nodes, as shown in the following example. Here, we * take a unit square, apply gravity downward, and suppose the Y=0 surface is like a frictionless boundary, * so that, for the nodes on Y=0, we specify y=0 but leave x free (Here (X,Y)=old position, (x,y)=new position). * (Note though that this wouldn't be enough to uniquely specify the final solution - an arbitrary * translation in the Y direction could be added a solution to obtain another valid solution, so we * fully fix the node at the origin.) */ void TestWithSlidingDirichletBoundaryConditions() throw(Exception) { QuadraticMesh<2> mesh; mesh.ConstructRegularSlabMesh(0.1 /*stepsize*/, 1.0 /*width*/, 1.0 /*height*/); ExponentialMaterialLaw<2> law(1.0, 0.5); // First parameter is 'a', second 'b', in W=a*exp(b(I1-3)) /* Create fixed nodes and locations... */ std::vector<unsigned> fixed_nodes; std::vector<c_vector<double,2> > locations; /* Fix node 0 (the node at the origin) */ fixed_nodes.push_back(0); locations.push_back(zero_vector<double>(2)); /* For the rest, if the node is on the Y=0 surface.. */ for (unsigned i=1; i<mesh.GetNumNodes(); i++) { if ( fabs(mesh.GetNode(i)->rGetLocation()[1])<1e-6) { /* ..add it to the list of fixed nodes.. */ fixed_nodes.push_back(i); /* ..and define y to be 0 but x is fixed */ c_vector<double,2> new_location; new_location(0) = SolidMechanicsProblemDefinition<2>::FREE; new_location(1) = 0.0; locations.push_back(new_location); } } /* Set the material law and fixed nodes, add some gravity, and solve */ SolidMechanicsProblemDefinition<2> problem_defn(mesh); problem_defn.SetMaterialLaw(INCOMPRESSIBLE,&law); problem_defn.SetFixedNodes(fixed_nodes, locations); c_vector<double,2> gravity = zero_vector<double>(2); gravity(1) = -0.5; problem_defn.SetBodyForce(gravity); IncompressibleNonlinearElasticitySolver<2> solver(mesh, problem_defn, "ElasticitySlidingBcsExample"); solver.Solve(); solver.CreateCmguiOutput(); /* Check the node at (1,0) has moved but has stayed on Y=0 */ TS_ASSERT_LESS_THAN(1.0, solver.rGetDeformedPosition()[10](0)); TS_ASSERT_DELTA(solver.rGetDeformedPosition()[10](1), 0.0, 1e-3); }
ReturnOop LocationModifier::new_location(JavaFrame *fr, LocationModifier *loc) { UsingFastOops fast_oops; Method::Fast m = fr->method(); // we may not be creating a location in a frame of the current thread // Therefore we must get the correct class list from the task InstanceClass::Fast ic = m().holder(fr->thread()); return new_location(&ic, &m, fr->bci(), loc); }
string SNetStorageByKeyRPC::Relocate(const string& unique_key, TNetStorageFlags flags, TNetStorageFlags old_flags) { m_NetStorageRPC->m_UseNextSubHitID.ProperCommand(); CJsonNode request(m_NetStorageRPC->MkObjectRequest( "RELOCATE", unique_key, old_flags)); CJsonNode new_location(CJsonNode::NewObjectNode()); SNetStorageRPC::x_SetStorageFlags(new_location, flags); request.SetByKey("NewLocation", new_location); return m_NetStorageRPC->Exchange(m_NetStorageRPC->m_Service, request).GetString("ObjectLoc"); }
string SNetStorageRPC::Relocate(const string& object_loc, TNetStorageFlags flags) { if (x_NetCacheMode(object_loc)) NCBI_THROW_FMT(CNetStorageException, eNotSupported, object_loc << ": Relocate for NetCache blobs is not implemented"); m_UseNextSubHitID.ProperCommand(); CJsonNode request(MkObjectRequest("RELOCATE", object_loc)); CJsonNode new_location(CJsonNode::NewObjectNode()); x_SetStorageFlags(new_location, flags); request.SetByKey("NewLocation", new_location); return Exchange(GetServiceFromLocator(object_loc), request).GetString("ObjectLoc"); }
/** * Convert existing rail to waypoint. Eg build a waypoint station over * piece of rail * @param start_tile northern most tile where waypoint will be built * @param flags type of operation * @param p1 various bitstuffed elements * - p1 = (bit 4) - orientation (Axis) * - p1 = (bit 8-15) - width of waypoint * - p1 = (bit 16-23) - height of waypoint * - p1 = (bit 24) - allow waypoints directly adjacent to other waypoints. * @param p2 various bitstuffed elements * - p2 = (bit 0- 7) - custom station class * - p2 = (bit 8-15) - custom station id * @param text unused * @return the cost of this operation or an error */ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { /* Unpack parameters */ Axis axis = Extract<Axis, 4, 1>(p1); byte width = GB(p1, 8, 8); byte height = GB(p1, 16, 8); bool adjacent = HasBit(p1, 24); StationClassID spec_class = Extract<StationClassID, 0, 8>(p2); byte spec_index = GB(p2, 8, 8); StationID station_to_join = GB(p2, 16, 16); /* Check if the given station class is valid */ if (spec_class != STAT_CLASS_WAYP) return CMD_ERROR; if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR; /* The number of parts to build */ byte count = axis == AXIS_X ? height : width; if ((axis == AXIS_X ? width : height) != 1) return CMD_ERROR; if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR; bool reuse = (station_to_join != NEW_STATION); if (!reuse) station_to_join = INVALID_STATION; bool distant_join = (station_to_join != INVALID_STATION); if (distant_join && (!_settings_game.station.distant_join_stations || !Waypoint::IsValidID(station_to_join))) return CMD_ERROR; /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */ StationID est = INVALID_STATION; /* Check whether the tiles we're building on are valid rail or not. */ TileIndexDiff offset = TileOffsByDiagDir(AxisToDiagDir(OtherAxis(axis))); for (int i = 0; i < count; i++) { TileIndex tile = start_tile + i * offset; CommandCost ret = IsValidTileForWaypoint(tile, axis, &est); if (ret.Failed()) return ret; } Waypoint *wp = NULL; TileArea new_location(TileArea(start_tile, width, height)); CommandCost ret = FindJoiningWaypoint(est, station_to_join, adjacent, new_location, &wp); if (ret.Failed()) return ret; /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */ TileIndex center_tile = start_tile + (count / 2) * offset; if (wp == NULL && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company); if (wp != NULL) { /* Reuse an existing waypoint. */ if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT); /* check if we want to expand an already existing waypoint? */ if (wp->train_station.tile != INVALID_TILE) { CommandCost ret = CanExpandRailStation(wp, new_location, axis); if (ret.Failed()) return ret; } CommandCost ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST); if (ret.Failed()) return ret; } else { /* allocate and initialize new waypoint */ if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING); } if (flags & DC_EXEC) { if (wp == NULL) { wp = new Waypoint(start_tile); } else if (!wp->IsInUse()) { /* Move existing (recently deleted) waypoint to the new location */ wp->xy = start_tile; } wp->owner = GetTileOwner(start_tile); wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY); wp->delete_ctr = 0; wp->facilities |= FACIL_TRAIN; wp->build_date = _date; wp->string_id = STR_SV_STNAME_WAYPOINT; wp->train_station = new_location; if (wp->town == NULL) MakeDefaultName(wp); wp->UpdateVirtCoord(); const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index); byte *layout_ptr = AllocaM(byte, count); if (spec == NULL) { /* The layout must be 0 for the 'normal' waypoints by design. */ memset(layout_ptr, 0, count); } else { /* But for NewGRF waypoints we like to have their style. */ GetStationLayout(layout_ptr, count, 1, spec); } byte map_spec_index = AllocateSpecToStation(spec, wp, true); Company *c = Company::Get(wp->owner); for (int i = 0; i < count; i++) { TileIndex tile = start_tile + i * offset; byte old_specindex = HasStationTileRail(tile) ? GetCustomStationSpecIndex(tile) : 0; if (!HasStationTileRail(tile)) c->infrastructure.station++; bool reserved = IsTileType(tile, MP_RAILWAY) ? HasBit(GetRailReservationTrackBits(tile), AxisToTrack(axis)) : HasStationReservation(tile); MakeRailWaypoint(tile, wp->owner, wp->index, axis, layout_ptr[i], GetRailType(tile)); SetCustomStationSpecIndex(tile, map_spec_index); SetRailStationReservation(tile, reserved); MarkTileDirtyByTile(tile); DeallocateSpecFromStation(wp, old_specindex); YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis)); } DirtyCompanyInfrastructureWindows(wp->owner); } return CommandCost(EXPENSES_CONSTRUCTION, count * _price[PR_BUILD_WAYPOINT_RAIL]); }
void LocationsMgr::on_new_connection( Connection* con ) { new_location( std::make_shared<ProtocolLocation>( "welcome" , std::make_shared<WelcomeProt>(loc_factory, server_config) , con ) ); }
/* == Incompressible deformation: non-zero displacement boundary conditions, functional tractions == * * We now consider a more complicated example. We prescribe particular new locations for the nodes * on the Dirichlet boundary, and also show how to prescribe a traction that is given in functional form * rather than prescribed for each boundary element. */ void TestIncompressibleProblemMoreComplicatedExample() throw(Exception) { /* Create a mesh */ QuadraticMesh<2> mesh; mesh.ConstructRegularSlabMesh(0.1 /*stepsize*/, 1.0 /*width*/, 1.0 /*height*/); /* Use a different material law this time, an exponential material law. * The material law needs to inherit from `AbstractIncompressibleMaterialLaw`, * and there are a few implemented, see `continuum_mechanics/src/problem/material_laws` */ ExponentialMaterialLaw<2> law(1.0, 0.5); // First parameter is 'a', second 'b', in W=a*exp(b(I1-3)) /* Now specify the fixed nodes, and their new locations. Create `std::vector`s for each. */ std::vector<unsigned> fixed_nodes; std::vector<c_vector<double,2> > locations; /* Loop over the mesh nodes */ for (unsigned i=0; i<mesh.GetNumNodes(); i++) { /* If the node is on the Y=0 surface (the LHS) */ if ( fabs(mesh.GetNode(i)->rGetLocation()[1])<1e-6) { /* Add it to the list of fixed nodes */ fixed_nodes.push_back(i); /* and define a new position x=(X,0.1*X^2^) */ c_vector<double,2> new_location; double X = mesh.GetNode(i)->rGetLocation()[0]; new_location(0) = X; new_location(1) = 0.1*X*X; locations.push_back(new_location); } } /* Now collect all the boundary elements on the top surface, as before, except * here we don't create the tractions for each element */ std::vector<BoundaryElement<1,2>*> boundary_elems; for (TetrahedralMesh<2,2>::BoundaryElementIterator iter = mesh.GetBoundaryElementIteratorBegin(); iter != mesh.GetBoundaryElementIteratorEnd(); ++iter) { /* If Y=1, have found a boundary element */ if (fabs((*iter)->CalculateCentroid()[1] - 1.0)<1e-6) { BoundaryElement<1,2>* p_element = *iter; boundary_elems.push_back(p_element); } } /* Create a problem definition object, and this time calling `SetFixedNodes` * which takes in the new locations of the fixed nodes. */ SolidMechanicsProblemDefinition<2> problem_defn(mesh); problem_defn.SetMaterialLaw(INCOMPRESSIBLE,&law); problem_defn.SetFixedNodes(fixed_nodes, locations); /* Now call `SetTractionBoundaryConditions`, which takes in a vector of * boundary elements as in the previous test. However this time the second argument * is a ''function pointer'' (just the name of the function) to a * function returning traction in terms of position (and time [see below]). * This function is defined above, before the tests. It has to take in a `c_vector` (position) * and a double (time), and returns a `c_vector` (traction), and will only be called * using points in the boundary elements being passed in. The function `MyTraction` * (defined above, before the tests) above defines a horizontal traction (ie a shear stress, since it is * applied to the top surface) which increases in magnitude across the object. */ problem_defn.SetTractionBoundaryConditions(boundary_elems, MyTraction); /* Note: You can also call `problem_defn.SetBodyForce(MyBodyForce)`, passing in a function * instead of a vector, although isn't really physically useful, it is only really useful * for constructing problems with exact solutions. * * Create the solver as before */ IncompressibleNonlinearElasticitySolver<2> solver(mesh, problem_defn, "IncompressibleElasticityMoreComplicatedExample"); /* Call `Solve()` */ solver.Solve(); /* Another quick check */ TS_ASSERT_EQUALS(solver.GetNumNewtonIterations(), 6u); /* Visualise as before. * * '''Advanced:''' Note that the function `MyTraction` takes in time, which it didn't use. In the above it would have been called * with t=0. The current time can be set using `SetCurrentTime()`. The idea is that the user may want to solve a * sequence of static problems with time-dependent tractions (say), for which they should allow `MyTraction` to * depend on time, and put the solve inside a time-loop, for example: */ //for (double t=0; t<T; t+=dt) //{ // solver.SetCurrentTime(t); // solver.Solve(); //} /* In this the current time would be passed through to `MyTraction` * * Create Cmgui output */ solver.CreateCmguiOutput(); /* This is just to check that nothing has been accidentally changed in this test */ TS_ASSERT_DELTA(solver.rGetDeformedPosition()[98](0), 1.4543, 1e-3); TS_ASSERT_DELTA(solver.rGetDeformedPosition()[98](1), 0.5638, 1e-3); }
void GameState::updateGameState() { // Do nothing if the game is not in playing state if(m_game_state == STATE_MENU) { //s->setBgVolume(0); s->playSound(SOUND_INTRO); } else if (m_game_state == STATE_SHOP) { //s->playSound(SOUND_INTRO); } else if(m_game_state == STATE_PLAYING) { // Update the player location sf::Vector2f delta; switch(m_player_direction) { case DIRECTION_LEFT: delta = sf::Vector2f(-5,0); m_velocity -= gravity/(rocket.aerodynamic/10); break; case DIRECTION_RIGHT: delta = sf::Vector2f(5,0); m_velocity -= gravity/(rocket.aerodynamic/10); break; default: delta = sf::Vector2f(0,0); break; } delta.y -= m_velocity; m_velocity -= gravity; // Apply delta to the player position sf::Vector2f new_location(getPlayerLocation() + delta); // Check if new position is inside the game area if(new_location.x < 0) { new_location.x = 0; } else if(new_location.x + ROBOT_WIDTH >= m_size_x) { new_location.x = m_size_x - ROBOT_WIDTH; } setPlayerLocation(new_location); // Update location if(new_location.y < 0 && m_velocity < 0) { setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected); m_dodgecoins_collected =0; setPlayerLocation(sf::Vector2f(m_size_x/2-ROBOT_WIDTH/2,m_size_y/2-ROBOT_HEIGHT/2)); // Reset Player Location std::cout << "totalcoins: " << total_dodgecoins <<std::endl; startShop(); } else if ((getPlayerLocation().y/100)*-1 >= 2500 && rocket.coolness >= 9000) // Aus PräsentationsgrĂ¼nden auf 500 gesetzt, normal 2000 { startEnd(); } // Bounding box of the player sf::FloatRect player_box(getPlayerLocation(),sf::Vector2f(ROBOT_WIDTH,ROBOT_HEIGHT)); //ADD COIN addDodgecoin(); //add meteor addMeteor(); std::vector<sf::Vector2f>::iterator s_it; s_it = m_dodgecoin_locations.begin(); // Check for each coin location ... while(s_it != m_dodgecoin_locations.end()) { // ... if the rocket is collecting the coin sf::FloatRect dodgecoin_box(*s_it,sf::Vector2f(COIN_WIDTH,COIN_HEIGHT)); if(dodgecoin_box.intersects(player_box)) { // Remove coin m_dodgecoin_locations.erase(s_it); m_dodgecoins_collected++; } else { // Advance iterator to next coin s_it++; } } s_it = m_meteor_locations.begin(); // Check for each meteor location ... while(s_it != m_meteor_locations.end()) { // ... if the rocket is colliding the meteor sf::FloatRect meteor_box(*s_it,sf::Vector2f(80,80)); if(meteor_box.intersects(player_box)) { // Remove meteor m_meteor_locations.erase(s_it); m_velocity -= 50*gravity; } else { // Advance iterator to next coin s_it++; } } } else if(m_game_state == STATE_MINI) { // Update the player location sf::Vector2f delta; switch(m_player_direction) { case DIRECTION_LEFT: delta = sf::Vector2f(-5,0); break; //std::cout << "leftmini" <<std::endl; case DIRECTION_RIGHT: delta = sf::Vector2f(5,0); break; //std::cout << "rightmini" <<std::endl; case DIRECTION_UP: delta = sf::Vector2f(0,0); break; case DIRECTION_DOWN: delta = sf::Vector2f(0,0); break; default: delta = sf::Vector2f(0,0); break; } // Apply delta to the player position sf::Vector2f new_location(getPlayerLocation() + delta); // Check if new position is inside the game area if(new_location.x >= 0 && new_location.x + ROBOT_WIDTH <= m_size_x) { setPlayerLocation(new_location); // Update location //std::cout << "neue position??" << std::endl; } if(new_location.x >=1200) { setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected); m_dodgecoins_collected =0; startShop(); } // Bounding box of the player sf::FloatRect player_box(getPlayerLocation(),sf::Vector2f(ROBOT_WIDTH,ROBOT_HEIGHT)); std::vector<sf::Vector2f>::iterator s_it; s_it = m_dodgecoin_locations.begin(); // Check for each coin location ... while(s_it != m_dodgecoin_locations.end()) { // ... if the nils is collecting the coin sf::FloatRect dodgecoin_box(*s_it,sf::Vector2f(COIN_WIDTH,COIN_HEIGHT)); if(dodgecoin_box.intersects(player_box)) { // Remove coin m_dodgecoin_locations.erase(s_it); m_dodgecoins_collected++; //std::cout << "coooooooooooooiiiiin" << std::endl; //setTotalDodgecoins(total_dodgecoins + m_dodgecoins_collected); std::cout << "totalcoins: " << total_dodgecoins <<std::endl; std::cout << "collectedcoins: " << m_dodgecoins_collected <<std::endl; } else { // Advance iterator to next coin s_it++; } } } else if(m_game_state == STATE_CREDITS) { } else if (m_game_state == STATE_END) { } else // Do nothing if the game is not in mini state { return; } //startEnd(); }