MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / ExportVisFunctions

Function ExportVisFunctions

solve/python_solve.cpp:450–955  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

448}
449
450void ExportVisFunctions(py::module &m) {
451 m.def("_GetVisualizationData", [] (shared_ptr<ngcomp::MeshAccess> ma, map<ngfem::ELEMENT_TYPE, IntegrationRule> irs) {
452 struct ElementInformation {
453 ElementInformation( ngfem::ELEMENT_TYPE type_, bool curved_=false)
454 : type(type_), curved(curved_), nelements(0) { }
455 Array<int> data; // the data that will go into the gpu texture buffer
456 ngfem::ELEMENT_TYPE type;
457 bool curved;
458 int nelements;
459 };
460
461 auto getVB = [](int codim) {
462 switch(codim) {
463 case 0: return VOL;
464 case 1: return BND;
465 case 2: return BBND;
466 case 3: return BBBND;
467 default: throw Exception("invalid codim");
468 }
469 };
470
471 Vector<> min(3);
472 min = std::numeric_limits<double>::max();
473 Vector<> max(3);
474 max = std::numeric_limits<double>::lowest();
475
476 ngstd::Array<float> vertices;
477 vertices.SetAllocSize(ma->GetNV()*3);
478 for ( auto vi : Range(ma->GetNV()) ) {
479 auto v = ma->GetPoint<3>(vi);
480 for (auto i : Range(3)) {
481 vertices.Append(v[i]);
482 min[i] = min2(min[i], v[i]);
483 max[i] = max2(max[i], v[i]);
484 }
485 }
486
487 LocalHeap lh(1000000, "GetMeshData");
488 auto toDict = [] (ElementInformation &ei) {
489 py::dict res;
490 res["data"] = py::cast(ei.data);
491 res["type"] = py::cast(ei.type);
492 res["curved"] = py::cast(ei.curved);
493 res["nelements"] = py::cast(ei.nelements);
494 return res;
495 };
496
497 const int dim = ma->GetDimension();
498
499 std::map<VorB, py::list> element_data;
500 ElementInformation points(ET_POINT);
501 points.nelements = ma->GetNE(getVB(dim));
502 points.data.SetAllocSize(points.nelements);
503 for(auto el : ma->Elements(getVB(dim)))
504 points.data.Append(el.vertices[0]);
505 element_data[getVB(dim)].append(toDict(points));
506
507 ElementInformation edges(ET_SEGM);

Callers 1

Calls 15

MoveToNumpyArrayFunction · 0.85
ElementsMethod · 0.80
VerticesMethod · 0.80
FacesMethod · 0.80
ClearMethod · 0.80
RangeFunction · 0.50
GetNFacetsFunction · 0.50
AppendMethod · 0.45
GetDimensionMethod · 0.45
NrMethod · 0.45
SizeMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected