/[escript]/trunk/finley/src/Mesh_merge.cpp
ViewVC logotype

Contents of /trunk/finley/src/Mesh_merge.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6939 - (show annotations)
Mon Jan 20 03:37:18 2020 UTC (4 months, 2 weeks ago) by uqaeller
File size: 7863 byte(s)
Updated the copyright header.


1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2020 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14 * Development from 2019 by School of Earth and Environmental Sciences
15 **
16 *****************************************************************************/
17
18 #include "FinleyDomain.h"
19 #include "Util.h"
20
21 using escript::ValueError;
22
23 namespace finley {
24
25 FinleyDomain* FinleyDomain::merge(const std::vector<const FinleyDomain*>& msh)
26 {
27 if (msh.empty()) {
28 throw ValueError("merge: Empty mesh list");
29 }
30 for (int i = 0; i < msh.size(); i++) {
31 if (msh[i]->getMPISize() > 1) {
32 throw escript::NotImplementedError("merge: more than 1 processor is not supported yet.");
33 }
34 }
35
36 dim_t numNodes = 0;
37 dim_t numElements = 0;
38 dim_t numFaceElements = 0;
39 dim_t numContactElements = 0;
40 dim_t numPoints = 0;
41 index_t maxNodeID = 0;
42 index_t maxDOF = 0;
43 index_t maxElementID = 0;
44 index_t maxElementID2 = 0;
45 ElementTypeId elementTypeId = NoRef;
46 ElementTypeId faceElementTypeId = NoRef;
47 ElementTypeId pointTypeId = NoRef;
48 ElementTypeId contactTypeId = NoRef;
49
50 int order = msh[0]->integrationOrder;
51 int reducedOrder = msh[0]->reducedIntegrationOrder;
52 const int numDim = msh[0]->getDim();
53 escript::JMPI mpiInfo = msh[0]->getMPI();
54 std::stringstream newName;
55
56 for (int i=0; i < msh.size(); i++) {
57 // check if all meshes have the same type and dimensions
58 order = std::max(order, msh[i]->integrationOrder);
59 reducedOrder = std::min(reducedOrder, msh[i]->reducedIntegrationOrder);
60 numNodes += msh[i]->getNodes()->getNumNodes();
61 if (mpiInfo->comm != msh[i]->getMPIComm()) {
62 throw ValueError("merge: MPI communicators of meshes don't match.");
63 }
64 if (numDim != msh[i]->getDim()) {
65 throw ValueError("merge: Spatial dimensions of meshes don't match.");
66 }
67
68 if (msh[i]->getElements()) {
69 numElements += msh[i]->getElements()->numElements;
70 if (elementTypeId == NoRef) {
71 elementTypeId = msh[i]->getElements()->referenceElementSet->referenceElement->Type->TypeId;
72 } else {
73 if (elementTypeId != msh[i]->getElements()->referenceElementSet->referenceElement->Type->TypeId) {
74 throw ValueError("merge: element types of meshes don't match.");
75 }
76 }
77 }
78
79 if (msh[i]->getFaceElements()) {
80 numFaceElements += msh[i]->getFaceElements()->numElements;
81 if (faceElementTypeId == NoRef) {
82 faceElementTypeId = msh[i]->getFaceElements()->referenceElementSet->referenceElement->Type->TypeId;
83 } else {
84 if (faceElementTypeId != msh[i]->getFaceElements()->referenceElementSet->referenceElement->Type->TypeId) {
85 throw ValueError("merge: face element types of meshes don't match.");
86 }
87 }
88 }
89
90 if (msh[i]->getContactElements()) {
91 numContactElements += msh[i]->getContactElements()->numElements;
92 if (contactTypeId == NoRef) {
93 contactTypeId = msh[i]->getContactElements()->referenceElementSet->referenceElement->Type->TypeId;
94 } else {
95 if (contactTypeId != msh[i]->getContactElements()->referenceElementSet->referenceElement->Type->TypeId) {
96 throw ValueError("merge: contact element types of meshes don't match.");
97 }
98 }
99 }
100
101 if (msh[i]->getPoints()) {
102 numPoints += msh[i]->getPoints()->numElements;
103 if (pointTypeId == NoRef) {
104 pointTypeId = msh[i]->getPoints()->referenceElementSet->referenceElement->Type->TypeId;
105 } else {
106 if (pointTypeId != msh[i]->getPoints()->referenceElementSet->referenceElement->Type->TypeId ) {
107 throw ValueError("merge: point element types of meshes don't match.");
108 }
109 }
110 }
111
112 if (i > 0)
113 newName << "+";
114 newName << msh[i]->m_name;
115 }
116
117 // allocate
118 FinleyDomain* out = new FinleyDomain(newName.str(), numDim, mpiInfo);
119 const_ReferenceElementSet_ptr refElements(new ReferenceElementSet(elementTypeId, order, reducedOrder));
120 const_ReferenceElementSet_ptr refFaceElements(new ReferenceElementSet(faceElementTypeId, order, reducedOrder));
121 const_ReferenceElementSet_ptr refContactElements(new ReferenceElementSet(contactTypeId, order, reducedOrder));
122 const_ReferenceElementSet_ptr refPoints(new ReferenceElementSet(pointTypeId, order, reducedOrder));
123
124 NodeFile* nodes = out->getNodes();
125 out->setElements(new ElementFile(refElements, mpiInfo));
126 out->setFaceElements(new ElementFile(refFaceElements, mpiInfo));
127 out->setPoints(new ElementFile(refPoints, mpiInfo));
128 out->setContactElements(new ElementFile(refContactElements, mpiInfo));
129
130 // allocate new tables
131 nodes->allocTable(numNodes);
132 out->getElements()->allocTable(numElements);
133 out->getFaceElements()->allocTable(numFaceElements);
134 out->getContactElements()->allocTable(numContactElements);
135 out->getPoints()->allocTable(numPoints);
136
137 // copy tables
138 numNodes = 0;
139 numElements = 0;
140 numFaceElements = 0;
141 numContactElements = 0;
142 numPoints = 0;
143
144 for (int i = 0; i < msh.size(); i++) {
145 nodes->copyTable(numNodes, maxNodeID, maxDOF, msh[i]->getNodes());
146 out->getElements()->copyTable(numElements, numNodes, maxElementID, msh[i]->getElements());
147 out->getFaceElements()->copyTable(numFaceElements, numNodes, maxElementID, msh[i]->getFaceElements());
148 out->getContactElements()->copyTable(numContactElements, numNodes, maxElementID, msh[i]->getContactElements());
149 out->getPoints()->copyTable(numPoints, numNodes, maxElementID, msh[i]->getPoints());
150
151 numNodes += msh[i]->getNodes()->getNumNodes();
152 numElements += msh[i]->getElements()->numElements;
153 numFaceElements += msh[i]->getFaceElements()->numElements;
154 numContactElements += msh[i]->getContactElements()->numElements;
155 numPoints += msh[i]->getPoints()->numElements;
156
157 if (msh[i]->getNodes()->getNumNodes() > 0)
158 maxNodeID += util::getMaxInt(1, msh[i]->getNodes()->getNumNodes(), msh[i]->getNodes()->Id) + 1;
159 maxDOF += util::getMaxInt(1, msh[i]->getNodes()->getNumNodes(), msh[i]->getNodes()->globalDegreesOfFreedom) + 1;
160 maxElementID2 = 0;
161 if (msh[i]->getElements()->numElements > 0)
162 maxElementID2 = std::max(maxElementID2, util::getMaxInt(1, msh[i]->getElements()->numElements, msh[i]->getElements()->Id));
163 if (msh[i]->getFaceElements()->numElements > 0)
164 maxElementID2 = std::max(maxElementID2, util::getMaxInt(1, msh[i]->getFaceElements()->numElements, msh[i]->getFaceElements()->Id));
165 if (msh[i]->getContactElements()->numElements > 0)
166 maxElementID2 = std::max(maxElementID2, util::getMaxInt(1, msh[i]->getContactElements()->numElements, msh[i]->getContactElements()->Id));
167 if (msh[i]->getPoints()->numElements > 0)
168 maxElementID2 = std::max(maxElementID2, util::getMaxInt(1, msh[i]->getPoints()->numElements, msh[i]->getPoints()->Id));
169 maxElementID += maxElementID2 + 1;
170 }
171
172 // all done
173 out->prepare(false);
174 return out;
175 }
176
177 } // namespace finley
178

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/4.0fordebian/finley/src/Mesh_merge.cpp:5567-5588 /branches/lapack2681/finley/src/Mesh_merge.cpp:2682-2741 /branches/pasowrap/finley/src/Mesh_merge.cpp:3661-3674 /branches/py3_attempt2/finley/src/Mesh_merge.cpp:3871-3891 /branches/restext/finley/src/Mesh_merge.cpp:2610-2624 /branches/ripleygmg_from_3668/finley/src/Mesh_merge.cpp:3669-3791 /branches/stage3.0/finley/src/Mesh_merge.cpp:2569-2590 /branches/symbolic_from_3470/finley/src/Mesh_merge.cpp:3471-3974 /branches/trilinos_from_5897/finley/src/Mesh_merge.cpp:5898-6118 /release/3.0/finley/src/Mesh_merge.cpp:2591-2601 /release/4.0/finley/src/Mesh_merge.cpp:5380-5406 /trunk/finley/src/Mesh_merge.cpp:4257-4344

  ViewVC Help
Powered by ViewVC 1.1.26