Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample PR - C++ #2

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"files.associations": {
"string": "cpp",
"array": "cpp",
"string_view": "cpp",
"initializer_list": "cpp",
"utility": "cpp"
}
}
15 changes: 15 additions & 0 deletions ChildClass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "ChildClass.h"

using namespace GlobalContextClassNameSpace;

ChildClass::ChildClass()
: ParentClass()
{

}

ChildClass::~ChildClass()
{

}

29 changes: 29 additions & 0 deletions ChildClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef CHILD_CLASS_CONTEXT_MODEL_H
#define CHILD_CLASS_CONTEXT_MODEL_H

#include "ParentClass.h"

namespace GlobalContextClassNameSpace
{

// only use this context when defined
class ChildClass: public ParentClass
{
public:
ChildClass();
virtual ~ChildClass(){};

virtual int getValue() const override;
};

inline int ChildClass::getValue() const
{
return 3;
}


} // GlobalContextClassNameSpace



#endif
17 changes: 17 additions & 0 deletions ParentClass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "ParentClass.h"

using namespace GlobalContextClassNameSpace;

ParentClass::ParentClass()
: m_A(0)
, m_B(0.0)
, m_name("hello")
{
std::cout << "ParentClass:" << m_name << std::endl;
}

ParentClass::~ParentClass()
{

}

26 changes: 26 additions & 0 deletions ParentClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef PARENT_CLASS_CONTEXT_MODEL_H
#define PARENT_CLASS_CONTEXT_MODEL_H


namespace GlobalContextClassNameSpace
{
class ParentClass
{
public:
ParentClass();
virtual ~ParentClass();

virtual int getValue() const = 0;

protected:
int m_A = 0;
double m_B = 0.0;

private:
std::string m_name = "";
};
} // GlobalContextClassNameSpace



