Debian Codegraph @

packages/nox/test/epetra/MultiPhysics/Xfer_Operator.C

raw
1 // @HEADER
2 // *****************************************************************************
3 // NOX: An Object-Oriented Nonlinear Solver Package
4 //
5 // Copyright 2002 NTESS and the NOX contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #include "Xfer_Operator.H"
11 #include "GenericEpetraProblem.H"
12 #include "Epetra_Vector.h"
13
14 #undef DEBUG_TRANSFER_OPERATOR
15
16 // Constructor
17 XferOp::XferOp(GenericEpetraProblem& probA, const GenericEpetraProblem& probB)
18 {
19 // Establish mappings from problem meshes. This is based solely on each
20 // problem's mesh and involves a simple linear interpolation (possibly
21 // extrapolation).
22 Epetra_Vector &meshA = probA.getMesh();
23 Epetra_Vector &meshB = const_cast<GenericEpetraProblem&>(probB).getMesh();
24
25 // For now, this is designed for serial execution since some problemA
26 // nodes will lie within off-processor problemB elements in general.
27
28 // The following assumes that 1D elements exist such that an element is
29 // defined by a left and right end-node which are sequentially numbered.
30 double tol(1.e-8);
31 for( int i = 0; i < meshA.MyLength(); i++)
32 {
33 double xlocA = meshA[i];
34 for( int j = 0; j < (meshB.MyLength()-1); ++j )
35 {
36 double xlocB_left = meshB[j] ;
37 double xlocB_right = meshB[j+1] ;
38 // First check for what we choose to define as a direct match (within tol)
39 if( fabs(xlocB_left - xlocA) <= tol )
40 {
41 dependentNodes.insert( multimap<int,int>::value_type(i, j) );
42 dependentWeights.insert( multimap<int,double>::value_type(i, double(1.0)) );
43 break;
44 }
45 // Next determine which two nodes of meshB xlocA lies between
46 else if( (xlocA > xlocB_left) && (xlocA < xlocB_right) )
47 {
48 dependentNodes.insert( multimap<int,int>::value_type(i, j) );
49 dependentNodes.insert( multimap<int,int>::value_type(i, j+1) );
50 double wt_right = (xlocA - xlocB_left)/(xlocB_right - xlocB_left);
51 double wt_left = 1.0 - wt_right;
52 dependentWeights.insert( multimap<int,double>::value_type(i, wt_left) );
53 dependentWeights.insert( multimap<int,double>::value_type(i, wt_right) );
54 break;
55 }
56 // Finally check for a direct match of the right node
57 else if( fabs(xlocB_right - xlocA) <= tol )
58 {
59 dependentNodes.insert( multimap<int,int>::value_type(i, j+1) );
60 dependentWeights.insert( multimap<int,double>::value_type(i, double(1.0)) );
61 break;
62 }
63 }
64 if( !dependentNodes.count(i) )
65 std::cout << "WARNING: Node " << i << " at position " << xlocA
66 << " not interpolated to transfer mesh !!" << std::endl;
67 }
68
69 #ifdef DEBUG_TRANSFER_OPERATOR
70 for( int i = 0; i < meshA.MyLength(); i++)
71 {
72 std::cout << "meshA node " << i << " at loc --> " << meshA[i]
73 << " needs node(s) from meshB: ";
74 pair< multimap<int, int>::iterator,
75 multimap<int, int>::iterator > rangeN
76 = dependentNodes.equal_range(i);
77 pair< multimap<int, double>::iterator,
78 multimap<int, double>::iterator > rangeW
79 = dependentWeights.equal_range(i);
80 multimap<int, int>::iterator iterN;
81 multimap<int, double>::iterator iterW;
82 int j;
83 for( j = 0, iterN = rangeN.first, iterW = rangeW.first;
84 iterN != rangeN.second; j++, iterN++, iterW++)
85 std::cout << "(" << (*iterN).second << ", " << (*iterW).second << ") ";
86 std::cout << std::endl;
87 }
88 #endif
89
90 }
91
92 //-----------------------------------------------------------------------------
93
94 // Destructor
95 XferOp::~XferOp()
96 {
97 }
98
99 //-----------------------------------------------------------------------------
100
101 void
102 XferOp::transferField(Epetra_Vector& vecTo, Epetra_Vector& vecFrom)
103 {
104 // Do the transfer using Epetra_Vectors
105 for( int i = 0; i < vecTo.MyLength(); i++)
106 {
107 vecTo[i] = 0.0;
108 pair< multimap<int, int>::iterator,
109 multimap<int, int>::iterator > rangeN
110 = dependentNodes.equal_range(i);
111 pair< multimap<int, double>::iterator,
112 multimap<int, double>::iterator > rangeW
113 = dependentWeights.equal_range(i);
114 multimap<int, int>::iterator iterN;
115 multimap<int, double>::iterator iterW;
116 int j;
117 for( j = 0, iterN = rangeN.first, iterW = rangeW.first;
118 iterN != rangeN.second; j++, iterN++, iterW++)
119 vecTo[i] += (*iterW).second * vecFrom[(*iterN).second];
120 }
121 }
122
123 //-----------------------------------------------------------------------------