GPPtr<GPParameter> GPParticleSwarmOpt::vFindBest(int n, IGPOptimizor::OPTFUNC computer, GPFLOAT* target) const
{
    GPASSERT(n>0);
    GPASSERT(mSize>=1);
    GPASSERT(mTimes>=1);
    std::vector<GPPtr<Particle> > group;
    group.reserve(mSize);

    GPRandom::init();
    for (int i=0; i<mSize; ++i)
    {
        GPPtr<Particle> p = (new Particle(n, mVmax, mThe1, mThe2));
        p->randomInit();
        GPFLOAT fit = computer(p->expand());
        p->setFit(fit);
        group.push_back(p);
    }
    GPPtr<Particle> bestP;
    for (int i=0; i<mTimes; ++i)
    {
        for (int j=0; j<mSize; ++j)
        {
            GPPtr<Particle> p = group[j];
            GPFLOAT fit = computer(p->expand());
            p->updateFit(fit);
        }
        /*Find Best One*/
        bestP = group[0];
        for (int j=1; j<mSize; ++j)
        {
            if (group[j]->fit() > bestP->fit())
            {
                bestP = group[j];
            }
        }
        if (NULL!=target)
        {
            if (*target <= bestP->fit())
            {
                break;
            }
        }
        /*Get the max distance before, Determin if we can break*/
        GPFLOAT maxDis_before = max_distance(group);
        /*Move all Particle*/
        for (int j=0; j<mSize; ++j)
        {
            GPPtr<Particle> p = group[j];
            p->move(bestP);
        }
        /*Get the max distance after, Determin if we can break*/
        GPFLOAT maxDis_after = max_distance(group);
        if (maxDis_before < mMinDistance*n && maxDis_after < mMinDistance*n)
        {
            break;
        }
    }
    bestP->fix();
    return bestP->expand();
}
Esempio n. 2
0
uint max_distance(TreeNode* root)
{
    if (root == NULL) {
        return 0;
    }

    static std::tr1::unordered_map<void*, uint> cache;

    typeof(cache.begin()) it = cache.find(root);
    if (it != cache.end()) {
        return it->second;
    }

    uint leftCost = max_distance(root->left);
    uint rightCost = max_distance(root->right);

    uint leftHeight = height(root->left);
    uint rightHeight = height(root->right);

    uint childCost = leftCost > rightCost ? leftCost : rightCost;
    uint throughRoot = leftHeight + rightHeight + root->cost;

    uint ret = childCost > throughRoot ? childCost : throughRoot;
    cache.insert(std::make_pair(root, ret));

    return ret;
}
Esempio n. 3
0
void test_with_ax(std::string const& wkt,
        std::string const& expected,
        T const& adt,
        T const& xdt)
{
    typedef typename bg::point_type<Geometry>::type point_type;
    typedef bg::strategy::distance::detail::projected_point_ax<> ax_type;
    typedef typename bg::strategy::distance::services::return_type
    <
        bg::strategy::distance::detail::projected_point_ax<>,
        point_type,
        point_type
    >::type return_type;

    typedef bg::strategy::distance::detail::projected_point_ax_less
    <
        return_type
    > comparator_type;

    typedef bg::strategy::simplify::detail::douglas_peucker
    <
        point_type,
        bg::strategy::distance::detail::projected_point_ax<>,
        comparator_type
    > dp_ax;

    return_type max_distance(adt, xdt);
    comparator_type comparator(max_distance);
    dp_ax strategy(comparator);

    test_geometry<Geometry>(wkt, expected, max_distance, strategy);
}
Esempio n. 4
0
static void test_central_extraction() {
    engine::InputPlane traits;
    traits.image.size.fill( 100 * camera::pixel );
    traits.image.set_resolution( 0, 230 * si::nanometre / camera::pixel );
    traits.image.set_resolution( 1, 120 * si::nanometre / camera::pixel );
    traits.optics.set_projection_factory(  traits::test_scaled_projection() );
    traits.create_projection();

    Spot max_distance( Spot::Constant( 1.6 ) );
    Optics optics( max_distance, traits );

    Spot position;
    position.x() = 5.6;
    position.y() = 3.0;

    dStorm::engine::Image2D image( traits.image.size );
    for (int x = 0; x < traits.image.size.x().value(); ++x)
        for (int y = 0; y < traits.image.size.y().value(); ++y)
            image(x,y) = x + y;

    PlaneCreatorImpl< nonlinfit::plane::xs_disjoint<double,14>::type > extractor(optics);
    std::auto_ptr<Plane> data = extractor.extract_data( image, position );
    BOOST_CHECK_CLOSE( data->pixel_size, 230E-3 * 120E-3, 1 );
    BOOST_CHECK_CLOSE( data->highest_pixel.x(), 7130E-3, 1 );
    BOOST_CHECK_CLOSE( data->highest_pixel.y(), 4560E-3, 1 );
    BOOST_CHECK_CLOSE( data->integral, 18711, 1 );
    BOOST_CHECK_CLOSE( data->peak_intensity, 69, 1 );
    BOOST_CHECK_CLOSE( data->background_estimate, 43, 1 );
    BOOST_CHECK_CLOSE( data->standard_deviation[0], 870E-3, 1 );
    BOOST_CHECK_CLOSE( data->standard_deviation[1], 636E-3, 1 );
    BOOST_CHECK_EQUAL( data->pixel_count, 378 );
}
Esempio n. 5
0
/**
   \brief Select features by coordinates
 
   \param[in] Map vector map
   \param[in] type feature type
   \param[in] coords coordinates GRASS parameters
   \param[in] thresh threshold value for searching
   \param[in,out] List list of selected features

   \return number of selected lines
*/
int sel_by_coordinates(struct Map_info *Map,
		       int type, struct line_pnts *coords, double thresh,
		       struct ilist *List)
{
    int i;
    double east, north, maxdist;

    struct ilist *List_tmp, *List_in_box;
    struct line_pnts *box;

    if (first_selection) {
	List_tmp = List;
	first_selection = 0;
    }
    else {
	List_tmp = Vect_new_list();
    }

    box = Vect_new_line_struct();
    List_in_box = Vect_new_list();

    if (thresh < 0)
	maxdist = max_distance(thresh);
    else
	maxdist = thresh;

    for (i = 0; i < coords->n_points; i++) {
	east = coords->x[i];
	north = coords->y[i];

	coord2bbox(east, north, maxdist, box);

	Vect_select_lines_by_polygon(Map, box, 0, NULL, type, List_in_box);

	if (List_in_box->n_values > 0)
	    Vect_list_append_list(List_tmp, List_in_box);
    }

    G_debug(1, "  %d lines selected (by coordinates)", List_tmp->n_values);

    /* merge lists (only duplicate items) */
    if (List_tmp != List) {
	merge_lists(List, List_tmp);
	Vect_destroy_list(List_tmp);
    }

    Vect_destroy_line_struct(box);
    Vect_destroy_list(List_in_box);

