Пример #1
0
void MainWindow::saveasFile()
{
    if (path=="") return;
    path = QFileDialog::getSaveFileName(this,
                                        tr("Save File"),
                                        ".",
                                        tr("Text Files(*.asm *.ASM)"));
    if(!path.isEmpty()) {
        QFile file(path);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            QMessageBox::warning(this, tr("Write File"),
                                       tr("Cannot open file:\n%1").arg(path));
            return;
        }
        QTextStream out(&file);
        out << ui->textEdit->toPlainText();
        QTextStream in(&file);
        in.seek(0);
        QFileInfo fi(path);
        if (fi.suffix()=="asm"||fi.suffix()=="ASM"){
            Mips mip(in);
            instrutions=mip;
        }else if (fi.suffix()=="coe"){
            Mipscoe mipcoe(in);
            coeinst=mipcoe;
        }else {

        }
        file.close();
        this->setWindowTitle("Mips-ide by fh"+fi.completeBaseName()+"[*]");
        emit hasSaved();
    }
}
Пример #2
0
  /*
    Calculates the element vector.

    Input is:
    the finite element: fel 
    the geometry of the element: eltrans
    
    Output is:
    the element vector: elvec
    
    Efficient memorymanagement is provided my locheap
  */
  void MySourceIntegrator ::
  CalcElementVector (const FiniteElement & base_fel,
		     const ElementTransformation & eltrans, 
		     FlatVector<double> elvec,
		     LocalHeap & lh) const
  {
    const ScalarFiniteElement<2> & fel =
      dynamic_cast<const ScalarFiniteElement<2> &> (base_fel);

    int ndof = fel.GetNDof();

    elvec = 0;

    Vector<> shape(ndof); 

    IntegrationRule ir(fel.ElementType(), 2*fel.Order());

    for (int i = 0 ; i < ir.GetNIP(); i++)
      {
        MappedIntegrationPoint<2,2> mip(ir[i], eltrans);

        double f = coef_f -> Evaluate (mip);

        // calculate shape functions 
        fel.CalcShape (ir[i], shape);
        
        // integration weight and Jacobi determinant
        double fac = mip.IP().Weight() * mip.GetMeasure();

        // elvec_{i} += (fac*f) shape_i
        elvec += (fac*f) * shape;
      }     
  }
Пример #3
0
void MainWindow::saveFile()
{
    QFileInfo filepath(path);
    if(filepath.exists()) {
        QFile file(path);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            QMessageBox::warning(this, tr("Write File"),
                                       tr("Cannot open file:\n%1").arg(path));
            return;
        }
        QTextStream out(&file);
        out << ui->textEdit->toPlainText();
        QTextStream in(&file);
        in.seek(0);
        QFileInfo fi(path);
        if (fi.suffix()=="asm"||fi.suffix()=="ASM"){
            Mips mip(in);
            instrutions=mip;
        }else if (fi.suffix()=="coe"){
            Mipscoe mipcoe(in);
            coeinst=mipcoe;
        }else {

        }
        file.close();
        emit hasSaved();
    }else
        saveasFile();
}
Пример #4
0
  /*
    Calculates the element matrix.

    Input is:
    the finite element: fel 
    the geometry of the element: eltrans
    
    Output is:
    the element matrix: elmat
    
    Efficient memorymanagement is provided my locheap
  */
  void MyLaplaceIntegrator ::
  CalcElementMatrix (const FiniteElement & base_fel,
		     const ElementTransformation & eltrans, 
		     FlatMatrix<double> elmat,
		     LocalHeap & lh) const
  {
    /*
      tell the compiler that we are expecting to get an scalar fe in 2D.
      if not, an exception will be raised
    */
    const ScalarFiniteElement<2> & fel =
      dynamic_cast<const ScalarFiniteElement<2> &> (base_fel);

    // number of element basis functions:
    int ndof = fel.GetNDof();

    elmat = 0;

    Matrix<> dshape_ref(ndof, 2); // gradient on reference element
    Matrix<> dshape(ndof, 2);     // gradient on mapped element

    /*
      get integration rule for element geometry, 
      integration order is 2 times element order
    */
    IntegrationRule ir(fel.ElementType(), 2*fel.Order());

    // loop over integration points
    for (int i = 0 ; i < ir.GetNIP(); i++)
      {
        // calculate Jacobi matrix in the integration point
        MappedIntegrationPoint<2,2> mip(ir[i], eltrans);

        // lambda(x)
        double lam = coef_lambda -> Evaluate (mip);

        /*
          gradient on reference element
          the i-th row of the matrix is the grad of the i-th shape function
        */
        fel.CalcDShape (ir[i], dshape_ref);
        
        // transform it for the mapped element
        dshape = dshape_ref * mip.GetJacobianInverse();
        
        // integration weight and Jacobi determinant
        double fac = mip.IP().Weight() * mip.GetMeasure();

        // elmat_{i,j} += (fac*lam) * InnerProduct (grad shape_i, grad shape_j)
        elmat += (fac*lam) * dshape * Trans(dshape);
      }     
  }
