src/broadcastmeshbuilder.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           broadcastmeshbuilder.cpp  -  description
00003                              -------------------
00004     begin                : Mon Dec 15 2003
00005     copyright            : (C) 2003 by Roman Geus
00006     email                : roman.geus@psi.ch
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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     // broadcast nof_node
00040     _comm->Broadcast(&nof_node, 1, 0);
00041     _nof_node = nof_node;
00042     // call builder
00043     _builder->init_coord(_nof_node);
00044     // allocate buffer
00045     _coord = new double[3*nof_node];
00046 }
00047 
00048 void BroadcastMeshBuilder::set_coord(int i, double x, double y, double z) {
00049     // this function will only be called on the master processor
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     // broadcast coord data
00057     _comm->Broadcast(_coord, 3*_nof_node, 0);
00058     // call builder
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     // delete _coord buffer
00064     delete[] _coord;
00065 }
00066 
00067 void BroadcastMeshBuilder::init_tet(int nof_tet) {
00068     // broadcast nof_tet
00069     _comm->Broadcast(&nof_tet, 1, 0);
00070     _nof_tet = nof_tet;
00071     // allocate _tet_node buffer
00072     _tet_node = new int[4*_nof_tet];
00073     _material = new int[_nof_tet];
00074     // call builder
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     // this function will only be called on the master processor
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     // broadcast tet_node data
00089     _comm->Broadcast(_tet_node, 4*_nof_tet, 0);
00090     // call builder
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     // delete _tet_node buffer
00097     delete[] _tet_node;
00098 }
00099 
00100 void BroadcastMeshBuilder::init_bc(int nof_bc_face) {
00101     // broadcast nof_bc_face
00102     _comm->Broadcast(&nof_bc_face, 1, 0);
00103     _nof_bc_face = nof_bc_face;
00104     // allocate _bc_face buffer
00105     _bc_face = new int[4*_nof_bc_face];
00106     // call builder
00107     _builder->init_bc(_nof_bc_face);
00108 }
00109 
00110 void BroadcastMeshBuilder::set_bc(int id0, int id1, int id2, int bc_id) {
00111     // this function will only be called on the master processor
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     // broadcast _bc_face data
00120     _comm->Broadcast(_bc_face, 4*_nof_bc_face, 0);
00121     // call builder
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     // delete _bc_face buffer
00129     delete[] _bc_face;
00130     // broadcast nof_sym
00131     _comm->Broadcast(&nof_sym, 1, 0);
00132     _nof_sym = nof_sym;
00133     // call builder
00134     _builder->finalize_bc(_nof_sym);
00135 }

Generated on Fri Oct 26 13:35:11 2007 for FEMAXX (Finite Element Maxwell Eigensolver) by  doxygen 1.4.7