#endif
33 changes: 33 additions & 0 deletions diff_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/sample_code.cpp b/sample_code.cpp
index 1cfa8b8..3e6c7bd 100644
--- a/sample_code.cpp
+++ b/sample_code.cpp
@@ -8,7 +8,7 @@ int functionA()
int num = 5;
while (num < 10) {
std::cout << num << std::endl;
- num++;
+ num--;
}
return 0;
}
@@ -16,7 +16,7 @@ int functionA()
int sum(std::list<int> lst)
{
int total = 0;
- for (auto it = lst.begin(); it != lst.end(); it++)
+ for (auto it = lst.begin(); it != --lst.end(); it++)
{
total += *it;
}
@@ -28,8 +28,8 @@ double average(int arr[], int size) {
for (int i = 0; i < size; i++) {
sum += arr[i];
}
- int num = size;
- return sum / double(num);
+ int num = rand() % 10 + 1;
+ return sum / num;
}

int main() {
56 changes: 56 additions & 0 deletions extract_git_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

#!/usr/bin/python3

import os
import shutil
import subprocess
import pandas as pd
import numpy as np
import string
import enum
from typing import List, Optional


THIS_DIR = os.path.abspath(os.path.dirname(__file__))
FILE_DIR = THIS_DIR + '/mesh/'
DST_FOLDER_OUTPUT = THIS_DIR + '/git_diff_output/'

def git_diff_per_file(in_list: list):
numb = len(in_list)
print(f'Number of files: {numb}')
data = pd.DataFrame(columns=['code_files','size'], index=range(numb))

index = 0
for item in in_list:
if not os.path.isfile(item):
continue
print(f'{index}: {item}')

source = FILE_DIR + item
output = DST_FOLDER_OUTPUT + item + ".gitdiff.txt"
cmd = (
"git diff master 2e7237f "
f"{source} "
f"> {output} "
)
os.system(cmd)


def main():
print(f'directory {FILE_DIR}')
if not os.path.exists(FILE_DIR):
print('File structure not as expected!\n')
return

dst = os.path.join(THIS_DIR, DST_FOLDER_OUTPUT )
if not os.path.exists(dst):
os.makedirs(DST_FOLDER_OUTPUT)

os.chdir(FILE_DIR)
git_diff_per_file(os.listdir(os.curdir))


exit(0)

if __name__ == '__main__':
main()
12 changes: 12 additions & 0 deletions git_diff_output/AnalysisInfo.h.gitdiff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/mesh/AnalysisInfo.h b/mesh/AnalysisInfo.h
index a48c431..6f8142b 100644
--- a/mesh/AnalysisInfo.h
+++ b/mesh/AnalysisInfo.h
@@ -190,6 +190,7 @@ class MeshAnalysisInfo : public AnalysisInfo
double dOccGeometryVolume = 0;
double dSurfaceArea = 0;
double dMeshingDuration = 0; // time in seconds to tet mesh
+ double dPrimeFileIODuration = 0; // time in seconds to read/write prime files
double dTetVolume = 0; // tet volume before projection
double dTetVolumeAfterProjection = 0; // tet volume after projection
double dVolumeDiffPercent = 0;
44 changes: 44 additions & 0 deletions git_diff_output/CMakeLists.txt.gitdiff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
diff --git a/mesh/CMakeLists.txt b/mesh/CMakeLists.txt
index 4c3c187..51bda9d 100644
--- a/mesh/CMakeLists.txt
+++ b/mesh/CMakeLists.txt
@@ -215,6 +215,21 @@ if(NOT CadEx_FOUND OR CAD_FORCE_DATAKIT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCAD_HAS_DATAKIT")
endif()

+if(DEFINED ENV{PRIME_MESHER_VER})
+ set(PRIME_VER "20.01.23-centos_7_2.7")
+ message(STATUS "Found PRIME Version at: ${PRIME_VER}")
+ set(PRIME_SOURCE_LIB /opt/onscale/pyprimemesh-v${PRIME_VER}/pyprimemesh-v${PRIME_VER}.tar)
+ message(STATUS "Found PRIME_SOURCE_LIB: ${PRIME_SOURCE_LIB}")
+ set(PRIME_TARGET_LIB ${CMAKE_BINARY_DIR}/lib/pyprimemesh.tar)
+ set(PRIME_TARGET_DES ${CMAKE_BINARY_DIR}/lib)
+ message(STATUS "PRIME_TARGET_LIB: ${PRIME_TARGET_LIB}")
+ file(COPY ${PRIME_SOURCE_LIB} DESTINATION ${PRIME_TARGET_DES})
+ set(PRIME_LIB ${CMAKE_BINARY_DIR}/lib/pyprimemesh-v${PRIME_VER}.tar)
+ file(RENAME ${PRIME_LIB} ${PRIME_TARGET_LIB})
+else()
+ message(STATUS "No PRIME_MESHER_VER defined")
+endif()
+
# add CM2 mesher library
if(DEFINED ENV{CM2_VER})
message(STATUS "Use cm2 version: " $ENV{CM2_VER})
@@ -305,7 +320,7 @@ find_library(LIB_ANSYS_PRIME_MESH_DIR PrimeMesh PATHS "$ENV{ANSYS_PRIME_MESH_DIR
find_path(INC_ANSYS_PRIME_MESH PrimeModel PATHS "$ENV{ANSYS_PRIME_MESH_DIR}/include")

if(NOT LIB_ANSYS_PRIME_MESH_DIR)
- message(STATUS "OnScale::CAD -> Won't use Ansys Prime Mesher.")
+ message(STATUS "OnScale::CAD -> Won't use Ansys Prime Mesher dlls.")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCAD_HAS_ANSYS_PRIME")

@@ -463,6 +478,8 @@ if(NOT ${OnScale_CAD_LITE})
Cm2Construction3D.h
Cm2ConstructionTet3D.cpp
Cm2ConstructionTet3D.h
+ PrimeFileIO.h
+ PrimeFileIO.cpp
PrimeConstructionTet3D.cpp
PrimeConstructionTet3D.h
AnsysConstruction3D.cpp
27 changes: 27 additions & 0 deletions git_diff_output/Cm2Construction3D.cpp.gitdiff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/mesh/Cm2Construction3D.cpp b/mesh/Cm2Construction3D.cpp
index e7e347a..bb59f67 100644
--- a/mesh/Cm2Construction3D.cpp
+++ b/mesh/Cm2Construction3D.cpp
@@ -154,6 +154,13 @@ bool Cm2Construction3D::build()
{
iNumberOfMesherRestart++;

+ //[TODO] remove following msg stmts
+ m_occData->addMsg("Remesher Error Code: " + std::to_string(m_iRemesherErrorCode));
+ m_occData->addMsg("Tetmesher Error Code: " + std::to_string(m_iTetmesherErrorCode));
+ m_occData->addMsg("Tetmesher Warning Code: " + std::to_string(m_iTetmesherWarningCode));
+ m_occData->addMsg("Number of Tets: " + std::to_string(numberOfElements()));
+ m_occData->addMsg("PartIDs with No Elements: " + std::to_string(m_meshInfo.partListWithNoElements.size()));
+
// CM2_BOUNDARY_WARNING = -15
// CM2_FACE_DISCARDED = -14
// CM2_NODE_DISCARDED = -12
@@ -169,7 +176,7 @@ bool Cm2Construction3D::build()
(m_iTetmesherWarningCode == cm2::tetramesh_iso::mesher::data_type::CM2_FACE_DISCARDED &&
m_meshInfo.partListWithNoElements.size() != 0) ||
(m_iTetmesherWarningCode == cm2::tetramesh_iso::mesher::data_type::CM2_NODE_DISCARDED &&
- m_meshInfo.partListWithNoElements.size() != 0) )
+ m_meshInfo.partListWithNoElements.size() != 0))
{
// We are in a situation, where the default fix intersection tolerance doesn't work.
// So, we try to use a smaller fix intersection tolerance and restart the meshing process.
13 changes: 13 additions & 0 deletions git_diff_output/Cm2Construction3D.h.gitdiff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/mesh/Cm2Construction3D.h b/mesh/Cm2Construction3D.h
index f8f56ad..ce2ba7a 100644
--- a/mesh/Cm2Construction3D.h
+++ b/mesh/Cm2Construction3D.h
@@ -125,6 +125,8 @@ class Cm2Construction3D : public Cgal3DPolyhedronConstruction
double m_dBondingDurationUntilNow = 0;
bool m_bModelTooComplexForBonding = false;

+ double m_dPrimeFileIODuration = 0;
+
cm2::element_type m_feType; // CM2_TETRA4 or CM2_HEXA8

cm2::DoubleMat m_pos; // mesh coordinates
75 changes: 75 additions & 0 deletions git_diff_output/Cm2ConstructionTet3D.cpp.gitdiff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
diff --git a/mesh/Cm2ConstructionTet3D.cpp b/mesh/Cm2ConstructionTet3D.cpp
index 1580e15..8aad957 100644
--- a/mesh/Cm2ConstructionTet3D.cpp
+++ b/mesh/Cm2ConstructionTet3D.cpp
@@ -7,6 +7,8 @@
#include "Cm2ConstructionTet3D.h"
#include "DistanceTetMeshToCad.h"

+#include "PrimeFileIO.h"
+
#include "OccFileReader.h"
#include "OccFileWriter.h"

@@ -262,7 +264,7 @@ void Cm2ConstructionTet3D::generateTetMesh(cm2::intersect_t3::mesher::data_type
dataAll.colors = secondAll.colors;
}
}
- m_iNumberOfRemesherIterations = iCount -1;
+ m_iNumberOfRemesherIterations = iCount - 1;
m_occData->addMsg("Number of remeshing iterations: " + std::to_string(m_iNumberOfRemesherIterations));

if (m_bRemesherFailed)
@@ -294,6 +296,12 @@ void Cm2ConstructionTet3D::generateTetMesh(cm2::intersect_t3::mesher::data_type
return;
}

+ if (m_occData->isAddDebugInfoFlag() >= 5)
+ {
+ PrimeFileIO fileio(this);
+ fileio.writeBoundaryMesh(secondAll);
+ }
+
// tetra meshing
if (!createTetMesh(secondAll))
return;
@@ -312,6 +320,7 @@ void Cm2ConstructionTet3D::generateTetMesh(cm2::intersect_t3::mesher::data_type

m_cellColors = m_tetData.colors;
m_connectM = m_tetData.connectM;
+ m_connectB = m_tetData.connectB;
m_pos = m_tetData.pos;
m_shape_qualities = m_tetData.shape_qualities;

@@ -326,6 +335,7 @@ void Cm2ConstructionTet3D::generateTetMesh(cm2::intersect_t3::mesher::data_type
Standard_Real rVolDiff2 = std::fabs(rVolTest3 - rVolTest2);

meshInfo.dMeshingDuration = m_tetData.total_time;
+ meshInfo.dPrimeFileIODuration = m_dPrimeFileIODuration;
m_meshInfo.dOccGeometryVolume = rVolTest3;
m_meshInfo.dSurfaceArea = m_dSurfaceArea;
m_meshInfo.dTetVolume = rVolTest2;
@@ -348,18 +358,17 @@ void Cm2ConstructionTet3D::generateTetMesh(cm2::intersect_t3::mesher::data_type
meshInfo.dJacobianMin = dMinJacobian;
meshInfo.dJacobianMax = dMaxJacobian;

- const cm2::misc::histogram &histo_Qs = m_tetData.histo_Qs;
- meshInfo.dAverageCellQuality = histo_Qs.mean_value();
- meshInfo.dWorstCellQuality = histo_Qs.min_value();
+ meshInfo.dAverageCellQuality = getAverageCellQuality();
+ meshInfo.dWorstCellQuality = getWorstCellQuality();

- size_t numberOfBins = histo_Qs.bins();
- const cm2::DoubleVec &bin_boundaries = histo_Qs.bin_boundaries();
+ size_t numberOfBins = m_tetData.histo_Qs.bins();
+ const cm2::DoubleVec &bin_boundaries = m_tetData.histo_Qs.bin_boundaries();

for (size_t i = 0; i < numberOfBins; ++i)
{
const double lower = bin_boundaries.at(i);
const double upper = bin_boundaries.at(i + 1);
- const unsigned int hits = histo_Qs.hits(i);
+ const unsigned int hits = m_tetData.histo_Qs.hits(i);
meshInfo.cellQualities.push_back(std::make_tuple(lower, upper, hits));
}

15 changes: 15 additions & 0 deletions git_diff_output/Cm2ConstructionTet3D.h.gitdiff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/mesh/Cm2ConstructionTet3D.h b/mesh/Cm2ConstructionTet3D.h
index 1b0a890..c5e9ae7 100644
--- a/mesh/Cm2ConstructionTet3D.h
+++ b/mesh/Cm2ConstructionTet3D.h
@@ -54,6 +54,9 @@ class Cm2ConstructionTet3D : public Cm2Construction3D
void checkMeshToCadFit();

void cellCenter(int iE, double &dX, double &dY, double &dZ) override;
+
+ virtual double getAverageCellQuality() { return m_tetData.histo_Qs.mean_value(); }
+ virtual double getWorstCellQuality() { return m_tetData.histo_Qs.min_value(); }
};

#endif
\ No newline at end of file
Loading