Пример #5
0
  void FluxFluxBoundary<D> ::
  T_CalcElementMatrix (const FiniteElement & base_fel,
		       const ElementTransformation & eltrans, 
		       FlatMatrix<SCAL> elmat,
		       LocalHeap & lh) const {

    const CompoundFiniteElement &  cfel      // product space 
      =  dynamic_cast<const CompoundFiniteElement&> (base_fel);
    
    // This FE is already multiplied by normal:
    const HDivNormalFiniteElement<D-1> & fel_q = // q.n space
      dynamic_cast<const HDivNormalFiniteElement<D-1>&> (cfel[GetInd1()]);

    const HDivNormalFiniteElement<D-1> & fel_r = // r.n space
      dynamic_cast<const HDivNormalFiniteElement<D-1>&> (cfel[GetInd2()]);
    
    elmat = SCAL(0.0);

    IntRange rq = cfel.GetRange(GetInd1());
    IntRange rr = cfel.GetRange(GetInd2());
    int ndofq = rq.Size();
    int ndofr = rr.Size();
 
    FlatMatrix<SCAL> submat(ndofr, ndofq, lh);  
    submat = SCAL(0.0);
    
    FlatVector<> qshape(fel_q.GetNDof(), lh);
    FlatVector<> rshape(fel_r.GetNDof(), lh);

    const IntegrationRule ir(fel_q.ElementType(), 
			     fel_q.Order() + fel_r.Order());

    for (int i = 0 ; i < ir.GetNIP(); i++) {

      MappedIntegrationPoint<D-1,D> mip(ir[i], eltrans);

      SCAL cc = coeff_c -> T_Evaluate<SCAL>(mip);

      fel_r.CalcShape (ir[i], rshape);
      fel_q.CalcShape (ir[i], qshape);
      // mapped q.n-shape is simply reference q.n-shape / measure
      qshape *= 1.0/mip.GetMeasure();
      rshape *= 1.0/mip.GetMeasure();
      //                              [ndofr x 1]  [1 x ndofq]
      submat += (cc*mip.GetWeight()) * rshape  * Trans(qshape);
    }       

    elmat.Rows(rr).Cols(rq) += submat;
    if (GetInd1() != GetInd2())
      elmat.Rows(rq).Cols(rr) += Conj(Trans(submat));
  }
static void AllocationGenerateScriptMips(RsContext con, RsAllocation va) {
    Context *rsc = static_cast<Context *>(con);
    Allocation *texAlloc = static_cast<Allocation *>(va);
    uint32_t numFaces = texAlloc->getType()->getDimFaces() ? 6 : 1;
    for (uint32_t face = 0; face < numFaces; face ++) {
        Adapter2D adapt(rsc, texAlloc);
        Adapter2D adapt2(rsc, texAlloc);
        adapt.setFace(face);
        adapt2.setFace(face);
        for (uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
            adapt.setLOD(lod);
            adapt2.setLOD(lod + 1);
            mip(adapt2, adapt);
        }
    }
}
Пример #7
0
  void TraceTraceBoundary<D> ::
  T_CalcElementMatrix (const FiniteElement & base_fel,
		       const ElementTransformation & eltrans, 
		       FlatMatrix<SCAL> elmat,
		       LocalHeap & lh) const {

    const CompoundFiniteElement &  cfel      // product space 
      =  dynamic_cast<const CompoundFiniteElement&> (base_fel);

    // get surface elements
    const ScalarFiniteElement<D-1> & fel_u = // u space
      dynamic_cast<const ScalarFiniteElement<D-1>&> (cfel[GetInd1()]);
    const ScalarFiniteElement<D-1> & fel_e = // u space
      dynamic_cast<const ScalarFiniteElement<D-1>&> (cfel[GetInd2()]);

    elmat = SCAL(0.0);

    IntRange ru = cfel.GetRange(GetInd1());
    IntRange re = cfel.GetRange(GetInd2());
    int ndofu = ru.Size();
    int ndofe = re.Size();
 
    FlatMatrix<SCAL> submat(ndofe, ndofu, lh);  
    submat = SCAL(0.0);
    
    FlatVector<> ushape(fel_u.GetNDof(), lh);
    FlatVector<> eshape(fel_e.GetNDof(), lh);

    const IntegrationRule ir(fel_u.ElementType(), 
			     fel_u.Order() + fel_e.Order());

    for (int i = 0 ; i < ir.GetNIP(); i++) {

      MappedIntegrationPoint<D-1,D> mip(ir[i], eltrans);

      SCAL cc = coeff_c -> T_Evaluate<SCAL>(mip);

      fel_u.CalcShape (ir[i], ushape);
      fel_e.CalcShape (ir[i], eshape);
      //                             [ndofe x 1]  [1 x ndofu]
      submat += (cc*mip.GetWeight()) * eshape  * Trans(ushape);
    }       

    elmat.Rows(re).Cols(ru) += submat;
    if (GetInd1() != GetInd2())
      elmat.Rows(ru).Cols(re) += Conj(Trans(submat));
  }
