void testQLDSolver() { BaseVariable xy("xy",2); BaseVariable z("z",1); CompositeVariable T("T", xy, z); MatrixXd A1(1,1); A1 << 1; VectorXd b1(1); b1 << -3; LinearFunction lf1(z, A1, b1); LinearConstraint c1(&lf1, true); MatrixXd A2(1,2); A2 << 3,1 ; VectorXd b2(1); b2 << 0; LinearFunction lf2(xy, A2, b2); LinearConstraint c2(&lf2, true); MatrixXd A3(2,2); A3 << 2,1,-0.5,1 ; VectorXd b3(2); b3 << 0, 1; LinearFunction lf3(xy, A3, b3); LinearConstraint c3(&lf3, false); QuadraticFunction objFunc(T, Matrix3d::Identity(), Vector3d::Zero(), 0); QuadraticObjective obj(&objFunc); QLDSolver solver; solver.addConstraint(c1); solver.addConstraint(c2); solver.addConstraint(c3); solver.addObjective(obj); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); solver.removeConstraint(c1); IdentityFunction id(z); VectorXd lz(1); lz << 1; VectorXd uz(1); uz << 2; IdentityConstraint bnd1(&id, lz, uz); solver.addBounds(bnd1); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); BaseVariable t("t", 2); VectorXd ut(2); ut << -4,-1; BoundFunction bf(t, ut, BOUND_TYPE_SUPERIOR); BoundConstraint bnd2(&bf, false); solver.addBounds(bnd2); QuadraticFunction objFunc2(t, Matrix2d::Identity(), Vector2d::Constant(2.71828),0); QuadraticObjective obj2(&objFunc2); solver.addObjective(obj2); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); Vector2d c3l(-1,-1); c3.setL(c3l); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); }
int main(void) { UnitTest ut("Swift Image Analysis Classes"); // test_lowercomplete(ut); test_channeloffsets(ut); //test_runlengthencode(ut); // test_segmentation(ut); //test_swiftimage(ut); //test_crosschannelregistration(ut); //test_imageanalysis(ut); // test_channelregistration(ut); // test_watershed(ut); //test_morphologicalopening(ut); //test_morphologicalclosing(ut); //test_sobeloperator(ut); //test_adaptivethreshold(ut); //test_nwthreshold(ut); // test_euclideandistancemap(ut); // test_localmaxima(ut); ut.test_report(); return 0; }
ExecStatus ManProp<ManTask,Cap>::propagate(Space& home, const ModEventDelta& med) { // Only bounds changes? if (Int::IntView::me(med) != Int::ME_INT_DOM) GECODE_ES_CHECK(overload(home,c.max(),t)); GECODE_ES_CHECK(edgefinding(home,c.max(),t)); bool subsumed; ExecStatus es = basic(home,subsumed,c,t); GECODE_ES_CHECK(es); if (subsumed) return home.ES_SUBSUMED(*this); if (Cap::varderived() && c.assigned() && c.val()==1) { // Check that tasks do not overload resource for (int i=t.size(); i--; ) if (t[i].c() > 1) return ES_FAILED; // Rewrite to unary resource constraint TaskArray<typename TaskTraits<ManTask>::UnaryTask> ut(home,t.size()); for (int i=t.size(); i--;) ut[i]=t[i]; GECODE_REWRITE(*this, (Unary::ManProp<typename TaskTraits<ManTask>::UnaryTask> ::post(home(*this),ut))); } else { return es; } }
ExecStatus ManProp<ManTask,Cap,PL>::propagate(Space& home, const ModEventDelta& med) { // Only bounds changes? if (IntView::me(med) != ME_INT_DOM) GECODE_ES_CHECK(overload(home,c.max(),t)); if (PL::advanced) GECODE_ES_CHECK(edgefinding(home,c.max(),t)); if (PL::basic) GECODE_ES_CHECK(timetabling(home,*this,c,t)); if (Cap::varderived() && c.assigned() && (c.val() == 1)) { // Check that tasks do not overload resource for (int i=t.size(); i--; ) if (t[i].c() > 1) return ES_FAILED; // Rewrite to unary resource constraint TaskArray<typename TaskTraits<ManTask>::UnaryTask> ut(home,t.size()); for (int i=t.size(); i--;) ut[i]=t[i]; GECODE_REWRITE(*this, (Unary::ManProp<typename TaskTraits<ManTask>::UnaryTask,PL> ::post(home(*this),ut))); } if (!PL::basic && c.assigned()) GECODE_ES_CHECK(subsumed(home,*this,c.val(),t)); return ES_NOFIX; }
int main(void) { UnitTest ut("Repeatscore Tests"); test_repeatscore(ut); ut.test_report(); return 0; }
void KStarsData::resetToNewDST(GeoLocation *geo, const bool automaticDSTchange) { // reset tzrules data with local time, timezone offset and time direction (forward or backward) // force a DST change with option true for 3. parameter geo->tzrule()->reset_with_ltime( LTime, geo->TZ0(), TimeRunsForward, automaticDSTchange ); // reset next DST change time setNextDSTChange( geo->tzrule()->nextDSTChange() ); //reset LTime, because TZoffset has changed LTime = geo->UTtoLT( ut() ); }
FX_BOOL CFX_DateTime::FromUnitime(FX_UNITIME t) { CFX_Unitime ut(t); FX_DaysToDate(ut.GetDayOfAD(), m_DateTime.Date.sDate.year, m_DateTime.Date.sDate.month, m_DateTime.Date.sDate.day); m_DateTime.Date.sDate.day = ut.GetHour(); m_DateTime.Time.sTime.minute = ut.GetMinute(); m_DateTime.Time.sTime.second = ut.GetSecond(); m_DateTime.Time.sTime.millisecond = ut.GetMillisecond(); return TRUE; }
int main(void) { UnitTest ut("CrossTalkCorrection Classes"); test_crosstalkcorrection(ut); ut.test_report(); return 0; }
/** * Simplifies the given UnionType by removing duplicate types. If the resulting * UnionType contains only one type, that type is returned instead of the union. */ NodePtr simplify(const UnionType::Ptr& input) { // Remove duplicate types. NodeVector newTypes; copyUnique(input->getTypes(), newTypes); // Return either the new union or the only type left in the vector, if there's one. if (newTypes.size() == 1) { return newTypes.front(); } UnionType::Ptr ut(new UnionType); ut->setTypes(newTypes); return ut; }
int main() { ServerRouting server(*(BaseWorld*)0, "mason", "test_server", "1", 1, "2", 2); CommServer comm_server(server); { UpdateTester ut(comm_server); } { UpdateTester ut(comm_server); ut.idle(0); } { UpdateTester ut(comm_server); stub_getclass_returns = NULLCLASS; ut.idle(0); stub_getclass_returns = NOCLASS; } { UpdateTester ut(comm_server); stub_getclass_returns = OAKCLASS; ut.idle(0); stub_getclass_returns = NOCLASS; } return 0; }
static void test_value_move_ctor () { rw_info (0, __FILE__, __LINE__, "value move constructor"); #define INTEGER_CONSTANT 256 std::tuple<int> it1 (INTEGER_CONSTANT); test (__LINE__, it1, INTEGER_CONSTANT); const int c = std::rand (); int i = c; // move semantics can alter source value std::tuple<int> it2 (i); // temporary source value test (__LINE__, it2, c); const std::tuple<int> it3 (INTEGER_CONSTANT); test (__LINE__, it3, INTEGER_CONSTANT); i = c; const std::tuple<int> it4 (i); test (__LINE__, it4, c); std::tuple<const int> ct1 (INTEGER_CONSTANT); test (__LINE__, ct1, INTEGER_CONSTANT); i = c; std::tuple<const int> ct2 (i); test (__LINE__, ct2, c); // ill-formed for tuples with element types containing references std::tuple<std::tuple<int> > nt (it1); test (__LINE__, nt, it1); std::tuple<long, const char*> pt (123456789L, "string"); test (__LINE__, pt, 123456789L, (const char*) "string"); const UserDefined src (c); UserDefined tmp (src); UserDefined::reset (); std::tuple<UserDefined> ut (tmp); UserDefined::expect.move_ctor = 1; test (__LINE__, ut, src); tmp = src; ++UserDefined::expect.copy_asgn; std::tuple<bool, char, int, double, void*, UserDefined> bt (true, 'a', INTEGER_CONSTANT, 3.14159, (void*) 0, tmp); ++UserDefined::expect.move_ctor; test (__LINE__, bt, true, 'a', INTEGER_CONSTANT, 3.14159, (void*) 0, src); }
void KStarsData::changeDateTime( const KStarsDateTime &newDate ) { //Turn off animated slews for the next time step. setSnapNextFocus(); clock()->setUTC( newDate ); LTime = geo()->UTtoLT( ut() ); //set local sideral time syncLST(); //Make sure Numbers, Moon, planets, and sky objects are updated immediately setFullTimeUpdate(); // reset tzrules data with new local time and time direction (forward or backward) geo()->tzrule()->reset_with_ltime(LTime, geo()->TZ0(), isTimeRunningForward() ); // reset next dst change time setNextDSTChange( geo()->tzrule()->nextDSTChange() ); }
static void test_value_copy_ctor () { rw_info (0, __FILE__, __LINE__, "value copy constructor"); const int i = std::rand (); std::tuple<int> it1 (i); test (__LINE__, it1, i); const std::tuple<int> it2 (i); test (__LINE__, it2, i); std::tuple<const int> ct (i); test (__LINE__, ct, i); int j = std::rand (); const std::tuple<int&> rt (j); test (__LINE__, rt, j); std::tuple<std::tuple<int> > nt (it2); //std::get<0> (it2) = std::rand (); // diliberately cause assertion test (__LINE__, nt, it2); const long l = std::rand (); std::tuple<long, const char*> pt (l, "string"); test (__LINE__, pt, l, (const char*) "string"); const UserDefined ud (i); UserDefined::reset (); std::tuple<UserDefined> ut (ud); UserDefined::expect.copy_ctor = 1; test (__LINE__, ut, ud); const bool b = true; const char c = 'a'; const double d = 3.14159; void* const p = (void*) &i; std::tuple<bool, char, int, double, void*, UserDefined> bt (b, c, i, d, p, ud); ++UserDefined::expect.copy_ctor; test (__LINE__, bt, b, c, i, d, p, ud); }
void ReceiverTest::onData() { bool forMe = false; // Broadcast BroadcastTransmissionPtr bt( new BroadcastTransmission( wns::osi::PDUPtr(new wns::ldk::helper::FakePDU(100)), transmitter)); forMe = receiver->onData(bt); CPPUNIT_ASSERT_EQUAL( 1, handler->cOnData ); WNS_ASSERT_MAX_REL_ERROR( 0.1, handler->ber, 1E-10); CPPUNIT_ASSERT( forMe ); // Unicast UnicastTransmissionPtr ut( new UnicastTransmission( wns::service::dll::UnicastAddress(2), wns::osi::PDUPtr(new wns::ldk::helper::FakePDU(100)), transmitter)); forMe = receiver->onData(ut); CPPUNIT_ASSERT_EQUAL( 1, handler->cOnData ); CPPUNIT_ASSERT( !forMe ); UnicastTransmissionPtr ut2( new UnicastTransmission( wns::service::dll::UnicastAddress(1), wns::osi::PDUPtr(new wns::ldk::helper::FakePDU(100)), transmitter)); forMe = receiver->onData(ut2); CPPUNIT_ASSERT_EQUAL( 2, handler->cOnData ); CPPUNIT_ASSERT( forMe ); }
constexpr Direction left(Direction d) { using ut = std::underlying_type<Direction>::type; return (Direction)((ut(d) + ut(Direction::NUMBER_OF_DIRECTIONS)-1) % ut(Direction::NUMBER_OF_DIRECTIONS)); }
utree invoke (phxpr::shared_ptr<F> const& f) const { utree ut(spirit::any_ptr(checkout().get())); return f->eval(ut); }
utree invoke (F const& f) const { utree ut(spirit::any_ptr(checkout().get())); return f.eval(ut); }
void KStarsData::syncLST() { LST = geo()->GSTtoLST( ut().gst() ); }
void KStarsData::updateTime( GeoLocation *geo, SkyMap *skymap, const bool automaticDSTchange ) { // sync LTime with the simulation clock LTime = geo->UTtoLT( ut() ); syncLST(); //Only check DST if (1) TZrule is not the empty rule, and (2) if we have crossed //the DST change date/time. if ( !geo->tzrule()->isEmptyRule() ) { if ( TimeRunsForward ) { // timedirection is forward // DST change happens if current date is bigger than next calculated dst change if ( ut() > NextDSTChange ) resetToNewDST(geo, automaticDSTchange); } else { // timedirection is backward // DST change happens if current date is smaller than next calculated dst change if ( ut() < NextDSTChange ) resetToNewDST(geo, automaticDSTchange); } } KSNumbers num( ut().djd() ); if ( fabs( ut().djd() - LastNumUpdate.djd() ) > 1.0 ) { LastNumUpdate = ut().djd(); m_preUpdateNumID++; m_preUpdateNum = KSNumbers( num ); skyComposite()->update( &num ); } if ( fabs( ut().djd() - LastPlanetUpdate.djd() ) > 0.01 ) { LastPlanetUpdate = ut().djd(); skyComposite()->updatePlanets( &num ); } // Moon moves ~30 arcmin/hr, so update its position every minute. if ( fabs( ut().djd() - LastMoonUpdate.djd() ) > 0.00069444 ) { LastMoonUpdate = ut(); skyComposite()->updateMoons( &num ); } //Update Alt/Az coordinates. Timescale varies with zoom level //If Clock is in Manual Mode, always update. (?) if ( fabs( ut().djd() - LastSkyUpdate.djd() ) > 0.1/Options::zoomFactor() || clock()->isManualMode() ) { LastSkyUpdate = ut(); m_preUpdateID++; skyComposite()->update(); //omit KSNumbers arg == just update Alt/Az coords //Update focus skymap->updateFocus(); if ( clock()->isManualMode() ) QTimer::singleShot( 0, skymap, SLOT( forceUpdateNow() ) ); else skymap->forceUpdate(); } }
int main(int argc, char *argv[]) { Opt2 opt(argc, argv, "v", 0); opt_ut_verbose = opt.Has('v', "- some verboseness"); opt.AutoUsageErr(""); ut_optspec = "A:ab:C:"; ut("prog -A argA -a -b 22 -C argC Pos1 Pos2", false, "argA", 22, true, "Pos1", "Pos2"); ut("prog Pos1 -A argA -a -C argC Pos2", false, "argA", 2, true, "Pos1", "Pos2"); ut("prog -A argA Pos1 -b22 Pos2 -C argC", false, "argA", 22, false, "Pos1", "Pos2"); ut("prog -A argA Pos1 -b 22 Pos2 -C", true, "argA", 22, false, "Pos1", "Pos2"); ut("prog -A argA -a -b 22 -C Pos1 Pos2", true, "argA", 22, true, "Pos1", "Pos2"); ut("prog -A argA -a -b two -C argC Pos1 Pos2", true, "argA", 2, true, "Pos1", "Pos2"); ut("prog -a -b 22 -C argC Pos1 Pos2", true, "argA", 22, true, "Pos1", "Pos2"); ut("prog Pos1 --option-1=argA -a -C argC Pos2", false, "argA", 2, true, "Pos1", "Pos2"); ut("prog Pos1 -A argA --option-1 -a -C argC Pos2", true, "argA", 2, true, "Pos1", "Pos2"); ut("prog -A argA --option-2 -b -22 -C argC Pos1 Pos2", false, "argA", -22, true, "Pos1", "Pos2"); ut("prog -A argA --option-2 -b -22 -- -C argC", false, "argA", -22, true, "-C", "argC"); ut("prog -A argA --option-2=1 -b -22 -C argC Pos1 Pos2", true, "argA", -22, true, "Pos1", "Pos2"); ut_optspec = "+A:ab:C:"; ut("prog -A argA --option-2 v1 -C", false, "argA", 2, true, "v1", "-C"); ut("prog -A argA --option-2 v1 -C argC", true, "argA", 2, true, "v1", "-C"); if (!opt2_ut_fail) fprintf(stderr, "All OK\n"); return opt2_ut_fail; }
int ns_data_print(pp_Data * p, double x[], const Exo_DB * exo, const double time_value, const double time_step_size) { const int quantity = p->data_type; int mat_num = p->mat_num; const int elemBlock_id = p->elem_blk_id; const int node_set_id = p->ns_id; const int species_id = p->species_number; const char * filenm = p->data_filenm; const char * qtity_str = p->data_type_name; const char * format_flag = p->format_flag; int * first_time = &(p->first_time); static int err=0; int num_nodes_on_side; int ebIndex_first = -1; int local_side[2]; int side_nodes[3]; /* Assume quad has no more than 3 per side. */ int elem_list[4], elem_ct=0, face, ielem, node2; int local_node[4]; int node = -1; int idx, idy, idz, id_var; int iprint; int nsp; /* node set pointer for this node set */ dbl x_pos, y_pos, z_pos; int j, wspec; int doPressure = 0; #ifdef PARALLEL double some_time=0.0; #endif double abscissa=0; double ordinate=0; double n1[3], n2[3]; double xi[3]; /* * Find an element block that has the desired material id. */ if (elemBlock_id != -1) { for (j = 0; j < exo->num_elem_blocks; j++) { if (elemBlock_id == exo->eb_id[j]) { ebIndex_first = j; break; } } if (ebIndex_first == -1) { sprintf(err_msg, "Can't find an element block with the elem Block id %d\n", elemBlock_id); if (Num_Proc == 1) { EH(-1, err_msg); } } mat_num = Matilda[ebIndex_first]; p->mat_num = mat_num; pd = pd_glob[mat_num]; } else { mat_num = -1; p->mat_num = -1; pd = pd_glob[0]; } nsp = match_nsid(node_set_id); if( nsp != -1 ) { node = Proc_NS_List[Proc_NS_Pointers[nsp]]; } else { sprintf(err_msg, "Node set ID %d not found.", node_set_id); if( Num_Proc == 1 ) EH(-1,err_msg); } /* first right time stamp or run stamp to separate the sets */ print_sync_start(FALSE); if (*first_time) { if ( format_flag[0] != '\0' ) { if (ProcID == 0) { uf = fopen(filenm,"a"); if (uf != NULL) { fprintf(uf,"# %s %s @ nsid %d node (%d) \n", format_flag, qtity_str, node_set_id, node ); *first_time = FALSE; fclose(uf); } } } } if (format_flag[0] == '\0') { if (ProcID == 0) { if ((uf = fopen(filenm,"a")) != NULL) { fprintf(uf,"Time/iteration = %e \n", time_value); fprintf(uf," %s Node_Set %d Species %d\n", qtity_str,node_set_id,species_id); fflush(uf); fclose(uf); } } } if (nsp != -1 ) { for (j = 0; j < Proc_NS_Count[nsp]; j++) { node = Proc_NS_List[Proc_NS_Pointers[nsp]+j]; if (node < num_internal_dofs + num_boundary_dofs ) { idx = Index_Solution(node, MESH_DISPLACEMENT1, 0, 0, -1); if (idx == -1) { x_pos = Coor[0][node]; WH(idx, "Mesh variable not found. May get undeformed coords."); } else { x_pos = Coor[0][node] + x[idx]; } idy = Index_Solution(node, MESH_DISPLACEMENT2, 0, 0, -1); if (idy == -1) { y_pos = Coor[1][node]; } else { y_pos = Coor[1][node] + x[idy]; } z_pos = 0.; if(pd->Num_Dim == 3) { idz = Index_Solution(node, MESH_DISPLACEMENT3, 0, 0, -1); if (idz == -1) { z_pos = Coor[2][node]; } else{ z_pos = Coor[2][node] + x[idz]; } } if (quantity == MASS_FRACTION) { id_var = Index_Solution(node, quantity, species_id, 0, mat_num); } else if (quantity < 0) { id_var = -1; } else { id_var = Index_Solution(node, quantity, 0, 0, mat_num); } /* * In the easy case, the variable can be found somewhere in the * big vector of unknowns. But sometimes we want a derived quantity * that requires a little more work than an array reference. * * For now, save the good result if we have it. */ if ( id_var != -1 ) { ordinate = x[id_var]; iprint = 1; } else { /* * If we have an element based interpolation, let's calculate the interpolated value */ if (quantity == PRESSURE) { if ((pd->i[PRESSURE] == I_P1) || ( (pd->i[PRESSURE] > I_PQ1) && (pd->i[PRESSURE] < I_Q2_HVG) )) { doPressure = 1; } } iprint = 0; } /* * If the quantity is "theta", an interior angle that only * makes sense at a point, in 2D, we'll need to compute it. */ if ( strncasecmp(qtity_str, "theta", 5 ) == 0 || doPressure) { /* * Look for the two sides connected to this node...? * * Premise: * 1. The node appears in only one element(removed-RBS,6/14/06) * 2. Exactly two sides emanate from the node. * 3. Quadrilateral. * * Apologies to people who wish to relax premise 1. I know * there are some obtuse angles out there that benefit from * having more than one element at a vertex. With care, this * procedure could be extended to cover that case as well. */ if ( ! exo->node_elem_conn_exists ) { EH(-1, "Cannot compute angle without node_elem_conn."); } elem_list[0] = exo->node_elem_list[exo->node_elem_pntr[node]]; /* * Find out where this node appears in the elements local * node ordering scheme... */ local_node[0] = in_list(node, exo->elem_node_pntr[elem_list[0]], exo->elem_node_pntr[elem_list[0]+1], exo->elem_node_list); EH(local_node[0], "Can not find node in elem node connectivity!?! "); local_node[0] -= exo->elem_node_pntr[elem_list[0]]; /* check for neighbors*/ if( mat_num == find_mat_number(elem_list[0], exo)) {elem_ct = 1;} else {WH(-1,"block id doesn't match first element");} for (face=0 ; face<ei->num_sides ; face++) { ielem = exo->elem_elem_list[exo->elem_elem_pntr[elem_list[0]]+face]; if (ielem != -1) { node2 = in_list(node, exo->elem_node_pntr[ielem], exo->elem_node_pntr[ielem+1], exo->elem_node_list); if (node2 != -1 && (mat_num == find_mat_number(ielem, exo))) { elem_list[elem_ct] = ielem; local_node[elem_ct] = node2; local_node[elem_ct] -= exo->elem_node_pntr[ielem]; elem_ct++; } } } /* * Note that indeces are zero based! */ ordinate = 0.0; for (ielem = 0 ; ielem < elem_ct ; ielem++) { if ( local_node[ielem] < 0 || local_node[ielem] > 3 ) { if (strncasecmp(qtity_str, "theta", 5 ) == 0) { EH(-1, "Node out of bounds."); } } /* * Now, determine the local name of the sides adjacent to this * node...this works for the exo patran convention for quads... * * Again, local_node and local_side are zero based... */ local_side[0] = (local_node[ielem]+3)%4; local_side[1] = local_node[ielem]; /* * With the side names, we can find the normal vector. * Again, assume the sides live on the same element. */ load_ei(elem_list[ielem], exo, 0); /* * We abuse the argument list under the conditions that * we're going to do read-only operations and that * we're not interested in old time steps, time derivatives * etc. */ if (x == x_static) /* be the least disruptive possible */ { err = load_elem_dofptr(elem_list[ielem], exo, x_static, x_old_static, xdot_static, xdot_old_static, x_static, 1); } else { err = load_elem_dofptr(elem_list[ielem], exo, x, x, x, x, x, 1); } /* * What are the local coordinates of the nodes in a quadrilateral? */ find_nodal_stu(local_node[ielem], ei->ielem_type, xi, xi+1, xi+2); err = load_basis_functions(xi, bfd); EH( err, "problem from load_basis_functions"); err = beer_belly(); EH( err, "beer_belly"); err = load_fv(); EH( err, "load_fv"); err = load_bf_grad(); EH( err, "load_bf_grad"); err = load_bf_mesh_derivs(); EH(err, "load_bf_mesh_derivs"); if (doPressure) { ordinate = fv->P; iprint = 1; } else { /* First, one side... */ get_side_info(ei->ielem_type, local_side[0]+1, &num_nodes_on_side, side_nodes); surface_determinant_and_normal(elem_list[ielem], exo->elem_node_pntr[elem_list[ielem]], ei->num_local_nodes, ei->ielem_dim-1, local_side[0]+1, num_nodes_on_side, side_nodes); n1[0] = fv->snormal[0]; n1[1] = fv->snormal[1]; /* Second, the adjacent side of the quad... */ get_side_info(ei->ielem_type, local_side[1]+1, &num_nodes_on_side, side_nodes); surface_determinant_and_normal(elem_list[ielem], exo->elem_node_pntr[elem_list[ielem]], ei->num_local_nodes, ei->ielem_dim-1, local_side[1]+1, num_nodes_on_side, side_nodes); n2[0] = fv->snormal[0]; n2[1] = fv->snormal[1]; /* cos (theta) = n1.n2 / ||n1|| ||n2|| */ ordinate += 180. - (180./M_PI)*acos((n1[0]*n2[0] + n1[1]*n2[1])/ (sqrt(n1[0]*n1[0]+n1[1]*n1[1])* sqrt(n2[0]*n2[0]+n2[1]*n2[1]))); } iprint = 1; } /*ielem loop */ } else if ( strncasecmp(qtity_str, "timestepsize", 12 ) == 0 ) { ordinate = time_step_size; iprint = 1; } else if ( strncasecmp(qtity_str, "cputime", 7 ) == 0 ) { ordinate = ut(); iprint = 1; } else if ( strncasecmp(qtity_str, "wallclocktime", 13 ) == 0 ) { /* Get these from extern via main...*/ #ifdef PARALLEL some_time = MPI_Wtime(); ordinate = some_time - time_goma_started; #endif #ifndef PARALLEL time_t now=0; (void)time(&now); ordinate = (double)(now) - time_goma_started; #endif iprint = 1; } else if ( strncasecmp(qtity_str, "speed", 5 ) == 0 ) { id_var = Index_Solution(node, VELOCITY1, 0, 0, mat_num); ordinate = SQUARE(x[id_var]); id_var = Index_Solution(node, VELOCITY2, 0, 0, mat_num); ordinate += SQUARE(x[id_var]); id_var = Index_Solution(node, VELOCITY3, 0, 0, mat_num); ordinate += SQUARE(x[id_var]); ordinate = sqrt(ordinate); iprint = 1; } else if ( strncasecmp(qtity_str, "ac_pres", 7 ) == 0 ) { id_var = Index_Solution(node, ACOUS_PREAL, 0, 0, mat_num); ordinate = SQUARE(x[id_var]); id_var = Index_Solution(node, ACOUS_PIMAG, 0, 0, mat_num); ordinate += SQUARE(x[id_var]); ordinate = sqrt(ordinate); iprint = 1; } else if ( strncasecmp(qtity_str, "light_comp", 10 ) == 0 ) { id_var = Index_Solution(node, LIGHT_INTP, 0, 0, mat_num); ordinate = x[id_var]; id_var = Index_Solution(node, LIGHT_INTM, 0, 0, mat_num); ordinate += x[id_var]; iprint = 1; } else if ( strncasecmp(qtity_str, "nonvolatile", 11 ) == 0 ) { ordinate = 1.0; for(wspec = 0 ; wspec < pd->Num_Species_Eqn ; wspec++) { id_var = Index_Solution(node, MASS_FRACTION, wspec, 0, mat_num); ordinate -= x[id_var]*mp_glob[mat_num]->molar_volume[wspec]; } iprint = 1; } else { WH(id_var, "Requested print variable is not defined at all nodes. May get 0."); if(id_var == -1) iprint = 0; } if ((uf=fopen(filenm,"a")) != NULL) { if ( format_flag[0] == '\0' ) { if (iprint) { fprintf(uf," %e %e %e %e \n", x_pos, y_pos, z_pos, ordinate); } } else { if ( strncasecmp(format_flag, "t", 1) == 0 ) { abscissa = time_value; } else if ( strncasecmp(format_flag, "x", 1) == 0 ) { abscissa = x_pos; } else if ( strncasecmp(format_flag, "y", 1) == 0 ) { abscissa = y_pos; } else if ( strncasecmp(format_flag, "z", 1) == 0 ) { abscissa = z_pos; } else { abscissa = 0; } if (iprint) { fprintf(uf, "%.16g\t%.16g\n", abscissa, ordinate); } } fclose(uf); } } } } print_sync_end(FALSE); return(1); } /* END of routine ns_data_print */
void RBBIAPITest::TestGetSetAdoptText() { logln((UnicodeString)"Testing getText setText "); IcuTestErrorCode status(*this, "TestGetSetAdoptText"); UnicodeString str1="first string."; UnicodeString str2="Second string."; LocalPointer<RuleBasedBreakIterator> charIter1((RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status)); LocalPointer<RuleBasedBreakIterator> wordIter1((RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status)); if(status.isFailure()){ errcheckln(status, "Fail : in construction - %s", status.errorName()); return; } CharacterIterator* text1= new StringCharacterIterator(str1); CharacterIterator* text1Clone = text1->clone(); CharacterIterator* text2= new StringCharacterIterator(str2); CharacterIterator* text3= new StringCharacterIterator(str2, 3, 10, 3); // "ond str" wordIter1->setText(str1); CharacterIterator *tci = &wordIter1->getText(); UnicodeString tstr; tci->getText(tstr); TEST_ASSERT(tstr == str1); if(wordIter1->current() != 0) errln((UnicodeString)"ERROR:1 setText did not set the iteration position to the beginning of the text, it is" + wordIter1->current() + (UnicodeString)"\n"); wordIter1->next(2); wordIter1->setText(str2); if(wordIter1->current() != 0) errln((UnicodeString)"ERROR:2 setText did not reset the iteration position to the beginning of the text, it is" + wordIter1->current() + (UnicodeString)"\n"); charIter1->adoptText(text1Clone); TEST_ASSERT(wordIter1->getText() != charIter1->getText()); tci = &wordIter1->getText(); tci->getText(tstr); TEST_ASSERT(tstr == str2); tci = &charIter1->getText(); tci->getText(tstr); TEST_ASSERT(tstr == str1); LocalPointer<RuleBasedBreakIterator> rb((RuleBasedBreakIterator*)wordIter1->clone()); rb->adoptText(text1); if(rb->getText() != *text1) errln((UnicodeString)"ERROR:1 error in adoptText "); rb->adoptText(text2); if(rb->getText() != *text2) errln((UnicodeString)"ERROR:2 error in adoptText "); // Adopt where iterator range is less than the entire orignal source string. // (With the change of the break engine to working with UText internally, // CharacterIterators starting at positions other than zero are not supported) rb->adoptText(text3); TEST_ASSERT(rb->preceding(2) == 0); TEST_ASSERT(rb->following(11) == BreakIterator::DONE); //if(rb->preceding(2) != 3) { // errln((UnicodeString)"ERROR:3 error in adoptText "); //} //if(rb->following(11) != BreakIterator::DONE) { // errln((UnicodeString)"ERROR:4 error in adoptText "); //} // UText API // // Quick test to see if UText is working at all. // const char *s1 = "\x68\x65\x6C\x6C\x6F\x20\x77\x6F\x72\x6C\x64"; /* "hello world" in UTF-8 */ const char *s2 = "\x73\x65\x65\x20\x79\x61"; /* "see ya" in UTF-8 */ // 012345678901 status.reset(); LocalUTextPointer ut(utext_openUTF8(NULL, s1, -1, status)); wordIter1->setText(ut.getAlias(), status); TEST_ASSERT_SUCCESS(status); int32_t pos; pos = wordIter1->first(); TEST_ASSERT(pos==0); pos = wordIter1->next(); TEST_ASSERT(pos==5); pos = wordIter1->next(); TEST_ASSERT(pos==6); pos = wordIter1->next(); TEST_ASSERT(pos==11); pos = wordIter1->next(); TEST_ASSERT(pos==UBRK_DONE); status.reset(); LocalUTextPointer ut2(utext_openUTF8(NULL, s2, -1, status)); TEST_ASSERT_SUCCESS(status); wordIter1->setText(ut2.getAlias(), status); TEST_ASSERT_SUCCESS(status); pos = wordIter1->first(); TEST_ASSERT(pos==0); pos = wordIter1->next(); TEST_ASSERT(pos==3); pos = wordIter1->next(); TEST_ASSERT(pos==4); pos = wordIter1->last(); TEST_ASSERT(pos==6); pos = wordIter1->previous(); TEST_ASSERT(pos==4); pos = wordIter1->previous(); TEST_ASSERT(pos==3); pos = wordIter1->previous(); TEST_ASSERT(pos==0); pos = wordIter1->previous(); TEST_ASSERT(pos==UBRK_DONE); status.reset(); UnicodeString sEmpty; LocalUTextPointer gut2(utext_openUnicodeString(NULL, &sEmpty, status)); wordIter1->getUText(gut2.getAlias(), status); TEST_ASSERT_SUCCESS(status); status.reset(); }
void MapModuleNoticeContainer:: initUsingCC( const vector<MapModuleNotice*>& oldVector ) { // This method should only be used for the old index.db. // Go through all the notices for ( uint32 i = 0; i < oldVector.size(); i++ ) { MapModuleNotice* notice = oldVector[i]; addNotice( notice, true ); // True means that regions should be faked. } // Build the ItemIDTrees // We know that the top-regions only contain countries. // Save all the overview maps in a map sorted by cc. // WARNING: This will not work when there is more than // one overview map per region,. map<StringTable::countryCode, uint32> overviewMaps; typedef multimap<StringTable::countryCode, uint32> underviewMapMap_t; underviewMapMap_t underviewMaps; for( uint32 i = 0; i < oldVector.size(); ++i ) { MapModuleNotice* notice = m_allNotices[i]; if ( MapBits::isCountryMap(notice->getMapID()) ) { overviewMaps[m_allNotices[i]->getCountryCode()] = MapBits::countryToOverview(notice->getMapID()); } else if ( MapBits::isUnderviewMap( notice->getMapID() ) ) { underviewMaps.insert(make_pair(m_allNotices[i]->getCountryCode(), notice->getMapID())); } } // Loop over the found overview maps. for( map<StringTable::countryCode, uint32>::iterator it(overviewMaps.begin()); it != overviewMaps.end(); ++it ) { // Add the top level. ItemIDTree* idTree = findRegion( it->first )->getItemIDTreeForWriting(); idTree->addMap( MAX_UINT32, it->second ); // Add to or internal tree of all maps too. m_mapTree.addMap( MAX_UINT32, it->second ); // Get the range of underview maps with the same county code pair<underviewMapMap_t::const_iterator, underviewMapMap_t::const_iterator> range = underviewMaps.equal_range( it->first ); for ( underviewMapMap_t::const_iterator ut(range.first); ut != range.second; ++ut ) { // Add it to the tree of the region idTree->addMap( it->second, ut->second); // Also add it to our tree of maps. m_mapTree.addMap( it->second, ut->second ); } } #ifdef DEBUG_LEVEL_4 for(uint32 i = 0; i < m_allNotices.size(); ++i ) { mc2dbg << "Overview maps for " << m_allNotices[i]->getMapID() << endl; vector<uint32> overviewIDs; m_mapTree.getOverviewMapsFor(m_allNotices[i]->getMapID(), overviewIDs); for(uint32 j = 0; j < overviewIDs.size(); ++j ) { mc2dbg << " " << j << "=" << overviewIDs[j] << endl; } } #endif #ifdef DEBUG_LEVEL_4 // Print stuff mc2dbg << "MAP_HIERARCHY" << endl; set<uint32> mapIDs; m_mapTree.getTopLevelMapIDs(mapIDs); for(set<uint32>::const_iterator it = mapIDs.begin(); it != mapIDs.end(); ++it) { mc2dbg << "TopLevelMap :" << hex << *it << dec << " contains " << endl; set<IDPair_t> items; m_mapTree.getContents(*it, items); for( set<IDPair_t>::iterator it = items.begin(); it != items.end(); ++it ) { mc2dbg << " " << it->getMapID() << ":" << hex << it->getItemID() << dec << endl; } } #endif }