Пример #1
0
TEST(GenericField, all) {
    Profiler::initialize();

    FilePath mesh_file( string(UNIT_TESTS_SRC_DIR) + "/mesh/simplest_cube.msh", FilePath::input_file);
    Mesh mesh;
    ifstream in(string(mesh_file).c_str());
    mesh.read_gmsh_from_stream(in);

    GenericField<3>::IndexField subdomain;
    subdomain.flags(FieldFlag::input_copy);
    GenericField<3>::IndexField region_id;
    region_id.flags(FieldFlag::input_copy);

    subdomain = GenericField<3>::subdomain(mesh);
    subdomain.set_limit_side(LimitSide::right);
    subdomain.set_time(TimeGovernor().step());
    // TODO: After we have support to read partitioning form the MSH file.

    region_id = GenericField<3>::region_id(mesh);
    region_id.set_limit_side(LimitSide::right);
    region_id.set_time(TimeGovernor().step());
    FOR_ELEMENTS(&mesh, ele)
    	EXPECT_EQ( ele->region().id(),
    			   region_id.value(ele->centre(), ele->element_accessor())
    			   );
}
 void
 writePLY(const pcl::PointCloud<PointT>& cloud_m, const std::string& mesh_file_name)
 {
   std::ofstream mesh_file(std::string(mesh_file_name).c_str());
   mesh_file << "ply\n"
             "format ascii 1.0\n"
             "element vertex "
             << cloud_m.points.size() << "\n"
             "property float x\n"
             "property float y\n"
             "property float z\n"
             "property uchar red\n"
             "property uchar green\n"
             "property uchar blue\n"
             "property float nx\n"
             "property float ny\n"
             "property float nz\n"
             "end_header\n";
   //<x> <y> <z> <r> <g> <b>
   for (size_t i = 0; i < cloud_m.points.size(); i++)
   {
     rgb color;
     const PointT& p = cloud_m.points[i];
     color.data = p.rgb;
     mesh_file << p.x << " " << p.y << " " << p.z << " " << int(color.color[2]) << " " << int(color.color[1]) << " "
               << int(color.color[0]) << " " << p.normal_x << " " << p.normal_y << " " << p.normal_z << "\n";
   }
 }
Пример #3
0
    virtual void SetUp() {
        // setup FilePath directories
        FilePath::set_io_dirs(".",UNIT_TESTS_SRC_DIR,"",".");

        Profiler::initialize();
        PetscInitialize(0,PETSC_NULL,PETSC_NULL,PETSC_NULL);
        
        FilePath mesh_file( "fields/one_element_2d.msh", FilePath::input_file);
        mesh= new Mesh;
        ifstream in(string( mesh_file ).c_str());
        mesh->read_gmsh_from_stream(in);
        dh = new DOFHandlerMultiDim(*mesh);
        VecCreateSeqWithArray(PETSC_COMM_SELF, 1, 3, dof_values, &v);
    }