Пример #8
0
void MainWindow::openFile()
{
    path = QFileDialog::getOpenFileName(this,
                                        tr("Open File"),
                                        ".",
                                        tr("Text Files(*.asm *.ASM *.bin *.coe)"));
    QFileInfo filepath(path);
    if(filepath.exists()) {
        QFile file(path);
        if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
            QMessageBox::warning(this, tr("Read File"),
                                 tr("Cannot open file:\n%1").arg(path));
            return;
        }
        QFileInfo fi(path);
        QTextStream in(&file);
        ui->textEdit->setText(in.readAll());
        ui->textEdit->setEnabled(true);
        this->setWindowTitle(fi.completeBaseName()+"[*]");
        emit hasSaved();
        in.seek(0);
        if (fi.suffix()=="asm"||fi.suffix()=="ASM"){
            Mips mip(in);
            instrutions=mip;
        }else if (fi.suffix()=="coe"){
            Mipscoe mipcoe(in);
            coeinst=mipcoe;
        }else {

        }
        file.close();
        ui->textBrowser->clear();
        hasbuild=false;
    }

}
Пример #9
0
int _main_(int _argc, char** _argv)
{
	bx::CommandLine cmdLine(_argc, _argv);

	if (cmdLine.hasArg('h', "help") )
	{
		help();
		return EXIT_FAILURE;
	}
	else if (cmdLine.hasArg("associate") )
	{
		associate();
		return EXIT_FAILURE;
	}

	uint32_t width  = 1280;
	uint32_t height = 720;
	uint32_t debug  = BGFX_DEBUG_TEXT;
	uint32_t reset  = BGFX_RESET_VSYNC;

	inputAddBindings(s_bindingName[Binding::App],  s_binding[Binding::App]);
	inputAddBindings(s_bindingName[Binding::View], s_binding[Binding::View]);

	View view;
	cmdAdd("view", cmdView, &view);

	bgfx::init();
	bgfx::reset(width, height, reset);

	// Set view 0 clear state.
	bgfx::setViewClear(0
		, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
		, 0x101010ff
		, 1.0f
		, 0
		);

	imguiCreate();

	PosUvColorVertex::init();

	bgfx::RendererType::Enum type = bgfx::getRendererType();

	bgfx::ShaderHandle vsTexture      = bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_texture");
	bgfx::ShaderHandle fsTexture      = bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture");
	bgfx::ShaderHandle fsTextureArray = bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_array");

	bgfx::ProgramHandle textureProgram = bgfx::createProgram(
			  vsTexture
			, fsTexture
			, true
			);

	bgfx::ProgramHandle textureArrayProgram = bgfx::createProgram(
			  vsTexture
			, bgfx::isValid(fsTextureArray)
			? fsTextureArray
			: fsTexture
			, true
			);

	bgfx::ProgramHandle textureCubeProgram = bgfx::createProgram(
			  bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_texture_cube")
			, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_cube")
			, true
			);

	bgfx::ProgramHandle textureSDFProgram = bgfx::createProgram(
			  vsTexture
			, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_sdf")
			, true);

	bgfx::UniformHandle s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1);
	bgfx::UniformHandle u_mtx      = bgfx::createUniform("u_mtx",      bgfx::UniformType::Mat4);
	bgfx::UniformHandle u_params   = bgfx::createUniform("u_params",   bgfx::UniformType::Vec4);

	float speed = 0.37f;
	float time  = 0.0f;

	Interpolator mip(0.0f);
	Interpolator layer(0.0f);
	Interpolator zoom(1.0f);
	Interpolator scale(1.0f);

	const char* filePath = _argc < 2 ? "" : _argv[1];
	bool directory = false;

	bx::FileInfo fi;
	bx::stat(filePath, fi);
	directory = bx::FileInfo::Directory == fi.m_type;

	std::string path = filePath;
	if (!directory)
	{
		const char* fileName = directory ? filePath : bx::baseName(filePath);
		path.assign(filePath, fileName);
		view.updateFileList(path.c_str(), fileName);
	}
	else
	{
		view.updateFileList(path.c_str() );
	}

	int exitcode = EXIT_SUCCESS;
	bgfx::TextureHandle texture = BGFX_INVALID_HANDLE;

	if (view.m_fileList.empty() )
	{
		exitcode = EXIT_FAILURE;
		if (2 > _argc)
		{
			help("File path is not specified.");
		}
		else
		{
			fprintf(stderr, "Unable to load '%s' texture.\n", filePath);
		}
	}
	else
	{
		uint32_t fileIndex = 0;

		entry::MouseState mouseState;
		while (!entry::processEvents(width, height, debug, reset, &mouseState) )
		{
			imguiBeginFrame(mouseState.m_mx
				, mouseState.m_my
				, (mouseState.m_buttons[entry::MouseButton::Left  ] ? IMGUI_MBUT_LEFT   : 0)
				| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT  : 0)
				| (mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
				, mouseState.m_mz
				, width
				, height
				);

			static bool help = false;

			if (help == false
			&&  help != view.m_help)
			{
				ImGui::OpenPopup("Help");
			}

			if (ImGui::BeginPopupModal("Help", NULL, ImGuiWindowFlags_AlwaysAutoResize) )
			{
				ImGui::SetWindowFontScale(1.0f);

				ImGui::Text(
					"texturev, bgfx texture viewer tool " ICON_KI_WRENCH "\n"
					"Copyright 2011-2017 Branimir Karadzic. All rights reserved.\n"
					"License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause\n"
					);
				ImGui::Separator();
				ImGui::NextLine();

				ImGui::Text("Key bindings:\n\n");

				ImGui::PushFont(ImGui::Font::Mono);
				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "ESC");   ImGui::SameLine(64); ImGui::Text("Exit.");
				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "h");     ImGui::SameLine(64); ImGui::Text("Toggle help screen.");
				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "f");     ImGui::SameLine(64); ImGui::Text("Toggle full-screen.");
				ImGui::NextLine();

				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "-");     ImGui::SameLine(64); ImGui::Text("Zoom out.");
				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "=");     ImGui::SameLine(64); ImGui::Text("Zoom in.");
				ImGui::NextLine();

				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), ",");     ImGui::SameLine(64); ImGui::Text("MIP level up.");
				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), ".");     ImGui::SameLine(64); ImGui::Text("MIP level down.");
				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "/");     ImGui::SameLine(64); ImGui::Text("Toggle linear/point texture sampling.");
				ImGui::NextLine();

				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "left");  ImGui::SameLine(64); ImGui::Text("Previous layer in texture array.");
				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "right"); ImGui::SameLine(64); ImGui::Text("Next layer in texture array.");
				ImGui::NextLine();

				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "up");    ImGui::SameLine(64); ImGui::Text("Previous texture.");
				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "down");  ImGui::SameLine(64); ImGui::Text("Next texture.");
				ImGui::NextLine();

				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "r/g/b"); ImGui::SameLine(64); ImGui::Text("Toggle R, G, or B color channel.");
				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "a");     ImGui::SameLine(64); ImGui::Text("Toggle alpha blending.");
				ImGui::NextLine();

				ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "s");     ImGui::SameLine(64); ImGui::Text("Toggle Multi-channel SDF rendering");

				ImGui::PopFont();

				ImGui::NextLine();

				ImGui::Dummy(ImVec2(0.0f, 0.0f) );
				ImGui::SameLine(ImGui::GetWindowWidth() - 136.0f);
				if (ImGui::Button("Close", ImVec2(128.0f, 0.0f) )
				|| !view.m_help)
				{
					view.m_help = false;
					ImGui::CloseCurrentPopup();
				}

				ImGui::EndPopup();
			}

			help = view.m_help;

			imguiEndFrame();

			if (!bgfx::isValid(texture)
			||  view.m_fileIndex != fileIndex)
			{
				if (bgfx::isValid(texture) )
				{
					bgfx::destroyTexture(texture);
				}

				fileIndex = view.m_fileIndex;

				filePath = view.m_fileList[view.m_fileIndex].c_str();

				texture = loadTexture(filePath
						, 0
						| BGFX_TEXTURE_U_CLAMP
						| BGFX_TEXTURE_V_CLAMP
						| BGFX_TEXTURE_W_CLAMP
						, 0
						, &view.m_info
						);

				std::string title;
				bx::stringPrintf(title, "%s (%d x %d%s, %s)"
					, filePath
					, view.m_info.width
					, view.m_info.height
					, view.m_info.cubeMap ? " CubeMap" : ""
					, bgfx::getName(view.m_info.format)
					);
				entry::WindowHandle handle = { 0 };
				entry::setWindowTitle(handle, title.c_str() );
			}

			int64_t now = bx::getHPCounter();
			static int64_t last = now;
			const int64_t frameTime = now - last;
			last = now;
			const double freq = double(bx::getHPFrequency() );

			time += (float)(frameTime*speed/freq);

			float ortho[16];
			bx::mtxOrtho(ortho, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f);
			bgfx::setViewTransform(0, NULL, ortho);
			bgfx::setViewRect(0, 0, 0, width, height);
			bgfx::touch(0);

			bgfx::dbgTextClear();

			scale.set(
				  bx::fmin( float(width) / float(view.m_info.width)
				, float(height) / float(view.m_info.height)
				)
				, 0.1f
				);
			zoom.set(view.m_zoom, 0.25);

			float ss = scale.getValue() * zoom.getValue();

			screenQuad( int(width  - view.m_info.width  * ss)/2
				, int(height - view.m_info.height * ss)/2
				, int(view.m_info.width  * ss)
				, int(view.m_info.height * ss)
				, view.m_abgr
				);

			float mtx[16];
			bx::mtxRotateXY(mtx, 0.0f, time);
			bgfx::setUniform(u_mtx, mtx);

			mip.set(float(view.m_mip), 0.5f);
			layer.set(float(view.m_layer), 0.25f);

			float params[4] = { mip.getValue(), layer.getValue(), 0.0f, 0.0f };
			bgfx::setUniform(u_params, params);

			bgfx::setTexture(0
				, s_texColor
				, texture
				, view.m_filter
				? BGFX_TEXTURE_NONE
				: 0
				| BGFX_TEXTURE_MIN_POINT
				| BGFX_TEXTURE_MIP_POINT
				| BGFX_TEXTURE_MAG_POINT
				);
			bgfx::setState(0
				| BGFX_STATE_RGB_WRITE
				| BGFX_STATE_ALPHA_WRITE
				| (view.m_alpha ? BGFX_STATE_BLEND_ALPHA : BGFX_STATE_NONE)
				);
			bgfx::submit(0
					,     view.m_info.cubeMap   ? textureCubeProgram
					: 1 < view.m_info.numLayers ? textureArrayProgram
					:     view.m_sdf            ? textureSDFProgram
					:                             textureProgram
					);

			bgfx::frame();
		}
	}

	if (bgfx::isValid(texture) )
	{
		bgfx::destroyTexture(texture);
	}
	bgfx::destroyUniform(s_texColor);
	bgfx::destroyUniform(u_mtx);
	bgfx::destroyUniform(u_params);
	bgfx::destroyProgram(textureProgram);
	bgfx::destroyProgram(textureArrayProgram);
	bgfx::destroyProgram(textureCubeProgram);

	imguiDestroy();

	bgfx::shutdown();

	return exitcode;
}
Пример #10
0
  void MyVTKOutput<D>::BuildGridString()
  {
    ostringstream ss;
    // header:
    ss << "# vtk DataFile Version 3.0" << endl;
    ss << "vtk output" << endl;
    ss << "ASCII" << endl;
    ss << "DATASET UNSTRUCTURED_GRID" << endl;

    int ne = ma->GetNE();

    IntRange range = only_element >= 0 ? IntRange(only_element,only_element+1) : IntRange(ne);

    Array<Vec<D>> points;
    Array<Array<int>> cells;
    Array<int> cell_types;
    int pointcnt = 0;
    LocalHeap lh(1000000);
    bool maybewarn = subdivision != 0;
    for (int elnr : range)
    {
      HeapReset hr(lh);

      auto el = ma->GetElement(elnr);
      auto et = el.GetType();
      if (et == ET_TRIG || et == ET_TET)
      {
        ElementTransformation & eltrans = ma->GetTrafo(elnr, VOL, lh);

        int offset = points.Size();
        for (auto ip : ref_vertices)
        {
          MappedIntegrationPoint<D,D> mip(ip, eltrans);
          points.Append(mip.GetPoint());
        }

        for (auto tet : ref_elements)
        {
          Array<int> new_tet;
          for (int i = 0; i < D+1; ++i)
          {
            pointcnt++;
            new_tet.Append(tet[i] + offset);
          }
          cells.Append(new_tet);
          cell_types.Append(ElementTypeToVTKType(et));
        }
      }
      else
      {
        if (maybewarn)
        {
          cout << endl << " Warning: VTKOutput: subdivision not implemented for element types other than trigs / tets" << endl;
          maybewarn = false;
        }
        auto vertices = el.Vertices();

        Array<int> element_point_ids;
        for (int p : vertices)
        {
          points.Append(ma->GetPoint<D>(p));
          element_point_ids.Append(points.Size() - 1);
          pointcnt++;
        }

        cells.Append(element_point_ids);
        cell_types.Append(ElementTypeToVTKType(et));
      }
    }

    ss << "POINTS " << points.Size() << " float" << endl;
    for (const Vec<D> & p : points)
    {
      int i = 0;
      for (; i < D; ++i)
        ss << p[i] << " ";

      for (; i < 3; ++i)
        ss << "\t 0.0";
      ss << endl;
    }

    ss << "CELLS " << cells.Size() << " " << pointcnt + cells.Size() << endl;
    for (const Array<int> & c : cells)
    {
      ss << c.Size() << " ";
      for (int point : c)
        ss << point << " ";
      ss << endl;
    }

    ss << "CELL_TYPES " << cell_types.Size() << endl;
    for (int ct : cell_types)
      ss << ct << endl;

    ss << "CELL_DATA " << cells.Size() << endl;
    ss << "POINT_DATA " << points.Size() << endl;

    grid_str = ss.str();
  }
