00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <new>
00019 #include "broadcastmeshbuilder.h"
00020
00021 BroadcastMeshBuilder::BroadcastMeshBuilder(const Epetra_Comm* comm, MeshBuilder* builder)
00022 : _builder(builder), _comm(comm), _bc_face_counter(0)
00023 {
00024 }
00025
00026 BroadcastMeshBuilder::~BroadcastMeshBuilder() {
00027 }
00028
00029 void BroadcastMeshBuilder::receiver() {
00030 init_coord(0);
00031 finalize_coord();
00032 init_tet(0);
00033 finalize_tet();
00034 init_bc(0);
00035 finalize_bc(0);
00036 }
00037
00038 void BroadcastMeshBuilder::init_coord(int nof_node) {
00039
00040 _comm->Broadcast(&nof_node, 1, 0);
00041 _nof_node = nof_node;
00042
00043 _builder->init_coord(_nof_node);
00044
00045 _coord = new double[3*nof_node];
00046 }
00047
00048 void BroadcastMeshBuilder::set_coord(int i, double x, double y, double z) {
00049
00050 _coord[3*i + 0] = x;
00051 _coord[3*i + 1] = y;
00052 _coord[3*i + 2] = z;
00053 }
00054
00055 void BroadcastMeshBuilder::finalize_coord() {
00056
00057 _comm->Broadcast(_coord, 3*_nof_node, 0);
00058
00059 for (int i = 0; i < _nof_node; i ++) {
00060 _builder->set_coord(i, _coord[3*i + 0], _coord[3*i + 1], _coord[3*i + 2]);
00061 }
00062 _builder->finalize_coord();
00063
00064 delete[] _coord;
00065 }
00066
00067 void BroadcastMeshBuilder::init_tet(int nof_tet) {
00068
00069 _comm->Broadcast(&nof_tet, 1, 0);
00070 _nof_tet = nof_tet;
00071
00072 _tet_node = new int[4*_nof_tet];
00073 _material = new int[_nof_tet];
00074
00075 _builder->init_tet(_nof_tet);
00076 }
00077
00078 void BroadcastMeshBuilder::set_tet(int t, int id0, int id1, int id2, int id3, int material) {
00079
00080 _tet_node[4*t + 0] = id0;
00081 _tet_node[4*t + 1] = id1;
00082 _tet_node[4*t + 2] = id2;
00083 _tet_node[4*t + 3] = id3;
00084 _material[t] = material;
00085 }
00086
00087 void BroadcastMeshBuilder::finalize_tet() {
00088
00089 _comm->Broadcast(_tet_node, 4*_nof_tet, 0);
00090
00091 for (int t = 0; t < _nof_tet; t ++) {
00092 _builder->set_tet(t, _tet_node[4*t + 0], _tet_node[4*t + 1],
00093 _tet_node[4*t + 2], _tet_node[4*t + 3], _material[t]);
00094 }
00095 _builder->finalize_tet();
00096
00097 delete[] _tet_node;
00098 }
00099
00100 void BroadcastMeshBuilder::init_bc(int nof_bc_face) {
00101
00102 _comm->Broadcast(&nof_bc_face, 1, 0);
00103 _nof_bc_face = nof_bc_face;
00104
00105 _bc_face = new int[4*_nof_bc_face];
00106
00107 _builder->init_bc(_nof_bc_face);
00108 }
00109
00110 void BroadcastMeshBuilder::set_bc(int id0, int id1, int id2, int bc_id) {
00111
00112 _bc_face[_bc_face_counter ++] = id0;
00113 _bc_face[_bc_face_counter ++] = id1;
00114 _bc_face[_bc_face_counter ++] = id2;
00115 _bc_face[_bc_face_counter ++] = bc_id;
00116 }
00117
00118 void BroadcastMeshBuilder::finalize_bc(int nof_sym) {
00119
00120 _comm->Broadcast(_bc_face, 4*_nof_bc_face, 0);
00121
00122 int k = 0;
00123 for (int t = 0; t < _nof_bc_face; t ++) {
00124 _builder->set_bc(_bc_face[k], _bc_face[k+1],
00125 _bc_face[k+2], _bc_face[k+3]);
00126 k += 4;
00127 }
00128
00129 delete[] _bc_face;
00130
00131 _comm->Broadcast(&nof_sym, 1, 0);
00132 _nof_sym = nof_sym;
00133
00134 _builder->finalize_bc(_nof_sym);
00135 }