From 4e6b8a2e88f5e0972cbb4a54c45f2db7c1387f0f Mon Sep 17 00:00:00 2001 From: Graeme Kennedy Date: Wed, 6 Mar 2024 15:08:21 -0500 Subject: [PATCH 01/10] fixed cython interface --- Makefile | 4 +- setup.py | 9 +- tmr/TMR.pxd | 685 +---------------------------------- tmr/TMR.pyx | 107 +++--- tmr/__init__.pxd | 0 tmr/__init__.py | 2 + tmr/cpp_headers/TMR.pxd | 684 ++++++++++++++++++++++++++++++++++ tmr/cpp_headers/__init__.pxd | 0 8 files changed, 757 insertions(+), 734 deletions(-) create mode 100644 tmr/__init__.pxd create mode 100644 tmr/cpp_headers/TMR.pxd create mode 100644 tmr/cpp_headers/__init__.pxd diff --git a/Makefile b/Makefile index 5dbbba11..c32c27e3 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ default: echo "making $@ in $$subdir"; \ echo; (cd $$subdir && $(MAKE) TMR_DIR=${TMR_DIR}) || exit 1; \ done - ${CXX} ${SO_LINK_FLAGS} ${TMR_OBJS} ${TMR_EXTERN_LIBS} -o ${TMR_DIR}/lib/libtmr.${SO_EXT} + ${CXX} ${SO_LINK_FLAGS} ${TMR_OBJS} ${TMR_EXTERN_LIBS} -o ${TMR_DIR}/lib/libtmr.${SO_EXT} debug: echo "Building Real TMR" @@ -24,7 +24,7 @@ debug: ${CXX} ${SO_LINK_FLAGS} ${TMR_OBJS} ${TMR_EXTERN_LIBS} -o ${TMR_DIR}/lib/libtmr.${SO_EXT} interface: - ${PYTHON} setup.py build_ext --inplace + pip install -e .\[all\] clean: ${RM} lib/*.a lib/*.so diff --git a/setup.py b/setup.py index 083bfd65..471c395c 100644 --- a/setup.py +++ b/setup.py @@ -2,17 +2,16 @@ from subprocess import check_output import sys -# Numpy/mpi4py must be installed prior to installing TACS +# Numpy/mpi4py must be installed prior to installing import numpy import mpi4py # Import distutils -from setuptools import setup +from setuptools import setup, find_packages from distutils.core import Extension as Ext from Cython.Build import cythonize from Cython.Compiler import Options -Options.embedsignature = True Options.docstrings = True @@ -127,16 +126,16 @@ def get_mpi_flags(): for e in exts: e.cython_directives = { - "language_level": "3", "embedsignature": True, "binding": True, } setup( name="tmr", - version=0.1, + version=1.0, description="Parallel mesh generation utilities", author="Graeme J. Kennedy", author_email="graeme.kennedy@ae.gatech.edu", + packages=find_packages(include=["tmr*"]), ext_modules=cythonize(exts, include_path=inc_dirs), ) diff --git a/tmr/TMR.pxd b/tmr/TMR.pxd index a960e27e..7a7d36a2 100644 --- a/tmr/TMR.pxd +++ b/tmr/TMR.pxd @@ -22,23 +22,29 @@ from mpi4py.libmpi cimport * cimport mpi4py.MPI as MPI -# Import string stuff -from libc.string cimport const_char -from libc.stdint cimport int32_t, int16_t - -# Import the python version information -from cpython.version cimport PY_MAJOR_VERSION - # Import numpy cimport numpy as np import numpy as np # Import TACS -from paropt.ParOpt cimport * +from tacs import TACS +from tacs cimport TACS +from tacs.TACS import * from tacs.TACS cimport * +from tacs.constitutive import * from tacs.constitutive cimport * + +# Import ParOpt +from paropt.ParOpt import * +from paropt.ParOpt cimport * + +# Import EGADS +from egads4py.egads import * from egads4py.egads cimport * +# Import all of the TMR header files +from tmr.cpp_headers.TMR cimport * + cdef inline char* tmr_convert_str_to_chars(s): if isinstance(s, unicode): s = (s).encode('utf-8') @@ -47,666 +53,5 @@ cdef inline char* tmr_convert_str_to_chars(s): cdef inline str tmr_convert_char_to_str(const char* s): if s == NULL: return None - elif PY_MAJOR_VERSION >= 3: - return s.decode('utf-8') else: - return str(s) - -cdef extern from "TMRBase.h": - enum: - TMR_MAX_LEVEL"TMR_MAX_LEVEL" - - cdef cppclass TMREntity: - void incref() - void decref() - void setName(const char*) - const char* getName() - int getEntityId() - - cdef cppclass TMRPoint: - double x - double y - double z - - cdef cppclass TMRIndexWeight: - int index - double weight - - cdef cppclass TMR_STLTriangle: - TMRPoint p[3] - - void TMRInitialize() - int TMRIsInitialized() - void TMRFinalize() - - enum TMRInterpolationType: - TMR_UNIFORM_POINTS - TMR_GAUSS_LOBATTO_POINTS - TMR_BERNSTEIN_POINTS - -cdef extern from "TMRTopology.h": - cdef cppclass TMRTopology(TMREntity): - TMRTopology(MPI_Comm, TMRModel*) - void getVolume(int, TMRVolume**) - void getFace(int, TMRFace**) - void getEdge(int, TMREdge**) - void getVertex(int, TMRVertex**) - - cdef cppclass TMRVertex(TMREntity): - TMRVertex() - int evalPoint(TMRPoint*) - int setNodeNum(int*) - int getNodeNum(int*) - void setCopySource(TMRVertex*) - void getCopySource(TMRVertex**) - int isSame(TMRVertex*) - - cdef cppclass TMREdge(TMREntity): - TMREdge() - void setSource(TMREdge*) - void getSource(TMREdge**) - void getRange(double*, double*) - int evalPoint(double, TMRPoint*) - int evalDeriv(double, TMRPoint*, TMRPoint*) - int invEvalPoint(TMRPoint, double*) - void setVertices(TMRVertex*, TMRVertex*) - void getVertices(TMRVertex**, TMRVertex**) - int isDegenerate() - void setMesh(TMREdgeMesh*) - void getMesh(TMREdgeMesh**) - void setCopySource(TMREdge*) - void getCopySource(TMREdge**) - void writeToVTK(char*) - int isSame(TMREdge*) - - cdef cppclass TMRFace(TMREntity): - TMRFace() - TMRFace(int) - void getRange(double*, double*, double*, double*) - int evalPoint(double, double, TMRPoint*) - void setSource(TMRVolume*, TMRFace*) - void getSource(TMRVolume**, TMRFace**) - int getNumEdgeLoops() - void addEdgeLoop(int, TMREdgeLoop*) - void getEdgeLoop(int, TMREdgeLoop**) - void setMesh(TMRFaceMesh*) - void getMesh(TMRFaceMesh**) - void setCopySource(int, TMRFace*) - void getCopySource(int*, TMRFace**) - void writeToVTK(char*) - int isSame(TMRFace*) - - cdef cppclass TMREdgeLoop(TMREntity): - TMREdgeLoop(int, TMREdge**, const int*) - void getEdgeLoop(int*, TMREdge***, const int**) - - cdef cppclass TMRVolume(TMREntity): - TMRVolume(int, TMRFace**) - void getFaces(int*, TMRFace***) - void writeToVTK(char*) - - cdef cppclass TMRModel(TMREntity): - TMRModel(int, TMRVertex**, - int, TMREdge**, - int, TMRFace**, - int, TMRVolume**) - void getVertices(int*,TMRVertex***) - void getEdges(int*,TMREdge***) - void getFaces(int*,TMRFace***) - void getVolumes(int*,TMRVolume***) - -cdef extern from "TMRGeometry.h": - cdef cppclass TMRCurve(TMREntity): - void writeToVTK(char*) - - cdef cppclass TMRSurface(TMREntity): - void addCurveSegment(int, TMRCurve**, int*) - void writeToVTK(char*) - - cdef cppclass TMRPcurve(TMREntity): - pass - -cdef extern from "TMRNativeTopology.h": - cdef cppclass TMRVertexFromPoint(TMRVertex): - TMRVertexFromPoint(TMRPoint) - - cdef cppclass TMRVertexFromEdge(TMRVertex): - TMRVertexFromEdge(TMREdge*, double) - TMRVertexFromEdge(TMREdge*, TMRPoint) - - cdef cppclass TMRVertexFromFace(TMRVertex): - TMRVertexFromFace(TMRFace*, double, double) - TMRVertexFromFace(TMRFace*, TMRPoint) - - cdef cppclass TMREdgeFromFace(TMREdge): - TMREdgeFromFace(TMRFace*, TMRPcurve*) - TMREdgeFromFace(TMRFace*, TMRPcurve*, int) - void addEdgeFromFace(TMRFace*, TMRPcurve*) - - cdef cppclass TMRSplitEdge(TMREdge): - TMRSplitEdge(TMREdge*, double, double) - TMRSplitEdge(TMREdge*, TMRVertex*, TMRVertex*) - - cdef cppclass TMREdgeFromCurve(TMREdge): - TMREdgeFromCurve(TMRCurve*) - - cdef cppclass TMRFaceFromSurface(TMRFace): - TMRFaceFromSurface(TMRSurface*) - - cdef cppclass TMRTFIEdge(TMREdge): - TMRTFIEdge(TMRVertex*, TMRVertex*) - - cdef cppclass TMRTFIFace(TMRFace): - TMRTFIFace(TMREdge**, const int*, TMRVertex**) - -cdef extern from "TMRBspline.h": - cdef cppclass TMRBsplineCurve(TMRCurve): - TMRBsplineCurve(int, int, TMRPoint*) - TMRBsplineCurve(int, int, double*, TMRPoint*) - TMRBsplineCurve(int, int, double*, double*, TMRPoint*) - void getData(int*, int*, const double**, - const double**, const TMRPoint**) - void split(double, TMRBsplineCurve**, TMRBsplineCurve**) - - cdef cppclass TMRBsplineSurface(TMRSurface): - TMRBsplineSurface(int, int, int, int, TMRPoint*) - TMRBsplineSurface(int, int, int, int, - double*, double*, TMRPoint*) - TMRBsplineSurface(int, int, int, int, - double*, double*, double*, TMRPoint*) - void getData(int*, int*, int*, int*, const double**, const double**, - const double**, const TMRPoint**) - - cdef cppclass TMRBsplinePcurve(TMRPcurve): - TMRBsplinePcurve(int, int, double*) - TMRBsplinePcurve(int, int, double*, double*) - TMRBsplinePcurve(int, int, double*, double*, double*) - - cdef cppclass TMRCurveInterpolation(TMREntity): - TMRCurveInterpolation(TMRPoint*, int) - void setNumControlPoints(int) - TMRBsplineCurve *createCurve(int) - - cdef cppclass TMRCurveLofter(TMREntity): - TMRCurveLofter(TMRBsplineCurve**, int) - TMRBsplineSurface* createSurface(int) - -cdef extern from "": - void _deleteMe "delete [] "(int *array) - TMRBsplineCurve* _dynamicBsplineCurve "dynamic_cast"(TMRCurve*) - TMRBsplineSurface* _dynamicBsplineSurface "dynamic_cast"(TMRSurface*) - TMREdgeFromFace* _dynamicEdgeFromFace "dynamic_cast"(TMREdge*) - TMRTopoProblem* _dynamicTopoProblem "dynamic_cast"(ParOptProblem*) - ParOptBVecWrap* _dynamicParOptBVecWrap "dynamic_cast"(ParOptVec*) - -cdef extern from "TMRFeatureSize.h": - cdef cppclass TMRElementFeatureSize(TMREntity): - TMRElementFeatureSize() - TMRElementFeatureSize(double) - double getFeatureSize(TMRPoint) - - cdef cppclass TMRLinearElementSize(TMRElementFeatureSize): - TMRLinearElementSize(double, double, - double, double, double, double) - - cdef cppclass TMRBoxFeatureSize(TMRElementFeatureSize): - TMRBoxFeatureSize(TMRPoint, TMRPoint, double, double) - void addBox(TMRPoint, TMRPoint, double) - - cdef cppclass TMRPointFeatureSize(TMRElementFeatureSize): - TMRPointFeatureSize(int, TMRPoint*, double*, double, double, int) - - cdef cppclass TMRPointLocator(TMREntity): - TMRPointLocator(int, TMRPoint*) - void locateClosest(int, TMRPoint, int*, int*, double*) - -cdef class PointLocator: - cdef TMRPointLocator *ptr - -cdef extern from "TMREdgeMesh.h": - cdef cppclass TMREdgeMesh(TMREntity): - TMREdgeMesh(MPI_Comm, TMREdge*, TMRPoint*, int) - void mesh(TMRMeshOptions, TMRElementFeatureSize*) - void writeToVTK(const char*) - -cdef extern from "TMRFaceMesh.h": - cdef cppclass TMRFaceMesh(TMREntity): - TMRFaceMesh(MPI_Comm, TMRFace*, TMRPoint*, int, int*, int) - void mesh(TMRMeshOptions, TMRElementFeatureSize*) - void writeToVTK(const char*) - -cdef extern from "TMRVolumeMesh.h": - cdef cppclass TMRVolumeMesh(TMREntity): - TMRVolumeMesh(MPI_Comm, TMRVolume*) - void mesh(TMRMeshOptions) - void writeToVTK(const char*) - -cdef extern from "TMRMesh.h": - enum TMRFaceMeshType: - TMR_NO_MESH - TMR_STRUCTURED - TMR_UNSTRUCTURED - TMR_TRIANGLE - - cdef cppclass TMRMesh(TMREntity): - TMRMesh(MPI_Comm, TMRModel*) - void mesh(TMRMeshOptions, double) - void mesh(TMRMeshOptions, TMRElementFeatureSize*) - int getMeshPoints(TMRPoint**) - int getQuadConnectivity(int*, const int**) - int getTriConnectivity(int*, const int**) - int getHexConnectivity(int*, const int**) - int getTetConnectivity(int*, const int**) - - TMRModel *createModelFromMesh() - void writeToVTK(const char*, int) - void writeToBDF(const char*, int, TMRBoundaryConditions*) - - cdef cppclass TMRMeshOptions: - TMRMeshOptions() - TMRFaceMeshType mesh_type_default - int triangularize_print_level - int triangularize_print_iter - int write_mesh_quality_histogram - int num_smoothing_steps - double frontal_quality_factor - int reset_mesh_objects - int write_init_domain_triangle - int write_triangularize_intermediate - int write_pre_smooth_triangle - int write_post_smooth_triangle - int write_dual_recombine - int write_pre_smooth_quad - int write_post_smooth_quad - int write_quad_dual - -cdef extern from "TMRQuadrant.h": - cdef cppclass TMRQuadrant: - int childId() - void getSibling(int, TMRQuadrant*) - void parent(TMRQuadrant*) - void edgeNeighbor(int, TMRQuadrant*) - void cornerNeighbor(int, TMRQuadrant*) - int contains(TMRQuadrant*) - int32_t face - int32_t x - int32_t y - int32_t tag - int16_t level - int16_t info - - cdef cppclass TMRQuadrantArray: - TMRQuadrantArray(TMRQuadrant*, int) - TMRQuadrantArray* duplicate() - void getArray(TMRQuadrant**, int*) - void sort() - TMRQuadrant* contains(TMRQuadrant *q, int) - -cdef extern from "TMRQuadForest.h": - cdef cppclass TMRQuadForest(TMREntity): - TMRQuadForest(MPI_Comm, int, TMRInterpolationType) - MPI_Comm getMPIComm() - void setTopology(TMRTopology*) - TMRTopology* getTopology() - void setConnectivity(int, const int*, int) - void setFullConnectivity(int, int, int, const int*, const int*) - void repartition() - void createTrees(int) - void createRandomTrees(int, int, int) - void refine(int*, int, int) - TMRQuadForest *duplicate() - TMRQuadForest *coarsen() - void balance(int) - void createNodes() - int getMeshOrder() - TMRInterpolationType getInterpType() - void setMeshOrder(int, TMRInterpolationType) - void getNodeConn(const int**, int*) - int getDepNodeConn(const int**, const int**, const double**) - TMRQuadrantArray* getQuadsWithName(const char*) - int getNodesWithName(const char*, int**) - void createInterpolation(TMRQuadForest*, TACSBVecInterp*) - int getOwnedNodeRange(const int**) - void getQuadrants(TMRQuadrantArray**) - int getPoints(TMRPoint**) - int getLocalNodeNumber(int); - int getExtPreOffset() - void writeToVTK(const char*) - void writeForestToVTK(const char*) - -cdef extern from "TMROctant.h": - cdef cppclass TMROctant: - int childId() - void getSibling(int, TMROctant*) - void parent(TMROctant*) - void edgeNeighbor(int, TMROctant*) - void cornerNeighbor(int, TMROctant*) - void faceNeighbor(int, TMROctant) - int contains(TMROctant*) - int32_t block - int32_t x - int32_t y - int32_t z - int32_t tag - int16_t level - int16_t info - - cdef cppclass TMROctantArray: - TMROctantArray(TMROctant*, int) - TMROctantArray* duplicate() - void getArray(TMROctant**, int*) - void sort() - TMROctant* contains(TMROctant*, int) - -cdef extern from "TMROctForest.h": - cdef cppclass TMROctForest(TMREntity): - TMROctForest(MPI_Comm, int, TMRInterpolationType) - MPI_Comm getMPIComm() - void setTopology(TMRTopology*) - TMRTopology* getTopology() - void setConnectivity(int, const int*, int) - void setFullConnectivity(int, int, int, const int*, const int*) - void repartition(int) - void createTrees(int) - void createRandomTrees(int, int, int) - void refine(int*, int, int) - TMROctForest *duplicate() - TMROctForest *coarsen() - void balance(int) - void createNodes() - int getMeshOrder() - TMRInterpolationType getInterpType() - void setMeshOrder(int, TMRInterpolationType) - void getNodeConn(const int**, int*) - int getDepNodeConn(const int**, const int**, const double**) - TMROctantArray* getOctsWithName(const char*) - int getNodesWithName(const char*, int**) - void createInterpolation(TMROctForest*, TACSBVecInterp*) - int getOwnedNodeRange(const int**) - void getOctants(TMROctantArray**) - int getPoints(TMRPoint**) - int getExtPreOffset() - void writeToVTK(const char*) - void writeForestToVTK(const char*) - -cdef extern from "TMRBoundaryConditions.h": - cdef cppclass TMRBoundaryConditions(TMREntity): - TMRBoundaryConditions() - void addBoundaryCondition(const char*, int, const int*, - const TacsScalar*) - int getNumBoundaryConditions() - -cdef extern from "TMR_TACSCreator.h": - cdef cppclass TMRQuadTACSCreator(TMREntity): - TMRQuadTACSCreator(TMRBoundaryConditions*, int, TMRQuadForest*) - TMRQuadForest* getFilter() - - cdef cppclass TMROctTACSCreator(TMREntity): - TMROctTACSCreator(TMRBoundaryConditions*, int, TMROctForest*) - TMROctForest* getFilter() - -cdef extern from "TMROpenCascade.h": - cdef void TMR_SewModelIGES(char *, const char *, int, double, bool) - cdef void TMR_SewModelSTEP(char *, const char *, int, double, bool) - cdef TMRModel* TMR_LoadModelFromIGESFile(const char*, const char*, int) - cdef TMRModel* TMR_LoadModelFromSTEPFile(const char*, const char*, int) - -cdef extern from "TMREgads.h" namespace "TMR_EgadsInterface": - cdef TMRModel* TMR_ConvertEGADSModel"TMR_EgadsInterface::TMR_ConvertEGADSModel"(ego, int) - cdef TMRModel* TMR_LoadModelFromEGADSFile"TMR_EgadsInterface::TMR_LoadModelFromEGADSFile"(const char*, const char*, int) - -cdef extern from "TMR_RefinementTools.h": - void TMR_CreateTACSMg(int, TACSAssembler**, - TMRQuadForest**, TACSMg**, double, int, int, int) - void TMR_ComputeInterpSolution(TMRQuadForest*, TACSAssembler*, - TMRQuadForest*, TACSAssembler*, - TACSBVec*, TACSBVec*) - void TMR_ComputeReconSolution(TMRQuadForest*, TACSAssembler*, - TMRQuadForest*, TACSAssembler*, - TACSBVec*, TACSBVec*, int) - double TMR_StrainEnergyErrorEst(TMRQuadForest*, TACSAssembler*, - TMRQuadForest *, TACSAssembler*, - double*) - double TMR_AdjointErrorEst(TMRQuadForest*, TACSAssembler*, - TMRQuadForest*, TACSAssembler*, - TACSBVec*, TACSBVec*, double*, double*, double*) - - void TMR_CreateTACSMg(int, TACSAssembler**, - TMROctForest**, TACSMg**, double, int, int, int) - void TMR_ComputeInterpSolution(TMROctForest*, TACSAssembler*, - TMROctForest*, TACSAssembler*, - TACSBVec*, TACSBVec*) - void TMR_ComputeReconSolution(TMROctForest*, TACSAssembler*, - TMROctForest*, TACSAssembler*, - TACSBVec*, TACSBVec*, int) - double TMR_StrainEnergyErrorEst(TMROctForest*, TACSAssembler*, - TMROctForest *, TACSAssembler*, - double*) - double TMR_AdjointErrorEst(TMROctForest*, TACSAssembler*, - TMROctForest*, TACSAssembler*, - TACSBVec*, TACSBVec*, double*, double*) - -cdef extern from "TMRCyCreator.h": - ctypedef TACSElement* (*createquadelements)(void*, int, TMRQuadrant*) - ctypedef TACSElement* (*createoctelements)(void*, int, TMROctant*) - ctypedef TACSElement* (*createquadtopoelements)( - void*, int, TMRQuadrant*, int, TMRIndexWeight*) - ctypedef TACSElement* (*createocttopoelements)( - void*, int, TMROctant*, int, TMRIndexWeight*) - - cdef cppclass TMRCyQuadCreator(TMRQuadTACSCreator): - TMRCyQuadCreator(TMRBoundaryConditions*, int, TMRQuadForest*) - void setSelfPointer(void*) - void setCreateQuadElement( - TACSElement* (*createquadelements)(void*, int, TMRQuadrant*)) - TACSAssembler *createTACS(TMRQuadForest*, OrderingType, int, const char**) - - cdef cppclass TMRCyOctCreator(TMROctTACSCreator): - TMRCyOctCreator(TMRBoundaryConditions*, int, TMROctForest*) - void setSelfPointer(void*) - void setCreateOctElement( - TACSElement* (*createoctelements)(void*, int, TMROctant*)) - TACSAssembler *createTACS(TMROctForest*, OrderingType, int, const char**) - - cdef cppclass TMRCyTopoQuadCreator(TMRQuadTACSCreator): - TMRCyTopoQuadCreator(TMRBoundaryConditions*, int, TMRQuadForest*) - void setSelfPointer(void*) - void setCreateQuadTopoElement( - TACSElement* (*createquadtopoelements)( - void*, int, TMRQuadrant*, int, TMRIndexWeight*)) - TACSAssembler *createTACS(TMRQuadForest*, OrderingType) - - cdef cppclass TMRCyTopoOctCreator(TMROctTACSCreator): - TMRCyTopoOctCreator(TMRBoundaryConditions*, int, TMROctForest*) - void setSelfPointer(void*) - void setCreateOctTopoElement( - TACSElement* (*createocttopoelements)( - void*, int, TMROctant*, int, TMRIndexWeight*)) - TACSAssembler *createTACS(TMROctForest*, OrderingType) - - cdef cppclass TMRCyTopoQuadConformCreator(TMRQuadTACSCreator): - TMRCyTopoQuadConformCreator(TMRBoundaryConditions*, int, TMRQuadForest*, - int, TMRInterpolationType) - void setSelfPointer(void*) - void setCreateQuadTopoElement( - TACSElement* (*createquadtopoelements)( - void*, int, TMRQuadrant*, int, const int*, TMRQuadForest*)) - TACSAssembler *createTACS(TMRQuadForest*, OrderingType) - - cdef cppclass TMRCyTopoOctConformCreator(TMROctTACSCreator): - TMRCyTopoOctConformCreator(TMRBoundaryConditions*, int, TMROctForest*, - int, TMRInterpolationType) - void setSelfPointer(void*) - void setCreateOctTopoElement( - TACSElement* (*createocttopoelements)( - void*, int, TMROctant*, int, const int*, TMROctForest*)) - TACSAssembler *createTACS(TMROctForest*, OrderingType) - -cdef extern from "TMRTopoFilter.h": - cdef cppclass TMRTopoFilter(TMREntity): - TACSAssembler* getAssembler() - TMRQuadForest* getFilterQuadForest() - TMROctForest* getFilterOctForest() - void setDesignVars(TACSBVec*) - void getDesignVars(TACSBVec*) - void addValues(TACSBVec*) - void applyFilter(TACSBVec*, TACSBVec*) - void applyTranspose(TACSBVec*, TACSBVec*) - -cdef class TopoFilter: - cdef TMRTopoFilter *ptr - -cdef inline _init_TopoFilter(TMRTopoFilter *ptr): - fltr = TopoFilter() - fltr.ptr = ptr - fltr.ptr.incref() - return fltr - -cdef extern from "TMRLagrangeFilter.h": - cdef cppclass TMRLagrangeFilter(TMRTopoFilter): - TMRLagrangeFilter(int, TACSAssembler**, TMROctForest**) - TMRLagrangeFilter(int, TACSAssembler**, TMRQuadForest**) - -cdef extern from "TMRConformFilter.h": - cdef cppclass TMRConformFilter(TMRTopoFilter): - TMRConformFilter(int, TACSAssembler**, TMROctForest**) - TMRConformFilter(int, TACSAssembler**, TMRQuadForest**) - -cdef extern from "TMRHelmholtzFilter.h": - cdef cppclass TMRHelmholtzFilter(TMRTopoFilter): - TMRHelmholtzFilter(double, int, TACSAssembler**, TMROctForest**) - TMRHelmholtzFilter(double, int, TACSAssembler**, TMRQuadForest**) - -cdef extern from "TMRMatrixFilter.h": - cdef cppclass TMRMatrixFilter(TMRTopoFilter): - TMRMatrixFilter(double, int, int, TACSAssembler**, TMROctForest**) - TMRMatrixFilter(double, int, int, TACSAssembler**, TMRQuadForest**) - -cdef extern from "TMROctConstitutive.h": - cdef enum TMRTopoPenaltyType: - TMR_SIMP_PENALTY - TMR_RAMP_PENALTY - - cdef cppclass TMRStiffnessProperties(TMREntity): - TMRStiffnessProperties(int, TACSMaterialProperties**, - double, double, double, - TMRTopoPenaltyType, double, double, - double, double, double, double, int) - int nmats - TACSMaterialProperties **props - TMRTopoPenaltyType penalty_type - double stiffness_penalty_value - double stiffness_offset - double mass_penalty_value - double conduction_penalty_value - double temperature_penalty_value - double stress_relax_value - double ks_penalty - double beta - double xoffset - int use_project - - cdef cppclass TMROctConstitutive(TACSSolidConstitutive): - TMROctConstitutive(TMRStiffnessProperties*, TMROctForest*) - -cdef extern from "TMRQuadConstitutive.h": - cdef cppclass TMRQuadConstitutive(TACSPlaneStressConstitutive): - TMRQuadConstitutive(TMRStiffnessProperties*, TMRQuadForest*) - -cdef extern from "TMRHelmholtzPUFilter.h": - ctypedef int (*getinteriorstencil)( void*, int, int, - TacsScalar*, double* ) - ctypedef int (*getboundarystencil)( void*, int, TacsScalar*, int, - TacsScalar*, double* ) - - cdef cppclass TMRCallbackHelmholtzPUFilter(TMRTopoFilter): - TMRCallbackHelmholtzPUFilter(int, int, TACSAssembler**, - TMROctForest**) - TMRCallbackHelmholtzPUFilter(int, int, TACSAssembler**, - TMRQuadForest**) - void initialize() - void setSelfPointer(void*) - void setGetInteriorStencil(getinteriorstencil) - void setGetBoundaryStencil(getboundarystencil) - -cdef extern from "TMRTopoProblem.h": - ctypedef void (*writeoutputcallback)(void*, const char*, int, - TMROctForest*, TMRQuadForest*, - TACSBVec*) - ctypedef void (*constraintcallback)(void*, TMRTopoFilter*, TACSMg*, - int, TacsScalar*) - ctypedef void (*constraintgradientcallback)(void*, TMRTopoFilter*, TACSMg*, - int, TACSBVec**) - ctypedef void (*objectivecallback)(void*, TMRTopoFilter*, TACSMg*, - TacsScalar*) - ctypedef void (*objectivegradientcallback)(void*, TMRTopoFilter*, TACSMg*, - TACSBVec*) - ctypedef void (*qncorrectioncallback)(int, void*, ParOptVec*, ParOptScalar*, - ParOptVec*, ParOptVec*, ParOptVec*) - - cdef cppclass TMRTopoProblem(ParOptProblem): - TMRTopoProblem(TMRTopoFilter*, TACSMg*, int, double) - TACSAssembler *getAssembler() - TMRQuadForest* getFilterQuadForest() - TMROctForest* getFilterOctForest() - TMRTopoFilter* getTopoFilter() - TACSMg* getMg() - void setLoadCases(TACSBVec**, int) - int getNumLoadCases() - void addConstraints(int, TACSFunction**, - const TacsScalar*, const TacsScalar*, int) - void addLinearConstraints(ParOptVec**, TacsScalar*, int) - void addFrequencyConstraint(double, int, TacsScalar, - TacsScalar, TacsScalar, int, - double, int, int, double, double, - int, JDRecycleType) - void addBucklingConstraint(double, int, TacsScalar, - TacsScalar, TacsScalar, int, double) - void addConstraintCallback(int, int, void*, - void (*constraintcallback)(void*, TMRTopoFilter*, TACSMg*, - int, TacsScalar*), - void*, - void (*constraintgradientcallback)(void*, TMRTopoFilter*, TACSMg*, - int, TACSBVec**)) - void addQnCorrectionCallback(int, void*, - void (*qncorrectioncallback)(int, void*, ParOptVec*, ParOptScalar*, - ParOptVec*, ParOptVec*, ParOptVec*)) - void setObjective(const TacsScalar*) - void setObjective(const TacsScalar*, TACSFunction**) - void addObjectiveCallback(void*, - void (*objectivecallback)(void*, TMRTopoFilter*, TACSMg*, - TacsScalar*), - void*, - void (*objectivegradientcallback)(void*, TMRTopoFilter*, TACSMg*, - TACSBVec*)) - void initialize() - void setPrefix(const char*) - void setInitDesignVars(ParOptVec*,ParOptVec*,ParOptVec*) - void setIterationCounter(int) - ParOptVec* createDesignVec() - void setF5OutputFlags(int, ElementType, int) - void setF5EigenOutputFlags(int, ElementType, int) - void setOutputCallback(void*, - void (*writeoutputcallback)(void*, const char*, int, - TMROctForest*, TMRQuadForest*, - TACSBVec*)) - void useQnCorrectionComplianceObj() - void addNonDesignMass(ParOptVec*) - int evalObjCon(ParOptVec*, ParOptScalar*, ParOptScalar*) - int evalObjConGradient(ParOptVec*, ParOptVec*, ParOptVec**) - - cdef cppclass ParOptBVecWrap(ParOptVec): - ParOptBVecWrap(TACSBVec*) - TACSBVec *vec - -cdef extern from "TMR_STLTools.h": - int TMR_GenerateBinFile(const char*, TMROctForest*, - TACSBVec*, int, double) - int TMR_GenerateSTLTriangles(int, TMROctForest*, TACSBVec*, - int, double, int*, TMR_STLTriangle**) - -cdef extern from "TMRApproximateDistance.h": - void TMRApproximateDistance(TMRQuadForest*, int, double, double, - TACSBVec*, const char*, double*) - void TMRApproximateDistance(TMROctForest*, int, double, double, - TACSBVec*, const char*, double*) + return s.decode('utf-8') diff --git a/tmr/TMR.pyx b/tmr/TMR.pyx index 9a0fae67..31e64844 100644 --- a/tmr/TMR.pyx +++ b/tmr/TMR.pyx @@ -1,4 +1,4 @@ -# distutils: language=c++ +#distutils: language=c++ # This file is part of the package TMR for adaptive mesh refinement. @@ -18,9 +18,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function, division - -# For the use of MPI +# # For the use of MPI from mpi4py.libmpi cimport * cimport mpi4py.MPI as MPI @@ -32,6 +30,17 @@ import numpy as np from libcpp.string cimport string from libc.string cimport strcpy +# Import tracebacks for callbacks +import traceback +from sys import exit + +# Import the definition required for const strings +from libc.stdlib cimport const_char, malloc, free +from libcpp cimport bool + +# Import C methods for python +from cpython cimport PyObject, Py_INCREF + cdef tmr_init(): if not TMRIsInitialized(): TMRInitialize() @@ -42,32 +51,9 @@ np.import_array() # Initialize the MPI libraries in TMR (if not already done) tmr_init() -# Import tracebacks for callbacks -import traceback -from sys import exit - -# Import the definition required for const strings -from libc.string cimport const_char -from libc.stdlib cimport malloc, free - -# Import C methods for python -from cpython cimport PyObject, Py_INCREF - # Include numpy and datatype related definitions include "ParOptDefs.pxi" -# Import TACS and ParOpt -from tacs.TACS cimport * -from tacs.constitutive cimport * -from tacs.functions cimport * -from paropt.ParOpt cimport * -from egads4py.egads cimport * -from tacs import TACS -from egads4py import egads - -# Import the definitions -from TMR cimport * - # Include the mpi4py header cdef extern from "mpi-compat.h": pass @@ -2345,6 +2331,7 @@ cdef class PointFeatureSize(ElementFeatureSize): return cdef class PointLocator: + cdef TMRPointLocator *ptr def __cinit__(self, np.ndarray[double, ndim=2, mode='c'] X): cdef int npts = 0 cdef TMRPoint *pts @@ -3814,16 +3801,16 @@ def sewModel(file, units="M", int print_level=0, sew_options={}): cdef char *filename = tmr_convert_str_to_chars(file) cdef const char *units_chars = tmr_convert_str_to_chars(units) if file.lower().endswith(('step', 'stp')): - TMR_SewModelSTEP(filename, - units_chars, - print_level, - sew_options.get("sew_tol",1e-6), + TMR_SewModelSTEP(filename, + units_chars, + print_level, + sew_options.get("sew_tol",1e-6), sew_options.get("nonmanifold_mode",False)) elif file.lower().endswith(('iges', 'igs')): - TMR_SewModelIGES(filename, - units_chars, - print_level, - sew_options.get("sew_tol",1e-6), + TMR_SewModelIGES(filename, + units_chars, + print_level, + sew_options.get("sew_tol",1e-6), sew_options.get("nonmanifold_mode",False)) else: print("model file extension not supported") @@ -3948,7 +3935,7 @@ cdef class BoundaryConditions: return cdef TACSElement* _createQuadElement(void *_self, int order, - TMRQuadrant *quad): + TMRQuadrant *quad) noexcept: cdef TACSElement *elem = NULL q = Quadrant() q.quad.x = quad.x @@ -4032,7 +4019,7 @@ cdef class QuadCreator: return None cdef TACSElement* _createOctElement(void *_self, int order, - TMROctant *octant): + TMROctant *octant) noexcept: cdef TACSElement *elem = NULL o = Octant() o.octant.x = octant.x @@ -4122,7 +4109,7 @@ cdef class OctCreator: cdef TACSElement* _createQuadTopoElement(void *_self, int order, TMRQuadrant *quad, int nweights, - TMRIndexWeight *weights): + TMRIndexWeight *weights) noexcept: cdef TACSElement *elem = NULL q = Quadrant() q.quad.x = quad.x @@ -4171,7 +4158,7 @@ cdef TACSElement* _createQuadConformTopoElement(void *_self, int order, TMRQuadrant *quad, int nweights, const int *index, - TMRQuadForest *filtr): + TMRQuadForest *filtr) noexcept: cdef TACSElement *elem = NULL q = Quadrant() q.quad.x = quad.x @@ -4222,7 +4209,7 @@ cdef class QuadConformTopoCreator: cdef TACSElement* _createOctTopoElement(void *_self, int order, TMROctant *octant, int nweights, - TMRIndexWeight *weights): + TMRIndexWeight *weights) noexcept: cdef TACSElement *elem = NULL oct = Octant() oct.octant.x = octant.x @@ -4273,7 +4260,7 @@ cdef TACSElement* _createOctConformTopoElement( void *_self, int order, TMROctant *octant, int nweights, const int *index, - TMROctForest *filtr): + TMROctForest *filtr) noexcept: cdef TACSElement *elem = NULL Oct = Octant() Oct.octant.x = octant.x @@ -4504,7 +4491,7 @@ def adjointError(forest, Assembler coarse, err_est = TMR_AdjointErrorEst(quad_forest, coarse.ptr, quad_forest_refined, refined.ptr, solution.getBVecPtr(), adjoint.getBVecPtr(), - node_error.data, + node_error.data, elem_error.data, &adj_corr) return err_est, adj_corr, elem_error, node_error @@ -4513,7 +4500,7 @@ def computeInterpSolution(forest, Assembler coarse, forest_refined, Assembler refined, Vec uvec=None, Vec uvec_refined=None): """ - Given coarse and fine sets of forests and assemblers, interpolates a field + Given coarse and fine sets of forests and assemblers, interpolates a field from the coarse space in the fine space using its higher-order basis. Parameters @@ -4563,9 +4550,9 @@ def computeReconSolution(forest, Assembler coarse, compute_diff=False): """ Given coarse and fine sets of forests and assemblers, reconstruct a field - in the fine-space given a field in the coarse-space. Enriches the field in + in the fine-space given a field in the coarse-space. Enriches the field in the fine-space with higher-order information obtained from local least- - square solutions on each element. + square solutions on each element. Parameters ----------- @@ -4584,10 +4571,10 @@ def computeReconSolution(forest, Assembler coarse, The fine-space field that is returned. If None, a vector is created by the fine assembler. compute_diff: Bool - If True, uvec_refined is the difference between the high-order + If True, uvec_refined is the difference between the high-order reconstructed field in the fine-space and the coarse-space field that is interpolated on the fine-space. If False, uvec_refined is just the high- - order reconstructed field in the fine-space. + order reconstructed field in the fine-space. """ cdef TMROctForest *oct_forest = NULL cdef TMROctForest *oct_forest_refined = NULL @@ -4664,11 +4651,11 @@ def getSTLTriangles(OctForest forest, Vec x, int offset=0, else: points = np.array([[]]) - # delete [] tris - return points cdef class TopoFilter: + cdef TMRTopoFilter *ptr + def __cinit__(self, *args, **kwargs): self.ptr = NULL @@ -4776,6 +4763,12 @@ cdef class TopoFilter: if self.ptr != NULL: self.ptr.applyTranspose(vec_in.getBVecPtr(), vec_out.getBVecPtr()) +cdef _init_TopoFilter(TMRTopoFilter *ptr): + fltr = TopoFilter() + fltr.ptr = ptr + fltr.ptr.incref() + return fltr + cdef class LagrangeFilter(TopoFilter): def __cinit__(self, list assemblers, list filters): cdef int nlevels = 0 @@ -4956,7 +4949,7 @@ cdef inplace_array_1d(int nptype, int dim1, void *data_ptr): return ndarray cdef int _getinteriorstencil(void *_self, int diag, int npts, - const TacsScalar *X, double *alphas ): + const TacsScalar *X, double *alphas) noexcept: cdef int fail = 0 try: _X = inplace_array_1d(np.NPY_DOUBLE, 3*npts, X) @@ -4971,7 +4964,7 @@ cdef int _getinteriorstencil(void *_self, int diag, int npts, cdef int _getboundarystencil(void *_self, int diag, const TacsScalar *n, int npts, - const TacsScalar *X, double *alphas ): + const TacsScalar *X, double *alphas) noexcept: cdef int fail = 0 try: _n = np.array([n[0], n[1], n[2]]) @@ -5279,7 +5272,7 @@ def ApproximateDistance(filtr, Vec x, int index=0, cdef void writeOutputCallback(void *func, const char *prefix, int iter, TMROctForest *octforest, TMRQuadForest *quadforest, - TACSBVec *x): + TACSBVec *x) noexcept: try: oct = None quad = None @@ -5296,7 +5289,7 @@ cdef void writeOutputCallback(void *func, const char *prefix, int iter, return cdef void constraintCallback(void *func, TMRTopoFilter *fltr, TACSMg *mg, - int ncon, TacsScalar *cvals): + int ncon, TacsScalar *cvals) noexcept: try: mgobj = None if mg != NULL: @@ -5311,7 +5304,7 @@ cdef void constraintCallback(void *func, TMRTopoFilter *fltr, TACSMg *mg, return cdef void constraintGradientCallback(void *func, TMRTopoFilter *fltr, TACSMg *mg, - int ncon, TACSBVec **dcdx): + int ncon, TACSBVec **dcdx) noexcept: try: mgobj = None if mg != NULL: @@ -5327,7 +5320,7 @@ cdef void constraintGradientCallback(void *func, TMRTopoFilter *fltr, TACSMg *mg return cdef void objectiveCallback(void *func, TMRTopoFilter *fltr, TACSMg *mg, - TacsScalar *fobj): + TacsScalar *fobj) noexcept: try: mgobj = None if mg != NULL: @@ -5340,7 +5333,7 @@ cdef void objectiveCallback(void *func, TMRTopoFilter *fltr, TACSMg *mg, return cdef void objectiveGradientCallback(void *func, TMRTopoFilter *fltr, TACSMg *mg, - TACSBVec *dfdx): + TACSBVec *dfdx) noexcept: try: mgobj = None if mg != NULL: @@ -5355,7 +5348,7 @@ cdef void objectiveGradientCallback(void *func, TMRTopoFilter *fltr, TACSMg *mg, return cdef void qnCorrectionCallback(int ncon, void *func, ParOptVec *_x, ParOptScalar *_z, - ParOptVec *_zw, ParOptVec *_s, ParOptVec *_y): + ParOptVec *_zw, ParOptVec *_s, ParOptVec *_y) noexcept: try: x = _init_PVec(_x) z = inplace_array_1d(np.NPY_DOUBLE, ncon, _z) diff --git a/tmr/__init__.pxd b/tmr/__init__.pxd new file mode 100644 index 00000000..e69de29b diff --git a/tmr/__init__.py b/tmr/__init__.py index fcb21eff..55b0793f 100644 --- a/tmr/__init__.py +++ b/tmr/__init__.py @@ -4,6 +4,8 @@ import os +__all__ = [] + def get_cython_include(): """ diff --git a/tmr/cpp_headers/TMR.pxd b/tmr/cpp_headers/TMR.pxd new file mode 100644 index 00000000..09a215b9 --- /dev/null +++ b/tmr/cpp_headers/TMR.pxd @@ -0,0 +1,684 @@ +# distutils: language=c++ + +# This file is part of the package TMR for adaptive mesh refinement. + +# Copyright (C) 2015 Georgia Tech Research Corporation. +# Additional copyright (C) 2015 Graeme Kennedy. +# All rights reserved. + +# TMR is licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For MPI +from mpi4py.libmpi cimport * +cimport mpi4py.MPI as MPI + +# Import string stuff +from libc.string cimport const_char +from libc.stdint cimport int32_t, int16_t + +# Import numpy +cimport numpy as np +import numpy as np + +# Import TACS +from paropt.cpp_headers.ParOpt cimport * +from tacs.cpp_headers.TACS cimport * +from tacs.cpp_headers.constitutive cimport * +from egads4py.egads cimport * + +cdef extern from "TMRBase.h": + enum: + TMR_MAX_LEVEL"TMR_MAX_LEVEL" + + cdef cppclass TMREntity: + void incref() + void decref() + void setName(const char*) + const char* getName() + int getEntityId() + + cdef cppclass TMRPoint: + double x + double y + double z + + cdef cppclass TMRIndexWeight: + int index + double weight + + cdef cppclass TMR_STLTriangle: + TMRPoint p[3] + + void TMRInitialize() + int TMRIsInitialized() + void TMRFinalize() + + enum TMRInterpolationType: + TMR_UNIFORM_POINTS + TMR_GAUSS_LOBATTO_POINTS + TMR_BERNSTEIN_POINTS + +cdef extern from "TMRTopology.h": + cdef cppclass TMRTopology(TMREntity): + TMRTopology(MPI_Comm, TMRModel*) + void getVolume(int, TMRVolume**) + void getFace(int, TMRFace**) + void getEdge(int, TMREdge**) + void getVertex(int, TMRVertex**) + + cdef cppclass TMRVertex(TMREntity): + TMRVertex() + int evalPoint(TMRPoint*) + int setNodeNum(int*) + int getNodeNum(int*) + void setCopySource(TMRVertex*) + void getCopySource(TMRVertex**) + int isSame(TMRVertex*) + + cdef cppclass TMREdge(TMREntity): + TMREdge() + void setSource(TMREdge*) + void getSource(TMREdge**) + void getRange(double*, double*) + int evalPoint(double, TMRPoint*) + int evalDeriv(double, TMRPoint*, TMRPoint*) + int invEvalPoint(TMRPoint, double*) + void setVertices(TMRVertex*, TMRVertex*) + void getVertices(TMRVertex**, TMRVertex**) + int isDegenerate() + void setMesh(TMREdgeMesh*) + void getMesh(TMREdgeMesh**) + void setCopySource(TMREdge*) + void getCopySource(TMREdge**) + void writeToVTK(char*) + int isSame(TMREdge*) + + cdef cppclass TMRFace(TMREntity): + TMRFace() + TMRFace(int) + void getRange(double*, double*, double*, double*) + int evalPoint(double, double, TMRPoint*) + void setSource(TMRVolume*, TMRFace*) + void getSource(TMRVolume**, TMRFace**) + int getNumEdgeLoops() + void addEdgeLoop(int, TMREdgeLoop*) + void getEdgeLoop(int, TMREdgeLoop**) + void setMesh(TMRFaceMesh*) + void getMesh(TMRFaceMesh**) + void setCopySource(int, TMRFace*) + void getCopySource(int*, TMRFace**) + void writeToVTK(char*) + int isSame(TMRFace*) + + cdef cppclass TMREdgeLoop(TMREntity): + TMREdgeLoop(int, TMREdge**, const int*) + void getEdgeLoop(int*, TMREdge***, const int**) + + cdef cppclass TMRVolume(TMREntity): + TMRVolume(int, TMRFace**) + void getFaces(int*, TMRFace***) + void writeToVTK(char*) + + cdef cppclass TMRModel(TMREntity): + TMRModel(int, TMRVertex**, + int, TMREdge**, + int, TMRFace**, + int, TMRVolume**) + void getVertices(int*,TMRVertex***) + void getEdges(int*,TMREdge***) + void getFaces(int*,TMRFace***) + void getVolumes(int*,TMRVolume***) + +cdef extern from "TMRGeometry.h": + cdef cppclass TMRCurve(TMREntity): + void writeToVTK(char*) + + cdef cppclass TMRSurface(TMREntity): + void addCurveSegment(int, TMRCurve**, int*) + void writeToVTK(char*) + + cdef cppclass TMRPcurve(TMREntity): + pass + +cdef extern from "TMRNativeTopology.h": + cdef cppclass TMRVertexFromPoint(TMRVertex): + TMRVertexFromPoint(TMRPoint) + + cdef cppclass TMRVertexFromEdge(TMRVertex): + TMRVertexFromEdge(TMREdge*, double) + TMRVertexFromEdge(TMREdge*, TMRPoint) + + cdef cppclass TMRVertexFromFace(TMRVertex): + TMRVertexFromFace(TMRFace*, double, double) + TMRVertexFromFace(TMRFace*, TMRPoint) + + cdef cppclass TMREdgeFromFace(TMREdge): + TMREdgeFromFace(TMRFace*, TMRPcurve*) + TMREdgeFromFace(TMRFace*, TMRPcurve*, int) + void addEdgeFromFace(TMRFace*, TMRPcurve*) + + cdef cppclass TMRSplitEdge(TMREdge): + TMRSplitEdge(TMREdge*, double, double) + TMRSplitEdge(TMREdge*, TMRVertex*, TMRVertex*) + + cdef cppclass TMREdgeFromCurve(TMREdge): + TMREdgeFromCurve(TMRCurve*) + + cdef cppclass TMRFaceFromSurface(TMRFace): + TMRFaceFromSurface(TMRSurface*) + + cdef cppclass TMRTFIEdge(TMREdge): + TMRTFIEdge(TMRVertex*, TMRVertex*) + + cdef cppclass TMRTFIFace(TMRFace): + TMRTFIFace(TMREdge**, const int*, TMRVertex**) + +cdef extern from "TMRBspline.h": + cdef cppclass TMRBsplineCurve(TMRCurve): + TMRBsplineCurve(int, int, TMRPoint*) + TMRBsplineCurve(int, int, double*, TMRPoint*) + TMRBsplineCurve(int, int, double*, double*, TMRPoint*) + void getData(int*, int*, const double**, + const double**, const TMRPoint**) + void split(double, TMRBsplineCurve**, TMRBsplineCurve**) + + cdef cppclass TMRBsplineSurface(TMRSurface): + TMRBsplineSurface(int, int, int, int, TMRPoint*) + TMRBsplineSurface(int, int, int, int, + double*, double*, TMRPoint*) + TMRBsplineSurface(int, int, int, int, + double*, double*, double*, TMRPoint*) + void getData(int*, int*, int*, int*, const double**, const double**, + const double**, const TMRPoint**) + + cdef cppclass TMRBsplinePcurve(TMRPcurve): + TMRBsplinePcurve(int, int, double*) + TMRBsplinePcurve(int, int, double*, double*) + TMRBsplinePcurve(int, int, double*, double*, double*) + + cdef cppclass TMRCurveInterpolation(TMREntity): + TMRCurveInterpolation(TMRPoint*, int) + void setNumControlPoints(int) + TMRBsplineCurve *createCurve(int) + + cdef cppclass TMRCurveLofter(TMREntity): + TMRCurveLofter(TMRBsplineCurve**, int) + TMRBsplineSurface* createSurface(int) + +cdef extern from "": + void _deleteMe "delete [] "(int *array) + TMRBsplineCurve* _dynamicBsplineCurve "dynamic_cast"(TMRCurve*) + TMRBsplineSurface* _dynamicBsplineSurface "dynamic_cast"(TMRSurface*) + TMREdgeFromFace* _dynamicEdgeFromFace "dynamic_cast"(TMREdge*) + TMRTopoProblem* _dynamicTopoProblem "dynamic_cast"(ParOptProblem*) + ParOptBVecWrap* _dynamicParOptBVecWrap "dynamic_cast"(ParOptVec*) + +cdef extern from "TMRFeatureSize.h": + cdef cppclass TMRElementFeatureSize(TMREntity): + TMRElementFeatureSize() + TMRElementFeatureSize(double) + double getFeatureSize(TMRPoint) + + cdef cppclass TMRLinearElementSize(TMRElementFeatureSize): + TMRLinearElementSize(double, double, + double, double, double, double) + + cdef cppclass TMRBoxFeatureSize(TMRElementFeatureSize): + TMRBoxFeatureSize(TMRPoint, TMRPoint, double, double) + void addBox(TMRPoint, TMRPoint, double) + + cdef cppclass TMRPointFeatureSize(TMRElementFeatureSize): + TMRPointFeatureSize(int, TMRPoint*, double*, double, double, int) + + cdef cppclass TMRPointLocator(TMREntity): + TMRPointLocator(int, TMRPoint*) + void locateClosest(int, TMRPoint, int*, int*, double*) + +cdef extern from "TMREdgeMesh.h": + cdef cppclass TMREdgeMesh(TMREntity): + TMREdgeMesh(MPI_Comm, TMREdge*, TMRPoint*, int) + void mesh(TMRMeshOptions, TMRElementFeatureSize*) + void writeToVTK(const char*) + +cdef extern from "TMRFaceMesh.h": + cdef cppclass TMRFaceMesh(TMREntity): + TMRFaceMesh(MPI_Comm, TMRFace*, TMRPoint*, int, int*, int) + void mesh(TMRMeshOptions, TMRElementFeatureSize*) + void writeToVTK(const char*) + +cdef extern from "TMRVolumeMesh.h": + cdef cppclass TMRVolumeMesh(TMREntity): + TMRVolumeMesh(MPI_Comm, TMRVolume*) + void mesh(TMRMeshOptions) + void writeToVTK(const char*) + +cdef extern from "TMRMesh.h": + enum TMRFaceMeshType: + TMR_NO_MESH + TMR_STRUCTURED + TMR_UNSTRUCTURED + TMR_TRIANGLE + + cdef cppclass TMRMesh(TMREntity): + TMRMesh(MPI_Comm, TMRModel*) + void mesh(TMRMeshOptions, double) + void mesh(TMRMeshOptions, TMRElementFeatureSize*) + int getMeshPoints(TMRPoint**) + int getQuadConnectivity(int*, const int**) + int getTriConnectivity(int*, const int**) + int getHexConnectivity(int*, const int**) + int getTetConnectivity(int*, const int**) + + TMRModel *createModelFromMesh() + void writeToVTK(const char*, int) + void writeToBDF(const char*, int, TMRBoundaryConditions*) + + cdef cppclass TMRMeshOptions: + TMRMeshOptions() + TMRFaceMeshType mesh_type_default + int triangularize_print_level + int triangularize_print_iter + int write_mesh_quality_histogram + int num_smoothing_steps + double frontal_quality_factor + int reset_mesh_objects + int write_init_domain_triangle + int write_triangularize_intermediate + int write_pre_smooth_triangle + int write_post_smooth_triangle + int write_dual_recombine + int write_pre_smooth_quad + int write_post_smooth_quad + int write_quad_dual + +cdef extern from "TMRQuadrant.h": + cdef cppclass TMRQuadrant: + int childId() + void getSibling(int, TMRQuadrant*) + void parent(TMRQuadrant*) + void edgeNeighbor(int, TMRQuadrant*) + void cornerNeighbor(int, TMRQuadrant*) + int contains(TMRQuadrant*) + int32_t face + int32_t x + int32_t y + int32_t tag + int16_t level + int16_t info + + cdef cppclass TMRQuadrantArray: + TMRQuadrantArray(TMRQuadrant*, int) + TMRQuadrantArray* duplicate() + void getArray(TMRQuadrant**, int*) + void sort() + TMRQuadrant* contains(TMRQuadrant *q, int) + +cdef extern from "TMRQuadForest.h": + cdef cppclass TMRQuadForest(TMREntity): + TMRQuadForest(MPI_Comm, int, TMRInterpolationType) + MPI_Comm getMPIComm() + void setTopology(TMRTopology*) + TMRTopology* getTopology() + void setConnectivity(int, const int*, int) + void setFullConnectivity(int, int, int, const int*, const int*) + void repartition() + void createTrees(int) + void createRandomTrees(int, int, int) + void refine(int*, int, int) + TMRQuadForest *duplicate() + TMRQuadForest *coarsen() + void balance(int) + void createNodes() + int getMeshOrder() + TMRInterpolationType getInterpType() + void setMeshOrder(int, TMRInterpolationType) + void getNodeConn(const int**, int*) + int getDepNodeConn(const int**, const int**, const double**) + TMRQuadrantArray* getQuadsWithName(const char*) + int getNodesWithName(const char*, int**) + void createInterpolation(TMRQuadForest*, TACSBVecInterp*) + int getOwnedNodeRange(const int**) + void getQuadrants(TMRQuadrantArray**) + int getPoints(TMRPoint**) + int getLocalNodeNumber(int); + int getExtPreOffset() + void writeToVTK(const char*) + void writeForestToVTK(const char*) + +cdef extern from "TMROctant.h": + cdef cppclass TMROctant: + int childId() + void getSibling(int, TMROctant*) + void parent(TMROctant*) + void edgeNeighbor(int, TMROctant*) + void cornerNeighbor(int, TMROctant*) + void faceNeighbor(int, TMROctant) + int contains(TMROctant*) + int32_t block + int32_t x + int32_t y + int32_t z + int32_t tag + int16_t level + int16_t info + + cdef cppclass TMROctantArray: + TMROctantArray(TMROctant*, int) + TMROctantArray* duplicate() + void getArray(TMROctant**, int*) + void sort() + TMROctant* contains(TMROctant*, int) + +cdef extern from "TMROctForest.h": + cdef cppclass TMROctForest(TMREntity): + TMROctForest(MPI_Comm, int, TMRInterpolationType) + MPI_Comm getMPIComm() + void setTopology(TMRTopology*) + TMRTopology* getTopology() + void setConnectivity(int, const int*, int) + void setFullConnectivity(int, int, int, const int*, const int*) + void repartition(int) + void createTrees(int) + void createRandomTrees(int, int, int) + void refine(int*, int, int) + TMROctForest *duplicate() + TMROctForest *coarsen() + void balance(int) + void createNodes() + int getMeshOrder() + TMRInterpolationType getInterpType() + void setMeshOrder(int, TMRInterpolationType) + void getNodeConn(const int**, int*) + int getDepNodeConn(const int**, const int**, const double**) + TMROctantArray* getOctsWithName(const char*) + int getNodesWithName(const char*, int**) + void createInterpolation(TMROctForest*, TACSBVecInterp*) + int getOwnedNodeRange(const int**) + void getOctants(TMROctantArray**) + int getPoints(TMRPoint**) + int getExtPreOffset() + void writeToVTK(const char*) + void writeForestToVTK(const char*) + +cdef extern from "TMRBoundaryConditions.h": + cdef cppclass TMRBoundaryConditions(TMREntity): + TMRBoundaryConditions() + void addBoundaryCondition(const char*, int, const int*, + const TacsScalar*) + int getNumBoundaryConditions() + +cdef extern from "TMR_TACSCreator.h": + cdef cppclass TMRQuadTACSCreator(TMREntity): + TMRQuadTACSCreator(TMRBoundaryConditions*, int, TMRQuadForest*) + TMRQuadForest* getFilter() + + cdef cppclass TMROctTACSCreator(TMREntity): + TMROctTACSCreator(TMRBoundaryConditions*, int, TMROctForest*) + TMROctForest* getFilter() + +cdef extern from "TMROpenCascade.h": + cdef void TMR_SewModelIGES(char *, const char *, int, double, bool) + cdef void TMR_SewModelSTEP(char *, const char *, int, double, bool) + cdef TMRModel* TMR_LoadModelFromIGESFile(const char*, const char*, int) + cdef TMRModel* TMR_LoadModelFromSTEPFile(const char*, const char*, int) + +cdef extern from "TMREgads.h" namespace "TMR_EgadsInterface": + cdef TMRModel* TMR_ConvertEGADSModel"TMR_EgadsInterface::TMR_ConvertEGADSModel"(ego, int) + cdef TMRModel* TMR_LoadModelFromEGADSFile"TMR_EgadsInterface::TMR_LoadModelFromEGADSFile"(const char*, const char*, int) + +cdef extern from "TMR_RefinementTools.h": + void TMR_CreateTACSMg(int, TACSAssembler**, + TMRQuadForest**, TACSMg**, double, int, int, int) + void TMR_ComputeInterpSolution(TMRQuadForest*, TACSAssembler*, + TMRQuadForest*, TACSAssembler*, + TACSBVec*, TACSBVec*) + void TMR_ComputeReconSolution(TMRQuadForest*, TACSAssembler*, + TMRQuadForest*, TACSAssembler*, + TACSBVec*, TACSBVec*, int) + double TMR_StrainEnergyErrorEst(TMRQuadForest*, TACSAssembler*, + TMRQuadForest *, TACSAssembler*, + double*) + double TMR_AdjointErrorEst(TMRQuadForest*, TACSAssembler*, + TMRQuadForest*, TACSAssembler*, + TACSBVec*, TACSBVec*, double*, double*, double*) + + void TMR_CreateTACSMg(int, TACSAssembler**, + TMROctForest**, TACSMg**, double, int, int, int) + void TMR_ComputeInterpSolution(TMROctForest*, TACSAssembler*, + TMROctForest*, TACSAssembler*, + TACSBVec*, TACSBVec*) + void TMR_ComputeReconSolution(TMROctForest*, TACSAssembler*, + TMROctForest*, TACSAssembler*, + TACSBVec*, TACSBVec*, int) + double TMR_StrainEnergyErrorEst(TMROctForest*, TACSAssembler*, + TMROctForest *, TACSAssembler*, + double*) + double TMR_AdjointErrorEst(TMROctForest*, TACSAssembler*, + TMROctForest*, TACSAssembler*, + TACSBVec*, TACSBVec*, double*, double*) + +cdef extern from "TMRCyCreator.h": + ctypedef TACSElement* (*createquadelements)(void*, int, TMRQuadrant*) + ctypedef TACSElement* (*createoctelements)(void*, int, TMROctant*) + ctypedef TACSElement* (*createquadtopoelements)( + void*, int, TMRQuadrant*, int, TMRIndexWeight*) + ctypedef TACSElement* (*createocttopoelements)( + void*, int, TMROctant*, int, TMRIndexWeight*) + + cdef cppclass TMRCyQuadCreator(TMRQuadTACSCreator): + TMRCyQuadCreator(TMRBoundaryConditions*, int, TMRQuadForest*) + void setSelfPointer(void*) + void setCreateQuadElement( + TACSElement* (*createquadelements)(void*, int, TMRQuadrant*)) + TACSAssembler *createTACS(TMRQuadForest*, OrderingType, int, const char**) + + cdef cppclass TMRCyOctCreator(TMROctTACSCreator): + TMRCyOctCreator(TMRBoundaryConditions*, int, TMROctForest*) + void setSelfPointer(void*) + void setCreateOctElement( + TACSElement* (*createoctelements)(void*, int, TMROctant*)) + TACSAssembler *createTACS(TMROctForest*, OrderingType, int, const char**) + + cdef cppclass TMRCyTopoQuadCreator(TMRQuadTACSCreator): + TMRCyTopoQuadCreator(TMRBoundaryConditions*, int, TMRQuadForest*) + void setSelfPointer(void*) + void setCreateQuadTopoElement( + TACSElement* (*createquadtopoelements)( + void*, int, TMRQuadrant*, int, TMRIndexWeight*)) + TACSAssembler *createTACS(TMRQuadForest*, OrderingType) + + cdef cppclass TMRCyTopoOctCreator(TMROctTACSCreator): + TMRCyTopoOctCreator(TMRBoundaryConditions*, int, TMROctForest*) + void setSelfPointer(void*) + void setCreateOctTopoElement( + TACSElement* (*createocttopoelements)( + void*, int, TMROctant*, int, TMRIndexWeight*)) + TACSAssembler *createTACS(TMROctForest*, OrderingType) + + cdef cppclass TMRCyTopoQuadConformCreator(TMRQuadTACSCreator): + TMRCyTopoQuadConformCreator(TMRBoundaryConditions*, int, TMRQuadForest*, + int, TMRInterpolationType) + void setSelfPointer(void*) + void setCreateQuadTopoElement( + TACSElement* (*createquadtopoelements)( + void*, int, TMRQuadrant*, int, const int*, TMRQuadForest*)) + TACSAssembler *createTACS(TMRQuadForest*, OrderingType) + + cdef cppclass TMRCyTopoOctConformCreator(TMROctTACSCreator): + TMRCyTopoOctConformCreator(TMRBoundaryConditions*, int, TMROctForest*, + int, TMRInterpolationType) + void setSelfPointer(void*) + void setCreateOctTopoElement( + TACSElement* (*createocttopoelements)( + void*, int, TMROctant*, int, const int*, TMROctForest*)) + TACSAssembler *createTACS(TMROctForest*, OrderingType) + +cdef extern from "TMRTopoFilter.h": + cdef cppclass TMRTopoFilter(TMREntity): + TACSAssembler* getAssembler() + TMRQuadForest* getFilterQuadForest() + TMROctForest* getFilterOctForest() + void setDesignVars(TACSBVec*) + void getDesignVars(TACSBVec*) + void addValues(TACSBVec*) + void applyFilter(TACSBVec*, TACSBVec*) + void applyTranspose(TACSBVec*, TACSBVec*) + +cdef extern from "TMRLagrangeFilter.h": + cdef cppclass TMRLagrangeFilter(TMRTopoFilter): + TMRLagrangeFilter(int, TACSAssembler**, TMROctForest**) + TMRLagrangeFilter(int, TACSAssembler**, TMRQuadForest**) + +cdef extern from "TMRConformFilter.h": + cdef cppclass TMRConformFilter(TMRTopoFilter): + TMRConformFilter(int, TACSAssembler**, TMROctForest**) + TMRConformFilter(int, TACSAssembler**, TMRQuadForest**) + +cdef extern from "TMRHelmholtzFilter.h": + cdef cppclass TMRHelmholtzFilter(TMRTopoFilter): + TMRHelmholtzFilter(double, int, TACSAssembler**, TMROctForest**) + TMRHelmholtzFilter(double, int, TACSAssembler**, TMRQuadForest**) + +cdef extern from "TMRMatrixFilter.h": + cdef cppclass TMRMatrixFilter(TMRTopoFilter): + TMRMatrixFilter(double, int, int, TACSAssembler**, TMROctForest**) + TMRMatrixFilter(double, int, int, TACSAssembler**, TMRQuadForest**) + +cdef extern from "TMROctConstitutive.h": + cdef enum TMRTopoPenaltyType: + TMR_SIMP_PENALTY + TMR_RAMP_PENALTY + + cdef cppclass TMRStiffnessProperties(TMREntity): + TMRStiffnessProperties(int, TACSMaterialProperties**, + double, double, double, + TMRTopoPenaltyType, double, double, + double, double, double, double, int) + int nmats + TACSMaterialProperties **props + TMRTopoPenaltyType penalty_type + double stiffness_penalty_value + double stiffness_offset + double mass_penalty_value + double conduction_penalty_value + double temperature_penalty_value + double stress_relax_value + double ks_penalty + double beta + double xoffset + int use_project + + cdef cppclass TMROctConstitutive(TACSSolidConstitutive): + TMROctConstitutive(TMRStiffnessProperties*, TMROctForest*) + +cdef extern from "TMRQuadConstitutive.h": + cdef cppclass TMRQuadConstitutive(TACSPlaneStressConstitutive): + TMRQuadConstitutive(TMRStiffnessProperties*, TMRQuadForest*) + +cdef extern from "TMRHelmholtzPUFilter.h": + ctypedef int (*getinteriorstencil)( void*, int, int, + TacsScalar*, double* ) + ctypedef int (*getboundarystencil)( void*, int, TacsScalar*, int, + TacsScalar*, double* ) + + cdef cppclass TMRCallbackHelmholtzPUFilter(TMRTopoFilter): + TMRCallbackHelmholtzPUFilter(int, int, TACSAssembler**, + TMROctForest**) + TMRCallbackHelmholtzPUFilter(int, int, TACSAssembler**, + TMRQuadForest**) + void initialize() + void setSelfPointer(void*) + void setGetInteriorStencil(getinteriorstencil) + void setGetBoundaryStencil(getboundarystencil) + +cdef extern from "TMRTopoProblem.h": + ctypedef void (*writeoutputcallback)(void*, const char*, int, + TMROctForest*, TMRQuadForest*, + TACSBVec*) + ctypedef void (*constraintcallback)(void*, TMRTopoFilter*, TACSMg*, + int, TacsScalar*) + ctypedef void (*constraintgradientcallback)(void*, TMRTopoFilter*, TACSMg*, + int, TACSBVec**) + ctypedef void (*objectivecallback)(void*, TMRTopoFilter*, TACSMg*, + TacsScalar*) + ctypedef void (*objectivegradientcallback)(void*, TMRTopoFilter*, TACSMg*, + TACSBVec*) + ctypedef void (*qncorrectioncallback)(int, void*, ParOptVec*, ParOptScalar*, + ParOptVec*, ParOptVec*, ParOptVec*) + + cdef cppclass TMRTopoProblem(ParOptProblem): + TMRTopoProblem(TMRTopoFilter*, TACSMg*, int, double) + TACSAssembler *getAssembler() + TMRQuadForest* getFilterQuadForest() + TMROctForest* getFilterOctForest() + TMRTopoFilter* getTopoFilter() + TACSMg* getMg() + void setLoadCases(TACSBVec**, int) + int getNumLoadCases() + void addConstraints(int, TACSFunction**, + const TacsScalar*, const TacsScalar*, int) + void addLinearConstraints(ParOptVec**, TacsScalar*, int) + void addFrequencyConstraint(double, int, TacsScalar, + TacsScalar, TacsScalar, int, + double, int, int, double, double, + int, JDRecycleType) + void addBucklingConstraint(double, int, TacsScalar, + TacsScalar, TacsScalar, int, double) + void addConstraintCallback(int, int, void*, + void (*constraintcallback)(void*, TMRTopoFilter*, TACSMg*, + int, TacsScalar*), + void*, + void (*constraintgradientcallback)(void*, TMRTopoFilter*, TACSMg*, + int, TACSBVec**)) + void addQnCorrectionCallback(int, void*, + void (*qncorrectioncallback)(int, void*, ParOptVec*, ParOptScalar*, + ParOptVec*, ParOptVec*, ParOptVec*)) + void setObjective(const TacsScalar*) + void setObjective(const TacsScalar*, TACSFunction**) + void addObjectiveCallback(void*, + void (*objectivecallback)(void*, TMRTopoFilter*, TACSMg*, + TacsScalar*), + void*, + void (*objectivegradientcallback)(void*, TMRTopoFilter*, TACSMg*, + TACSBVec*)) + void initialize() + void setPrefix(const char*) + void setInitDesignVars(ParOptVec*,ParOptVec*,ParOptVec*) + void setIterationCounter(int) + ParOptVec* createDesignVec() + void setF5OutputFlags(int, ElementType, int) + void setF5EigenOutputFlags(int, ElementType, int) + void setOutputCallback(void*, + void (*writeoutputcallback)(void*, const char*, int, + TMROctForest*, TMRQuadForest*, + TACSBVec*)) + void useQnCorrectionComplianceObj() + void addNonDesignMass(ParOptVec*) + int evalObjCon(ParOptVec*, ParOptScalar*, ParOptScalar*) + int evalObjConGradient(ParOptVec*, ParOptVec*, ParOptVec**) + + cdef cppclass ParOptBVecWrap(ParOptVec): + ParOptBVecWrap(TACSBVec*) + TACSBVec *vec + +cdef extern from "TMR_STLTools.h": + int TMR_GenerateBinFile(const char*, TMROctForest*, + TACSBVec*, int, double) + int TMR_GenerateSTLTriangles(int, TMROctForest*, TACSBVec*, + int, double, int*, TMR_STLTriangle**) + +cdef extern from "TMRApproximateDistance.h": + void TMRApproximateDistance(TMRQuadForest*, int, double, double, + TACSBVec*, const char*, double*) + void TMRApproximateDistance(TMROctForest*, int, double, double, + TACSBVec*, const char*, double*) diff --git a/tmr/cpp_headers/__init__.pxd b/tmr/cpp_headers/__init__.pxd new file mode 100644 index 00000000..e69de29b From 5776c255c1c64765cbba437ba5443614f47b4da0 Mon Sep 17 00:00:00 2001 From: Braden Frigoletto Date: Fri, 22 Sep 2023 11:17:34 -0400 Subject: [PATCH 02/10] fixed QuadForest::getNodeConn() --- src/TMRQuadForest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TMRQuadForest.cpp b/src/TMRQuadForest.cpp index 483fe62e..a9432007 100644 --- a/src/TMRQuadForest.cpp +++ b/src/TMRQuadForest.cpp @@ -4017,8 +4017,8 @@ void TMRQuadForest::getNodeConn(const int **_conn, int *_num_elements, if (_num_owned_nodes) { *_num_owned_nodes = num_owned_nodes; } - if (_num_owned_nodes) { - *_num_owned_nodes = num_owned_nodes; + if (_num_local_nodes) { + *_num_local_nodes = num_local_nodes; } } From c2a87478107c81f96d45ef0a4d9b829fa1d30fa9 Mon Sep 17 00:00:00 2001 From: Braden Frigoletto Date: Wed, 24 Jan 2024 15:22:27 -0500 Subject: [PATCH 03/10] updated error localization - moved the absolute value function to allow for error concellation within an element - total output error changed to the sum of the element errors --- src/TMR_RefinementTools.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/TMR_RefinementTools.cpp b/src/TMR_RefinementTools.cpp index 7a530e82..1089dcbf 100644 --- a/src/TMR_RefinementTools.cpp +++ b/src/TMR_RefinementTools.cpp @@ -3016,8 +3016,11 @@ double TMR_AdjointErrorEst(TMRQuadForest *forest, TACSAssembler *tacs, // skip dependent nodes - handled in beginSetValues() with dep weights continue; } - elem_error[elem] += fabs(TacsRealPart(err[i])) / weights[i]; + elem_error[elem] += TacsRealPart(err[i]) / weights[i]; } + // absolute value after the sum allows for error cancellation between each + // basis function within an element + elem_error[elem] = fabs(elem_error[elem]); } // Add up the absolute value of the nodal errors to get the output @@ -3025,8 +3028,8 @@ double TMR_AdjointErrorEst(TMRQuadForest *forest, TACSAssembler *tacs, TacsScalar *nerr; int size = nodal_error->getArray(&nerr); memcpy(node_error, nerr, size * sizeof(double)); - for (int i = 0; i < size; i++) { - total_error_est += fabs(TacsRealPart(nerr[i])); + for (int i = 0; i < nelems; i++) { + total_error_est += elem_error[i]; } // Sum up the contributions across all processors From b86ae358f816e2699c4e22cae8cae06c2d3f7ed2 Mon Sep 17 00:00:00 2001 From: Braden Frigoletto Date: Wed, 24 Jan 2024 15:24:27 -0500 Subject: [PATCH 04/10] updated model history storage - output correction given its own group in hdf5 file --- tmr/pytacsadapt.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tmr/pytacsadapt.py b/tmr/pytacsadapt.py index f2dd5a79..48e67d06 100644 --- a/tmr/pytacsadapt.py +++ b/tmr/pytacsadapt.py @@ -327,8 +327,8 @@ def __init__( # initialize the storage for saving model info self.mesh_history = {} # mesh size (ndof) - self.output_history = {} # outputs/corrected outputs - self.error_history = {} # error estimates + self.output_history = {} # outputs + self.error_history = {} # error estimates and output corrections self.adaptation_history = { "threshold": {}, # refine/coarsen thresholds "element_errors": {}, @@ -661,10 +661,10 @@ def estimateOutputError(self, writeSolution=False): ) # update histories - self.output_history[ - f"{self.fine.prob_name}_{self.fine.output_name}" - ] += output_correction - self.error_history[f"adapt_iter_{self.fine.refine_iter}"] = error_estimate + self.error_history[f"adapt_iter_{self.fine.refine_iter}_error"] = error_estimate + self.error_history[ + f"adapt_iter_{self.fine.refine_iter}_correction" + ] = output_correction # write out the nodal error field if writeSolution: @@ -908,7 +908,20 @@ def writeModelHistory(self, filename=""): # store the error estimate history h5["error_estimate_history"] = np.array( - list(self.error_history.values()) + [ + self.error_history[key] + for key in self.error_history.keys() + if "error" in key + ] + ) + + # store the output correction history + h5["output_correction_history"] = np.array( + [ + self.error_history[key] + for key in self.error_history.keys() + if "correction" in key + ] ) # store the adaptation refinement histories From 7328569783f39cff2c22acc672de5f6c0de06be9 Mon Sep 17 00:00:00 2001 From: Braden Frigoletto Date: Wed, 24 Jan 2024 16:52:02 -0500 Subject: [PATCH 05/10] updated .gitignore - added *.hdf5 files to be ignored --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6fdd2eac..fd586d39 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ tmr/*.cpp *.stp *.step *.egads +*.hdf5 # vscode config files .vscode/* From ff646da8ebf080ecf12433b69fd8be872618d08f Mon Sep 17 00:00:00 2001 From: Braden Frigoletto Date: Wed, 24 Jan 2024 16:54:00 -0500 Subject: [PATCH 06/10] updated plate example for pytacsadapt - updated example to use most recent features of pytacsadapt - fixed the units in the script to generate the plate geometry --- examples/pytacsadapt/plate/make_plate_geom.py | 3 +- examples/pytacsadapt/plate/plate_adapt.py | 89 ++++++++++--------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/examples/pytacsadapt/plate/make_plate_geom.py b/examples/pytacsadapt/plate/make_plate_geom.py index 17d6ec9f..1d7a7c7d 100644 --- a/examples/pytacsadapt/plate/make_plate_geom.py +++ b/examples/pytacsadapt/plate/make_plate_geom.py @@ -45,6 +45,7 @@ def makePlateGeom(width=1.0, height=1.0, npanels=1, makeIGES=False): coords = np.zeros([nverts, 3]) coords[:, 0] = X.ravel() coords[:, 1] = Y.ravel() + coords *= 1000.0 # egads defaults to use mm as units, not m # print(coords) # make the quad node connectivity - used to make the edge and face connectivity @@ -159,7 +160,7 @@ def makePlateGeom(width=1.0, height=1.0, npanels=1, makeIGES=False): fname += ".iges" else: fname += ".step" - model.saveModel(fname, overwrite=True) + model.saveModel(fname, units="M", overwrite=True) return diff --git a/examples/pytacsadapt/plate/plate_adapt.py b/examples/pytacsadapt/plate/plate_adapt.py index 2892e1e3..27478428 100644 --- a/examples/pytacsadapt/plate/plate_adapt.py +++ b/examples/pytacsadapt/plate/plate_adapt.py @@ -1,7 +1,7 @@ """ A simple example to test adaptive analysis with TACS/TMR. -This example uses a square flat plate, fully fixed on all edges, with a uniform +This example uses a square flat plate, fully fixed on two edges, with a uniform pressure load. Static analysis is performed, followed by either uniform or adaptive refinement. Adaptive refinement is based on a selected output of interest. Various options for this example can be selected through command line @@ -9,11 +9,10 @@ To run a simple adaptive analysis on the KS failure output, do the following: 1. run `python make_plate_geom.py` to generate the square plate geometry file -2. run `mpirun -np 4 python plate_adapt.py --niters 8 --adapt` -3. run `mpirun -np 4 python plate_adapt.py --niters 5` -4. compare the results of adaptive and uniform refinement between step 2 and 3 +2. run `mpirun -np 4 python plate_adapt.py --niters 4` +3. run `mpirun -np 4 python plate_adapt.py --niters 10 --strategy fixed_growth --ref_factor 0.1` +4. compare the results of uniform and adaptive refinement between step 2 and 3 """ -import sys import os import argparse from mpi4py import MPI @@ -114,28 +113,25 @@ def initCallBack(coarse_space, **kwargs): # load the geometry for the coarse model coarse_space.geomLoader = pyGeometryLoader(coarse_space.comm, geom_type) - coarse_space.geomLoader.readGeometryFile(geom_file) + coarse_space.geomLoader.readGeometryFile(geom_file=geom_file, print_lev=0) - # name the face and edges - face_names = {0: "panel"} - edge_names = {0: "south", 1: "east", 2: "north", 3: "west"} + # name the geometry + edge_names = {0: "bottom", 1: "right", 2: "top", 3: "left"} + face_names = {0: "plate"} coarse_space.geomLoader.nameGeometricEntities( face_names=face_names, edge_names=edge_names ) # specify boundary conditions - use defaults for nums and vals to fully fix - bc_names = ["south", "east", "north", "west"] - bc_nums = {} - bc_info = {"type": "edge", "bc_names": bc_names, "bc_nums": bc_nums} + bc_names = ["left", "right"] + bc_info = {"type": "edge", "bc_names": bc_names} coarse_space.geomLoader.setBoundaryConditions(bc_info) # set the meshing options - coarse_space.geomLoader.setMeshOptions(write_mesh_quality_histogram=0) - if not args.adapt: - coarse_space.geomLoader.setMeshOptions(mesh_type_default=TMR.STRUCTURED) + coarse_space.geomLoader.setMeshOptions(write_mesh_quality_histogram=False) # create the initial coarse mesh - coarse_space.geomLoader.createMesh(h=args.hinit) + coarse_space.geomLoader.createMesh(h=args.hinit, writeBDF=False) # create the topology coarse_space.geomLoader.createTopology(useMesh=True) @@ -168,26 +164,26 @@ def printroot(msg): # parse input arguments parser = argparse.ArgumentParser( - description="Mesh refinement test case for a fully-clamped flat plate" + description="Mesh refinement test case for a plate" ) parser.add_argument( "--hinit", - default=0.25, + default=0.125, type=float, help="target mesh size used for initial mesh generation", ) parser.add_argument( - "--order", default=3, type=int, help="order of elements in the mesh" + "--p", default=-3.0e4, type=float, help="uniform pressure load to apply" ) parser.add_argument( - "--p", default=-1.0e2, type=float, help="uniform pressure load to apply" + "--order", default=3, type=int, help="order of elements in the mesh" ) parser.add_argument( "--output", default="ks_fail", type=str, help="name of output of interest" ) parser.add_argument( "--ksweight", - default=1.0e6, + default=1.0e2, type=float, help="weight factor (rho) used for KS-aggregated outputs", ) @@ -198,28 +194,28 @@ def printroot(msg): help="number of refinement iterations to perform", ) parser.add_argument( - "--adapt", - default=False, - action="store_true", - help="boolean flag to apply adaptive/uniform mesh refinement", + "--strategy", + default="", + type=str, + help="type of adaptation strategy to use (leave empty for uniform refinement)", ) parser.add_argument( "--err_tol", - default=1.0e-6, + default=1.0e-3, type=float, help="target output error criterion used for adaptation termination", ) - parser.add_argument( - "--nmaxlevs", - default=30, - type=int, - help="max number of refinement levels allowed during adaptation", - ) parser.add_argument( "--ndecrease", default=5, type=int, - help="number of iterations needed to decrease the refinement threshold to 1", + help="number of iterations needed to decrease the refinement threshold to 0", + ) + parser.add_argument( + "--ref_factor", + default=0.0, + type=float, + help="fixed-growth refinement fraction applied each adaptive iteraton", ) args = parser.parse_args() for key in vars(args): @@ -229,21 +225,24 @@ def printroot(msg): if comm.rank == 0: for item in os.listdir(os.getcwd()): fname, fext = os.path.splitext(item) - if fext in [".f5", ".plt"]: + if fext in [".hdf5", ".f5", ".plt"]: os.remove(os.path.join(os.getcwd(), item)) # create the adaptive model + adapt_params = { + "adapt_strategy": args.strategy, + "error_tol": args.err_tol, + "num_decrease_iters": args.ndecrease, + "growth_refine_factor": args.ref_factor, + } model = pyTACSAdapt( comm, initCallBack, elemCallBack, probCallBack, args.output.lower(), - error_tol=args.err_tol, - num_max_ref_levels=args.nmaxlevs, - num_decrease_iters=args.ndecrease, + adapt_params, ) - model.setOutputOfInterest(args.output.lower()) # initialize the coarse-space model model.initializeCoarseSpace( @@ -257,7 +256,7 @@ def printroot(msg): # set up the coarse-space model model.setupModel(model_type="coarse", cmd_ln_args=args) model.coarse.setAuxElements( - geom_labels=["panel"], aux_type="pressure", faceIndex=0, p=args.p + geom_labels=["plate"], aux_type="pressure", faceIndex=0, p=args.p ) printroot("coarse model set up") @@ -265,7 +264,7 @@ def printroot(msg): model.solvePrimal(model_type="coarse", writeSolution=True) printroot("coarse primal problem solved") - if args.adapt: + if args.strategy: # solve the coarse adjoint problem model.solveAdjoint(model_type="coarse", writeSolution=False) printroot("coarse adjoint problem solved") @@ -273,7 +272,7 @@ def printroot(msg): # set up the fine-space model model.createFineSpace(cmd_ln_args=args) model.fine.setAuxElements( - geom_labels=["panel"], aux_type="pressure", faceIndex=0, p=args.p + geom_labels=["plate"], aux_type="pressure", faceIndex=0, p=args.p ) printroot("fine model set up") @@ -293,6 +292,7 @@ def printroot(msg): error_estimate, output_correction, element_errors, + node_errors, ) = model.estimateOutputError() printroot("output error estimated") @@ -303,16 +303,19 @@ def printroot(msg): elif k < (args.niters): # do the adaptation if not yet satisfied printroot("applying adaptive refinement") - model.adaptModelDecreasingThreshold(element_errors) + model.refineModel(element_errors) # otherwise do uniform mesh refinement else: if k < (args.niters): printroot("applying uniform refinement") - model.coarse.applyRefinement() + model.refineModel() # print out final information printroot(f"mesh_history: {model.mesh_history}") printroot(f"output_history: {model.output_history}") printroot(f"error_history: {model.error_history}") printroot(f"adaptation_history: {model.adaptation_history}") + + # write the model history file + model.writeModelHistory() From 4e8eb7142eb1cda7338a5ff5242f05dc58713e85 Mon Sep 17 00:00:00 2001 From: Graeme Kennedy Date: Wed, 6 Mar 2024 17:34:27 -0500 Subject: [PATCH 07/10] updated cython --- Makefile | 2 +- setup.py | 3 +++ tmr/TMR.pxd | 47 +++++++++++++++++++++++++++++++++++------------ tmr/TMR.pyx | 4 +++- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index c32c27e3..8f35eeb5 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ debug: ${CXX} ${SO_LINK_FLAGS} ${TMR_OBJS} ${TMR_EXTERN_LIBS} -o ${TMR_DIR}/lib/libtmr.${SO_EXT} interface: - pip install -e .\[all\] + pip install -e . clean: ${RM} lib/*.a lib/*.so diff --git a/setup.py b/setup.py index 471c395c..78cfc43b 100644 --- a/setup.py +++ b/setup.py @@ -76,6 +76,7 @@ def get_mpi_flags(): if "tacs" in sys.modules: inc_dirs.extend(tacs.get_include()) inc_dirs.extend(tacs.get_cython_include()) + inc_dirs.append(os.path.split(tacs.get_cython_include()[0])[0]) tacs_lib_dirs, tacs_libs = tacs.get_libraries() lib_dirs.extend(tacs_lib_dirs) libs.extend(tacs_libs) @@ -87,6 +88,7 @@ def get_mpi_flags(): if "paropt" in sys.modules: inc_dirs.extend(paropt.get_include()) inc_dirs.extend(paropt.get_cython_include()) + inc_dirs.append(os.path.split(paropt.get_cython_include()[0])[0]) paropt_lib_dirs, paropt_libs = paropt.get_libraries() lib_dirs.extend(paropt_lib_dirs) libs.extend(paropt_libs) @@ -98,6 +100,7 @@ def get_mpi_flags(): if "egads4py" in sys.modules: inc_dirs.extend(egads4py.get_include()) inc_dirs.extend(egads4py.get_cython_include()) + inc_dirs.append(os.path.split(egads4py.get_cython_include()[0])[0]) egads4py_lib_dirs, egads4py_libs = egads4py.get_libraries() lib_dirs.extend(egads4py_lib_dirs) libs.extend(egads4py_libs) diff --git a/tmr/TMR.pxd b/tmr/TMR.pxd index 7a7d36a2..721e5737 100644 --- a/tmr/TMR.pxd +++ b/tmr/TMR.pxd @@ -19,7 +19,6 @@ # limitations under the License. # For MPI -from mpi4py.libmpi cimport * cimport mpi4py.MPI as MPI # Import numpy @@ -29,21 +28,45 @@ import numpy as np # Import TACS from tacs import TACS from tacs cimport TACS -from tacs.TACS import * -from tacs.TACS cimport * -from tacs.constitutive import * -from tacs.constitutive cimport * +from tacs.TACS import Vec, VecInterp, Assembler, Mg, Element, Function, Pc +from tacs.TACS cimport ( + Vec, + VecInterp, + Assembler, + Mg, + Element, + Function, + Pc, + TACSFunction, + TACSBVec, + TACSBVecInterp, + TACSAssembler, + TACSMg, + _init_Vec, + _init_VecInterp, + _init_Assembler, + _init_Mg, + _dynamicTACSMg, +) +from tacs.constitutive import ( + PlaneStressConstitutive, + SolidConstitutive, + MaterialProperties, +) +from tacs.constitutive cimport ( + PlaneStressConstitutive, + SolidConstitutive, + MaterialProperties, + TACSMaterialProperties, +) # Import ParOpt -from paropt.ParOpt import * -from paropt.ParOpt cimport * +from paropt.ParOpt import PVec, ProblemBase +from paropt.ParOpt cimport PVec, ProblemBase, ParOptVec, _init_PVec # Import EGADS -from egads4py.egads import * -from egads4py.egads cimport * - -# Import all of the TMR header files -from tmr.cpp_headers.TMR cimport * +from egads4py.egads import pyego +from egads4py.egads cimport pyego cdef inline char* tmr_convert_str_to_chars(s): if isinstance(s, unicode): diff --git a/tmr/TMR.pyx b/tmr/TMR.pyx index 31e64844..346f72cb 100644 --- a/tmr/TMR.pyx +++ b/tmr/TMR.pyx @@ -19,7 +19,6 @@ # limitations under the License. # # For the use of MPI -from mpi4py.libmpi cimport * cimport mpi4py.MPI as MPI # Import numpy @@ -41,6 +40,9 @@ from libcpp cimport bool # Import C methods for python from cpython cimport PyObject, Py_INCREF +# Import all of the TMR header files +from tmr.cpp_headers.TMR cimport * + cdef tmr_init(): if not TMRIsInitialized(): TMRInitialize() From 1c787b7534ab32e9385c8c15385ea0f516458095 Mon Sep 17 00:00:00 2001 From: Yicong Fu Date: Wed, 6 Mar 2024 19:54:57 -0500 Subject: [PATCH 08/10] fix black formatting --- examples/egads/crm/dcel.py | 1 + examples/poisson/poisson_agg_error.py | 1 + examples/pygeometryloader/plate/plate.py | 1 + examples/pytacsadapt/plate/plate_adapt.py | 1 + examples/smooth/smooth_stl.py | 1 + .../eigenvalue/lbracket_eigenvalue.py | 1 + .../qn-correction/compliance/comp-min.py | 6 +++--- .../qn-correction/eigenvalue/eig-max-lite.py | 1 + .../frequency-baseline/baseline.py | 1 + .../refactor_compfreq/compfreq.py | 6 +++--- .../refactor_frequency/refactor_frequency.py | 6 +++--- tmr/pytacsadapt.py | 18 +++++++++--------- 12 files changed, 26 insertions(+), 18 deletions(-) diff --git a/examples/egads/crm/dcel.py b/examples/egads/crm/dcel.py index d483d461..ecee3efc 100644 --- a/examples/egads/crm/dcel.py +++ b/examples/egads/crm/dcel.py @@ -1,6 +1,7 @@ """ Implementation of a DECL data structure """ + import numpy as np diff --git a/examples/poisson/poisson_agg_error.py b/examples/poisson/poisson_agg_error.py index a836edf7..8d57e825 100644 --- a/examples/poisson/poisson_agg_error.py +++ b/examples/poisson/poisson_agg_error.py @@ -2,6 +2,7 @@ Plot the aggregation error as a function of rho for the KS and p-norm functionals """ + from __future__ import print_function import tikzplots as tkz import numpy as np diff --git a/examples/pygeometryloader/plate/plate.py b/examples/pygeometryloader/plate/plate.py index 82841875..6b0f1882 100644 --- a/examples/pygeometryloader/plate/plate.py +++ b/examples/pygeometryloader/plate/plate.py @@ -3,6 +3,7 @@ To run the defaults: mpirun -np 2 python plate.py """ + # imports import os from mpi4py import MPI diff --git a/examples/pytacsadapt/plate/plate_adapt.py b/examples/pytacsadapt/plate/plate_adapt.py index 27478428..eee08d40 100644 --- a/examples/pytacsadapt/plate/plate_adapt.py +++ b/examples/pytacsadapt/plate/plate_adapt.py @@ -13,6 +13,7 @@ 3. run `mpirun -np 4 python plate_adapt.py --niters 10 --strategy fixed_growth --ref_factor 0.1` 4. compare the results of uniform and adaptive refinement between step 2 and 3 """ + import os import argparse from mpi4py import MPI diff --git a/examples/smooth/smooth_stl.py b/examples/smooth/smooth_stl.py index 3e4255c2..e33dd7e3 100644 --- a/examples/smooth/smooth_stl.py +++ b/examples/smooth/smooth_stl.py @@ -1,6 +1,7 @@ """ Imports a STL file and applies a smoothing to it """ + from __future__ import print_function # Import the locate point code diff --git a/examples/topology_optimization/eigenvalue/lbracket_eigenvalue.py b/examples/topology_optimization/eigenvalue/lbracket_eigenvalue.py index c6452fd3..d5d0ea2e 100644 --- a/examples/topology_optimization/eigenvalue/lbracket_eigenvalue.py +++ b/examples/topology_optimization/eigenvalue/lbracket_eigenvalue.py @@ -2,6 +2,7 @@ Solve the eigenvalue-constrained optimization problem """ + from mpi4py import MPI from tmr import TMR, TopOptUtils from paropt import ParOpt, ParOptEig diff --git a/examples/topology_optimization/qn-correction/compliance/comp-min.py b/examples/topology_optimization/qn-correction/compliance/comp-min.py index 0fe7601f..cc42cdb4 100644 --- a/examples/topology_optimization/qn-correction/compliance/comp-min.py +++ b/examples/topology_optimization/qn-correction/compliance/comp-min.py @@ -397,9 +397,9 @@ def evalObjConGrad(self, x, g, gcon): prob.driver.opt_settings["Minor print level"] = 0 if max_iterations > 1 and step == max_iterations - 1: - prob.driver.opt_settings[ - "Major iterations limit" - ] = args.niter_finest + prob.driver.opt_settings["Major iterations limit"] = ( + args.niter_finest + ) else: prob.driver.opt_settings["Major iterations limit"] = args.max_iter diff --git a/examples/topology_optimization/qn-correction/eigenvalue/eig-max-lite.py b/examples/topology_optimization/qn-correction/eigenvalue/eig-max-lite.py index 615fab7a..d3c19273 100644 --- a/examples/topology_optimization/qn-correction/eigenvalue/eig-max-lite.py +++ b/examples/topology_optimization/qn-correction/eigenvalue/eig-max-lite.py @@ -1,6 +1,7 @@ """ This script performs eigenvalue minimization with mass constraint """ + import numpy as np from mpi4py import MPI import argparse diff --git a/examples/topology_optimization/qn-correction/frequency-baseline/baseline.py b/examples/topology_optimization/qn-correction/frequency-baseline/baseline.py index 327fad04..623111e1 100644 --- a/examples/topology_optimization/qn-correction/frequency-baseline/baseline.py +++ b/examples/topology_optimization/qn-correction/frequency-baseline/baseline.py @@ -1,6 +1,7 @@ """ Compute the base frequencies for different domains with concentrated mass """ + from tmr import TMR, TopOptUtils from tacs import TACS, constitutive diff --git a/examples/topology_optimization/qn-correction/refactor_compfreq/compfreq.py b/examples/topology_optimization/qn-correction/refactor_compfreq/compfreq.py index 7478325b..fcb7d522 100644 --- a/examples/topology_optimization/qn-correction/refactor_compfreq/compfreq.py +++ b/examples/topology_optimization/qn-correction/refactor_compfreq/compfreq.py @@ -475,9 +475,9 @@ def evalObjConGrad(self, x, g, gcon): omprob.driver.opt_settings["Minor print level"] = 0 if args.n_mesh_refine > 1 and step == args.n_mesh_refine - 1: - omprob.driver.opt_settings[ - "Major iterations limit" - ] = args.niter_finest + omprob.driver.opt_settings["Major iterations limit"] = ( + args.niter_finest + ) else: omprob.driver.opt_settings["Major iterations limit"] = args.max_iter diff --git a/examples/topology_optimization/qn-correction/refactor_frequency/refactor_frequency.py b/examples/topology_optimization/qn-correction/refactor_frequency/refactor_frequency.py index 4d4f719b..f989bfef 100644 --- a/examples/topology_optimization/qn-correction/refactor_frequency/refactor_frequency.py +++ b/examples/topology_optimization/qn-correction/refactor_frequency/refactor_frequency.py @@ -447,9 +447,9 @@ def evalObjConGrad(self, x, g, gcon): omprob.driver.opt_settings["Minor print level"] = 0 if n_refine_steps > 1 and step == n_refine_steps - 1: - omprob.driver.opt_settings[ - "Major iterations limit" - ] = args.niter_finest + omprob.driver.opt_settings["Major iterations limit"] = ( + args.niter_finest + ) else: omprob.driver.opt_settings["Major iterations limit"] = args.max_iter diff --git a/tmr/pytacsadapt.py b/tmr/pytacsadapt.py index 48e67d06..a56b8013 100644 --- a/tmr/pytacsadapt.py +++ b/tmr/pytacsadapt.py @@ -436,9 +436,9 @@ def setupModel(self, model_type, **kwargs): # record the number of degrees of freedom for this model nnodes = model.assembler.getNumOwnedNodes() - self.mesh_history[ - model.prob_name - ] = model.assembler.getVarsPerNode() * model.comm.allreduce(nnodes, op=MPI.SUM) + self.mesh_history[model.prob_name] = ( + model.assembler.getVarsPerNode() * model.comm.allreduce(nnodes, op=MPI.SUM) + ) return def solvePrimal(self, model_type, writeSolution=False, **kwargs): @@ -662,9 +662,9 @@ def estimateOutputError(self, writeSolution=False): # update histories self.error_history[f"adapt_iter_{self.fine.refine_iter}_error"] = error_estimate - self.error_history[ - f"adapt_iter_{self.fine.refine_iter}_correction" - ] = output_correction + self.error_history[f"adapt_iter_{self.fine.refine_iter}_correction"] = ( + output_correction + ) # write out the nodal error field if writeSolution: @@ -942,9 +942,9 @@ def writeModelHistory(self, filename=""): for key, val in self.adaptation_history["element_errors"].items(): h5[f"adaptation_history/element_errors/{key}"] = val if self.adapt_strategy: - h5["adaptation_history"].attrs[ - "strategy" - ] = self.adapt_strategy.replace("_", " ").lower() + h5["adaptation_history"].attrs["strategy"] = ( + self.adapt_strategy.replace("_", " ").lower() + ) h5["adaptation_history"].attrs["error_tolerance"] = self.error_tol h5["adaptation_history"].attrs[ "max_refine_levels" From 429933aa33845743c7272ed5d6b6c479470b72a7 Mon Sep 17 00:00:00 2001 From: gkennedy Date: Wed, 6 Mar 2024 21:53:16 -0500 Subject: [PATCH 09/10] fixed cython interface to import python module --- tmr/TMR.pxd | 1 - tmr/TMR.pyx | 2 ++ tmr/cpp_headers/TMR.pxd | 26 +++++++++++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/tmr/TMR.pxd b/tmr/TMR.pxd index 721e5737..eef573f8 100644 --- a/tmr/TMR.pxd +++ b/tmr/TMR.pxd @@ -27,7 +27,6 @@ import numpy as np # Import TACS from tacs import TACS -from tacs cimport TACS from tacs.TACS import Vec, VecInterp, Assembler, Mg, Element, Function, Pc from tacs.TACS cimport ( Vec, diff --git a/tmr/TMR.pyx b/tmr/TMR.pyx index 346f72cb..b0f0ae1a 100644 --- a/tmr/TMR.pyx +++ b/tmr/TMR.pyx @@ -43,6 +43,8 @@ from cpython cimport PyObject, Py_INCREF # Import all of the TMR header files from tmr.cpp_headers.TMR cimport * +from tacs import TACS + cdef tmr_init(): if not TMRIsInitialized(): TMRInitialize() diff --git a/tmr/cpp_headers/TMR.pxd b/tmr/cpp_headers/TMR.pxd index 09a215b9..98793dac 100644 --- a/tmr/cpp_headers/TMR.pxd +++ b/tmr/cpp_headers/TMR.pxd @@ -30,11 +30,27 @@ from libc.stdint cimport int32_t, int16_t cimport numpy as np import numpy as np -# Import TACS -from paropt.cpp_headers.ParOpt cimport * -from tacs.cpp_headers.TACS cimport * -from tacs.cpp_headers.constitutive cimport * -from egads4py.egads cimport * +# Import the definitions from the headers +from paropt.cpp_headers.ParOpt cimport ParOptScalar, ParOptVec, ParOptProblem +from tacs.cpp_headers.TACS cimport ( + TacsScalar, + TACSAssembler, + TACSElement, + TACSFunction, + TACSBVec, + TACSBVecInterp, + TACSMg, + OrderingType, + ElementType, + JDRecycleType, + JD_NUM_RECYCLE, +) +from tacs.cpp_headers.constitutive cimport ( + TACSMaterialProperties, + TACSPlaneStressConstitutive, + TACSSolidConstitutive, +) +from egads4py.egads cimport ego cdef extern from "TMRBase.h": enum: From c818b1776832b403d3a6e93d934442f15330836a Mon Sep 17 00:00:00 2001 From: gkennedy Date: Wed, 6 Mar 2024 22:07:00 -0500 Subject: [PATCH 10/10] added impor_array call --- tmr/TMR.pxd | 7 ------- tmr/TMR.pyx | 6 +++--- tmr/cpp_headers/TMR.pxd | 4 ---- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/tmr/TMR.pxd b/tmr/TMR.pxd index eef573f8..71cf9834 100644 --- a/tmr/TMR.pxd +++ b/tmr/TMR.pxd @@ -18,13 +18,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# For MPI -cimport mpi4py.MPI as MPI - -# Import numpy -cimport numpy as np -import numpy as np - # Import TACS from tacs import TACS from tacs.TACS import Vec, VecInterp, Assembler, Mg, Element, Function, Pc diff --git a/tmr/TMR.pyx b/tmr/TMR.pyx index b0f0ae1a..a7851b96 100644 --- a/tmr/TMR.pyx +++ b/tmr/TMR.pyx @@ -25,6 +25,9 @@ cimport mpi4py.MPI as MPI cimport numpy as np import numpy as np +# Ensure that numpy is initialized +np.import_array() + # Import the string library from libcpp.string cimport string from libc.string cimport strcpy @@ -49,9 +52,6 @@ cdef tmr_init(): if not TMRIsInitialized(): TMRInitialize() -# Ensure that numpy is initialized -np.import_array() - # Initialize the MPI libraries in TMR (if not already done) tmr_init() diff --git a/tmr/cpp_headers/TMR.pxd b/tmr/cpp_headers/TMR.pxd index 98793dac..a1cfa638 100644 --- a/tmr/cpp_headers/TMR.pxd +++ b/tmr/cpp_headers/TMR.pxd @@ -26,10 +26,6 @@ cimport mpi4py.MPI as MPI from libc.string cimport const_char from libc.stdint cimport int32_t, int16_t -# Import numpy -cimport numpy as np -import numpy as np - # Import the definitions from the headers from paropt.cpp_headers.ParOpt cimport ParOptScalar, ParOptVec, ParOptProblem from tacs.cpp_headers.TACS cimport (