Пример #11
0
  void MyVTKOutput<D>::Do(LocalHeap & lh, const BitArray * drawelems)
  {
    ostringstream filenamefinal;
    filenamefinal << filename << output_cnt << ".vtk";
    ofstream fileout(filenamefinal.str());
    cout << " Writing VTK-Output";
    if (output_cnt > 0)
      cout << " ( " << output_cnt << " )";
    cout << ":" << flush;

    output_cnt++;

    if (nocache)
      BuildGridString();

    fileout << grid_str;

    int ne = ma->GetNE();

    IntRange range = only_element >= 0 ? IntRange(only_element,only_element+1) : IntRange(ne);

    for (int elnr : range)
    {
      if (drawelems && !(drawelems->Test(elnr)))
          continue;

      HeapReset hr(lh);

      ElementTransformation & eltrans = ma->GetTrafo(elnr, VOL, lh);
      auto el = ma->GetElement(elnr);
      ELEMENT_TYPE et = el.GetType();
      if (et == ET_TRIG || et == ET_TET)
      {
        for (auto ip : ref_vertices)
        {
          MappedIntegrationPoint<D,D> mip(ip, eltrans);
          for (int i = 0; i < coefs.Size(); i++)
          {
            const int dim = coefs[i]->Dimension();
            FlatVector<> tmp(dim,lh);
            coefs[i]->Evaluate(mip,tmp);
            for (int d = 0; d < dim; ++d)
              value_field[i]->Append(tmp(d));
          }
        }
      }
      else
      {
        const POINT3D *vertices = ElementTopology::GetVertices(et);
        int nv = ElementTopology::GetNVertices(et);

        for (int j = 0; j < nv; ++j)
        {
          MappedIntegrationPoint<D,D> mip(IntegrationPoint(vertices[j][0], vertices[j][1], vertices[j][2]), eltrans);
          for (int i = 0; i < coefs.Size(); ++i)
          {
            const int dim = coefs[i]->Dimension();
            FlatVector<> tmp(dim,lh);
            coefs[i]->Evaluate(mip,tmp);
            for (int d = 0; d < dim; ++d)
              value_field[i]->Append(tmp(d));
          }
        }
      }

    }

    PrintFieldData(fileout);

    for (auto field : value_field)
      field->SetSize(0);

    cout << " Done." << endl;
  }