Пример #1
0
int main(int argc, char **argv)
{
#ifdef HAVE_MPI
    int required_thread_support=MPI_THREAD_SINGLE;
    int provided_thread_support;
    MPI_Init_thread(&argc, &argv, required_thread_support, &provided_thread_support);
    assert(required_thread_support==provided_thread_support);
#endif

#ifdef HAVE_VTK
    Mesh<double> *mesh=VTKTools<double>::import_vtu("../data/box200x200.vtu");
    mesh->create_boundary();

    size_t NNodes = mesh->get_number_nodes();

    // Set up field - use first touch policy
    std::vector<double> psi(NNodes);
    #pragma omp parallel
    {
        #pragma omp for schedule(static)
        for(size_t i=0; i<NNodes; i++)
            psi[i] = pow(mesh->get_coords(i)[0]+0.1, 2) + pow(mesh->get_coords(i)[1]+0.1, 2);
    }

    MetricField<double,2> metric_field(*mesh);

    double tic = get_wtime();
    metric_field.add_field(&(psi[0]), 1.0);
    double toc = get_wtime();

    metric_field.update_mesh();

    std::vector<double> metric(NNodes*3);
    metric_field.get_metric(&(metric[0]));

    double rms[] = {0., 0., 0.};
    for(size_t i=0; i<NNodes; i++) {
        rms[0] += pow(2.0-metric[i*3  ], 2);
        rms[1] += pow(    metric[i*3+1], 2);
        rms[2] += pow(2.0-metric[i*3+2], 2);
    }

    double max_rms = 0;
    for(size_t i=0; i<3; i++) {
        rms[i] = sqrt(rms[i]/NNodes);
        max_rms = std::max(max_rms, rms[i]);
    }

    std::string vtu_filename("../data/test_hessian_2d");
    VTKTools<double>::export_vtu(vtu_filename.c_str(), mesh, &(psi[0]));

    std::cout<<"Hessian :: loop time = "<<toc-tic<<std::endl
             <<"RMS = "<<rms[0]<<", "<<rms[1]<<", "<<rms[2]<<std::endl;
    if(max_rms>0.01)
        std::cout<<"fail\n";
    else
        std::cout<<"pass\n";

    delete mesh;
#else
    std::cerr<<"Pragmatic was configured without VTK"<<std::endl;
#endif

#ifdef HAVE_MPI
    MPI_Finalize();
#endif

    return 0;
}
Пример #2
0
void VTKOutput<TDim>::
print(const char* filename, Domain<TDim>& domain)
{
//	get the grid associated to the solution
	MultiGrid& grid = *domain.grid();
	MGSubsetHandler& sh = *domain.subset_handler();

// 	attach help indices
	typedef ug::Attachment<int> AVrtIndex;
	AVrtIndex aVrtIndex;
	Grid::VertexAttachmentAccessor<AVrtIndex> aaVrtIndex;
	grid.attach_to_vertices(aVrtIndex);
	aaVrtIndex.access(grid, aVrtIndex);

//	get rank of process
	int rank = 0;
#ifdef UG_PARALLEL
	rank = pcl::ProcRank();
#endif

	const int si = -1;

//	get name for *.vtu file
	std::string name;
	try{
		vtu_filename(name, filename, rank, si, sh.num_subsets()-1, -1);
	}
	UG_CATCH_THROW("VTK::print_subset: Can not write vtu - file.");


//	open the file
	try
	{
	VTKFileWriter File(name.c_str());

//	header
	File << VTKFileWriter::normal;
	File << "<?xml version=\"1.0\"?>\n";
	File << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"";
	if(IsLittleEndian()) File << "LittleEndian";
	else File << "BigEndian";
	File << "\">\n";

//	opening the grid
	File << "  <UnstructuredGrid>\n";

// 	get dimension of grid-piece
	int dim = DimensionOfSubsets(sh);

//	write piece of grid
	if(dim >= 0)
	{
		try{
			write_grid_piece<MGSubsetHandler>
			(File, aaVrtIndex, domain.position_accessor(), grid,
			 sh, si, dim);
		}
		UG_CATCH_THROW("VTK::print: Can not write Subset: "<<si);
	}
	else
	{
	//	if dim < 0, some is wrong with grid, except no element is in the grid
		if( ((si < 0) && grid.num<Vertex>() != 0) ||
			((si >=0) && sh.num<Vertex>(si) != 0))
		{
			UG_THROW("VTK::print: Dimension of grid/subset not"
					" detected correctly although grid objects present.");
		}

		write_empty_grid_piece(File);
	}

//	write closing xml tags
	File << "  </UnstructuredGrid>\n";
	File << "</VTKFile>\n";

// 	detach help indices
	grid.detach_from_vertices(aVrtIndex);

	}
Пример #3
0
int main(int argc, char **argv)
{
  pugi::xml_document svg_xml;
  TCLAP::UnlabeledValueArg<std::string> svg_filename( "svg_filename", "SVG file name", true, "", "PipelineFile"  );
  TCLAP::UnlabeledValueArg<std::string> vtu_filename( "vtu_filename", "SVG file name", true, "", "PipelineFile"  );

  try
  {
    TCLAP::CmdLine cmd("SVG to vtu converter", ' ', "1.0");

    cmd.add( svg_filename );
    cmd.add( vtu_filename );
    cmd.parse( argc, argv );

    pugi::xml_parse_result result = svg_xml.load_file( svg_filename.getValue().c_str() );

    if (!result)
    {
      std::cerr << "Error loading or parsing XML file " << svg_filename.getValue().c_str() << std::endl;
      std::cerr << "XML error: " << result.description() << std::endl;
      return 0;
    }
  }
  catch (TCLAP::ArgException &e)  // catch any exceptions
  {
    std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
  }


  MeshType mesh;

  pugi::xml_node svg_node = svg_xml.child("svg");
  pugi::xml_node g_node = svg_node.child("g");


  for (pugi::xml_node path_node = g_node.child("path");
        path_node;
        path_node = path_node.next_sibling("path"))
  {
    std::string tmp = path_node.attribute("d").as_string();
    std::cout << tmp << std::endl;

    PointType translate = viennagrid::make_point(0,0);

    pugi::xml_attribute transform_attribute = path_node.attribute("transform");
    if ( !transform_attribute.empty() )
    {
      std::string transform_str = transform_attribute.as_string();
      if (transform_str.find("translate") != std::string::npos)
      {
//         std::cout << "translate x = " << ) << std::endl;
//         std::cout << "translate y = " << transform_str.substr( transform_str.find(",")+1, transform_str.find(")")-transform_str.find(",")-1 ) << std::endl;
        double x = atof( transform_str.substr( transform_str.find("(")+1, transform_str.find(",")-transform_str.find("(")-1 ).c_str() );
        double y = atof( transform_str.substr( transform_str.find(",")+1, transform_str.find(")")-transform_str.find(",")-1 ).c_str() );

        translate = viennagrid::make_point(x,y);
      }
      else
      {
        std::cerr << transform_str << " is an invalid transform (currently only translate is supported)" << std::endl;
        return 0;
      }
    }

    add_svg_polyline(mesh, tmp, translate);
  }




  int fixes = 0;
  do
  {
    MeshType tmp;
    fixes = eliminate_nonconformities(mesh, tmp);
    mesh = tmp;

    std::cout << "Fix count = " << fixes << std::endl;
  } while (fixes != 0);



  std::string output_filename = vtu_filename.getValue().c_str();
  if (output_filename.find(".vtu"))
    output_filename = output_filename.substr( 0, output_filename.find(".vtu") );
  if (output_filename.find(".pvd"))
    output_filename = output_filename.substr( 0, output_filename.find(".pvd") );

  viennagrid::io::vtk_writer<MeshType> writer;
  writer(mesh, output_filename);



//   viennamesh::context_handle context;
//
//   viennamesh::algorithm_handle mesher = context.make_algorithm("triangle_make_mesh");
//   mesher.set_input( "mesh", mesh.internal() );
//   mesher.set_input("cell_size", 10.0);
//   {
//     viennamesh::LoggingStack s("tetgen_make_mesh");
//     mesher.run();
//   }
//
//   viennamesh::algorithm_handle mesh_writer = context.make_algorithm("mesh_writer");
//   mesh_writer.set_default_source(mesher);
//   mesh_writer.set_input( "filename", "half_aircraft_mesh.vtu" );
//   {
//     viennamesh::LoggingStack s("mesh_writer");
//     mesh_writer.run();
//   }
}