Skip to content

Commit

Permalink
feat: capability to print a geoel to vtk
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanshauer committed Oct 2, 2023
1 parent 8e13c15 commit ce45489
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 77 deletions.
97 changes: 97 additions & 0 deletions Mesh/pzgeoel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2652,3 +2652,100 @@ TPZGeoEl::ComputeDetjac(TPZFMatrix<Fad<REAL> > &gradx, Fad<REAL> &detjac)
(gradx(2,0)*gradx(1,1)*gradx(0,2) + gradx(0,1)*gradx(2,2)*gradx(1,0) + gradx(1,2)*gradx(0,0)*gradx(2,1));
}
}


void TPZGeoEl::PrintVTK() {
std::string filename = "geoel_index_" + to_string(this->Index()) + ".vtk";
std::ofstream out(filename);
out << "# vtk DataFile Version 3.0" << std::endl;
out << "GeoEl VTK Visualization" << std::endl;
out << "ASCII" << std::endl;
out << "DATASET UNSTRUCTURED_GRID\n" << std::endl;

int nnodes = this->NNodes();
out << "POINTS " << nnodes << " float" << std::endl;

TPZFNMatrix<24,REAL> nodecoord(3,nnodes);
this->NodesCoordinates(nodecoord);
for(int in = 0 ; in < nnodes ; in++) {
for(int idim = 0 ; idim < 3 ; idim++) {
out << nodecoord(idim,in) << "\t";
}
out << std::endl;
}

out << "\nCELLS 1 " << nnodes+1 << std::endl;
out << nnodes << " ";
for(int in = 0 ; in < nnodes ; in++) out << in << " ";
out << std::endl;

out << "\nCELL_TYPES 1" << std::endl;
out << GetVTK_ElType(this) << std::endl;

out << "\nCELL_DATA 1" << std::endl;
out << "FIELD FieldData 1" << std::endl;
out << "elIndex 1 1 int" << std::endl;
out << this->Index() << std::endl;
}

int TPZGeoEl::GetVTK_ElType(TPZGeoEl * gel) {
MElementType pzElType = gel->Type();

int elType = -1;
switch (pzElType) {
case(EPoint):
{
elType = 1;
break;
}
case(EOned):
{
elType = 3;
break;
}
case (ETriangle):
{
elType = 5;
break;
}
case (EQuadrilateral):
{
elType = 9;
break;
}
case (ETetraedro):
{
elType = 10;
break;
}
case (EPiramide):
{
elType = 14;
break;
}
case (EPrisma):
{
elType = 13;
break;
}
case (ECube):
{
elType = 12;
break;
}
default:
{
std::cout << "Element type not found on " << __PRETTY_FUNCTION__ << std::endl;
DebugStop();
break;
}
}
if (elType == -1) {
std::cout << "Element type not found on " << __PRETTY_FUNCTION__ << std::endl;
std::cout << "MIGHT BE CURVED ELEMENT (quadratic or quarter point)" << std::endl;
DebugStop();
}

return elType;
}

