Commit 7ea85a72 authored by David Moxey's avatar David Moxey
Browse files

Cherry-pick CAD system files from feature/all-meshing

parent 194147e0
......@@ -96,6 +96,9 @@ MARK_AS_ADVANCED(NEKTAR_BUILD_PACKAGES)
OPTION(NEKTAR_TEST_ALL "Include full set of regression tests to this build." OFF)
# meshing and cad options
OPTION(NEKTAR_USE_OCC "Use opencascade for geometry interface." OFF)
# Build options
OPTION(NEKTAR_FULL_DEBUG "Enable Full Debugging." OFF)
MARK_AS_ADVANCED(NEKTAR_FULL_DEBUG)
......@@ -171,6 +174,7 @@ INCLUDE (ThirdPartyScotch)
INCLUDE (ThirdPartyZlib)
INCLUDE (ThirdPartyBoost)
INCLUDE (ThirdPartyFFTW)
INCLUDE (ThirdPartyOCC)
INCLUDE (ThirdPartyArpack)
INCLUDE (ThirdPartyMPI)
INCLUDE (ThirdPartyPETSc)
......
IF(NEKTAR_USE_OCC)
SET(BUILD_OCC ON)
OPTION(THIRDPARTY_DOWNLOAD_OCC
"Get OpenCascade from ThirdParty." ${BUILD_OCC})
IF (THIRDPARTY_DOWNLOAD_OCC)
IF(WIN32)
message(SEND_ERROR "Cannot use opencascade with netkar++ on windows")
ELSEIF(APPLE)
INCLUDE(ExternalProject)
EXTERNALPROJECT_ADD(
opencascade-6.8
PREFIX ${TPSRC}
URL http://ae-nektar.ae.ic.ac.uk/~mt4313/OCC680osx64.tgz
URL_MD5 626292523b0691304f0fa271989fbc44
STAMP_DIR ${TPBUILD}/stamp
DOWNLOAD_DIR ${TPSRC}
SOURCE_DIR ${TPSRC}/opencascade-6.8
INSTALL_DIR ${TPDIST}
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
SET(OCC_LIBS PTKernel TKernel TKMath TKBRep TKIGES TKSTEP TKSTEPAttr TKSTEP209 TKSTEPBase TKShapeSchema TKGeomBase TKGeomAlgo TKG3d TKG2d TKXSBase TKPShape TKTopAlgo)
LINK_DIRECTORIES(${TPSRC}/opencascade-6.8/i686/lib)
INCLUDE_DIRECTORIES(SYSTEM ${TPSRC}/opencascade-6.8/i686/inc)
ELSE()
INCLUDE(ExternalProject)
EXTERNALPROJECT_ADD(
opencascade-6.8
PREFIX ${TPSRC}
URL http://ae-nektar.ae.ic.ac.uk/~mt4313/OCC680lin64.tgz
URL_MD5 d655b6f50998bb9600e081907c247793
STAMP_DIR ${TPBUILD}/stamp
DOWNLOAD_DIR ${TPSRC}
SOURCE_DIR ${TPSRC}/opencascade-6.8
INSTALL_DIR ${TPDIST}
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
SET(OCC_LIBS PTKernel TKernel TKMath TKBRep TKIGES TKSTEP TKSTEPAttr TKSTEP209 TKSTEPBase TKShapeSchema TKGeomBase TKGeomAlgo TKG3d TKG2d TKXSBase TKPShape TKTopAlgo)
LINK_DIRECTORIES(${TPSRC}/opencascade-6.8/lib)
INCLUDE_DIRECTORIES(SYSTEM ${TPSRC}/opencascade-6.8/inc)
ENDIF()
ENDIF (THIRDPARTY_DOWNLOAD_OCC)
ENDIF(NEKTAR_USE_OCC)
////////////////////////////////////////////////////////////////////////////////
//
// File: CADSystem.cpp
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: cad object methods.
//
////////////////////////////////////////////////////////////////////////////////
#include <LibUtilities/CADSystem/CADCurve.h>
using namespace std;
namespace Nektar{
namespace LibUtilities{
NekDouble CADCurve::tAtArcLength(NekDouble s)
{
NekDouble dt = (occCurve.LastParameter()-occCurve.FirstParameter())/(5000);
NekDouble t = occCurve.FirstParameter();
NekDouble len=0.0;
while(len<=s)
{
gp_Pnt P1,P2;
gp_Vec drdt1,drdt2;
occCurve.D1(t,P1,drdt1);
t+=dt;
occCurve.D1(t,P2,drdt2);
len+=(drdt1.Magnitude()+drdt2.Magnitude())/2.0*dt;
}
return t-dt;
//this really needs improving for accuracy
}
NekDouble CADCurve::Length(NekDouble ti, NekDouble tf)
{
NekDouble len = 0;
NekDouble dt = (occCurve.LastParameter()-occCurve.FirstParameter())/(1000-1);
NekDouble t = ti;
while(t+dt<=tf)
{
gp_Pnt P1,P2;
gp_Vec drdt1,drdt2;
occCurve.D1(t,P1,drdt1);
t+=dt;
occCurve.D1(t,P2,drdt2);
len+=(drdt1.Magnitude()+drdt2.Magnitude())/2.0*dt;
}
return len;
}
void CADCurve::P(NekDouble t, Array<OneD, NekDouble> &out)
{
out = Array<OneD, NekDouble>(3);
gp_Pnt loc = occCurve.Value(t);
out[0] = loc.X();
out[1] = loc.Y();
out[2] = loc.Z();
}
void CADCurve::Bounds(Array<OneD, NekDouble> &out)
{
out = Array<OneD, NekDouble> (2);
out[0] = occCurve.FirstParameter();
out[1] = occCurve.LastParameter();
}
CADCurve::CADCurve(int i, TopoDS_Shape in) : ID(i)
{
gp_Trsf transform;
gp_Pnt ori(0.0,0.0,0.0);
transform.SetScale(ori,1.0/1000.0);
TopLoc_Location mv(transform);
in.Move(mv);
occCurve = BRepAdaptor_Curve(TopoDS::Edge(in));
}
void CADCurve::GetMinMax(gp_Pnt &start, gp_Pnt &end)
{
start = occCurve.Value(occCurve.FirstParameter());
end = occCurve.Value(occCurve.LastParameter());
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// File: CADSystem.h
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: cad object methods.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_LIB_UTILITIES_CADSYSTEM_CADCURVE_H
#define NEKTAR_LIB_UTILITIES_CADSYSTEM_CADCURVE_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
#include <LibUtilities/Memory/NekMemoryManager.hpp>
#include <STEPControl_Reader.hxx>
#include <IGESControl_Reader.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <TopoDS.hxx>
#include <TopExp.hxx>
#include <TopoDS_Shape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <BRepTools.hxx>
#include <BRep_Tool.hxx>
#include <gp_Trsf.hxx>
#include <TopLoc_Location.hxx>
namespace Nektar {
namespace LibUtilities {
class CADCurve
{
public:
friend class MemoryManager<CADCurve>;
CADCurve(int i, TopoDS_Shape in);
void GetMinMax(gp_Pnt &start, gp_Pnt &end);
void Bounds(Array<OneD, NekDouble> &out);
NekDouble Length(NekDouble ti, NekDouble tf);
void P(NekDouble t, Array<OneD, NekDouble> &out);
NekDouble tAtArcLength(NekDouble s);
int GetID(){return ID;}
void SetAdjSurf(std::vector<int> i){adjSurfs=i;}
std::vector<int> GetAdjSurf(){return adjSurfs;}
private:
int ID;
BRepAdaptor_Curve occCurve;
std::vector<int> adjSurfs;
};
typedef boost::shared_ptr<CADCurve> CADCurveSharedPtr;
}
}
#endif
////////////////////////////////////////////////////////////////////////////////
//
// File: CADSystem.cpp
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: cad object methods.
//
////////////////////////////////////////////////////////////////////////////////
#include <LibUtilities/CADSystem/CADSurf.h>
using namespace std;
namespace Nektar{
namespace LibUtilities{
CADSurf::CADSurf(int i, TopoDS_Shape in,
vector<vector<pair<int,int> > > ein) : ID(i), edges(ein)
{
gp_Trsf transform;
gp_Pnt ori(0.0,0.0,0.0);
transform.SetScale(ori,1.0/1000.0);
TopLoc_Location mv(transform);
s = BRep_Tool::Surface(TopoDS::Face(in));
in.Move(mv);
occSurface = BRepAdaptor_Surface(TopoDS::Face(in));
}
void CADSurf::locuv(NekDouble &u, NekDouble &v,
Array<OneD, NekDouble> p)
{
gp_Pnt loc(p[0]*1000.0,p[1]*1000.0,p[2]*1000.0);
GeomAPI_ProjectPointOnSurf projection(loc, s,
occSurface.FirstUParameter(),
occSurface.LastUParameter(),
occSurface.FirstVParameter(),
occSurface.LastVParameter(),
Extrema_ExtAlgo_Tree);
ASSERTL0(projection.NbPoints()>0, "locuv failed");
Quantity_Parameter ui;
Quantity_Parameter vi;
projection.Parameters(1,ui,vi);
//this is always true, stupid check
ASSERTL0(abs(ui - occSurface.FirstUParameter()) > -1E-6 &&
abs(occSurface.LastUParameter() - ui ) > -1E-6 &&
abs(vi - occSurface.FirstVParameter()) > -1E-6 &&
abs(occSurface.LastVParameter() - vi ) > -1E-6,
"locuv exceeded bounds");
u = ui;
v = vi;
if(!(projection.Distance(1)<1E-3))
cout << projection.Distance(1) << endl;
}
Array<OneD, NekDouble> CADSurf::P(NekDouble u, NekDouble v)
{
ASSERTL0(u-occSurface.FirstUParameter() > -1E-6 &&
occSurface.LastUParameter()-u > -1E-6 &&
v-occSurface.FirstVParameter() > -1E-6 &&
occSurface.LastVParameter()-v > -1E-6, "out of bounds");
Array<OneD, NekDouble> out(3);
gp_Pnt loc;
loc = occSurface.Value(u,v);
out[0]=loc.X();
out[1]=loc.Y();
out[2]=loc.Z();
return out;
}
Array<OneD, NekDouble> CADSurf::N(NekDouble u, NekDouble v)
{
Array<OneD, NekDouble> out(3);
gp_Pnt Loc;
gp_Vec D1U,D1V;
occSurface.D1(u,v,Loc,D1U,D1V);
gp_Vec n = D1U.Crossed(D1V);
if(n.X()==0 && n.Y() ==0 && n.Z()==0)
{
out[0]=0.0;
out[1]=0.0;
out[2]=0.0;
}
else
{
n.Normalize();
out[0]=n.X();
out[1]=n.Y();
out[2]=n.Z();
}
return out;
}
Array<OneD, NekDouble> CADSurf::D1(NekDouble u, NekDouble v)
{
Array<OneD, NekDouble> out(9);
gp_Pnt Loc;
gp_Vec D1U,D1V;
occSurface.D1(u,v,Loc,D1U,D1V);
out[0]=Loc.X();
out[1]=Loc.Y();
out[2]=Loc.Z();
out[3]=D1U.X();
out[4]=D1U.Y();
out[5]=D1U.Z();
out[6]=D1V.X();
out[7]=D1V.Y();
out[8]=D1V.Z();
return out;
}
Array<OneD, NekDouble> CADSurf::D2(NekDouble u, NekDouble v)
{
Array<OneD, NekDouble> out(18);
gp_Pnt Loc;
gp_Vec D1U,D1V,D2U,D2V,D2UV;
occSurface.D2(u,v,Loc,D1U,D1V,D2U,D2V,D2UV);
out[0]=Loc.X();
out[1]=Loc.Y();
out[2]=Loc.Z();
out[3]=D1U.X();
out[4]=D1U.Y();
out[5]=D1U.Z();
out[6]=D1V.X();
out[7]=D1V.Y();
out[8]=D1V.Z();
out[9]=D2U.X();
out[10]=D2U.Y();
out[11]=D2U.Z();
out[12]=D2V.X();
out[13]=D2V.Y();
out[14]=D2V.Z();
out[15]=D2UV.X();
out[16]=D2UV.Y();
out[17]=D2UV.Z();
return out;
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// File: CADSystem.h
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: cad object methods.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_LIB_UTILITIES_CADSYSTEM_CADSURF_H
#define NEKTAR_LIB_UTILITIES_CADSYSTEM_CADSURF_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
#include <LibUtilities/Memory/NekMemoryManager.hpp>
#include <STEPControl_Reader.hxx>
#include <IGESControl_Reader.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
#include <TopoDS.hxx>
#include <TopExp.hxx>
#include <TopoDS_Shape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <BRepTools.hxx>
#include <BRep_Tool.hxx>
#include <gp_Trsf.hxx>
#include <TopLoc_Location.hxx>
namespace Nektar {
namespace LibUtilities {
class CADSurf
{
public:
friend class MemoryManager<CADSurf>;
CADSurf(int i, TopoDS_Shape in,
std::vector<std::vector<std::pair<int,int> > > ein);
std::vector<std::vector<std::pair<int,int> > >
GetEdges(){return edges;}
Array<OneD, NekDouble> N(NekDouble u, NekDouble v);
Array<OneD, NekDouble> D1(NekDouble u, NekDouble v);
Array<OneD, NekDouble> D2(NekDouble u, NekDouble v);
Array<OneD, NekDouble> P(NekDouble u, NekDouble v);
void locuv(NekDouble &u, NekDouble &v, Array<OneD, NekDouble> p);
void GetBounds(Array<OneD,NekDouble> &out)
{
out = Array<OneD,NekDouble>(4);
out[0]=occSurface.FirstUParameter();
out[1]=occSurface.LastUParameter();
out[2]=occSurface.FirstVParameter();
out[3]=occSurface.LastVParameter();
}
private:
int ID;
BRepAdaptor_Surface occSurface;
Handle(Geom_Surface) s;
std::vector<std::vector<std::pair<int,int> > > edges;
};
typedef boost::shared_ptr<CADSurf> CADSurfSharedPtr;
}
}
#endif
////////////////////////////////////////////////////////////////////////////////
//
// File: CADSystem.cpp
//
// For more information, please see: http://www.nektar.info/
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included