DudleyDomain.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 __DUDLEY_DOMAIN_H__
#define __DUDLEY_DOMAIN_H__
/****************************************************************************
Dudley: 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. Dudley domains have three ElementFiles
containing the elements, surface and point sources, respectively.
Notice that the surface elements do not necessarily cover the entire
surface of the domain.
The element type is either Tri3 or Tet4 depending on dimensionality
and also determines the type of surface elements to be used.
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.
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.
*****************************************************************************/
#include "system_dep.h"
#include <dudley/Dudley.h>
#include <dudley/ElementFile.h>
#include <dudley/NodeFile.h>
#include <dudley/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 dudley {
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 DUDLEY_DLL_API DudleyDomain : 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, bool optimize);
static escript::Domain_ptr readGmsh(escript::JMPI mpiInfo,
const std::string& filename, int numDim,
bool optimize);
static escript::Domain_ptr create2D(dim_t NE0, dim_t NE1, double l0,
double l1, bool optimize,
escript::JMPI jmpi);
static escript::Domain_ptr create3D(dim_t NE0, dim_t NE1, dim_t NE2,
double l0, double l1, double l2,
bool optimize, escript::JMPI jmpi);
DudleyDomain(const std::string& name, int numDim, escript::JMPI jmpi);
DudleyDomain(const DudleyDomain& in);
~DudleyDomain();
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 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
boost::python::numpy::ndarray getNumpyX() const;
boost::python::numpy::ndarray getConnectivityInfo() const;
#endif
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 false; }
virtual escript::Data randomFill(const escript::DataTypes::ShapeType& shape,
const escript::FunctionSpace& what, long seed,
const boost::python::tuple& filter) const;
void createMappings(const std::vector<index_t>& dofDistribution,
const std::vector<index_t>& nodeDistribution);
void relabelElementNodes(const index_t* 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 getPasoPattern() const;
#endif
#ifdef ESYS_HAVE_TRILINOS
esys_trilinos::const_TrilinosGraph_ptr getTrilinosGraph() const {
return m_nodes->getTrilinosGraph();
}
#endif
private:
void prepare(bool optimize);
void resolveNodeIds();
#ifdef ESYS_HAVE_PASO
paso::SystemMatrixPattern_ptr makePasoPattern() const;
#endif
void createColoring(const index_t* dofMap);
void distributeByRankOfDOF(const IndexVector& distribution);
void markNodes(std::vector<short>& mask, index_t offset) const;
void optimizeDOFDistribution(IndexVector& distribution);
void optimizeDOFLabeling(const IndexVector& distribution);
void optimizeElementOrdering();
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;
NodeFile* m_nodes;
ElementFile* m_elements;
ElementFile* m_faceElements;
ElementFile* m_points;
TagMap m_tagMap;
#ifdef ESYS_HAVE_PASO
// pointer to the sparse matrix pattern
mutable paso::SystemMatrixPattern_ptr pasoPattern;
#endif
static FunctionSpaceNamesMapType m_functionSpaceTypeNames;
};
} // end of namespace
#endif // __DUDLEY_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
dudley::DudleyDomain
DudleyDomain implements the AbstractContinuousDomain interface for the Dudley library.
Definition: DudleyDomain.h:88
dudley::DudleyDomain::getDim
virtual int getDim() const
Returns the spatial dimension of the domain.
Definition: DudleyDomain.h:395
dudley::DudleyDomain::getMPI
virtual escript::JMPI getMPI() const
returns a reference to the MPI information wrapper for this domain
Definition: DudleyDomain.h:220
dudley::DudleyDomain::getFaceElements
ElementFile * getFaceElements() const
returns a pointer to this domain's face element file
Definition: DudleyDomain.h:202
dudley::DudleyDomain::getMPISize
virtual int getMPISize() const
returns the number of processors used for this domain
Definition: DudleyDomain.h:226
dudley::DudleyDomain::m_points
ElementFile * m_points
the table of points (treated as elements of dimension 0)
Definition: DudleyDomain.h:748
dudley::DudleyDomain::getPoints
ElementFile * getPoints() const
returns a pointer to this domain's point (nodal) element file
Definition: DudleyDomain.h:214
dudley::DudleyDomain::onMasterProcessor
virtual bool onMasterProcessor() const
returns true if on MPI processor 0, else false
Definition: DudleyDomain.h:244
dudley::DudleyDomain::m_elements
ElementFile * m_elements
the table of the elements
Definition: DudleyDomain.h:744
dudley::DudleyDomain::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.
dudley::DudleyDomain::m_faceElements
ElementFile * m_faceElements
the table of face elements
Definition: DudleyDomain.h:746
dudley::DudleyDomain::m_tagMap
TagMap m_tagMap
the tag map mapping names to tag keys
Definition: DudleyDomain.h:750
dudley::DudleyDomain::m_functionSpaceTypeNames
static FunctionSpaceNamesMapType m_functionSpaceTypeNames
Definition: DudleyDomain.h:756
dudley::DudleyDomain::supportsContactElements
virtual bool supportsContactElements() const
Definition: DudleyDomain.h:679
dudley::DudleyDomain::m_name
std::string m_name
domain description
Definition: DudleyDomain.h:740
dudley::DudleyDomain::getMPIRank
virtual int getMPIRank() const
returns the number MPI rank of this processor
Definition: DudleyDomain.h:232
dudley::DudleyDomain::FunctionSpaceNamesMapType
std::map< int, std::string > FunctionSpaceNamesMapType
Definition: DudleyDomain.h:390
dudley::DudleyDomain::m_nodes
NodeFile * m_nodes
the table of the nodes
Definition: DudleyDomain.h:742
dudley::DudleyDomain::getMPIComm
MPI_Comm getMPIComm() const
get the communicator for this domain. Returns an integer on non-MPI builds Routine must be implemente...
Definition: DudleyDomain.h:246
dudley::DudleyDomain::m_mpiInfo
escript::JMPI m_mpiInfo
MPI information.
Definition: DudleyDomain.h:738
dudley::DudleyDomain::getNodes
NodeFile * getNodes() const
returns a pointer to this domain's node file
Definition: DudleyDomain.h:178
dudley::DudleyDomain::setToIntegrals
virtual void setToIntegrals(std::vector< escript::DataTypes::cplx_t > &integrals, const escript::Data &arg) const
dudley::DudleyDomain::getElements
ElementFile * getElements() const
returns a pointer to this domain's element file
Definition: DudleyDomain.h:190
dudley::ElementFile
Definition: dudley/src/ElementFile.h:53
dudley::NodeFile
Definition: dudley/src/NodeFile.h:40
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
DUDLEY_DLL_API
#define DUDLEY_DLL_API
Definition: dudley/src/system_dep.h:29
dudley
A suite of factory methods for creating 2D and 3D dudley domains.
Definition: dudley/src/Assemble.h:32
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
dudley::SystemMatrixType
SystemMatrixType
Definition: DudleyDomain.h:75
dudley::SMT_PASO
@ SMT_PASO
Definition: DudleyDomain.h:76
dudley::SMT_TRILINOS
@ SMT_TRILINOS
Definition: DudleyDomain.h:77
dudley::SMT_COMPLEX
@ SMT_COMPLEX
Definition: DudleyDomain.h:78
dudley::SMT_UNROLL
@ SMT_UNROLL
Definition: DudleyDomain.h:79
dudley::TagMap
std::map< std::string, int > TagMap
Definition: DudleyDomain.h:73
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
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