Memosa-FVM  0.2
MPMCoupling.cpp
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifdef FVM_PARALLEL
6 #include <mpi.h>
7 #include <iostream>
8 #include <cassert>
9 #include "MPMCoupling.h"
10 #include "CRConnectivity.h"
11 
12 
13 using namespace std;
14 
15 MPMCoupling::MPMCoupling(MPM& mpm, Field& coordinate, Field& velocity, StorageSite& cell_site )
16 :_mpm(mpm), _coordinate(coordinate), _velocity(velocity), _cellSite(cell_site), MPM_PORTNAME_TAG(7777),
17  _dtTAG(1122), _timeTAG(2122), _totParticlesTAG(3122), _isContinueTAG(4122), _particlesPosTAG(5122), _particlesVelTAG(6122)
18 {
19  _procID = MPI::COMM_WORLD.Get_rank();
20  PARENT = MPI::Comm::Get_parent();
21  char port_name[ MPI::MAX_PORT_NAME];
22  assert( PARENT != MPI::COMM_NULL );
23 
24  // get portName from Parent ( which is sent to parent by MPM)
25  if ( _procID == 0 )
26  PARENT.Recv( port_name, MPI::MAX_PORT_NAME, MPI::CHAR, 0, MPM_PORTNAME_TAG, _portNameStatus);
27 
28  FVM_COMM_MPM = MPI::COMM_WORLD.Connect( port_name, MPI::INFO_NULL, 0);
29 
30  cout << " max-pot -name = " << MPI::MAX_PORT_NAME << " port_name = " << port_name << endl;
31  _pType = shared_ptr< Array<int> > ( new Array<int>(1) );
32 
33 }
34 
35 
36 MPMCoupling::~MPMCoupling()
37 {
38  FVM_COMM_MPM.Barrier();
39  FVM_COMM_MPM.Disconnect();
40  PARENT.Barrier();
41  PARENT.Disconnect();
42 
43 }
44 
45 
46 
47 
48 void
49 MPMCoupling::updateMPM()
50 {
51 
52 }
53 
54 
55 void
56 MPMCoupling::acceptMPM( )
57 {
58  cout << " isContine = " << _isContinueMPM << endl;
59  FVM_COMM_MPM.Recv( &_isContinueMPM, 1, MPI::BOOL, 0, _isContinueTAG );
60  cout << " isContine = " << _isContinueMPM << endl;
61  if ( _isContinueMPM ) {
62  FVM_COMM_MPM.Recv( &_dtMPM, 1, MPI::DOUBLE, 0, _dtTAG );
63  FVM_COMM_MPM.Recv( &_timeMPM , 1, MPI::DOUBLE, 0, _timeTAG );
64  FVM_COMM_MPM.Recv( &_totParticlesMPM, 1, MPI::INT, 0, _totParticlesTAG );
65  _px = _coordinate[_cellSite].newSizedClone( _totParticlesMPM );
66  _pv = _coordinate[_cellSite].newSizedClone( _totParticlesMPM );
67  _pType->resize( _totParticlesMPM );
68  *_pType = 1;
69  FVM_COMM_MPM.Recv( _px->getData(), _px->getDataSize(), MPI::BYTE, 0, _particlesPosTAG );
70  FVM_COMM_MPM.Recv( _pv->getData(), _pv->getDataSize(), MPI::BYTE, 0, _particlesVelTAG );
71  const StorageSite& particleSite = _mpm.getParticles( _totParticlesMPM );
72  _coordinate[particleSite] = *_px;
73  _velocity [particleSite] = *_pv;
74  _mpm.setCoordinates( _px );
75  _mpm.setVelocities ( _pv );
76  _mpm.setTypes ( _pType );
77 
78  }
79 
80 
81 
82 }
83 #endif
Definition: Field.h:14