    return List->n_values;
}
Esempio n. 6
0
double dist_ps(const struct graph *g, long x, long y)
{
  long lca, dax, day, dra;
  VEC(long) *lx, *ly;

  if (!init_metric)
    fatal("Error, uninitialized data for metric calcule");

  lx = get_list_ancestors(x);
  ly = get_list_ancestors(y);
  lca = LCA_CA(lx, ly, depth);
  dax = min_distance(g, lca, x);
  day = min_distance(g, lca, y);
  dra = max_distance(g, ROOT, lca);

  return dps(dax, day, dra);
}
Esempio n. 7
0
TEST(laplacian, laplacian_of_gaussian) {
	const size_t N = 42;
	const double len = 12;
	const double dx = len/N;
	const DataLayout dl(N, N, dx);
	const Transformer tr(dl);
	State G(dl, test_laplacian_reference::initfunc);
	StateArray work(0, dl);
	Laplacian Lapl(tr);
	Lapl(G, work);
	State R(dl, test_laplacian_reference::referencefunc);
	const double rmsdist = rms_distance(G,R);
	const double maxdist = max_distance(G,R);
	ASSERT_LT(rmsdist, 100*machine_epsilon);
	ASSERT_LT(maxdist, 1000*machine_epsilon);
	if (dump_data) {
		Datafile file("data/test_laplacian.h5", dl, true);
		file.write_state(0, 0, G);
		file.write_state(0, 1, R);
	}
}
Esempio n. 8
0
int main()
{
    TreeNode* root = new TreeNode;
    root->cost = 1;
    TreeNode* node1 = new TreeNode;
    node1->cost = 1;
    TreeNode* node2 = new TreeNode;
    node2->cost = 1;
    TreeNode* node3 = new TreeNode;
    node3->cost = 1;
    TreeNode* node4 = new TreeNode;
    node4->cost = 1;
    TreeNode* node5 = new TreeNode;
    node5->cost = 1;
    TreeNode* node6 = new TreeNode;
    node6->cost = 1;
    TreeNode* node7 = new TreeNode;
    node7->cost = 1;
    TreeNode* node8 = new TreeNode;
    node8->cost = 8;
    TreeNode* node9 = new TreeNode;
    node9->cost = 9;

    root->left = node1;
    root->right = node2;
    node1->left = node3;
    node2->left = node4;
    node2->right = node5;
    node3->left = node6;
    node4->left = node7;
    node5->left = node8;
    node5->right = node9;

    std::cout << max_distance(root) << std::endl;

    A* a = new B;
    a->f();

    return 0;
}
Esempio n. 9
0
int is_alive(int x, int y, int z, int* config, int n)
{
	int i, j, k, d;
	int alive_cnt = 0;
	int cnt = 0;
	int i_min, i_max, j_min, j_max, k_min, k_max;


	d = max_distance(x, y, z);
	i_min = max(x - d, 0);
	i_max = min(x + d + 1, n);
	j_min = max(y - d, 0);
	j_max = min(y + d + 1, n);
	k_min = max(z - d, 0);
	k_max = min(z + d + 1, n);
	for (i = i_min; i < i_max; ++ i) {
		for (j = j_min; j < j_max; ++ j) {
			for (k = k_min; k < k_max; ++ k) {
				if (x == i && y == j && z == k)
					continue;
				if (config[i * n * n + j * n + k]) 
					++ alive_cnt;
				++ cnt;
			}	
		}
	}
	if (alive_cnt * 100 < cnt * LOWER_DEATH_LIMIT)
		return 0;
	
	if (alive_cnt * 100 > cnt * UPPER_DEATH_LIMIT)
		return 0;
	
	if (alive_cnt * 100 > cnt * LOWER_CHANGE_LIMIT && alive_cnt * 100 < cnt * UPPER_CHANGE_LIMIT) {
		if (config[x * n * n + y * n + z]) 
			return 0;
		return 1;
	}
	return 1;
}
Esempio n. 10
0
Real FE<2,XYZ>::shape(const Elem* elem,
                      const Order libmesh_dbg_var(order),
                      const unsigned int i,
                      const Point& point_in)
{
#if LIBMESH_DIM > 1

  libmesh_assert(elem);

  // Only recompute the centroid if the element
  // has changed from the last one we computed.
  // This avoids repeated centroid calculations
  // when called in succession with the same element.
  if (elem->id() != old_elem_id)
    {
      centroid = elem->centroid();
      old_elem_id = elem->id();
      max_distance = Point(0.,0.,0.);
      for (unsigned int p = 0; p < elem->n_nodes(); p++)
        for (unsigned int d = 0; d < 2; d++)
          {
            const Real distance = std::abs(centroid(d) - elem->point(p)(d));
            max_distance(d) = std::max(distance, max_distance(d));
          }
    }

  // Using static globals for old_elem_id, etc. will fail
  // horribly with more than one thread.
  libmesh_assert_equal_to (libMesh::n_threads(), 1);

  const Real x  = point_in(0);
  const Real y  = point_in(1);
  const Real xc = centroid(0);
  const Real yc = centroid(1);
  const Real distx = max_distance(0);
  const Real disty = max_distance(1);
  const Real dx = (x - xc)/distx;
  const Real dy = (y - yc)/disty;

#ifndef NDEBUG
  // totalorder is only used in the assertion below, so
  // we avoid declaring it when asserts are not active.
  const unsigned int totalorder = order + elem->p_level();
#endif
  libmesh_assert_less (i, (totalorder+1)*(totalorder+2)/2);


  // monomials. since they are hierarchic we only need one case block.
  switch (i)
    {
      // constant
    case 0:
      return 1.;

      // linear
    case 1:
      return dx;

    case 2:
      return dy;

      // quadratics
    case 3:
      return dx*dx;

    case 4:
      return dx*dy;

    case 5:
      return dy*dy;

      // cubics
    case 6:
      return dx*dx*dx;

    case 7:
      return dx*dx*dy;

    case 8:
      return dx*dy*dy;

    case 9:
      return dy*dy*dy;

      // quartics
    case 10:
      return dx*dx*dx*dx;

    case 11:
      return dx*dx*dx*dy;

    case 12:
      return dx*dx*dy*dy;

    case 13:
      return dx*dy*dy*dy;

    case 14:
      return dy*dy*dy*dy;

    default:
      unsigned int o = 0;
      for (; i >= (o+1)*(o+2)/2; o++) { }
      unsigned int i2 = i - (o*(o+1)/2);
      Real val = 1.;
      for (unsigned int index=i2; index != o; index++)
        val *= dx;
      for (unsigned int index=0; index != i2; index++)
        val *= dy;
      return val;
    }

  libmesh_error();
  return 0.;

#endif
}
Esempio n. 11
0
int main(int argc, char **argv)
{
    std::vector<double> points;
    std::vector<unsigned> faces;
    geodesic::read_mesh_from_file("hedgehog_mesh.txt",points,faces);

    geodesic::Mesh mesh;
    mesh.initialize_mesh_data(points, faces);		//create internal mesh data structure including edges

    geodesic::GeodesicAlgorithmExact exact_algorithm(&mesh);		//exact algorithm
    geodesic::GeodesicAlgorithmDijkstra dijkstra_algorithm(&mesh);		//simplest approximate algorithm: path only allowed on the edges of the mesh
    unsigned const subdivision_level = 3;										//three additional vertices per every edge in subdivision algorithm
    geodesic::GeodesicAlgorithmSubdivision subdivision_algorithm(&mesh,2);	//with subdivision_level=0 this algorithm becomes Dijkstra, with subdivision_level->infinity it becomes exact

    std::vector<geodesic::GeodesicAlgorithmBase* > all_algorithms;		//for simplicity, store all possible geodesic algorithms here
    all_algorithms.push_back(&dijkstra_algorithm);
    all_algorithms.push_back(&subdivision_algorithm);
    all_algorithms.push_back(&exact_algorithm);

    std::vector<geodesic::SurfacePoint> sources;
    sources.push_back(geodesic::SurfacePoint(&mesh.vertices()[0]));		//one source is located at vertex zero
    sources.push_back(geodesic::SurfacePoint(&mesh.edges()[12]));		//second source is located in the middle of edge 12
    sources.push_back(geodesic::SurfacePoint(&mesh.faces()[20]));		//third source is located in the middle of face 20

    std::vector<geodesic::SurfacePoint> targets;		//same thing with targets
    targets.push_back(geodesic::SurfacePoint(&mesh.vertices().back()));
    targets.push_back(geodesic::SurfacePoint(&mesh.edges()[10]));
    targets.push_back(geodesic::SurfacePoint(&mesh.faces()[3]));

    for(unsigned index=0; index<all_algorithms.size(); ++index)
    {
        geodesic::GeodesicAlgorithmBase* algorithm = all_algorithms[index];		//all algorithms are derived from GeodesicAlgorithmBase
        std::cout << std::endl << "results for algorithm " << algorithm->name() << std::endl;

        algorithm->propagate(sources);		//cover the whole mesh
        algorithm->print_statistics();

        //------------------first task: compute the pathes to the targets----
        std::vector<geodesic::SurfacePoint> path;
        for(int i=0; i<targets.size(); ++i)
        {
            algorithm->trace_back(targets[i], path);
            print_info_about_path(path);
        }

        //------------------second task: for each source, find the furthest vertex that it covers ----
        std::vector<double> max_distance(sources.size(), 0.0);		//distance to the furthest vertex that is covered by the given source
        for(int i=0; i<mesh.vertices().size(); ++i)
        {
            geodesic::SurfacePoint p(&mesh.vertices()[i]);
            double distance;
            unsigned best_source = algorithm->best_source(p,distance);

            max_distance[best_source] = std::max(max_distance[best_source], distance);
        }

        std::cout << std::endl;
        for(int i=0; i<max_distance.size(); ++i)
        {
            std::cout << "distance to the furthest vertex that is covered by source " << i
                      << " is " << max_distance[i]
                      << std::endl;
        }
    }
    return 0;
}
Esempio n. 12
0
Real FE<3,XYZ>::shape_second_deriv(const Elem * elem,
                                   const Order libmesh_dbg_var(order),
                                   const unsigned int i,
                                   const unsigned int j,
                                   const Point & point_in)
{
#if LIBMESH_DIM == 3

  libmesh_assert(elem);
  libmesh_assert_less (j, 6);

  Point centroid = elem->centroid();
  Point max_distance = Point(0.,0.,0.);
  for (unsigned int p = 0; p < elem->n_nodes(); p++)
    for (unsigned int d = 0; d < 3; d++)
      {
        const Real distance = std::abs(centroid(d) - elem->point(p)(d));
        max_distance(d) = std::max(distance, max_distance(d));
      }

  const Real x  = point_in(0);
  const Real y  = point_in(1);
  const Real z  = point_in(2);
  const Real xc = centroid(0);
  const Real yc = centroid(1);
  const Real zc = centroid(2);
  const Real distx = max_distance(0);
  const Real disty = max_distance(1);
  const Real distz = max_distance(2);
  const Real dx = (x - xc)/distx;
  const Real dy = (y - yc)/disty;
  const Real dz = (z - zc)/distz;
  const Real dist2x = pow(distx,2.);
  const Real dist2y = pow(disty,2.);
  const Real dist2z = pow(distz,2.);
  const Real distxy = distx * disty;
  const Real distxz = distx * distz;
  const Real distyz = disty * distz;

#ifndef NDEBUG
  // totalorder is only used in the assertion below, so
  // we avoid declaring it when asserts are not active.
  const unsigned int totalorder = static_cast<Order>(order + elem->p_level());
#endif
  libmesh_assert_less (i, (static_cast<unsigned int>(totalorder)+1)*
                       (static_cast<unsigned int>(totalorder)+2)*
                       (static_cast<unsigned int>(totalorder)+3)/6);

  // monomials. since they are hierarchic we only need one case block.
  switch (j)
    {
      // d^2()/dx^2
    case 0:
      {
        switch (i)
          {
            // constant
          case 0:

            // linear
          case 1:
          case 2:
          case 3:
            return 0.;

            // quadratic
          case 4:
            return 2./dist2x;

          case 5:
          case 6:
          case 7:
          case 8:
          case 9:
            return 0.;

            // cubic
          case 10:
            return 6.*dx/dist2x;

          case 11:
            return 2.*dy/dist2x;

          case 12:
          case 13:
            return 0.;

          case 14:
            return 2.*dz/dist2x;

          case 15:
          case 16:
          case 17:
          case 18:
          case 19:
            return 0.;

            // quartics
          case 20:
            return 12.*dx*dx/dist2x;

          case 21:
            return 6.*dx*dy/dist2x;

          case 22:
            return 2.*dy*dy/dist2x;

          case 23:
          case 24:
            return 0.;

          case 25:
            return 6.*dx*dz/dist2x;

          case 26:
            return 2.*dy*dz/dist2x;

          case 27:
          case 28:
            return 0.;

          case 29:
            return 2.*dz*dz/dist2x;

          case 30:
          case 31:
          case 32:
          case 33:
          case 34:
            return 0.;

          default:
            unsigned int o = 0;
            for (; i >= (o+1)*(o+2)*(o+3)/6; o++) { }
            unsigned int i2 = i - (o*(o+1)*(o+2)/6);
            unsigned int block=o, nz = 0;
            for (; block < i2; block += (o-nz+1)) { nz++; }
            const unsigned int nx = block - i2;
            const unsigned int ny = o - nx - nz;
            Real val = nx * (nx - 1);
            for (unsigned int index=2; index < nx; index++)
              val *= dx;
            for (unsigned int index=0; index != ny; index++)
              val *= dy;
            for (unsigned int index=0; index != nz; index++)
              val *= dz;
            return val/dist2x;
          }
      }


      // d^2()/dxdy
    case 1:
      {
        switch (i)
          {
            // constant
          case 0:

            // linear
          case 1:
          case 2:
          case 3:
            return 0.;

            // quadratic
          case 4:
            return 0.;

          case 5:
            return 1./distxy;

          case 6:
          case 7:
          case 8:
          case 9:
            return 0.;

            // cubic
          case 10:
            return 0.;

          case 11:
            return 2.*dx/distxy;

          case 12:
            return 2.*dy/distxy;

          case 13:
          case 14:
            return 0.;

          case 15:
            return dz/distxy;

          case 16:
          case 17:
          case 18:
          case 19:
            return 0.;

            // quartics
          case 20:
            return 0.;

          case 21:
            return 3.*dx*dx/distxy;

          case 22:
            return 4.*dx*dy/distxy;

          case 23:
            return 3.*dy*dy/distxy;

          case 24:
          case 25:
            return 0.;

          case 26:
            return 2.*dx*dz/distxy;

          case 27:
            return 2.*dy*dz/distxy;

          case 28:
          case 29:
            return 0.;

          case 30:
            return dz*dz/distxy;

          case 31:
          case 32:
          case 33:
          case 34:
            return 0.;

          default:
            unsigned int o = 0;
            for (; i >= (o+1)*(o+2)*(o+3)/6; o++) { }
            unsigned int i2 = i - (o*(o+1)*(o+2)/6);
            unsigned int block=o, nz = 0;
            for (; block < i2; block += (o-nz+1)) { nz++; }
            const unsigned int nx = block - i2;
            const unsigned int ny = o - nx - nz;
            Real val = nx * ny;
            for (unsigned int index=1; index < nx; index++)
              val *= dx;
            for (unsigned int index=1; index < ny; index++)
              val *= dy;
            for (unsigned int index=0; index != nz; index++)
              val *= dz;
            return val/distxy;
          }
      }


      // d^2()/dy^2
    case 2:
      {
        switch (i)
          {
            // constant
          case 0:

            // linear
          case 1:
          case 2:
          case 3:
            return 0.;

            // quadratic
          case 4:
          case 5:
            return 0.;

          case 6:
            return 2./dist2y;

          case 7:
          case 8:
          case 9:
            return 0.;

            // cubic
          case 10:
          case 11:
            return 0.;

          case 12:
            return 2.*dx/dist2y;
          case 13:
            return 6.*dy/dist2y;

          case 14:
          case 15:
            return 0.;

          case 16:
            return 2.*dz/dist2y;

          case 17:
          case 18:
          case 19:
            return 0.;

            // quartics
          case 20:
          case 21:
            return 0.;

          case 22:
            return 2.*dx*dx/dist2y;

          case 23:
            return 6.*dx*dy/dist2y;

          case 24:
            return 12.*dy*dy/dist2y;

          case 25:
          case 26:
            return 0.;

          case 27:
            return 2.*dx*dz/dist2y;

          case 28:
            return 6.*dy*dz/dist2y;

          case 29:
          case 30:
            return 0.;

          case 31:
            return 2.*dz*dz/dist2y;

          case 32:
          case 33:
          case 34:
            return 0.;

          default:
            unsigned int o = 0;
            for (; i >= (o+1)*(o+2)*(o+3)/6; o++) { }
            unsigned int i2 = i - (o*(o+1)*(o+2)/6);
            unsigned int block=o, nz = 0;
            for (; block < i2; block += (o-nz+1)) { nz++; }
            const unsigned int nx = block - i2;
            const unsigned int ny = o - nx - nz;
            Real val = ny * (ny - 1);
            for (unsigned int index=0; index != nx; index++)
              val *= dx;
            for (unsigned int index=2; index < ny; index++)
              val *= dy;
            for (unsigned int index=0; index != nz; index++)
              val *= dz;
            return val/dist2y;
          }
      }


      // d^2()/dxdz
    case 3:
      {
        switch (i)
          {
            // constant
          case 0:

            // linear
          case 1:
          case 2:
          case 3:
            return 0.;

            // quadratic
          case 4:
          case 5:
          case 6:
            return 0.;

          case 7:
            return 1./distxz;

          case 8:
          case 9:
            return 0.;

            // cubic
          case 10:
          case 11:
          case 12:
          case 13:
            return 0.;

          case 14:
            return 2.*dx/distxz;

          case 15:
            return dy/distxz;

          case 16:
            return 0.;

          case 17:
            return 2.*dz/distxz;

          case 18:
          case 19:
            return 0.;

            // quartics
          case 20:
          case 21:
          case 22:
          case 23:
          case 24:
            return 0.;

          case 25:
            return 3.*dx*dx/distxz;

          case 26:
            return 2.*dx*dy/distxz;

          case 27:
            return dy*dy/distxz;

          case 28:
            return 0.;

          case 29:
            return 4.*dx*dz/distxz;

          case 30:
            return 2.*dy*dz/distxz;

          case 31:
            return 0.;

          case 32:
            return 3.*dz*dz/distxz;

          case 33:
          case 34:
            return 0.;

          default:
            unsigned int o = 0;
            for (; i >= (o+1)*(o+2)*(o+3)/6; o++) { }
            unsigned int i2 = i - (o*(o+1)*(o+2)/6);
            unsigned int block=o, nz = 0;
            for (; block < i2; block += (o-nz+1)) { nz++; }
            const unsigned int nx = block - i2;
            const unsigned int ny = o - nx - nz;
            Real val = nx * nz;
            for (unsigned int index=1; index < nx; index++)
              val *= dx;
            for (unsigned int index=0; index != ny; index++)
              val *= dy;
            for (unsigned int index=1; index < nz; index++)
              val *= dz;
            return val/distxz;
          }
      }

      // d^2()/dydz
    case 4:
      {
        switch (i)
          {
            // constant
          case 0:

            // linear
          case 1:
          case 2:
          case 3:
            return 0.;

            // quadratic
          case 4:
          case 5:
          case 6:
          case 7:
            return 0.;

          case 8:
            return 1./distyz;

          case 9:
            return 0.;

            // cubic
          case 10:
          case 11:
          case 12:
          case 13:
          case 14:
            return 0.;

          case 15:
            return dx/distyz;

          case 16:
            return 2.*dy/distyz;

          case 17:
            return 0.;

          case 18:
            return 2.*dz/distyz;

          case 19:
            return 0.;

            // quartics
          case 20:
          case 21:
          case 22:
          case 23:
          case 24:
          case 25:
            return 0.;

          case 26:
            return dx*dx/distyz;

          case 27:
            return 2.*dx*dy/distyz;

          case 28:
            return 3.*dy*dy/distyz;

          case 29:
            return 0.;

          case 30:
            return 2.*dx*dz/distyz;

          case 31:
            return 4.*dy*dz/distyz;

          case 32:
            return 0.;

          case 33:
            return 3.*dz*dz/distyz;

          case 34:
            return 0.;

          default:
            unsigned int o = 0;
            for (; i >= (o+1)*(o+2)*(o+3)/6; o++) { }
            unsigned int i2 = i - (o*(o+1)*(o+2)/6);
            unsigned int block=o, nz = 0;
            for (; block < i2; block += (o-nz+1)) { nz++; }
            const unsigned int nx = block - i2;
            const unsigned int ny = o - nx - nz;
            Real val = ny * nz;
            for (unsigned int index=0; index != nx; index++)
              val *= dx;
            for (unsigned int index=1; index < ny; index++)
              val *= dy;
            for (unsigned int index=1; index < nz; index++)
              val *= dz;
            return val/distyz;
          }
      }


      // d^2()/dz^2
    case 5:
      {
        switch (i)
          {
            // constant
          case 0:

            // linear
          case 1:
          case 2:
          case 3:
            return 0.;

            // quadratic
          case 4:
          case 5:
          case 6:
          case 7:
          case 8:
            return 0.;

          case 9:
            return 2./dist2z;

            // cubic
          case 10:
          case 11:
          case 12:
          case 13:
          case 14:
          case 15:
          case 16:
            return 0.;

          case 17:
            return 2.*dx/dist2z;

          case 18:
            return 2.*dy/dist2z;

          case 19:
            return 6.*dz/dist2z;

            // quartics
          case 20:
          case 21:
          case 22:
          case 23:
          case 24:
          case 25:
          case 26:
          case 27:
          case 28:
            return 0.;

          case 29:
            return 2.*dx*dx/dist2z;

          case 30:
            return 2.*dx*dy/dist2z;

          case 31:
            return 2.*dy*dy/dist2z;

          case 32:
            return 6.*dx*dz/dist2z;

          case 33:
            return 6.*dy*dz/dist2z;

          case 34:
            return 12.*dz*dz/dist2z;

          default:
            unsigned int o = 0;
            for (; i >= (o+1)*(o+2)*(o+3)/6; o++) { }
            unsigned int i2 = i - (o*(o+1)*(o+2)/6);
            unsigned int block=o, nz = 0;
            for (; block < i2; block += (o-nz+1)) { nz++; }
            const unsigned int nx = block - i2;
            const unsigned int ny = o - nx - nz;
            Real val = nz * (nz - 1);
            for (unsigned int index=0; index != nx; index++)
              val *= dx;
            for (unsigned int index=0; index != ny; index++)
              val *= dy;
            for (unsigned int index=2; index < nz; index++)
              val *= dz;
            return val/dist2z;
          }
      }


    default:
      libmesh_error_msg("Invalid j = " << j);
    }

#endif

  libmesh_error_msg("We'll never get here!");
  return 0.;
}
Esempio n. 13
0
Real FE<3,XYZ>::shape(const Elem * elem,
                      const Order libmesh_dbg_var(order),
                      const unsigned int i,
                      const Point & point_in)
{
#if LIBMESH_DIM == 3
  libmesh_assert(elem);

  Point centroid = elem->centroid();
  Point max_distance = Point(0.,0.,0.);
  for (unsigned int p = 0; p < elem->n_nodes(); p++)
    for (unsigned int d = 0; d < 3; d++)
      {
        const Real distance = std::abs(centroid(d) - elem->point(p)(d));
        max_distance(d) = std::max(distance, max_distance(d));
      }

  const Real x  = point_in(0);
  const Real y  = point_in(1);
  const Real z  = point_in(2);
  const Real xc = centroid(0);
  const Real yc = centroid(1);
  const Real zc = centroid(2);
  const Real distx = max_distance(0);
  const Real disty = max_distance(1);
  const Real distz = max_distance(2);
  const Real dx = (x - xc)/distx;
  const Real dy = (y - yc)/disty;
  const Real dz = (z - zc)/distz;

#ifndef NDEBUG
  // totalorder is only used in the assertion below, so
  // we avoid declaring it when asserts are not active.
  const unsigned int totalorder = order + elem->p_level();
#endif
  libmesh_assert_less (i, (static_cast<unsigned int>(totalorder)+1)*
                       (static_cast<unsigned int>(totalorder)+2)*
                       (static_cast<unsigned int>(totalorder)+3)/6);

  // monomials. since they are hierarchic we only need one case block.
  switch (i)
    {
      // constant
    case 0:
      return 1.;

      // linears
    case 1:
      return dx;

    case 2:
      return dy;

    case 3:
      return dz;

      // quadratics
    case 4:
      return dx*dx;

    case 5:
      return dx*dy;

    case 6:
      return dy*dy;

    case 7:
      return dx*dz;

    case 8:
      return dz*dy;

    case 9:
      return dz*dz;

      // cubics
    case 10:
      return dx*dx*dx;

    case 11:
      return dx*dx*dy;

    case 12:
      return dx*dy*dy;

    case 13:
      return dy*dy*dy;

    case 14:
      return dx*dx*dz;

    case 15:
      return dx*dy*dz;

    case 16:
      return dy*dy*dz;

    case 17:
      return dx*dz*dz;

    case 18:
      return dy*dz*dz;

    case 19:
      return dz*dz*dz;

      // quartics
    case 20:
      return dx*dx*dx*dx;

    case 21:
      return dx*dx*dx*dy;

    case 22:
      return dx*dx*dy*dy;

    case 23:
      return dx*dy*dy*dy;

    case 24:
      return dy*dy*dy*dy;

    case 25:
      return dx*dx*dx*dz;

    case 26:
      return dx*dx*dy*dz;

    case 27:
      return dx*dy*dy*dz;

    case 28:
      return dy*dy*dy*dz;

    case 29:
      return dx*dx*dz*dz;

    case 30:
      return dx*dy*dz*dz;

    case 31:
      return dy*dy*dz*dz;

    case 32:
      return dx*dz*dz*dz;

    case 33:
      return dy*dz*dz*dz;

    case 34:
      return dz*dz*dz*dz;

    default:
      unsigned int o = 0;
      for (; i >= (o+1)*(o+2)*(o+3)/6; o++) { }
      unsigned int i2 = i - (o*(o+1)*(o+2)/6);
      unsigned int block=o, nz = 0;
      for (; block < i2; block += (o-nz+1)) { nz++; }
      const unsigned int nx = block - i2;
      const unsigned int ny = o - nx - nz;
      Real val = 1.;
      for (unsigned int index=0; index != nx; index++)
        val *= dx;
      for (unsigned int index=0; index != ny; index++)
        val *= dy;
      for (unsigned int index=0; index != nz; index++)
        val *= dz;
      return val;
    }

#endif

  libmesh_error_msg("We'll never get here!");
  return 0.;
}
Esempio n. 14
0
 inline static Importance::value_type max_search_range() {
   return hi::square_of(max_distance());
 }
