1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkYoungsMaterialInterface.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .SECTION Thanks
// This file is part of the generalized Youngs material interface reconstruction algorithm contributed by
// CEA/DIF - Commissariat a l'Energie Atomique, Centre DAM Ile-De-France <br>
// BP12, F-91297 Arpajon, France. <br>
// Implementation by Thierry Carrard and Philippe Pebay
#include "vtkPYoungsMaterialInterface.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiProcessController.h"
vtkStandardNewMacro(vtkPYoungsMaterialInterface);
vtkCxxSetObjectMacro(vtkPYoungsMaterialInterface, Controller, vtkMultiProcessController);
//-----------------------------------------------------------------------------
vtkPYoungsMaterialInterface::vtkPYoungsMaterialInterface()
{
this->Controller = 0 ;
this->SetController( vtkMultiProcessController::GetGlobalController() );
vtkDebugMacro(<<"vtkPYoungsMaterialInterface::vtkPYoungsMaterialInterface() ok\n");
}
//-----------------------------------------------------------------------------
vtkPYoungsMaterialInterface::~vtkPYoungsMaterialInterface()
{
this->SetController( 0 );
}
//-----------------------------------------------------------------------------
void vtkPYoungsMaterialInterface::PrintSelf( ostream& os, vtkIndent indent )
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Controller: " << this->Controller << endl;
}
//-----------------------------------------------------------------------------
void vtkPYoungsMaterialInterface::Aggregate( int nmat, int* inputsPerMaterial )
{
vtkIdType nprocs = this->Controller->GetNumberOfProcesses();
if ( nprocs < 2 )
{
return;
}
// Now get ready for parallel calculations
vtkCommunicator* com = this->Controller->GetCommunicator();
if ( ! com )
{
vtkErrorMacro(<<"No parallel communicator.");
}
// Gather inputs per material from all processes
vtkIdType myid = this->Controller->GetLocalProcessId();
int* tmp = new int[nmat * nprocs];
com->AllGather( inputsPerMaterial, tmp, nmat );
// Scan sum : done by all processes, not optimal but easy
for ( vtkIdType m = 0; m < nmat; ++ m )
{
for( vtkIdType p = 1; p < nprocs; ++ p )
{
vtkIdType pnmat = p * nmat + m;
tmp[pnmat] += tmp[pnmat - nmat];
}
}
vtkIdType offset = (nprocs - 1) * nmat;
this->NumberOfDomains = 0;
for ( int m = 0; m < nmat; ++ m )
{
// Sum all counts from all processes
int inputsPerMaterialSum = tmp[offset + m];
if( inputsPerMaterialSum > this->NumberOfDomains )
{
this->NumberOfDomains = inputsPerMaterialSum;
}
// Calculate partial sum of all preceding processors
inputsPerMaterial[m] = ( myid ? tmp[( myid - 1) * nmat + m] : 0 );
}
delete[] tmp;
}
|