6 changes: 6 additions & 0 deletions Mesh/pzgeoel.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ class TPZGeoEl : public virtual TPZSavable {

/** @brief Print all relevant data of the element to cout*/
virtual void Print(std::ostream & out = std::cout);

/** @brief Prints the geoel to vtk format with the name geoel_index_#.vtk */
void PrintVTK();

/**
* @brief Prints the coordinates of all nodes (geometric)
Expand Down Expand Up @@ -738,6 +741,9 @@ class TPZGeoEl : public virtual TPZSavable {
{
return fIndex;
}

/** @brief Get type of the geometric element */
static int GetVTK_ElType(TPZGeoEl *gel);

private:
/** @brief To be used after the buid connectivity. If some neighbour isn't initialized */
Expand Down
87 changes: 13 additions & 74 deletions Post/TPZVTKGeoMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void TPZVTKGeoMesh::PrintCMeshVTK(TPZCompMesh * cmesh, std::ofstream &file, bool
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gel);
int elType = TPZGeoEl::GetVTK_ElType(gel);
type << elType << std::endl;

if (matColor == true) {
Expand Down Expand Up @@ -148,7 +148,7 @@ void TPZVTKGeoMesh::PrintCMeshVTK(TPZGeoMesh * gmesh, std::ofstream &file, bool
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gel);
int elType = TPZGeoEl::GetVTK_ElType(gel);
type << elType << std::endl;

if (matColor == true) {
Expand Down Expand Up @@ -239,7 +239,7 @@ void TPZVTKGeoMesh::PrintGMeshVTK(TPZGeoMesh * gmesh, std::ofstream &file, bool
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gel);
int elType = TPZGeoEl::GetVTK_ElType(gel);
type << elType << std::endl;

if (matColor == true) {
Expand Down Expand Up @@ -332,7 +332,7 @@ void TPZVTKGeoMesh::PrintGMeshVTK(TPZGeoMesh * gmesh, std::ofstream &file, TPZVe
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gel);
int elType = TPZGeoEl::GetVTK_ElType(gel);
type << elType << std::endl;

eldat << elData[el] << std::endl;
Expand Down Expand Up @@ -426,7 +426,7 @@ void TPZVTKGeoMesh::PrintGMeshVTK(TPZGeoMesh * gmesh, std::ofstream &file, TPZVe
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gel);
int elType = TPZGeoEl::GetVTK_ElType(gel);
type << elType << std::endl;

eldat << elData[el] << std::endl;
Expand Down Expand Up @@ -520,7 +520,7 @@ void TPZVTKGeoMesh::PrintCMeshVTK(TPZCompMesh * cmesh, std::ofstream &file, TPZV
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gel);
int elType = TPZGeoEl::GetVTK_ElType(gel);
type << elType << std::endl;

material << elData[el] << std::endl;
Expand Down Expand Up @@ -614,7 +614,7 @@ void TPZVTKGeoMesh::PrintGMeshVTK(TPZGeoMesh * gmesh, char *filename, TPZChunkVe
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gel);
int elType = TPZGeoEl::GetVTK_ElType(gel);
type << elType << std::endl;

material << elData[el] << std::endl;
Expand Down Expand Up @@ -713,7 +713,7 @@ void TPZVTKGeoMesh::PrintGMeshVTK(TPZGeoMesh * gmesh, char *filename, TPZVec<REA
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gel);
int elType = TPZGeoEl::GetVTK_ElType(gel);
type << elType << std::endl;

datael << elData[el] << std::endl;
Expand Down Expand Up @@ -815,7 +815,7 @@ void TPZVTKGeoMesh::PrintGMeshVTK(TPZGeoMesh * gmesh, char *filename, TPZVec<TPZ
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gel);
int elType = TPZGeoEl::GetVTK_ElType(gel);
type << elType << std::endl;
index << gel->Index() << std::endl;

Expand Down Expand Up @@ -918,7 +918,7 @@ void TPZVTKGeoMesh::PrintGMeshVTK(TPZGeoMesh * gmesh, const char *filename, int
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gel);
int elType = TPZGeoEl::GetVTK_ElType(gel);
type << elType << std::endl;

// calculando o valor da solucao para o elemento
Expand Down Expand Up @@ -1031,7 +1031,7 @@ void TPZVTKGeoMesh::PrintGMeshVTKneighbour_material(TPZGeoMesh * gmesh, std::ofs
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gmesh->ElementVec()[el]);
int elType = TPZGeoEl::GetVTK_ElType(gmesh->ElementVec()[el]);
type << elType << std::endl;

if (matColor == true) {
Expand Down Expand Up @@ -1145,7 +1145,7 @@ void TPZVTKGeoMesh::PrintGMeshVTK(TPZGeoMesh * gmesh, std::set<int64_t> & elInde
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gmesh->ElementVec()[el]);
int elType = TPZGeoEl::GetVTK_ElType(gmesh->ElementVec()[el]);
type << elType << std::endl;

elementindex << el << std::endl;
Expand Down Expand Up @@ -1263,7 +1263,7 @@ void TPZVTKGeoMesh::PrintGMeshVTKmy_material(TPZGeoMesh * gmesh, std::ofstream &
}
connectivity << std::endl;

int elType = TPZVTKGeoMesh::GetVTK_ElType(gmesh->ElementVec()[el]);
int elType = TPZGeoEl::GetVTK_ElType(gmesh->ElementVec()[el]);
type << elType << std::endl;

if (matColor == true) {
Expand Down Expand Up @@ -1309,67 +1309,6 @@ void TPZVTKGeoMesh::PrintGMeshVTKmy_material(TPZGeoMesh * gmesh, std::ofstream &
file.close();
}

int TPZVTKGeoMesh::GetVTK_ElType(TPZGeoEl * gel) {
MElementType pzElType = gel->Type();

int elType = -1;
switch (pzElType) {
case(EPoint):
{
elType = 1;
break;
}
case(EOned):
{
elType = 3;
break;
}
case (ETriangle):
{
elType = 5;
break;
}
case (EQuadrilateral):
{
elType = 9;
break;
}
case (ETetraedro):
{
elType = 10;
break;
}
case (EPiramide):
{
elType = 14;
break;
}
case (EPrisma):
{
elType = 13;
break;
}
case (ECube):
{
elType = 12;
break;
}
default:
{
std::cout << "Element type not found on " << __PRETTY_FUNCTION__ << std::endl;
DebugStop();
break;
}
}
if (elType == -1) {
std::cout << "Element type not found on " << __PRETTY_FUNCTION__ << std::endl;
std::cout << "MIGHT BE CURVED ELEMENT (quadratic or quarter point)" << std::endl;
DebugStop();
}

return elType;
}

/** Print a pointmesh whose values are the polynomial orders */
void TPZVTKGeoMesh::PrintPOrderPoints(TPZCompMesh &cmesh, std::set<int> dimensions, std::ofstream &file) {
//Header
Expand Down
3 changes: 0 additions & 3 deletions Post/TPZVTKGeoMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ class TPZVTKGeoMesh

/** @brief Based on a given geomesh, just the elements that have the given material id will be exported to an VTK file */
static void PrintGMeshVTKmy_material(TPZGeoMesh *gmesh, std::ofstream &file, std::set<int> myMaterial, bool matColor = true, bool dimension = false);

/** @brief Get type of the geometric element */
static int GetVTK_ElType(TPZGeoEl *gel);

/** Print a pointmesh whose values are the polynomial orders */
static void PrintPOrderPoints(TPZCompMesh &cmesh,std::set<int> dimensions, std::ofstream &outfile);
Expand Down

0 comments on commit ce45489

Please sign in to comment.