55 getProfiler()->start(
"buildFE",
"building finite elements and degrees of freedom");
58 CEPS_SAYS_NOENDL(
" 1/4 Creating reference finite elements of order " << order <<
"...");
59 initializeRefElements();
75 m_volElems->synchronize(
false);
76 m_bdrElems->synchronize(
false);
77 m_nodes ->synchronize(
true,&setGlobalIndexFunction<FENode>);
88 CEPS_SAYS_NOENDL(
" 4/4 Assembling finite elements mass and stiffness matrices...");
89 m_mass = newDofMatrix();
90 m_stiff = newDofMatrix();
94 for (
Unknown* u: m_problem->getSpatialUnknowns())
95 asbs.setKForUnknown(u,1.);
97 asbm.setMatrix(m_mass .
get());
98 asbs.setMatrix(m_stiff.get());
105 getProfiler()->stop(
"buildFE");
112 for (
auto& ref: it.second)
227 "you are trying to return a spatial index for a non-local "
228 "unknown with name '"
261 CepsBool restrictions = boundary or not attrs.empty() or not unknowns.empty();
263 if (not restrictions) {
295 CepsBool restrictions = boundary or not attrs.empty() or not unknowns.empty();
299 if (not restrictions) {
324 return(std::sqrt(
stiffProduct(v,v,boundary,attrs,unknowns)));
339 m_refElems[type][dim] = ceps::getNew<ReferenceFE>(dim,fetype);
357 CepsUInt nVolCells = 0u, nBdrCells = 0u;
397 cellId = cell->getGlobalIndex();
403 FEBase* fElem = ceps::getNew<FEBase>(cell,
false,refElem);
411 foundSameNode =
false;
427 if (not foundSameNode)
431 toBuild->
append(fElem,cellId,cellId);
453 CepsReal3D q = node->getGeomObject()->getCoordinates();
461 node->getProperties()->setOnBoundary(boundary);
462 node->addCell(fElem);
482 if (feNodeCellIndex!=-1)
487 fenode = ceps::getNew<FENode>(
const_cast<GeomNode*
>(gNode),
false);
504 GeomNode* gNode = ceps::getNew<GeomNode>(p[0],p[1],p[2],-1);
514 fenode = ceps::getNew<FENode>(gNode,
true);
533 for (
FEBase* el : all->getOwned())
543 nodes[i]->addNode(nodes[j]);
557 elems[i]->addCell(elems[j]);
586 for (
FENode* feNode : toParse)
595 auto attrs = feNode->getGeomObject()->getAttributes();
603 if (u->isSpatial() and (u->hasOneOfAttributes(attrs) or u->hasAttribute(
CepsUniversal)))
605 auto dof = ceps::getNew<DegreeOfFreedom>(u,attrs,gId,0x0,feNode->getGeomObject()->getOwner());
606 dof->setDiscrId(feId);
607 dof->setVertex(feNode->getGeomObject());
608 dof->setOnBoundary(feNode->getGeomObject()->isBoundary());
623 for (
FEBase* elem: toParse->getOwned())
631 Unknown* u1 = dof1->getUnknown();
632 Unknown* u2 = dof2->getUnknown();
639 while (not coupled and i<interactions.size())
642 or interactions[i]->getNumberOfAttributes()==0
643 or elem->getGeomObject()->hasOneOfAttributes(interactions[i]->getAttributes());
645 coupled = okAttribute and
646 ((u1==interactions[i]->u1 and u2==interactions[i]->u2) or
647 (u1==interactions[i]->u2 and u2==interactions[i]->u1));
653 dof1->addNeighbor(dof2);
654 dof2->addNeighbor(dof1);
679 for (
CepsProcId sndr=0; sndr<gridSize; sndr++)
680 for (
CepsProcId rcvr=0; rcvr<gridSize; rcvr++)
691 CepsInt tag = 5*(gridSize*sndr+rcvr);
696 adjSize += adjm.second.size();
698 MPI_Isend(&adjSize ,1,
CEPS_MPI_UINT,rcvr,0+tag,comm,&request);
699 MPI_Isend(&adjRowsSize,1,
CEPS_MPI_UINT,rcvr,1+tag,comm,&request);
704 MPI_Recv(&adjRowsSize,1,
CEPS_MPI_UINT,sndr,1+tag,comm,&status);
707 adj .resize(adjSize );
708 adjPtr .resize(adjRowsSize+1);
709 adjRows.resize(adjRowsSize );
711 if (adjSize!= 0 and rank==sndr)
722 adjRows[i ] = adjm.first;
723 adjPtr [i+1] = count;
728 MPI_Isend(adjPtr .data(),adjRowsSize+1,
CEPS_MPI_UINT ,rcvr,4+tag,comm,&request);
730 else if (adjSize!=0 and rank==rcvr)
734 MPI_Recv(adjPtr .data(),adjRowsSize+1,
CEPS_MPI_UINT ,sndr,4+tag,comm,&status);
736 for (
CepsUInt i=0;i<adjRowsSize;i++)
737 for (
CepsUInt ptr=adjPtr[i];ptr<adjPtr[i+1];ptr++)
763 if (returnGeomIndices)
769 and ((not sendToMaster) or dof->getOwner()==rank);
773 uId,vec,indices,values,sendToMaster,returnGeomIndices,selector
790 selec.onlyOnThisProc(
true);
791 selec.selectBetween(cells.begin(), cells.end());
801 for (
auto cell : cells)
802 locMeas += cell->getGeomObject()->getMeasure();
CepsBool areSameArray(const CepsArray< _Type, _N > &a, const CepsArray< _Type, _N > &b, const CepsReal error=1.)
Test equality of arrays, suitable for real numbers.
@ Cell
Data is defined at cell centers.
@ Point
Data is defined on each point.
@ ZeroD
Data is defined once.
CepsCellType
Enum for different shapes of cells.
#define CEPS_SAYS(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_SAYS_NOENDL(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_SAYS_INLINE(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
CepsIndex CepsUnknownIndex
For unknowns.
CepsGlobalIndex CepsCellGlobalIndex
Indices of cells.
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
#define CEPS_MPI_GLOBAL_INDEX
std::vector< _Type, _Alloc > CepsVector
C++ vector.
CepsGlobalIndex CepsDofGlobalIndex
Indices of degrees of freedom.
CepsIndex CepsGlobalIndex
Many uses. Has to be signed for PETSc.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
float CepsReal
Need single precision floating point.
CepsGlobalIndex CepsNodeGlobalIndex
Indices of nodes.
CepsUInt CepsProcId
For CPU indices.
CepsArray3< CepsReal > CepsReal3D
Three real scalars, used like this for compatibility in polynomials.
int32_t CepsInt
Need 32 bit integer.
constexpr CepsAttribute CepsUniversal
This attribute means "everywhere".
CepsInt CepsIndex
Index rowid etc.
std::shared_ptr< DistributedHaloVector > DHVecPtr
Typedef for pointer on Distributed Halo CepsVector.
std::shared_ptr< DistributedMatrix > DMatPtr
Short typedef for pointer on dist matrix.
std::shared_ptr< DistributedVector > DVecPtr
Short typedef for pointer on distributed vector.
std::pair< CepsCellType, CepsUInt > CepsFeLagrangeType
Typedef for descriptor of Lagrange finite elements type.
CepsReal getDomainMeasure(const CepsVector< FEBase * > &cells, const CepsSet< CepsAttribute > &attributes, CepsBool onlyOfThisProc)
Compute the measure of a set of a cells.
void setMatrix(DistributedMatrix *mat)
The matrix to assemble.
Abstract Class for all numerical method (FE, FD, FV etc)
void extractValuesForUnknownInternal(const CepsUnknownIndex &uId, DVecPtr vec, CepsVector< CepsIndex > &indices, CepsVector< CepsReal > &values, CepsBool sendToMaster, CepsBool returnGeomIndices, std::function< CepsBool(DegreeOfFreedom *)> &selector)
Slicing method that extracts the data corresponding to a specific unknown.
AbstractPdeProblem * m_problem
[not owned] Pointer on the pde problem
CepsMap< CepsDofGlobalIndex, CepsSet< CepsDofGlobalIndex > > m_extraAdjacencyToRecv
A map to correct the missing adjacency that can occur in rare occasions in 3D.
DVecPtr newDofVector() const
Get a new vector from the factory.
Geometry * m_geometry
[not owned] Pointer on the geometry
DMatPtr newDofMatrix() const
Get a new matrix from the factory.
CepsVector< CepsMap< CepsDofGlobalIndex, CepsSet< CepsDofGlobalIndex > > > m_extraAdjacencyToSend
A map to correct the missing adjacency that can occur in rare occasions in 3D.
DegreeOfFreedomTree m_dofsTree
[owned] Pointer on the distributed degree of freedom tree
virtual void registerSpatialUnkown(Unknown *u)
Changes the location of unknown u to be adapted to the discrectization for example CepsLocationFlag::...
Base class for creating PDEs to solve.
CepsVector< Unknown * > getSpatialUnknowns() const
A vector of all unknowns of pb defined on cells or points.
const CepsVector< UnknownInteraction * > & getUnknownsInteractions() const
All the interactions between unknowns.
const CepsVector< Unknown * > & getUnknowns() const
List of unknowns of the pb.
CepsReal3D & getCoordinates()
Get three coordinates, read & write.
A degree of freedom for any kind of problem The dof can be associated to a geometrical element or not...
const CepsGlobalIndex & getGeomId() const
Get the Geom Identity for the dof (-1 means no geometric entity)
Unknown * getUnknown() const
Get the unknow defined at this dof.
const CepsVector< _Type > & getOwned() const
Get data owned by the processor, const.
CepsUInt getNumberOfHalo() const
Number of shared data from other process stored.
LocalGlobalMapping< _Type, _Hash > * getHaloMapping()
Mapping between global and local index of halo data.
void add(const _Type &x, const _Hash &hashValue, const CepsGlobalIndex &globalId, const CepsUInt &pId)
Add entry with global ID to the container, hash must be provided, pId selects owned or halo.
CepsUInt getNumberOfOwned() const
Number of owned data stored.
LocalGlobalMapping< _Type, _Hash > * getOwnedMapping()
Mapping between global and local index of owned data.
_Type & atGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId)
Access with given global ID.
CepsBool hasGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId) const
Check if container has data with given global ID.
const CepsVector< _Type > & getHalo() const
Get halo data owned by neighbor processor, const.
void destroyObjects()
Clears the contents, keeps structure.
void assemble(CepsReal t=0., CepsBool finalize=true) override
Main assembly call. Fills the linear system pointed by the class.
Abstract class for finite elements.
ReferenceFE * getReferenceElement() const
Pointer on Reference element.
Assembles the stiffness matrix for a given k-simplexes geometry.
void setKForUnknown(Unknown *u, CepsMathScalar k)
Register the diffusion coefficient (x,t,...) for given unknown.
Computes the integral of a quantity on the whole domain or subdomains, using a FE matrix.
CepsReal integrate(DHVecPtr u, DMatPtr mat=nullptr)
Returns the value of the integral by computing ones dot Mu.
Assembles the mass matrix for a given k-simplexes geometry.
A nodal point on a finite element. It is different from a geom node as it may have different properti...
FENode * getFENode(CepsGlobalIndex nID)
Link to a single node.
CepsReal dotProduct(DHVecPtr u, DHVecPtr v, CepsBool boundary=false, const CepsSet< CepsAttribute > &attrs={}, const CepsVector< Unknown * > &unknowns={}) final
returns where is the mass matrix
DMatPtr m_mass
Mass matrix, computed at instantiation.
void initializeRefElements()
Configure reference elements.
CepsHash3 getNodeHash(const FENode *n) const
Get the hash value from the coordinates of the node.
CepsVector< FEBase * > & getBoundaryFiniteElements()
Get vector containing all finite elements of the maximum valid dim.
ReferenceFE * getReferenceElementOfDim(CepsCellType type, CepsUInt dim) const
Access to reference elements.
CepsVector< DegreeOfFreedom * > getDofsOnElement(FEBase *elem)
ALl the dofs defined on an element.
CepsUInt getNumberOfOwnedFENodes() const
Local number of nodes belonging to this process, halo nodes NOT included.
void createNewNode(FEBase *el, CepsUInt indexDof, CepsBool isBoundary, Mesh *mesh)
Allocate new node that it is not a geometrical node.
void buildElements()
main routine of FiniteElements called in the constructor
~FiniteElements() override
Destructor.
FiniteElements()=delete
Default Constuctor deleted.
const CepsVector< FENode * > & getHaloFENodes()
vector of halo nodes
CepsVector< FEBase * > & getFiniteElements()
Get vector containing all finite elements of the maximum valid dim.
CepsBool isHaloFENode(CepsGlobalIndex globalID) const
Tells if node is halo by current CPU.
void setSpatialUnknownsDofsInteractions() override
Build dofs neighboring list for spatial unknowns. Different in FE (same element dofs) and VF,...
CepsIndex getDofSpatialId(const DegreeOfFreedom *dof) const override
Return the Geom Node Id for a node (not the FENode index returned by dof->getGeomId())
DistributedInfos< FEBase * > * m_bdrElems
Holds 1D-3D finite boundary elements.
DMatPtr m_stiff
Stiffness matrix, computed at instantiation.
const CepsVector< FENode * > & getOwnedFENodes()
vector of owned nodes
DistributedInfos< FENode *, CepsHash3 > * m_nodes
Holds nodes.
DistributedInfos< FEBase * > * m_volElems
Holds 1D-3D finite elements.
CepsVector< DegreeOfFreedom * > getDofsOnElementForUnknowns(FEBase *elem, const CepsVector< Unknown * > &us)
All dofs defined on an element, considering unknowns us.
void checkNeighborsBeforeAssign(FEBase *fElem, FEBase *nElem, CepsUInt nID, CepsBool boundary, CepsBool &foundSameDof)
Checks if a FE node already exists in a neighbor element.
void extractValuesForUnknown(const CepsUnknownIndex &uId, DVecPtr vec, CepsVector< CepsIndex > &indices, CepsVector< CepsReal > &values, CepsBool sendToMaster=false, CepsBool returnGeomIndices=false) override
Slicing method that extracts the data corresponding to a specific unknown.
CepsReal h1Norm(DHVecPtr v, CepsBool boundary=false, const CepsSet< CepsAttribute > &attrs={}, const CepsVector< Unknown * > &unknowns={}) override
sqrt(stiffproduct(v,v))
CepsReal stiffProduct(DHVecPtr u, DHVecPtr v, CepsBool boundary=false, const CepsSet< CepsAttribute > &attrs={}, const CepsVector< Unknown * > &unknowns={})
returns where is the stiffness matrix
void buildDofsTree() override
Builds the degrees of freedom tree from the PDE data, uses previously build elements and nodes....
CepsMap< CepsCellType, CepsArray4< ReferenceFE * > > m_refElems
Reference elements (point, segment, tri, tetra)
CepsUInt getNumberOfHaloFENodes() const
Global number of owned nodes.
void computeNeighbors()
Compute Neighbors.
CepsUInt m_order
Order used to build elements.
DMatPtr getStiffnessMatrix() const
Pointer on stiffness matrix.
DMatPtr getMassMatrix() const
Pointer on mass matrix.
CepsBool isOwnedFENode(CepsGlobalIndex globalID) const
Tells if node is owned by current CPU.
Abstract class for geometrical cell. On top of index and attributes managament, the cell has informat...
Base class for nodes used in meshes.
Mesh * getMeshOfDim(CepsUInt dim) const
Return the mesh of requested dimension.
CepsBool hasMeshOfDim(CepsUInt dim) const
true if geometry has data of requested dimension
A map destined for things that have (or could have) a global index and must be distributed amongst CP...
void append(const _Type &x, const _Hash &hashValue)
Emplace an element in the map.
Geometrical information of 1,2 or 3D distributed cells.
CepsUInt getLocalNbCells() const
Number of non-boundary cells stored on this process.
const CepsVector< GeomCell * > & getCells()
CepsVector of cells stored on this process.
CepsUInt getLocalNbBoundaryCells() const
Number of boundary cells stored on this process.
const CepsVector< GeomCell * > & getBoundaryCells()
CepsVector of boundary cells stored on this process.
Base class for reference finite elements.
CepsReal3D getTransformedBasisVertex(CepsUInt i, GeomCell *cell) const
Get vertex 'i' used to create basis functions and transform it on GeomCell.
CepsInt getBasisVertexGeomCellIndex(CepsUInt i) const
Returns the index in geom cell of a basis vertex. -1 if basis vertex does not match a geom vertex.
CepsUInt getNumberOfBasisVertices() const
Get number of vertices used to create basis functions.
GeomNode * getNodeOfOwnerForBasisVertex(CepsUInt i, GeomCell *cell) const
Returns a node that determines ownership of a basis vertex, especially for those that do not match a ...
A class used to defined an unknown of a PDE problem The unknown can be defined on a specific region,...
const CepsString & getName() const
Get the name of the unknown.
CepsBool isSpatial() const
Tells if unknown is defined on geometrical elements.
void setAttributes(const CepsVector< CepsAttribute > &attributes)
Sets the attributes of the entity.
CepsSet< CepsAttribute > & getAttributes()
Returns the attributes of the entity.
void setOnBoundary(CepsBool value=true)
Sets the entity as being on boundary or not.
void addCell(CellType *&name)
Adds a cell to the list.
_GeomObject * getProperties() const
Get the properties (in fact it's just the geom object)
_GeomObject * getGeomObject() const
Get the geom object.
const CepsGlobalIndex & getGlobalIndex() const
Get the index
CepsVector< NodeType * > & getNodes()
Reference to the node pointers array.
void setNodeAt(const CepsUInt &i, NodeType *neigh)
Set the i-th node. If i>nNodes, nullptrs fill the vector.
CepsVector< NodeType * > getValidNodes() const
Get pointers on all valid nodes.
NodeType * getNodeAt(const CepsUInt &i)
Pointer to the i-th node.
const CepsProcId & getOwner() const
Get owner (processus id) of this entity.
void setOwner(const CepsProcId &pid)
Set shared between several processes ?
constexpr CepsHash get(_Type const &i)
get a hash from a single value
CepsHash3 getHash3(const CepsReal3D &xyz)
Get a triple hash from real coordinates.
void insert(CepsVector< _Type, _Alloc > &vec, const _Type &value)
Conditional insertion of several elements.
CepsBool contains(const CepsVector< _Type, _Alloc > &vec, const _Type &item)
Tells if vectors contains a given item.
CepsUInt getRank()
Returns current processor rank.
MPI_Comm getCommunicator()
Get the communicator.
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
CepsInt argVector(const CepsVector< _Type, _Alloc > &vec, const _Type &value)
Get position of element in vector, -1 if not found.
CepsUInt getGridSize()
Returns the number of process on the computing grid.
CepsBool isNullPtr(_Type *ptr)
Tells if passed pointer is null.
void barrier()
Explicit barrier: wait for all processors before continuing.
CepsBool isProfiling()
Check if we are currently profiling on the master proc (always false on slave procs).
void destroyObject(_Type &)
Destroy[delete] any type.
A triple hash to be used for coordinates (multiplied *10^12 then truncated)