Пример #4
0
void GLWidget::initializeGL (void)
{
	connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &GLWidget::cleanup);

	initGL();

	// look for shader dir 
	QDir dir;
	std::string shader_dir("effects/shaders/");
	for (int i = 0; i < 5; ++i)
		if (!dir.exists(shader_dir.c_str()))
			shader_dir.insert(0, "../");

	// look for mesh file
	QFile file;
	std::string mesh_file("samples/models/toy.ply");
	for (int i = 0; i < 5; ++i)
		if (!file.exists(mesh_file.c_str()))
			mesh_file.insert(0, "../");

	
	// initialize the widget, camera and light trackball, and opens default mesh
	Tucano::QtTrackballWidget::initialize();
	Tucano::QtTrackballWidget::openMesh(mesh_file);

    // initialize the effects
    ssao = new Effects::SSAO();
    ssao->setShadersDir(shader_dir);
    ssao->initialize();

    phong = new Effects::Phong();
	phong->setShadersDir(shader_dir);
    phong->initialize();

    toon = new Effects::Toon();
	toon->setShadersDir(shader_dir);
    toon->initialize();

}
Пример #5
0
void GLWidget::initializeGL (void)
{
	initGL();
	std::cout << infoGL() << std::endl;

	terrainMesh.initGL();

	// look for mesh file
	QFile file;
	std::string mesh_file("samples/models/cube.obj");
	for (int i = 0; i < 5; ++i)
		if (!file.exists(mesh_file.c_str()))
			mesh_file.insert(0, "../");

	// look for shader dir 
	QDir dir;
	std::string shader_dir("effects/shaders/");
	for (int i = 0; i < 5; ++i)
		if (!dir.exists(shader_dir.c_str()))
			shader_dir.insert(0, "../");

	loadTextures();
   
	shader.load("terrain", shader_dir);
	shader.initialize();

	terrainMesh.create(terrainWidth, terrainHeight, true);
	//terrainMesh.normalizeModelMatrix();

	Tucano::QtFlycameraWidget::initialize();
	camera->setPerspectiveMatrix(60.0, (float)this->width() / (float)this->height(), 0.1f, 100.0f);
	
	glClearColor(0.1f, 0.15f, 0.1f, 0.0f);		// background color
	glEnable(GL_DEPTH_TEST);					// Enable depth test
	glDepthFunc(GL_LESS);						// Accept fragment if it closer to the camera than the former one

	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
Пример #6
0
void
TiledMesh::buildMesh()
{
  // stitch_meshes() is only implemented for ReplicatedMesh.  So make sure
  // we have one here before continuing.
  ReplicatedMesh * serial_mesh = dynamic_cast<ReplicatedMesh *>(&getMesh());

  if (!serial_mesh)
    mooseError("Error, TiledMesh calls stitch_meshes() which only works on ReplicatedMesh.");
  else
  {
    std::string mesh_file(getParam<MeshFileName>("file"));

    if (mesh_file.rfind(".exd") < mesh_file.size() || mesh_file.rfind(".e") < mesh_file.size())
    {
      ExodusII_IO ex(*this);
      ex.read(mesh_file);
      serial_mesh->prepare_for_use();
    }
    else
      serial_mesh->read(mesh_file);

    BoundaryID left = getBoundaryID(getParam<BoundaryName>("left_boundary"));
    BoundaryID right = getBoundaryID(getParam<BoundaryName>("right_boundary"));
    BoundaryID top = getBoundaryID(getParam<BoundaryName>("top_boundary"));
    BoundaryID bottom = getBoundaryID(getParam<BoundaryName>("bottom_boundary"));
    BoundaryID front = getBoundaryID(getParam<BoundaryName>("front_boundary"));
    BoundaryID back = getBoundaryID(getParam<BoundaryName>("back_boundary"));

    {
      std::unique_ptr<MeshBase> clone = serial_mesh->clone();

      // Build X Tiles
      for (unsigned int i = 1; i < getParam<unsigned int>("x_tiles"); ++i)
      {
        MeshTools::Modification::translate(*clone, _x_width, 0, 0);
        serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
                                   right,
                                   left,
                                   TOLERANCE,
                                   /*clear_stitched_boundary_ids=*/true);
      }
    }
    {
      std::unique_ptr<MeshBase> clone = serial_mesh->clone();

      // Build Y Tiles
      for (unsigned int i = 1; i < getParam<unsigned int>("y_tiles"); ++i)
      {
        MeshTools::Modification::translate(*clone, 0, _y_width, 0);
        serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
                                   top,
                                   bottom,
                                   TOLERANCE,
                                   /*clear_stitched_boundary_ids=*/true);
      }
    }
    {
      std::unique_ptr<MeshBase> clone = serial_mesh->clone();

      // Build Z Tiles
      for (unsigned int i = 1; i < getParam<unsigned int>("z_tiles"); ++i)
      {
        MeshTools::Modification::translate(*clone, 0, 0, _z_width);
        serial_mesh->stitch_meshes(dynamic_cast<ReplicatedMesh &>(*clone),
                                   front,
                                   back,
                                   TOLERANCE,
                                   /*clear_stitched_boundary_ids=*/true);
      }
    }
  }
}
Пример #7
0
int RunDogpackHybrid(string outputdir)
{

    // Get current time
    timeval start_time = get_utime();

    // Output title information
    printf("\n"
            "   ------------------------------------------------   \n"
            "   | DoGPack: The Discontinuous Galerkin Package  |   \n"
            "   | Developed by the research group of           |   \n"
            "   |            James A. Rossmanith               |   \n"
            "   |            Department of Mathematics         |   \n"
            "   |            Iowa State University             |   \n"
            "   ------------------------------------------------   \n\n");

    // Get parameters from parameters.ini
    dogParams.init();  

    // Time stepping information (for global solves)
    dogStateHybrid.init();
    dogStateHybrid.set_initial_dt(dogParams.get_initial_dt());

    // ----------------------------------------------- //
    // ------------- Unstructured Stuff -------------- //
    // ----------------------------------------------- //

    // Check to see if a mesh has been generated,
    //   if YES, then read in basic mesh parameters
    ifstream mesh_file("Unstructured_Mesh/mesh_output/mesh_params.dat", ios::in);
    if(mesh_file.is_open()!=1)
    {
        printf(" ERROR: file not found:"
                " 'Unstructured_Mesh/mesh_output/mesh_params.dat' \n"
                "   In order to run DoGPack in unstructured grid mode \n"
                "   you must first generate a mesh. You can do this by \n"
                "   following these steps: \n \n"
                "      (1) Type: $DOGPACK/scripts/create_unst2_dir \n"
                "      (2) Type: cd Unstructured_Mesh \n"
                "      (3) Modify the following files as desired:  \n"
                "            - input2D.data  \n"
                "            - SignedDistance.cpp  \n"
                "            - GridSpacing.cpp  \n"
                "            - MeshPreProcess.cpp  \n"
                "            - MeshPostProcess1.cpp  \n"
                "            - MeshPostProcess2.cpp  \n"
                "      (4) Run mesh generator by typing: mesh2d.exe  \n"
                "      (5) Visualize mesh using the 'plotmesh2.m' MATLAB script  \n \n");
        exit(1);
    }

    // Check to see that the correct inversion routines have been called from
    // Matlab.
//  ifstream matlab_file("matlab/R.dat", ios::in);
//  if(matlab_file.is_open()!=1)
//  {
//      printf( " ERROR: file not found:"
//              " 'matlab/R.dat' \n"
//              " Open Matlab and call the function CreateMatrix( Morder ) \n"
//              " Also, I need to write some more testing here! (-DS) \n" );
//      exit(1);
//  }
    // TODO - might as well read in the Sparse matrix routines here! (-DS)


    // Read-in in basic mesh parameters
    int NumElems,NumPhysElems,NumGhostElems,NumNodes;
    int NumPhysNodes,NumBndNodes,NumEdges,NumBndEdges;
    char buffer[256];
    mesh_file >> NumElems;
    mesh_file.getline(buffer,256);
    mesh_file >> NumPhysElems;
    mesh_file.getline(buffer,256);
    mesh_file >> NumGhostElems;
    mesh_file.getline(buffer,256);
    mesh_file >> NumNodes;
    mesh_file.getline(buffer,256);
    mesh_file >> NumPhysNodes;
    mesh_file.getline(buffer,256);
    mesh_file >> NumBndNodes;
    mesh_file.getline(buffer,256);
    mesh_file >> NumEdges;
    mesh_file.getline(buffer,256);
    mesh_file >> NumBndEdges;
    mesh_file.getline(buffer,256);
    mesh_file.close();

    // Initialize 2d unstructured parameters
    dogParamsUnst2.init(NumElems,
            NumPhysElems,
            NumGhostElems,
            NumNodes,
            NumPhysNodes,
            NumBndNodes,
            NumEdges,
            NumBndEdges,
            outputdir);  

    // Create and read-in entire unstructured mesh
    mesh Mesh(NumElems,NumPhysElems,NumNodes,NumPhysNodes,
            NumBndNodes,NumEdges,NumBndEdges);
    string mesh_dir = "Unstructured_Mesh/mesh_output";
    Mesh.InputMesh(mesh_dir);

    // create help file for plotting purposes
    string qhelp;
    qhelp=outputdir+"/qhelp.dat";
    dogParams.write_qhelp(qhelp.c_str());
    dogParamsUnst2.write_qhelp(qhelp.c_str());

    // Copy mesh into output directory
    RunMeshCopyScript(outputdir);

    // ----------------------------------------------- //
    // ------------- Structured Stuff ---------------- //
    // ----------------------------------------------- //
    dogParamsCart2.init();  // well, now wasn't that easy?
    const int mx  = dogParamsCart2.get_mx();
    const int my  = dogParamsCart2.get_my();
    const int mbc = dogParamsCart2.get_mbc();

    // Get application parameters    
    // This is currently a blank routine located in lib/2d/IniApp.cpp
    // InitApp_Unst(ini_doc,Mesh);

    // Dimension arrays
    const int meqn = dogParams.get_meqn();
    const int kmax = dogParams.get_kmax();

    const int space_order = dogParams.get_space_order();

    // initialize state of solver
    int    nstart = 0;
    double tstart = 0.;

    // -------------------------- 
    // Start new computation
    // -------------------------- 

    // Set initial data on computational grid
    void L2Project( const mesh& Mesh, dTensorBC5& q);
    dTensorBC5 q(mx, my, NumElems, 1, kmax, mbc);
    L2Project(Mesh,q);

    // Apply post processing to initial data
    //
    // For the Vlasov Routines, this also reads in the vlasovParams section
    AfterQinit_Unst(Mesh,q);

printf("*** We also believe ethat NDIMS = %d ***\n", NDIMS );

    // Output initial data to file
    dogStateHybrid.set_time(tstart);
    Output_Hybrid(Mesh, q, 0., 0, outputdir); 

    // Compute conservation and print to file
    //  ConSoln_Unst(Mesh,aux,qnew,0.0,outputdir);

    // Set edge information needed later by Riemann solver
    edge_data_Unst EdgeData(NumEdges);
    SetEdgeData_Unst(Mesh,space_order,space_order,EdgeData);

    // Main loop for time stepping
    const int nout = dogParams.get_nout();
    const double tfinal = dogParams.get_tfinal(); 
    double tend = tstart;
    const double dtout = (tfinal-tstart)/double(nout-nstart);
    for (int n=nstart+1; n<=nout; n++)
    {
        tstart = tend;	  
        tend = tstart + dtout;

        // Solve hyperbolic system from tstart to tend and output to file
        DogSolveHybrid (Mesh,EdgeData,q,tstart,tend);
        Output_Hybrid  (Mesh, q, tend, n, outputdir); 

        printf("DOGPACK: Frame %3d: at time t =%12.5e\n\n", n,tend);
    }

    // Get current time
    timeval end_time = get_utime();

    // Output elapsed time
    double diff_utime = timeval_diff(end_time, start_time);
    printf(" Total elapsed time in seconds = %11.5f\n\n", diff_utime);

    return 0;

}
Пример #8
0
void read_mesh_face_fluent(const string& mesh_file_name,		// Mesh file name
							unsigned int	DIM,
							unsigned int	NFM,				// Grid information
							vector<Node>	&nodes,
							vector<Face>	&faces,
							vector<Cell>	&cells,
							vector<int>		&bc_zone)
{
	int index, index2, zone, first_index, last_index, bc_type, face_type, face_type2;
	int i, n;

	int type;
	int	nodes_num[4];
	int	cl, cr;


	string line;
	ifstream mesh_file(mesh_file_name.c_str());

	// Step 1: Open file to read
	if(!mesh_file) throw Common::ExceptionFileSystem (FromHere(), "Could not open file: " + mesh_file_name);

	// Step 2: Read Data
	n = 1;

	while (! mesh_file.eof())
	{
		// STEP 2.1: GET INDEX
		index = -1;
		getline(mesh_file, line);
		sscanf(line.c_str(), "(%d ", &index);

		if (index == FLU_INDEX_FACE)
		{
			index2			= -1;
			zone 			= -1;
			first_index 	= -1;
			last_index 		= -1;
			bc_type 		= -1;
			face_type 		= -1;

			sscanf(line.c_str(),"(%d (%x %x %x %d %d)", &index2, &zone, &first_index, &last_index, &bc_type, &face_type); // GETTING INDEX AND ZONE

			if (zone > 0)
			{
				// Assign BC type from data
				bc_type	= bc_zone[zone];

				switch (face_type)
				{
				case FaceType::f_mixed:
					for (i = first_index; i <= last_index; i++)
					{
						face_type2 = -1;
						getline(mesh_file, line);
						sscanf(line.c_str(), "%d", &face_type2);

						switch (face_type2)
						{
						case FaceType::f_line: // LINE
							sscanf(line.c_str(), "%d %x %x %x %x", &type, &nodes_num[0], &nodes_num[1], &cl, &cr);

							faces[i].geo.allocate(DIM, FaceType::f_line);
							faces[i].geo.ID = i;

							faces[i].geo.node_list[0] = &nodes[nodes_num[0]];
							faces[i].geo.node_list[1] = &nodes[nodes_num[1]];

							if (cl == 0)	faces[i].geo.cl[0]  = NULL;
							else			faces[i].geo.cl[0]	= &cells[cl];

							if (cr == 0)	faces[i].geo.cr[0] = NULL;
							else			faces[i].geo.cr[0]	= &cells[cr];

							break;

						case FaceType::f_triangle:	// TRIANGLE
							sscanf(line.c_str(), "%d %x %x %x %x %x", &type, &nodes_num[0], &nodes_num[1], &nodes_num[2], &cl, &cr);

							faces[i].geo.allocate(DIM, FaceType::f_triangle);
							faces[i].geo.ID = i;

							faces[i].geo.node_list[0] = &nodes[nodes_num[0]];
							faces[i].geo.node_list[1] = &nodes[nodes_num[1]];
							faces[i].geo.node_list[2] = &nodes[nodes_num[2]];

							if (cl == 0)	faces[i].geo.cl[0]  = NULL;
							else			faces[i].geo.cl[0]	= &cells[cl];

							if (cr == 0)	faces[i].geo.cr[0] = NULL;
							else			faces[i].geo.cr[0]	= &cells[cr];
							break;

						case FaceType::f_quadrilateral: // QUADRILATERAL
							sscanf(line.c_str(), "%d %x %x %x %x %x %x", &type, &nodes_num[0], &nodes_num[1], &nodes_num[2], &nodes_num[3], &cl, &cr);

							faces[i].geo.allocate(DIM, FaceType::f_quadrilateral);
							faces[i].geo.ID = i;

							faces[i].geo.node_list[0] = &nodes[nodes_num[0]];
							faces[i].geo.node_list[1] = &nodes[nodes_num[1]];
							faces[i].geo.node_list[2] = &nodes[nodes_num[2]];
							faces[i].geo.node_list[3] = &nodes[nodes_num[3]];

							if (cl == 0)	faces[i].geo.cl[0]  = NULL;
							else			faces[i].geo.cl[0]	= &cells[cl];

							if (cr == 0)	faces[i].geo.cr[0] = NULL;
							else			faces[i].geo.cr[0]	= &cells[cr];

							break;

						default:
							throw ExceptionNotSupportedType (FromHere(), "It is not supported Face-type");
							break;
						}

						faces[i].geo.BC = bc_type;
						n++;
					}
					break;


				case FaceType::f_line: // LINE
					for (i = first_index; i <= last_index; i++)
					{
						getline(mesh_file, line);
						sscanf(line.c_str(), "%x %x %x %x", &nodes_num[0], &nodes_num[1], &cl, &cr);

						faces[i].geo.allocate(DIM, FaceType::f_line);
						faces[i].geo.ID = i;

						faces[i].geo.node_list[0] = &nodes[nodes_num[0]];
						faces[i].geo.node_list[1] = &nodes[nodes_num[1]];


						if (cl == 0)	faces[i].geo.cl[0]  = NULL;
						else			faces[i].geo.cl[0]	= &cells[cl];

						if (cr == 0)	faces[i].geo.cr[0] = NULL;
						else			faces[i].geo.cr[0]	= &cells[cr];

						faces[i].geo.BC 	= bc_type;
						n++;
					}
					break;

				case FaceType::f_triangle:	// TRIANGLE
					for (i = first_index; i <= last_index; i++)
					{
						getline(mesh_file, line);
						sscanf(line.c_str(), "%x %x %x %x %x", &nodes_num[0], &nodes_num[1], &nodes_num[2], &cl, &cr);

						faces[i].geo.allocate(DIM, FaceType::f_triangle);
						faces[i].geo.ID = i;

						faces[i].geo.node_list[0] = &nodes[nodes_num[0]];
						faces[i].geo.node_list[1] = &nodes[nodes_num[1]];
						faces[i].geo.node_list[2] = &nodes[nodes_num[2]];


						if (cl == 0)	faces[i].geo.cl[0]  = NULL;
						else			faces[i].geo.cl[0]	= &cells[cl];

						if (cr == 0)	faces[i].geo.cr[0] = NULL;
						else			faces[i].geo.cr[0]	= &cells[cr];

						faces[i].geo.BC = bc_type;
						n++;
					}
					break;

				case FaceType::f_quadrilateral: // QUADRILATERAL
					for (i = first_index; i <= last_index; i++)
					{
						getline(mesh_file, line);
						sscanf(line.c_str(), "%x %x %x %x %x %x", &nodes_num[0], &nodes_num[1], &nodes_num[2], &nodes_num[3], &cl, &cr);

						faces[i].geo.allocate(DIM, FaceType::f_triangle);
						faces[i].geo.ID = i;

						faces[i].geo.node_list[0] = &nodes[nodes_num[0]];
						faces[i].geo.node_list[1] = &nodes[nodes_num[1]];
						faces[i].geo.node_list[2] = &nodes[nodes_num[2]];
						faces[i].geo.node_list[3] = &nodes[nodes_num[3]];

						if (cl == 0)	faces[i].geo.cl[0]  = NULL;
						else			faces[i].geo.cl[0]	= &cells[cl];

						if (cr == 0)	faces[i].geo.cr[0] = NULL;
						else			faces[i].geo.cr[0]	= &cells[cr];

						faces[i].geo.BC = bc_type;
						n++;
					}
					break;

				default:
					throw ExceptionNotSupportedType (FromHere(), "It is not supported Face-type");
					break;
				}
			}// END READ FACE DATA
		}// END READ MESH FILE
	}

	//Step 2.2 Check Error
	if ((n-1) != NFM)
	{
		throw ExceptionGridDataMismatch (FromHere(), "PROBLEM IN Face DATA. TOTAL NUMBER OF Face DATA DOES NOT MATHCH WITH MESH INFOMATION DATA");
	}

}