Commit 7bbf58d2 authored by Michael Turner's avatar Michael Turner

added factories to the CADsystem

parent b5474726
......@@ -192,6 +192,7 @@ INCLUDE (ThirdPartyOCC)
INCLUDE (ThirdPartyTetGen)
INCLUDE (ThirdPartyANN)
INCLUDE (ThirdPartyCCM)
INCLUDE (ThirdPartyCFI)
INCLUDE (Doxygen)
......
......@@ -2,17 +2,17 @@
#
# ThirdParty configuration for Nektar++
#
# Star CCM i/o
# Star CCM i/o
#
########################################################################
OPTION(NEKTAR_USE_CCM
OPTION(NEKTAR_USE_CCM
"CCM star i/o library is available." OFF)
IF( NEKTAR_USE_CCM )
FIND_LIBRARY(CCMIO_LIBRARY NAMES "ccmio" "adf" PATHS /usr/local/lib ${Nektar++_TP_LIBRARY_DIRS})
IF( CCMIO_LIBRARY )
MESSAGE(STATUS "Found Ccmio: ${CCMIO_LIBRARY}")
MESSAGE(STATUS "Found Ccmio: ${CCMIO_LIBRARY}")
MARK_AS_ADVANCED(CCMIO_LIBRARY)
ADD_DEFINITIONS(-DNEKTAR_USE_CCM)
FIND_PATH (CCMIO_INCLUDE_DIR ccmio.h)
......
......@@ -15,7 +15,7 @@ IF(NEKTAR_USE_MESHGEN)
ELSE()
SET(BUILD_OCC ON)
ENDIF()
OPTION(THIRDPARTY_BUILD_OCC "Build OpenCascade library from ThirdParty."
${BUILD_OCC})
......@@ -33,7 +33,7 @@ IF(NEKTAR_USE_MESHGEN)
IF(WIN32)
MESSAGE(SEND_ERROR "Cannot currently use OpenCascade with Nektar++ on Windows")
ENDIF()
EXTERNALPROJECT_ADD(
opencascade-6.9
PREFIX ${TPSRC}
......
......@@ -36,13 +36,6 @@
#ifndef NEKMESHUTILS_CADSYSTEM_CADCURVE
#define NEKMESHUTILS_CADSYSTEM_CADCURVE
#include <boost/shared_ptr.hpp>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/Memory/NekMemoryManager.hpp>
#include <NekMeshUtils/CADSystem/OpenCascade.h>
#include <NekMeshUtils/CADSystem/CADObj.h>
#include <NekMeshUtils/CADSystem/CADVert.h>
#include <NekMeshUtils/CADSystem/CADSurf.h>
......@@ -66,7 +59,7 @@ public:
/**
* @brief Default constructor.
*/
CADCurve(int i, TopoDS_Shape in);
CADCurve(){};
~CADCurve(){};
......@@ -75,7 +68,11 @@ public:
*
* @return Array of two entries, min and max parametric coordinate.
*/
Array<OneD, NekDouble> Bounds();
virtual Array<OneD, NekDouble> Bounds()
{
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/**
* @brief Calculates the arclength between the two paremetric points \p ti
......@@ -85,7 +82,11 @@ public:
* @param tf Second parametric coordinate.
* @return Arc length between \p ti and \p tf.
*/
NekDouble Length(NekDouble ti, NekDouble tf);
virtual NekDouble Length(NekDouble ti, NekDouble tf)
{
ASSERTL0(false,"must be implement at derived level");
return 0.0;
}
/**
* @brief Gets the location (x,y,z) in an array out of the curve at
......@@ -94,12 +95,20 @@ public:
* @param t Parametric coordinate
* @return Array of x,y,z
*/
Array<OneD, NekDouble> P(NekDouble t);
virtual Array<OneD, NekDouble> P(NekDouble t)
{
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/**
* @brief Gets the second derivatives at t
*/
Array<OneD, NekDouble> D2(NekDouble t);
virtual Array<OneD, NekDouble> D2(NekDouble t)
{
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/**
* @brief Calculates the parametric coordinate and arclength location
......@@ -110,14 +119,22 @@ public:
*
* @todo This really needs improving for accuracy.
*/
NekDouble tAtArcLength(NekDouble s);
virtual NekDouble tAtArcLength(NekDouble s)
{
ASSERTL0(false,"must be implement at derived level");
return 0.0;
}
/**
* @brief Gets the start and end of the curve.
*
* @return Array with 6 entries of endpoints x1,y1,z1,x2,y2,z2.
*/
Array<OneD, NekDouble> GetMinMax();
virtual Array<OneD, NekDouble> GetMinMax()
{
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/// set the ids of the surfaces either side of the curve
void SetAdjSurf(std::vector<CADSurfSharedPtr> i)
......@@ -152,11 +169,7 @@ public:
return m_mainVerts;
}
private:
/// OpenCascade object of the curve.
BRepAdaptor_Curve m_occCurve;
/// OpenCascade edge
TopoDS_Edge m_occEdge;
protected:
/// Length of edge
NekDouble m_length;
/// List of surfaces which this curve belongs to.
......@@ -166,6 +179,11 @@ private:
};
typedef boost::shared_ptr<CADCurve> CADCurveSharedPtr;
typedef LibUtilities::NekFactory<EngineKey,CADCurve> CADCurveFactory;
CADCurveFactory& GetCADCurveFactory();
}
}
......
......@@ -53,12 +53,6 @@ enum cadType
surf
};
/**
* @brief class for CAD curves.
*
* This class wraps the OpenCascade BRepAdaptor_Curve class for use with
* Nektar++.
*/
class CADObj
{
public:
......
......@@ -36,14 +36,9 @@
#ifndef NekMeshUtils_CADSYSTEM_CADSURF
#define NekMeshUtils_CADSYSTEM_CADSURF
#include <boost/shared_ptr.hpp>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/Memory/NekMemoryManager.hpp>
#include <NekMeshUtils/CADSystem/OpenCascade.h>
#include <NekMeshUtils/CADSystem/CADObj.h>
#include <NekMeshUtils/CADSystem/CADVert.h>
#include <NekMeshUtils/CADSystem/CADSystem.h>
namespace Nektar
{
......@@ -53,18 +48,6 @@ namespace NekMeshUtils
class CADCurve;
typedef boost::shared_ptr<CADCurve> CADCurveSharedPtr;
/**
* @brief struct which descibes a collection of cad edges which for a
* loop on the cad surface
*/
struct EdgeLoop
{
std::vector<CADCurveSharedPtr> edges;
std::vector<int> edgeo; //0 is forward 1 is backward
Array<OneD, NekDouble> center;
NekDouble area;
};
/**
* @brief class for handleing a cad surface
*/
......@@ -77,7 +60,7 @@ public:
/**
* @brief Default constructor.
*/
CADSurf(int i, TopoDS_Shape in, std::vector<EdgeLoop> ein);
CADSurf(){};
~CADSurf(){};
......@@ -100,16 +83,10 @@ public:
*
* @return Array of 4 entries with parametric umin,umax,vmin,vmax.
*/
Array<OneD, NekDouble> GetBounds()
virtual Array<OneD, NekDouble> GetBounds()
{
Array<OneD,NekDouble> b(4);
b[0] = m_occSurface.FirstUParameter();
b[1] = m_occSurface.LastUParameter();
b[2] = m_occSurface.FirstVParameter();
b[3] = m_occSurface.LastVParameter();
return b;
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/**
......@@ -118,7 +95,11 @@ public:
* @param uv Array of u and v parametric coords.
* @return Array of xyz components of normal vector.
*/
Array<OneD, NekDouble> N (Array<OneD, NekDouble> uv);
virtual Array<OneD, NekDouble> N (Array<OneD, NekDouble> uv)
{
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/**
* @brief Get the set of first derivatives at parametric point u,v
......@@ -126,7 +107,11 @@ public:
* @param uv Array of u and v parametric coords.
* @return Array of xyz copmonents of first derivatives.
*/
Array<OneD, NekDouble> D1 (Array<OneD, NekDouble> uv);
virtual Array<OneD, NekDouble> D1 (Array<OneD, NekDouble> uv)
{
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/**
* @brief Get the set of second derivatives at parametric point u,v
......@@ -134,7 +119,11 @@ public:
* @param uv array of u and v parametric coords
* @return array of xyz copmonents of second derivatives
*/
Array<OneD, NekDouble> D2 (Array<OneD, NekDouble> uv);
virtual Array<OneD, NekDouble> D2 (Array<OneD, NekDouble> uv)
{
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/**
* @brief Get the x,y,z at parametric point u,v.
......@@ -142,7 +131,11 @@ public:
* @param uv Array of u and v parametric coords.
* @return Array of xyz location.
*/
Array<OneD, NekDouble> P (Array<OneD, NekDouble> uv);
virtual Array<OneD, NekDouble> P (Array<OneD, NekDouble> uv)
{
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/**
* @brief Performs a reverse look up to find u,v and x,y,z.
......@@ -150,12 +143,40 @@ public:
* @param p Array of xyz location
* @return The parametric location of xyz on this surface
*/
Array<OneD, NekDouble> locuv(Array<OneD, NekDouble> p);
virtual Array<OneD, NekDouble> locuv(Array<OneD, NekDouble> p)
{
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/**
* @brief does unconstrained locuv to project point from anywhere
* and calculate the distance between the orthonormal projection to the surface
* and the point
*/
virtual NekDouble DistanceTo(Array<OneD, NekDouble> p)
{
ASSERTL0(false,"must be implement at derived level");
return 0.0;
}
/**
* @brief takes a point from anywhere find the nearest surface point and its
* uv
*/
virtual void ProjectTo(Array<OneD, NekDouble> &tp, Array<OneD, NekDouble> &uv)
{
ASSERTL0(false,"must be implement at derived level");
}
/**
* @brief returns true if the surface is flat (2D)
* @brief returns curvature at point uv
*/
bool IsPlane();
virtual NekDouble Curvature(Array<OneD, NekDouble> uv)
{
ASSERTL0(false,"must be implement at derived level");
return 0.0;
}
/**
* @brief sets the flag to reverse the normal for this suface,
......@@ -172,50 +193,26 @@ public:
return !m_correctNormal;
}
/**
* @brief surface needs to know if it is bounded by only two curves
*/
void SetTwoC()
{
m_hasTwoCurves = true;
}
/**
* @brief query two curves
*/
bool GetTwoC(){return m_hasTwoCurves;}
/**
* @brief does unconstrained locuv to project point from anywhere
*/
NekDouble DistanceTo(Array<OneD, NekDouble> p);
void ProjectTo(Array<OneD, NekDouble> &tp, Array<OneD, NekDouble> &uv);
/**
* @brief returns curvature at point uv
*/
NekDouble Curvature(Array<OneD, NekDouble> uv);
private:
void Initialise(int i, TopoDS_Shape in);
/// Function which tests the the value of uv used is within the surface
void Test(Array<OneD, NekDouble> uv);
protected:
/// normal
bool m_correctNormal;
/// flag to alert the mesh generation to a potential problem is both
/// curves have only two points in the mesh
bool m_hasTwoCurves;
/// OpenCascade object for surface.
BRepAdaptor_Surface m_occSurface;
/// Alternate OpenCascade object for surface. Used by reverse lookup.
Handle(Geom_Surface) m_s;
/// Function which tests the the value of uv used is within the surface
virtual void Test(Array<OneD, NekDouble> uv)
{
ASSERTL0(false,"must be implement at derived level");
}
/// List of bounding edges in loops with orientation.
std::vector<EdgeLoop> m_edges;
};
typedef boost::shared_ptr<CADSurf> CADSurfSharedPtr;
typedef LibUtilities::NekFactory<EngineKey,CADSurf> CADSurfFactory;
CADSurfFactory& GetCADSurfFactory();
}
}
......
......@@ -41,7 +41,7 @@
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/Memory/NekMemoryManager.hpp>
#include <NekMeshUtils/CADSystem/OpenCascade.h>
#include <LibUtilities/BasicUtils/NekFactory.hpp>
namespace Nektar
{
......@@ -54,7 +54,18 @@ class CADCurve;
typedef boost::shared_ptr<CADCurve> CADCurveSharedPtr;
class CADSurf;
typedef boost::shared_ptr<CADSurf> CADSurfSharedPtr;
struct EdgeLoop;
/**
* @brief struct which descibes a collection of cad edges which for a
* loop on the cad surface
*/
struct EdgeLoop
{
std::vector<CADCurveSharedPtr> edges;
std::vector<int> edgeo; //0 is forward 1 is backward
Array<OneD, NekDouble> center;
NekDouble area;
};
/**
* @brief Base class for CAD interface system.
......@@ -70,26 +81,38 @@ public:
/**
* @brief Default constructor.
*/
CADSystem(const std::string &name) : m_name(name)
{
}
CADSystem(std::string name) : m_name(name) {};
~CADSystem(){};
/**
* @brief Return the name of the CAD system.
*/
std::string GetName();
std::string GetName()
{
return m_name;
}
/**
* @brief Initialises CAD and makes surface, curve and vertex maps.
*
* @return true if completed successfully
*/
bool LoadCAD();
virtual bool LoadCAD()
{
ASSERTL0(false,"must be implement at derived level");
return false;
}
/**
* @brief Reports basic properties to screen.
*/
void Report();
void Report()
{
std::cout << std::endl << "CAD report:" << std::endl;
std::cout << "\tCAD has: " << m_curves.size() << " curves." << std::endl;
std::cout << "\tCAD has: " << m_surfs.size() << " surfaces." << std::endl;
}
/**
* @brief Returns bounding box of the domain.
......@@ -99,7 +122,11 @@ public:
*
* @return Array with 6 entries: xmin, xmax, ymin, ymax, zmin and zmax.
*/
Array<OneD, NekDouble> GetBoundingBox();
virtual Array<OneD, NekDouble> GetBoundingBox()
{
ASSERTL0(false,"must be implement at derived level");
return Array<OneD, NekDouble>();
}
/**
* @brief Get the number of surfaces.
......@@ -155,24 +182,7 @@ public:
return m_verts.size();
}
/**
* @brief based on location in space, uses opencascade routines to
* determin if the point is within the domain. This routine is slow
* and should be used sparingly, it is smart enough to take and form
* of geometry
*/
bool InsideShape(Array<OneD, NekDouble> loc);
std::vector<int> GetBoundarySurfs();
private:
/// Function to add curve to CADSystem::m_verts.
void AddVert(int i, TopoDS_Shape in);
/// Function to add curve to CADSystem::m_curves.
void AddCurve(int i, TopoDS_Shape in, int fv, int lv);
/// Function to add surface to CADSystem::m_surfs.
void AddSurf(int i, TopoDS_Shape in, std::vector<EdgeLoop> ein);
/// Name of cad file to be opened, including file extension.
protected:
std::string m_name;
/// Map of curves
std::map<int, CADCurveSharedPtr> m_curves;
......@@ -180,11 +190,22 @@ private:
std::map<int, CADSurfSharedPtr> m_surfs;
/// Map of vertices
std::map<int, CADVertSharedPtr> m_verts;
/// OCC master object
TopoDS_Shape shape;
};
typedef boost::shared_ptr<CADSystem> CADSystemSharedPtr;
enum EngineType{
eOCE,
eCFI
};
typedef std::pair<EngineType,std::string> EngineKey;
std::ostream& operator<<(std::ostream&os, const EngineKey& rhs);
typedef LibUtilities::NekFactory<EngineKey,CADSystem,std::string> EngineFactory;
EngineFactory& GetEngineFactory();
}
}
......
This diff is collapsed.
////////////////////////////////////////////////////////////////////////////////
//
// 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 NekMeshUtils_CADSYSTEM_CADSYSTEM
#define NekMeshUtils_CADSYSTEM_CADSYSTEM
#include <boost/shared_ptr.hpp>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/Memory/NekMemoryManager.hpp>
#include <NekMeshUtils/CADSystem/OpenCascade.h>
namespace Nektar
{
namespace NekMeshUtils
{
class CADVert;
typedef boost::shared_ptr<CADVert> CADVertSharedPtr;
class CADCurve;
typedef boost::shared_ptr<CADCurve> CADCurveSharedPtr;
class CADSurf;
typedef boost::shared_ptr<CADSurf> CADSurfSharedPtr;
struct EdgeLoop;
/**
* @brief Base class for CAD interface system.
*
* A class which can load and interact with CAD for Nektar++ using OpenCascade.
* This class contains maps to subclasses surface and curves.
*/
class CADSystem
{
public:
friend class MemoryManager<CADSystem>;
/**
* @brief Default constructor.
*/
CADSystemOCE(const std::string &name) : CADSystem(name)
{
}
/**
* @brief Initialises CAD and makes surface, curve and vertex maps.
*
* @return true if completed successfully
*/
bool LoadCAD();
/**
* @brief Returns bounding box of the domain.
*
* Gets the bounding box of the domain by considering the start and end
* points of each curve in the geometry.
*
* @return Array with 6 entries: xmin, xmax, ymin, ymax, zmin and zmax.
*/
Array<OneD, NekDouble> GetBoundingBox();
private:
/// Function to add curve to CADSystem::m_verts.
void AddVert(int i, TopoDS_Shape in);
/// Function to add curve to CADSystem::m_curves.
void AddCurve(int i, TopoDS_Shape in, int fv, int lv);
/// Function to add surface to CADSystem::m_surfs.
void AddSurf(int i, TopoDS_Shape in, std::vector<EdgeLoop> ein);
/// Name of cad file to be opened, including file extension.
std::string m_name;
/// Map of curves
std::map<int, CADCurveSharedPtr> m_curves;
/// Map of surfaces
std::map<int, CADSurfSharedPtr> m_surfs;
/// Map of vertices
std::map<int, CADVertSharedPtr> m_verts;
/// OCC master object
TopoDS_Shape shape;
};
}
}
#endif
......@@ -64,22 +64,8 @@ public:
/**
* @brief Default constructor.
*/
CADVert(int i, TopoDS_Shape in)
CADVert()
{
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);
m_id = i;
m_occVert = BRep_Tool::Pnt(TopoDS::Vertex(in));
m_node = boost::shared_ptr<Node>(
new Node(i - 1, m_occVert.X(), m_occVert.Y(), m_occVert.Z()));
degen = false;
m_type = vert;
}
~CADVert(){};
......@@ -90,9 +76,9 @@ public:
Array<OneD, NekDouble> GetLoc()
{
Array<OneD, NekDouble> out(3);
out[0] = m_occVert.X();
out[1] = m_occVert.Y();
out[2] = m_occVert.Z();
out[0] = m_node->m_x;
out[1] = m_node->m_y;
out[2] = m_node->m_z;
return out;
}
......@@ -132,9 +118,7 @@ public:
}
}
private:
/// OpenCascade object of the curve.
gp_Pnt m_occVert;
protected:
/// mesh convert object of vert
NodeSharedPtr m_node;
/// degen marker
......@@ -144,6 +128,11 @@ private:
};
typedef boost::shared_ptr<CADVert> CADVertSharedPtr;
typedef LibUtilities::NekFactory<EngineKey,CADVert> CADVertFactory;
CADVertFactory& GetCADVertFactory();
}
}
......
......@@ -33,7 +33,7 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <NekMeshUtils/CADSystem/CADCurve.h>
#include "CADCurveOCE.h"
using namespace std;
......@@ -42,26 +42,10 @@ namespace Nektar
namespace NekMeshUtils
{
CADCurve::CADCurve(int i, TopoDS_Shape in)
{
gp_Trsf transform;
gp_Pnt ori(0.0, 0.0, 0.0);