finley/src/FinleyDomain.h
Go to the documentation of this file.
/*****************************************************************************
*
* Copyright (c) 2003-2020 by The University of Queensland
* http://www.uq.edu.au
*
* Primary Business: Queensland, Australia
* Licensed under the Apache License, version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
* Development 2012-2013 by School of Earth Sciences
* Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
* Development from 2019 by School of Earth and Environmental Sciences
**
*****************************************************************************/
#ifndef __FINLEY_DOMAIN_H__
#define __FINLEY_DOMAIN_H__
/****************************************************************************
Finley: Domain
A mesh is built from nodes and elements which describe the domain, surface,
and point sources (the latter are needed to establish links with other
codes, in particular particle codes). The nodes are stored in a NodeFile
and elements in ElementFiles. Finley domains have four ElementFiles
containing the elements, surface, contact and point sources, respectively.
Notice that the surface elements do not necessarily cover the entire
surface of the domain.
The element type is fixed by the reference element, see ReferenceElement.h.
The numbering of the nodes starts with 0.
Important: it is assumed that every node appears in at least one element or
surface element and that any node used in an element, surface element or as
a point is specified in the NodeFile, see also resolveNodeIds.
In some cases it is useful to refer to a mesh entirely built from
order 1 (=linear) elements. The linear version of the mesh can be
accessed by referring to the first few nodes of each element
(thanks to the way the nodes are ordered). As the numbering of
these nodes is not continuous a relabeling vector is introduced
in the NodeFile. This feature is not fully implemented yet.
All nodes and elements are tagged. The tag allows to group nodes and
elements. A typical application is to mark surface elements on a
certain portion of the domain with the same tag. All these surface
elements can then be assigned the same value e.g. for the pressure.
The spatial dimensionality is determined by the type of elements
used and can be queried using getDim(). Notice that the element type
also determines the type of surface elements to be used.
*****************************************************************************/
#include "system_dep.h"
#include <finley/Finley.h>
#include <finley/ElementFile.h>
#include <finley/NodeFile.h>
#include <finley/Util.h>
#include <escript/AbstractContinuousDomain.h>
#include <escript/FunctionSpace.h>
#include <escript/FunctionSpaceFactory.h>
#ifdef ESYS_HAVE_PASO
#include <paso/SystemMatrixPattern.h>
#endif
#ifdef ESYS_HAVE_TRILINOS
#include <trilinoswrap/types.h>
#endif
#include <map>
#include <string>
#include <vector>
namespace finley {
typedef std::map<std::string, int> TagMap;
enum SystemMatrixType {
SMT_PASO = 1<<8,
SMT_TRILINOS = 1<<10,
SMT_COMPLEX = 1<<16,
SMT_UNROLL = 1<<17
};
class FINLEY_DLL_API FinleyDomain : public escript::AbstractContinuousDomain
{
public:
static escript::Domain_ptr load(const std::string& filename);
static escript::Domain_ptr read(escript::JMPI mpiInfo,
const std::string& fileName,
int integrationOrder = -1,
int reducedIntegrationOrder = -1,
bool optimize = false);
static escript::Domain_ptr readGmsh(escript::JMPI mpiInfo,
const std::string& filename,
int numDim, int integrationOrder = -1,
int reducedIntegrationOrder = -1,
bool optimize = false,
bool useMacroElements = false);
static escript::Domain_ptr createRec4(dim_t NE0, dim_t NE1,
double L0, double L1,
bool periodic0, bool periodic1, int order,
int reducedOrder, bool useElementsOnFace,
bool optimize, escript::JMPI jmpi);
static escript::Domain_ptr createRec8(dim_t NE0, dim_t NE1,
double l0, double l1,
bool periodic0, bool periodic1, int order,
int reducedOrder, bool useElementsOnFace,
bool useFullElementOrder,
bool useMacroElements, bool optimize,
escript::JMPI jmpi);
static escript::Domain_ptr createHex8(dim_t NE0, dim_t NE1, dim_t NE2,
double l0, double l1, double l2,
bool periodic0, bool periodic1, bool periodic2,
int order, int reducedOrder,
bool useElementsOnFace,
bool optimize, escript::JMPI jmpi);
static escript::Domain_ptr createHex20(dim_t NE0, dim_t NE1, dim_t NE2,
double l0, double l1, double l2,
bool periodic0, bool periodic1, bool periodic2,
int order, int reducedOrder,
bool useElementsOnFace,
bool useFullElementOrder,
bool useMacroElements, bool optimize,
escript::JMPI jmpi);
FinleyDomain(const std::string& name, int numDim, escript::JMPI jmpi);
FinleyDomain(const FinleyDomain& in);
~FinleyDomain();
void addDiracPoints(const std::vector<double>& points,
const std::vector<int>& tags);
NodeFile* getNodes() const { return m_nodes; }
void setElements(ElementFile* elements);
ElementFile* getElements() const { return m_elements; }
void setFaceElements(ElementFile* elements);
ElementFile* getFaceElements() const { return m_faceElements; }
void setContactElements(ElementFile* elements);
ElementFile* getContactElements() const { return m_contactElements; }
void setPoints(ElementFile* elements);
ElementFile* getPoints() const { return m_points; }
virtual escript::JMPI getMPI() const { return m_mpiInfo; }
virtual int getMPISize() const { return m_mpiInfo->size; }
virtual int getMPIRank() const { return m_mpiInfo->rank; }
virtual void MPIBarrier() const;
virtual bool onMasterProcessor() const { return getMPIRank() == 0; }
MPI_Comm getMPIComm() const { return m_mpiInfo->comm; }
void write(const std::string& fileName) const;
void Print_Mesh_Info(bool full=false) const;
void dump(const std::string& fileName) const;
int getTagFromSampleNo(int functionSpaceType, index_t sampleNo) const;
const index_t* borrowSampleReferenceIDs(int functionSpaceType) const;
virtual bool isValidFunctionSpaceType(int functionSpaceType) const;
virtual std::string getDescription() const;
virtual std::string functionSpaceTypeAsString(int functionSpaceType) const;
void setFunctionSpaceTypeNames();
virtual int getContinuousFunctionCode() const;
virtual int getReducedContinuousFunctionCode() const;
virtual int getFunctionCode() const;
virtual int getReducedFunctionCode() const;
virtual int getFunctionOnBoundaryCode() const;
virtual int getReducedFunctionOnBoundaryCode() const;
virtual int getFunctionOnContactZeroCode() const;
virtual int getReducedFunctionOnContactZeroCode() const;
virtual int getFunctionOnContactOneCode() const;
virtual int getReducedFunctionOnContactOneCode() const;
virtual int getSolutionCode() const;
virtual int getReducedSolutionCode() const;
virtual int getDiracDeltaFunctionsCode() const;
typedef std::map<int, std::string> FunctionSpaceNamesMapType;
virtual int getDim() const { return m_nodes->numDim; }
virtual StatusType getStatus() const;
virtual dim_t getNumDataPointsGlobal() const;
virtual std::pair<int,dim_t> getDataShape(int functionSpaceCode) const;
virtual void setToX(escript::Data& arg) const;
virtual void setTagMap(const std::string& name, int tag);
virtual int getTag(const std::string& name) const;
virtual bool isValidTagName(const std::string& name) const;
virtual std::string showTagNames() const;
virtual void setNewX(const escript::Data& arg);
virtual void interpolateOnDomain(escript::Data& target,
const escript::Data& source) const;
virtual bool probeInterpolationOnDomain(int functionSpaceType_source,
int functionSpaceType_target) const;
virtual signed char preferredInterpolationOnDomain(int functionSpaceType_source, int functionSpaceType_target) const;
bool commonFunctionSpace(const std::vector<int>& fs, int& resultcode) const;
virtual void interpolateAcross(escript::Data& target, const escript::Data& source) const;
virtual bool probeInterpolationAcross(int functionSpaceType_source,
const escript::AbstractDomain& targetDomain,
int functionSpaceType_target) const;
virtual void setToNormal(escript::Data& out) const;
virtual void setToSize(escript::Data& out) const;
virtual void setToGradient(escript::Data& grad, const escript::Data& arg) const;
virtual void setToIntegrals(std::vector<escript::DataTypes::real_t>& integrals,
const escript::Data& arg) const;
virtual void setToIntegrals(std::vector<escript::DataTypes::cplx_t>& integrals,
const escript::Data& arg) const;
virtual int getSystemMatrixTypeId(const boost::python::object& options) const;
virtual int getTransportTypeId(int solver, int preconditioner, int package,
bool symmetry) const;
virtual bool isCellOriented(int functionSpaceCode) const;
virtual bool ownSample(int fsCode, index_t id) const;
virtual void addPDEToSystem(
escript::AbstractSystemMatrix& mat, escript::Data& rhs,
const escript::Data& A, const escript::Data& B,
const escript::Data& C, const escript::Data& D,
const escript::Data& X, const escript::Data& Y,
const escript::Data& d, const escript::Data& y,
const escript::Data& d_contact,
const escript::Data& y_contact,
const escript::Data& d_dirac,
const escript::Data& y_dirac) const;
virtual void addPDEToLumpedSystem(escript::Data& mat,
const escript::Data& D,
const escript::Data& d,
const escript::Data& d_dirac,
bool useHRZ) const;
virtual void addPDEToRHS(escript::Data& rhs, const escript::Data& X,
const escript::Data& Y, const escript::Data& y,
const escript::Data& y_contact,
const escript::Data& y_dirac) const;
virtual void addPDEToTransportProblem(
escript::AbstractTransportProblem& tp,
escript::Data& source, const escript::Data& M,
const escript::Data& A, const escript::Data& B,
const escript::Data& C, const escript::Data& D,
const escript::Data& X, const escript::Data& Y,
const escript::Data& d, const escript::Data& y,
const escript::Data& d_contact,
const escript::Data& y_contact,
const escript::Data& d_dirac,
const escript::Data& y_dirac) const;
escript::ASM_ptr newSystemMatrix(
int row_blocksize,
const escript::FunctionSpace& row_functionspace,
int column_blocksize,
const escript::FunctionSpace& column_functionspace,
int type) const;
escript::ATP_ptr newTransportProblem(int blocksize,
const escript::FunctionSpace& functionspace,
int type) const;
virtual escript::Data getX() const;
#ifdef ESYS_HAVE_BOOST_NUMPY
virtual boost::python::numpy::ndarray getNumpyX() const;
virtual boost::python::numpy::ndarray getConnectivityInfo() const;
#endif
virtual int getVTKElementType() const;
virtual escript::Data getNormal() const;
virtual escript::Data getSize() const;
virtual bool operator==(const escript::AbstractDomain& other) const;
virtual bool operator!=(const escript::AbstractDomain& other) const;
virtual void setTags(int functionSpaceType, int newTag,
const escript::Data& mask) const;
virtual int getNumberOfTagsInUse(int functionSpaceCode) const;
virtual const int* borrowListOfTagsInUse(int functionSpaceCode) const;
virtual bool canTag(int functionSpaceCode) const;
virtual int getApproximationOrder(int functionSpaceCode) const;
virtual bool supportsContactElements() const { return true; }
virtual escript::Data randomFill(const escript::DataTypes::ShapeType& shape,
const escript::FunctionSpace& what, long seed,
const boost::python::tuple& filter) const;
const TagMap& getTagMap() const { return m_tagMap; }
void createMappings(const IndexVector& dofDistribution,
const IndexVector& nodeDistribution);
#ifdef ESYS_HAVE_PASO
paso::SystemMatrixPattern_ptr getPasoPattern(bool reducedRowOrder,
bool reducedColOrder) const;
#endif
#ifdef ESYS_HAVE_TRILINOS
esys_trilinos::const_TrilinosGraph_ptr getTrilinosGraph(bool reducedOrder) const;
#endif
void glueFaces(double safetyFactor, double tolerance, bool optimize);
void joinFaces(double safetyFactor, double tolerance, bool optimize);
static FinleyDomain* merge(const std::vector<const FinleyDomain*>& meshes);
private:
void prepare(bool optimize);
void setOrders();
void resolveNodeIds();
void relabelElementNodes(const IndexVector& newNode, index_t offset);
template<typename Scalar>
void setToIntegralsWorker(std::vector<Scalar>& integrals,
const escript::Data& arg) const;
#ifdef ESYS_HAVE_PASO
paso::SystemMatrixPattern_ptr makePasoPattern(bool reducedRowOrder,
bool reducedColOrder) const;
#endif
#ifdef ESYS_HAVE_TRILINOS
esys_trilinos::GraphType* createTrilinosGraph(bool reducedOrder) const;
#endif
void createColoring(const IndexVector& dofMap);
void distributeByRankOfDOF(const IndexVector& distribution);
void markNodes(std::vector<short>& mask, index_t offset, bool useLinear) const;
void optimizeDOFDistribution(IndexVector& distribution);
void optimizeDOFLabeling(const IndexVector& distribution);
void optimizeElementOrdering();
void findMatchingFaces(double safetyFactor, double tolerance, int* numPairs,
int* elem0, int* elem1, int* matchingNodes) const;
void updateTagList();
void printElementInfo(const ElementFile* e, const std::string& title,
const std::string& defaultType, bool full) const;
void writeElementInfo(std::ostream& stream, const ElementFile* e,
const std::string& defaultType) const;
escript::JMPI m_mpiInfo;
std::string m_name;
int approximationOrder;
int reducedApproximationOrder;
int integrationOrder;
int reducedIntegrationOrder;
NodeFile* m_nodes;
ElementFile* m_elements;
ElementFile* m_faceElements;
ElementFile* m_contactElements;
ElementFile* m_points;
TagMap m_tagMap;
#ifdef ESYS_HAVE_PASO
// pointer to the sparse matrix patterns
mutable paso::SystemMatrixPattern_ptr FullFullPattern;
mutable paso::SystemMatrixPattern_ptr FullReducedPattern;
mutable paso::SystemMatrixPattern_ptr ReducedFullPattern;
mutable paso::SystemMatrixPattern_ptr ReducedReducedPattern;
#endif
#ifdef ESYS_HAVE_TRILINOS
mutable esys_trilinos::TrilinosGraph_ptr m_fullGraph;
mutable esys_trilinos::TrilinosGraph_ptr m_reducedGraph;
#endif
static FunctionSpaceNamesMapType m_functionSpaceTypeNames;
};
} // end of namespace
#endif // __FINLEY_DOMAIN_H__
MPI_Comm
int MPI_Comm
Definition: EsysMPI.h:44
getTag
int getTag(unsigned char sourcex, unsigned char sourcey, unsigned char sourcez, unsigned char targetx, unsigned char targety, unsigned char targetz)
Definition: blocktools.cpp:413
escript::AbstractContinuousDomain
AbstractContinuousDomain, base class for continuous domains.
Definition: AbstractContinuousDomain.h:47
escript::AbstractDomain
Base class for all escript domains.
Definition: AbstractDomain.h:51
escript::AbstractSystemMatrix
Base class for escript system matrices.
Definition: AbstractSystemMatrix.h:44
escript::AbstractTransportProblem
Give a short description of what AbstractTransportProblem does.
Definition: AbstractTransportProblem.h:45
escript::Data
Data represents a collection of datapoints.
Definition: Data.h:64
escript::FunctionSpace
Definition: FunctionSpace.h:36
finley::ElementFile
Definition: finley/src/ElementFile.h:63
finley::FinleyDomain
FinleyDomain implements the AbstractContinuousDomain interface for the Finley library.
Definition: finley/src/FinleyDomain.h:97
finley::FinleyDomain::m_functionSpaceTypeNames
static FunctionSpaceNamesMapType m_functionSpaceTypeNames
Definition: finley/src/FinleyDomain.h:918
finley::FinleyDomain::integrationOrder
int integrationOrder
Definition: finley/src/FinleyDomain.h:892
finley::FinleyDomain::m_name
std::string m_name
domain description
Definition: finley/src/FinleyDomain.h:889
finley::FinleyDomain::m_faceElements
ElementFile * m_faceElements
the table of face elements
Definition: finley/src/FinleyDomain.h:899
finley::FinleyDomain::m_nodes
NodeFile * m_nodes
the table of the nodes
Definition: finley/src/FinleyDomain.h:895
finley::FinleyDomain::reducedApproximationOrder
int reducedApproximationOrder
Definition: finley/src/FinleyDomain.h:891
finley::FinleyDomain::getMPIRank
virtual int getMPIRank() const
returns the number MPI rank of this processor
Definition: finley/src/FinleyDomain.h:353
finley::FinleyDomain::getContactElements
ElementFile * getContactElements() const
returns a pointer to this domain's contact element file
Definition: finley/src/FinleyDomain.h:323
finley::FinleyDomain::supportsContactElements
virtual bool supportsContactElements() const
Definition: finley/src/FinleyDomain.h:808
finley::FinleyDomain::approximationOrder
int approximationOrder
Definition: finley/src/FinleyDomain.h:890
finley::FinleyDomain::getMPISize
virtual int getMPISize() const
returns the number of processors used for this domain
Definition: finley/src/FinleyDomain.h:347
finley::FinleyDomain::getPoints
ElementFile * getPoints() const
returns a pointer to this domain's point (nodal) element file
Definition: finley/src/FinleyDomain.h:335
finley::FinleyDomain::reducedIntegrationOrder
int reducedIntegrationOrder
Definition: finley/src/FinleyDomain.h:893
finley::FinleyDomain::getElements
ElementFile * getElements() const
returns a pointer to this domain's element file
Definition: finley/src/FinleyDomain.h:299
finley::FinleyDomain::getDim
virtual int getDim() const
returns the dimensionality of this domain
Definition: finley/src/FinleyDomain.h:516
finley::FinleyDomain::setToIntegrals
virtual void setToIntegrals(std::vector< escript::DataTypes::cplx_t > &integrals, const escript::Data &arg) const
finley::FinleyDomain::m_elements
ElementFile * m_elements
the table of the elements
Definition: finley/src/FinleyDomain.h:897
finley::FinleyDomain::onMasterProcessor
virtual bool onMasterProcessor() const
returns true if on MPI processor 0, else false
Definition: finley/src/FinleyDomain.h:365
finley::FinleyDomain::getFaceElements
ElementFile * getFaceElements() const
returns a pointer to this domain's face element file
Definition: finley/src/FinleyDomain.h:311
finley::FinleyDomain::m_tagMap
TagMap m_tagMap
the tag map mapping names to tag keys
Definition: finley/src/FinleyDomain.h:905
finley::FinleyDomain::m_points
ElementFile * m_points
the table of points (treated as elements of dimension 0)
Definition: finley/src/FinleyDomain.h:903
finley::FinleyDomain::m_contactElements
ElementFile * m_contactElements
the table of contact elements
Definition: finley/src/FinleyDomain.h:901
finley::FinleyDomain::getMPIComm
MPI_Comm getMPIComm() const
get the communicator for this domain. Returns an integer on non-MPI builds Routine must be implemente...
Definition: finley/src/FinleyDomain.h:367
finley::FinleyDomain::getNodes
NodeFile * getNodes() const
returns a pointer to this domain's node file
Definition: finley/src/FinleyDomain.h:287
finley::FinleyDomain::FunctionSpaceNamesMapType
std::map< int, std::string > FunctionSpaceNamesMapType
Definition: finley/src/FinleyDomain.h:511
finley::FinleyDomain::setToIntegrals
virtual void setToIntegrals(std::vector< escript::DataTypes::real_t > &integrals, const escript::Data &arg) const
copies the integrals of the function defined by arg into integrals. arg has to be defined on this.
finley::FinleyDomain::getMPI
virtual escript::JMPI getMPI() const
returns a reference to the MPI information wrapper for this domain
Definition: finley/src/FinleyDomain.h:341
finley::FinleyDomain::getTagMap
const TagMap & getTagMap() const
returns a reference to the tag name->value map
Definition: finley/src/FinleyDomain.h:818
finley::FinleyDomain::m_mpiInfo
escript::JMPI m_mpiInfo
MPI information.
Definition: finley/src/FinleyDomain.h:887
finley::NodeFile
Definition: finley/src/NodeFile.h:42
FINLEY_DLL_API
#define FINLEY_DLL_API
Definition: finley/src/system_dep.h:29
dudley::readGmsh
Domain_ptr readGmsh(const string &fileName, int numDim, int, int, bool optimize)
reads a gmsh mesh file
Definition: dudley/src/DomainFactory.cpp:681
escript::DataTypes::IndexVector
std::vector< index_t > IndexVector
Definition: DataTypes.h:64
escript::DataTypes::ShapeType
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:44
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:66
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:61
escript::load
Data load(const std::string fileName, const AbstractDomain &domain)
reads Data on domain from file in netCDF format
Definition: DataFactory.cpp:708
escript::ATP_ptr
boost::shared_ptr< AbstractTransportProblem > ATP_ptr
Definition: AbstractTransportProblem.h:161
escript::ASM_ptr
boost::shared_ptr< AbstractSystemMatrix > ASM_ptr
Definition: AbstractSystemMatrix.h:33
escript::Domain_ptr
boost::shared_ptr< AbstractDomain > Domain_ptr
Definition: AbstractDomain.h:41
escript::JMPI
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:74
finley
A suite of factory methods for creating various finley domains.
Definition: finley/src/Assemble.h:32
finley::SystemMatrixType
SystemMatrixType
Definition: finley/src/FinleyDomain.h:84
finley::SMT_TRILINOS
@ SMT_TRILINOS
Definition: finley/src/FinleyDomain.h:86
finley::SMT_PASO
@ SMT_PASO
Definition: finley/src/FinleyDomain.h:85
finley::SMT_COMPLEX
@ SMT_COMPLEX
Definition: finley/src/FinleyDomain.h:87
finley::SMT_UNROLL
@ SMT_UNROLL
Definition: finley/src/FinleyDomain.h:88
finley::TagMap
std::map< std::string, int > TagMap
Definition: finley/src/FinleyDomain.h:82
finley::glueFaces
Domain_ptr glueFaces(const bp::list &meshList, double safetyFactor, double tolerance, bool optimize)
Definition: finley/src/DomainFactory.cpp:1288
finley::joinFaces
Domain_ptr joinFaces(const bp::list &meshList, double safetyFactor, double tolerance, bool optimize)
Definition: finley/src/DomainFactory.cpp:1300
paso::util::l2
double l2(dim_t n, const double *x, escript::JMPI mpiinfo)
returns the global L2 norm of x
Definition: PasoUtil.cpp:501
paso::SystemMatrixPattern_ptr
boost::shared_ptr< SystemMatrixPattern > SystemMatrixPattern_ptr
Definition: SystemMatrixPattern.h:40
paso::M
static dim_t M
Definition: SparseMatrix_saveHB.cpp:37
speckley::probeInterpolationAcross
bool probeInterpolationAcross(int fsType_source, const escript::AbstractDomain &domain, int fsType_target, int dim)
Definition: CrossDomainCoupler.cpp:32
system_dep.h