Esempio n. 15
0
int main(int argc, char *argv[])
{
    struct GModule *module;
    struct GParams params;
    struct Map_info Map;
    struct Map_info **BgMap;	/* backgroud vector maps */
    int nbgmaps;		/* number of registrated background maps */
    enum mode action_mode;
    FILE *ascii;

    int i;
    int move_first, snap;
    int ret, layer;
    double move_x, move_y, move_z, thresh[3];

    struct line_pnts *coord;

    struct ilist *List;

    struct cat_list *Clist;

    ascii = NULL;
    List = NULL;
    BgMap = NULL;
    nbgmaps = 0;
    coord = NULL;
    Clist = NULL;

    G_gisinit(argv[0]);

    module = G_define_module();
    module->overwrite = TRUE;
    G_add_keyword(_("vector"));
    G_add_keyword(_("editing"));
    G_add_keyword(_("geometry"));
    module->description = _("Edits a vector map, allows adding, deleting "
			    "and modifying selected vector features.");

    if (!parser(argc, argv, &params, &action_mode))
	exit(EXIT_FAILURE);

    /* get list of categories */
    Clist = Vect_new_cat_list();
    if (params.cat->answer && Vect_str_to_cat_list(params.cat->answer, Clist)) {
	G_fatal_error(_("Unable to get category list <%s>"),
		      params.cat->answer);
    }

    /* open input file */
    if (params.in->answer) {
	if (strcmp(params.in->answer, "-") != 0) {
	    ascii = fopen(params.in->answer, "r");
	    if (ascii == NULL)
		G_fatal_error(_("Unable to open file <%s>"),
			      params.in->answer);
	}
	else {
	    ascii = stdin;
	}
    }
    if (!ascii && action_mode == MODE_ADD)
	G_fatal_error(_("Required parameter <%s> not set"), params.in->key);
    
    if (action_mode == MODE_CREATE) {
	int overwrite;

	overwrite = G_check_overwrite(argc, argv);
	if (G_find_vector2(params.map->answer, G_mapset())) {
	    if (!overwrite)
		G_fatal_error(_("Vector map <%s> already exists"),
			      params.map->answer);
	}

	/* 3D vector maps? */
	ret = Vect_open_new(&Map, params.map->answer, WITHOUT_Z);
	if (Vect_maptype(&Map) == GV_FORMAT_OGR_DIRECT) {
	    int type;
	    type = Vect_option_to_types(params.type);
	    if (type != GV_POINT && type != GV_LINE &&
		type != GV_BOUNDARY)
		G_fatal_error(_("Supported feature type for OGR layer: "
				"%s, %s or %s"), "point", "line", "boundary");
	    V2_open_new_ogr(&Map, type);
	}
	if (ret == -1) {
	    G_fatal_error(_("Unable to create vector map <%s>"),
			  params.map->answer);
	}

	G_debug(1, "Map created");

	if (ascii) {
	    /* also add new vector features */
	    action_mode = MODE_ADD;
	}
    }
    else {			/* open selected vector file */
	if (action_mode == MODE_ADD)	/* write */
	    ret = Vect_open_update2(&Map, params.map->answer, G_mapset(), params.fld->answer);
	else			/* read-only -- select features */
	    ret = Vect_open_old2(&Map, params.map->answer, G_mapset(), params.fld->answer);

	if (ret < 2)
	    G_fatal_error(_("Unable to open vector map <%s> at topological level %d"),
			  params.map->answer, 2);
    }

    G_debug(1, "Map opened");

    /* open backgroud maps */
    if (params.bmaps->answer) {
	i = 0;

	while (params.bmaps->answers[i]) {
	    const char *bmap = params.bmaps->answers[i];
	    const char *mapset = G_find_vector2(bmap, "");
	    if (!mapset)
		G_fatal_error(_("Vector map <%s> not found"), bmap);

	    if (strcmp(
		    G_fully_qualified_name(params.map->answer, G_mapset()),
		    G_fully_qualified_name(bmap, mapset)) == 0) {
		G_fatal_error(_("Unable to open vector map <%s> as the background map. "
			       "It is given as vector map to be edited."),
			      bmap);
	    }
	    nbgmaps++;
	    BgMap = (struct Map_info **)G_realloc(
		BgMap, nbgmaps * sizeof(struct Map_info *));
	    BgMap[nbgmaps - 1] =
		(struct Map_info *)G_malloc(sizeof(struct Map_info));
	    if (Vect_open_old(BgMap[nbgmaps - 1], bmap, "") == -1)
		G_fatal_error(_("Unable to open vector map <%s>"), bmap);
	    G_verbose_message(_("Background vector map <%s> registered"), bmap);
	    i++;
	}
    }

    layer = Vect_get_field_number(&Map, params.fld->answer);
    i = 0;
    while (params.maxdist->answers[i]) {
	switch (i) {
	case THRESH_COORDS:
	    thresh[THRESH_COORDS] =
		max_distance(atof(params.maxdist->answers[THRESH_COORDS]));
	    thresh[THRESH_SNAP] = thresh[THRESH_QUERY] =
		thresh[THRESH_COORDS];
	    break;
	case THRESH_SNAP:
	    thresh[THRESH_SNAP] =
		max_distance(atof(params.maxdist->answers[THRESH_SNAP]));
	    break;
	case THRESH_QUERY:
	    thresh[THRESH_QUERY] =
		atof(params.maxdist->answers[THRESH_QUERY]);
	    break;
	default:
	    break;
	}
	i++;
    }

    move_first = params.move_first->answer ? 1 : 0;
    snap = NO_SNAP;
    if (strcmp(params.snap->answer, "node") == 0)
	snap = SNAP;
    else if (strcmp(params.snap->answer, "vertex") == 0)
	snap = SNAPVERTEX;
    if (snap != NO_SNAP && thresh[THRESH_SNAP] <= 0) {
	G_warning(_("Threshold for snapping must be > 0. No snapping applied."));
	snap = NO_SNAP;
    }
    
    if (action_mode != MODE_CREATE && action_mode != MODE_ADD) {
	/* select lines */
	List = Vect_new_list();
	G_message(_("Selecting features..."));
	if (action_mode == MODE_COPY && BgMap && BgMap[0]) {
	    List = select_lines(BgMap[0], action_mode, &params, thresh, List);
	}
	else {
	    List = select_lines(&Map, action_mode, &params, thresh, List);
	}
    }

    if ((action_mode != MODE_CREATE && action_mode != MODE_ADD &&
	 action_mode != MODE_SELECT)) {
	if (List->n_values < 1) {
	    G_warning(_("No features selected, nothing to edit"));
	    action_mode = MODE_NONE;
	    ret = 0;
	}
	else {
	    /* reopen the map for updating */
	    if (action_mode == MODE_ZBULK && !Vect_is_3d(&Map)) {
		Vect_close(&Map);
		G_fatal_error(_("Vector map <%s> is not 3D. Tool '%s' requires 3D vector map. "
			       "Please convert the vector map "
			       "to 3D using e.g. %s."), params.map->answer,
			      params.tool->answer, "v.extrude");
	    }
	    Vect_close(&Map);

	    Vect_open_update2(&Map, params.map->answer, G_mapset(), params.fld->answer);
	}
    }

    /* coords option -> array */
    if (params.coord->answers) {
	coord = Vect_new_line_struct();
	int i = 0;
	double east, north;

	while (params.coord->answers[i]) {
	    east = atof(params.coord->answers[i]);
	    north = atof(params.coord->answers[i + 1]);
	    Vect_append_point(coord, east, north, 0.0);
	    i += 2;
	}
    }

    /* perform requested editation */
    switch (action_mode) {
    case MODE_CREATE:
	break;
    case MODE_ADD:
	if (!params.header->answer)
	    Vect_read_ascii_head(ascii, &Map);
	int num_lines;
	num_lines = Vect_get_num_lines(&Map);
	
	ret = Vect_read_ascii(ascii, &Map);
	G_message(_("%d features added"), ret);
	if (ret > 0) {
	    int iline;
	    struct ilist *List_added;
	    
	    List_added = Vect_new_list();
	    for (iline = num_lines + 1; iline <= Vect_get_num_lines(&Map); iline++)
		Vect_list_append(List_added, iline);
	    
	    G_verbose_message(_("Threshold value for snapping is %.2f"),
			      thresh[THRESH_SNAP]);
	    if (snap != NO_SNAP) { /* apply snapping */
		/* snap to vertex ? */
		Vedit_snap_lines(&Map, BgMap, nbgmaps, List_added,
				 thresh[THRESH_SNAP],
				 snap == SNAP ? FALSE : TRUE); 
	    }
	    if (params.close->answer) {	/* close boundaries */
		int nclosed;

		nclosed = close_lines(&Map, GV_BOUNDARY, thresh[THRESH_SNAP]);
		G_message(_("%d boundaries closed"), nclosed);
	    }
	    Vect_destroy_list(List_added);
	}
	break;
    case MODE_DEL:
	ret = Vedit_delete_lines(&Map, List);
	G_message(_("%d features deleted"), ret);
	break;
    case MODE_MOVE:
	move_x = atof(params.move->answers[0]);
	move_y = atof(params.move->answers[1]);
	move_z = atof(params.move->answers[2]);
	G_verbose_message(_("Threshold value for snapping is %.2f"),
			  thresh[THRESH_SNAP]);
	ret = Vedit_move_lines(&Map, BgMap, nbgmaps, List, move_x, move_y, move_z, snap, thresh[THRESH_SNAP]);
	G_message(_("%d features moved"), ret);
	break;
    case MODE_VERTEX_MOVE:
	move_x = atof(params.move->answers[0]);
	move_y = atof(params.move->answers[1]);
	move_z = atof(params.move->answers[2]);
	G_verbose_message(_("Threshold value for snapping is %.2f"),
			  thresh[THRESH_SNAP]);
	ret = Vedit_move_vertex(&Map, BgMap, nbgmaps, List, coord, thresh[THRESH_COORDS], thresh[THRESH_SNAP], move_x, move_y, move_z, move_first, snap);
	G_message(_("%d vertices moved"), ret);
	break;
    case MODE_VERTEX_ADD:
	ret = Vedit_add_vertex(&Map, List, coord, thresh[THRESH_COORDS]);
	G_message(_("%d vertices added"), ret);
	break;
    case MODE_VERTEX_DELETE:
	ret = Vedit_remove_vertex(&Map, List, coord, thresh[THRESH_COORDS]);
	G_message(_("%d vertices removed"), ret);
	break;
    case MODE_BREAK:
	if (params.coord->answer) {
	    ret = Vedit_split_lines(&Map, List,
				    coord, thresh[THRESH_COORDS], NULL);
	}
	else {
	    ret = Vect_break_lines_list(&Map, List, NULL, GV_LINES, NULL);
	}
	G_message(_("%d lines broken"), ret);
	break;
    case MODE_CONNECT:
	G_verbose_message(_("Threshold value for snapping is %.2f"),
			  thresh[THRESH_SNAP]);
	ret = Vedit_connect_lines(&Map, List, thresh[THRESH_SNAP]);
	G_message(_("%d lines connected"), ret);
	break;
    case MODE_MERGE:
	ret = Vedit_merge_lines(&Map, List);
	G_message(_("%d lines merged"), ret);
	break;
    case MODE_SELECT:
	ret = print_selected(List);
	break;
    case MODE_CATADD:
	ret = Vedit_modify_cats(&Map, List, layer, 0, Clist);
	G_message(_("%d features modified"), ret);
	break;
    case MODE_CATDEL:
	ret = Vedit_modify_cats(&Map, List, layer, 1, Clist);
	G_message(_("%d features modified"), ret);
	break;
    case MODE_COPY:
	if (BgMap && BgMap[0]) {
	    if (nbgmaps > 1)
		G_warning(_("Multiple background maps were given. "
			    "Selected features will be copied only from "
			    "vector map <%s>."),
			  Vect_get_full_name(BgMap[0]));

	    ret = Vedit_copy_lines(&Map, BgMap[0], List);
	}
	else {
	    ret = Vedit_copy_lines(&Map, NULL, List);
	}
	G_message(_("%d features copied"), ret);
	break;
    case MODE_SNAP:
	G_verbose_message(_("Threshold value for snapping is %.2f"),
			  thresh[THRESH_SNAP]);
	ret = snap_lines(&Map, List, thresh[THRESH_SNAP]);
	break;
    case MODE_FLIP:
	ret = Vedit_flip_lines(&Map, List);
	G_message(_("%d lines flipped"), ret);
	break;
    case MODE_NONE:
	break;
    case MODE_ZBULK:{
	    double start, step;
	    double x1, y1, x2, y2;

	    start = atof(params.zbulk->answers[0]);
	    step = atof(params.zbulk->answers[1]);

	    x1 = atof(params.bbox->answers[0]);
	    y1 = atof(params.bbox->answers[1]);
	    x2 = atof(params.bbox->answers[2]);
	    y2 = atof(params.bbox->answers[3]);

	    ret = Vedit_bulk_labeling(&Map, List,
				      x1, y1, x2, y2, start, step);

	    G_message(_("%d lines labeled"), ret);
	    break;
	}
    case MODE_CHTYPE:{
	    ret = Vedit_chtype_lines(&Map, List);

	    if (ret > 0) {
		G_message(_("%d features converted"), ret);
	    }
	    else {
		G_message(_("No feature modified"));
	    }
	    break;
	}
    default:
	G_warning(_("Operation not implemented"));
	ret = -1;
	break;
    }
    
    Vect_hist_command(&Map);

    /* build topology only if requested or if tool!=select */
    if (!(action_mode == MODE_SELECT || params.topo->answer == 1 ||
	 !MODE_NONE)) {
	Vect_build_partial(&Map, GV_BUILD_NONE);
	Vect_build(&Map);
    }

    if (List)
	Vect_destroy_list(List);

    Vect_close(&Map);

    G_debug(1, "Map closed");

    /* close background maps */
    for (i = 0; i < nbgmaps; i++) {
	Vect_close(BgMap[i]);
	G_free((void *)BgMap[i]);
    }
    G_free((void *)BgMap);

    if (coord)
	Vect_destroy_line_struct(coord);

    if (Clist)
	Vect_destroy_cat_list(Clist);

    G_done_msg(" ");

    if (ret > -1) {
	exit(EXIT_SUCCESS);
    }
    else {
	exit(EXIT_FAILURE);
    }
}
Esempio n. 16
0
Real FE<3,XYZ>::shape_deriv(const Elem* elem,
			    const Order libmesh_dbg_var(order),
			    const unsigned int i,
			    const unsigned int j,
			    const Point& point_in)
{
#if LIBMESH_DIM == 3

  libmesh_assert(elem);
  libmesh_assert_less (j, 3);

  // Only recompute the centroid if the element
  // has changed from the last one we computed.
  // This avoids repeated centroid calculations
  // when called in succession with the same element.
  if (elem->id() != old_elem_id)
    {
      centroid = elem->centroid();
      old_elem_id = elem->id();
      max_distance = Point(0.,0.,0.);
      for (unsigned int p = 0; p < elem->n_nodes(); p++)
        for (unsigned int d = 0; d < 3; d++)
        {
           const Real distance = std::abs(centroid(d) - elem->point(p)(d));
           max_distance(d) = std::max(distance, max_distance(d));
        }
    }

  // Using static globals for old_elem_id, etc. will fail
  // horribly with more than one thread.
  libmesh_assert_equal_to (libMesh::n_threads(), 1);

  const Real x  = point_in(0);
  const Real y  = point_in(1);
  const Real z  = point_in(2);
  const Real xc = centroid(0);
  const Real yc = centroid(1);
  const Real zc = centroid(2);
  const Real distx = max_distance(0);
  const Real disty = max_distance(1);
  const Real distz = max_distance(2);
  const Real dx = (x - xc)/distx;
  const Real dy = (y - yc)/disty;
  const Real dz = (z - zc)/distz;

#ifndef NDEBUG
  // totalorder is only used in the assertion below, so
  // we avoid declaring it when asserts are not active.
  const unsigned int totalorder = static_cast<Order>(order + elem->p_level());
#endif
  libmesh_assert_less (i, (static_cast<unsigned int>(totalorder)+1)*
              (static_cast<unsigned int>(totalorder)+2)*
              (static_cast<unsigned int>(totalorder)+3)/6);

  switch (j)
    {
      // d()/dx
    case 0:
      {
        switch (i)
  	{
  	  // constant
  	case 0:
  	  return 0.;

  	  // linear
  	case 1:
  	  return 1./distx;

  	case 2:
  	  return 0.;

  	case 3:
  	  return 0.;

  	  // quadratic
  	case 4:
  	  return 2.*dx/distx;

  	case 5:
  	  return dy/distx;

  	case 6:
  	  return 0.;

  	case 7:
  	  return dz/distx;

  	case 8:
  	  return 0.;

  	case 9:
  	  return 0.;

  	  // cubic
  	case 10:
  	  return 3.*dx*dx/distx;

  	case 11:
  	  return 2.*dx*dy/distx;

  	case 12:
  	  return dy*dy/distx;

  	case 13:
  	  return 0.;

  	case 14:
  	  return 2.*dx*dz/distx;

  	case 15:
  	  return dy*dz/distx;

  	case 16:
  	  return 0.;

  	case 17:
  	  return dz*dz/distx;

  	case 18:
  	  return 0.;

  	case 19:
  	  return 0.;

  	  // quartics
  	case 20:
  	  return 4.*dx*dx*dx/distx;

  	case 21:
  	  return 3.*dx*dx*dy/distx;

  	case 22:
  	  return 2.*dx*dy*dy/distx;

  	case 23:
  	  return dy*dy*dy/distx;

  	case 24:
  	  return 0.;

  	case 25:
  	  return 3.*dx*dx*dz/distx;

  	case 26:
  	  return 2.*dx*dy*dz/distx;

  	case 27:
  	  return dy*dy*dz/distx;

  	case 28:
  	  return 0.;

  	case 29:
  	  return 2.*dx*dz*dz/distx;

  	case 30:
  	  return dy*dz*dz/distx;

  	case 31:
  	  return 0.;

  	case 32:
  	  return dz*dz*dz/distx;

  	case 33:
  	  return 0.;

  	case 34:
  	  return 0.;

        default:
          unsigned int o = 0;
          for (; i >= (o+1)*(o+2)*(o+3)/6; o++) { }
          unsigned int i2 = i - (o*(o+1)*(o+2)/6);
          unsigned int block=o, nz = 0;
          for (; block < i2; block += (o-nz+1)) { nz++; }
          const unsigned int nx = block - i2;
          const unsigned int ny = o - nx - nz;
          Real val = nx;
          for (unsigned int index=1; index < nx; index++)
            val *= dx;
          for (unsigned int index=0; index != ny; index++)
            val *= dy;
          for (unsigned int index=0; index != nz; index++)
            val *= dz;
          return val/distx;
  	}
      }


      // d()/dy
    case 1:
      {
        switch (i)
  	{
  	  // constant
  	case 0:
  	  return 0.;

  	  // linear
  	case 1:
  	  return 0.;

  	case 2:
  	  return 1./disty;

  	case 3:
  	  return 0.;

  	  // quadratic
  	case 4:
  	  return 0.;

  	case 5:
  	  return dx/disty;

  	case 6:
  	  return 2.*dy/disty;

  	case 7:
  	  return 0.;

  	case 8:
  	  return dz/disty;

  	case 9:
  	  return 0.;

  	  // cubic
  	case 10:
  	  return 0.;

  	case 11:
  	  return dx*dx/disty;

  	case 12:
  	  return 2.*dx*dy/disty;

  	case 13:
  	  return 3.*dy*dy/disty;

  	case 14:
  	  return 0.;

  	case 15:
  	  return dx*dz/disty;

  	case 16:
  	  return 2.*dy*dz/disty;

  	case 17:
  	  return 0.;

  	case 18:
  	  return dz*dz/disty;

  	case 19:
  	  return 0.;

  	  // quartics
  	case 20:
  	  return 0.;

  	case 21:
  	  return dx*dx*dx/disty;

  	case 22:
  	  return 2.*dx*dx*dy/disty;

  	case 23:
  	  return 3.*dx*dy*dy/disty;

  	case 24:
  	  return 4.*dy*dy*dy/disty;

  	case 25:
  	  return 0.;

  	case 26:
  	  return dx*dx*dz/disty;

  	case 27:
  	  return 2.*dx*dy*dz/disty;

  	case 28:
  	  return 3.*dy*dy*dz/disty;

  	case 29:
  	  return 0.;

  	case 30:
  	  return dx*dz*dz/disty;

  	case 31:
  	  return 2.*dy*dz*dz/disty;

  	case 32:
  	  return 0.;

  	case 33:
  	  return dz*dz*dz/disty;

  	case 34:
  	  return 0.;

  	default:
          unsigned int o = 0;
          for (; i >= (o+1)*(o+2)*(o+3)/6; o++) { }
          unsigned int i2 = i - (o*(o+1)*(o+2)/6);
          unsigned int block=o, nz = 0;
          for (; block < i2; block += (o-nz+1)) { nz++; }
          const unsigned int nx = block - i2;
          const unsigned int ny = o - nx - nz;
          Real val = ny;
          for (unsigned int index=0; index != nx; index++)
            val *= dx;
          for (unsigned int index=1; index < ny; index++)
            val *= dy;
          for (unsigned int index=0; index != nz; index++)
            val *= dz;
          return val/disty;
  	}
      }


      // d()/dz
    case 2:
      {
        switch (i)
  	{
  	  // constant
  	case 0:
  	  return 0.;

  	  // linear
  	case 1:
  	  return 0.;

  	case 2:
  	  return 0.;

  	case 3:
  	  return 1./distz;

  	  // quadratic
  	case 4:
  	  return 0.;

  	case 5:
  	  return 0.;

  	case 6:
  	  return 0.;

  	case 7:
  	  return dx/distz;

  	case 8:
  	  return dy/distz;

  	case 9:
  	  return 2.*dz/distz;

  	  // cubic
  	case 10:
  	  return 0.;

  	case 11:
  	  return 0.;

  	case 12:
  	  return 0.;

  	case 13:
  	  return 0.;

  	case 14:
  	  return dx*dx/distz;

  	case 15:
  	  return dx*dy/distz;

  	case 16:
  	  return dy*dy/distz;

  	case 17:
  	  return 2.*dx*dz/distz;

  	case 18:
  	  return 2.*dy*dz/distz;

  	case 19:
  	  return 3.*dz*dz/distz;

  	  // quartics
  	case 20:
  	  return 0.;

  	case 21:
  	  return 0.;

  	case 22:
  	  return 0.;

  	case 23:
  	  return 0.;

  	case 24:
  	  return 0.;

  	case 25:
  	  return dx*dx*dx/distz;

  	case 26:
  	  return dx*dx*dy/distz;

  	case 27:
  	  return dx*dy*dy/distz;

  	case 28:
  	  return dy*dy*dy/distz;

  	case 29:
  	  return 2.*dx*dx*dz/distz;

  	case 30:
  	  return 2.*dx*dy*dz/distz;

  	case 31:
  	  return 2.*dy*dy*dz/distz;

  	case 32:
  	  return 3.*dx*dz*dz/distz;

  	case 33:
  	  return 3.*dy*dz*dz/distz;

  	case 34:
  	  return 4.*dz*dz*dz/distz;

  	default:
          unsigned int o = 0;
          for (; i >= (o+1)*(o+2)*(o+3)/6; o++) { }
          unsigned int i2 = i - (o*(o+1)*(o+2)/6);
          unsigned int block=o, nz = 0;
          for (; block < i2; block += (o-nz+1)) { nz++; }
          const unsigned int nx = block - i2;
          const unsigned int ny = o - nx - nz;
          Real val = nz;
          for (unsigned int index=0; index != nx; index++)
            val *= dx;
          for (unsigned int index=0; index != ny; index++)
            val *= dy;
          for (unsigned int index=1; index < nz; index++)
            val *= dz;
          return val/distz;
  	}
      }


    default:
      libmesh_error();
    }

#endif

  libmesh_error();
  return 0.;
}