@@ -90,29 +90,31 @@ void BuildBEMatrixBase::getOmega(
9090 Vector Ny ( y1.length () , y2.length () , y3.length () );
9191
9292 Vector Nyij ( y21.length () , y32.length () , y13.length () );
93-
94-
93+
9594 Vector gamma ( 0 , 0 , 0 );
9695 double NomGamma , DenomGamma;
9796
9897 NomGamma = Ny[0 ]*Nyij[0 ] + Dot (y1,y21);
9998 DenomGamma = Ny[1 ]*Nyij[0 ] + Dot (y2,y21);
100- if (fabs (DenomGamma-NomGamma) > epsilon && (DenomGamma != 0 ) && NomGamma != 0 )
99+ if (fabs (DenomGamma-NomGamma) > epsilon && (DenomGamma != 0 ) && NomGamma != 0 ){
101100 gamma[0 ] = -1 /Nyij[0 ] * log (NomGamma/DenomGamma);
102-
101+ }
103102 NomGamma = Ny[1 ]*Nyij[1 ] + Dot (y2,y32);
104103 DenomGamma = Ny[2 ]*Nyij[1 ] + Dot (y3,y32);
105- if (fabs (DenomGamma-NomGamma) > epsilon && (DenomGamma != 0 ) && NomGamma != 0 )
104+ if (fabs (DenomGamma-NomGamma) > epsilon && (DenomGamma != 0 ) && NomGamma != 0 ){
106105 gamma[1 ] = -1 /Nyij[1 ] * log (NomGamma/DenomGamma);
107-
106+ }
108107 NomGamma = Ny[2 ]*Nyij[2 ] + Dot (y3,y13);
109108 DenomGamma = Ny[0 ]*Nyij[2 ] + Dot (y1,y13);
110- if (fabs (DenomGamma-NomGamma) > epsilon && (DenomGamma != 0 ) && NomGamma != 0 )
109+ if (fabs (DenomGamma-NomGamma) > epsilon && (DenomGamma != 0 ) && NomGamma != 0 ){
111110 gamma[2 ] = -1 /Nyij[2 ] * log (NomGamma/DenomGamma);
111+ }
112112
113113 double d = Dot ( y1, Cross (y2, y3) );
114114
115115 Vector OmegaVec = (gamma[2 ]-gamma[0 ])*y1 + (gamma[0 ]-gamma[1 ])*y2 + (gamma[1 ]-gamma[2 ])*y3;
116+
117+
116118
117119 /*
118120 In order to avoid problems with the arctan used in de Muncks paper
@@ -127,6 +129,7 @@ void BuildBEMatrixBase::getOmega(
127129
128130 double Nn=0 , Omega=0 ;
129131 Nn = Ny[0 ]*Ny[1 ]*Ny[2 ] + Ny[0 ]*Dot (y2,y3) + Ny[2 ]*Dot (y1,y2) + Ny[1 ]*Dot (y3,y1);
132+
130133 if (Nn > 0 ) Omega = 2 * atan ( d / Nn );
131134 if (Nn < 0 ) Omega = 2 * atan ( d / Nn ) + 2 *M_PI ;
132135 if (Nn == 0 )
@@ -146,6 +149,7 @@ void BuildBEMatrixBase::getOmega(
146149 coef (0 ,0 ) = (1 /A2) * ( Zn1*Omega + d * Dot (y32, OmegaVec) );
147150 coef (0 ,1 ) = (1 /A2) * ( Zn2*Omega + d * Dot (y13, OmegaVec) );
148151 coef (0 ,2 ) = (1 /A2) * ( Zn3*Omega + d * Dot (y21, OmegaVec) );
152+
149153}
150154
151155void BuildBEMatrixBase::get_cruse_weights (
@@ -737,6 +741,8 @@ template <class MatrixType>
737741void BuildBEMatrixBaseCompute::make_auto_P_compute (VMesh* hsurf, MatrixType& auto_P, double in_cond, double out_cond, double op_cond)
738742{
739743 auto nnodes = auto_P.rows ();
744+
745+
740746
741747 // const double mult = 1/(2*M_PI)*((out_cond - in_cond)/op_cond); // op_cond=out_cond for all the surfaces but the outermost surface which in op_cond=in_cond
742748 const double mult = 1 /(4 *M_PI)*(out_cond - in_cond);
@@ -756,14 +762,15 @@ void BuildBEMatrixBaseCompute::make_auto_P_compute(VMesh* hsurf, MatrixType& aut
756762 Point pp = hsurf->get_point (ppi);
757763
758764 hsurf->begin (fi); hsurf->end (fie);
765+
759766 for (; fi != fie; ++fi) { // ! find contributions from every triangle
760767
761768 hsurf->get_nodes (nodes, *fi);
762769 if (ppi!=nodes[0 ] && ppi!=nodes[1 ] && ppi!=nodes[2 ]){
763770 Vector v1 = hsurf->get_point (nodes[0 ]) - pp;
764771 Vector v2 = hsurf->get_point (nodes[1 ]) - pp;
765772 Vector v3 = hsurf->get_point (nodes[2 ]) - pp;
766-
773+
767774 getOmega (v1, v2, v3, coef);
768775
769776 for (i=0 ; i<3 ; ++i)
@@ -1099,7 +1106,7 @@ MatrixHandle SurfaceToSurface::compute(const bemfield_vector& fields) const
10991106 else
11001107 {
11011108 auto block = EE.blockRef (i, j);
1102- make_cross_P_compute (fields[i].field_ ->vmesh (), fields[j].field_ ->vmesh (), block, fields[i ].insideconductivity , fields[i ].outsideconductivity , op_cond);
1109+ make_cross_P_compute (fields[i].field_ ->vmesh (), fields[j].field_ ->vmesh (), block, fields[j ].insideconductivity , fields[j ].outsideconductivity , op_cond);
11031110 }
11041111 }
11051112 }
@@ -1130,27 +1137,24 @@ MatrixHandle SurfaceToSurface::compute(const bemfield_vector& fields) const
11301137 if (i == sourcefieldindices[j])
11311138 {
11321139 auto block = EJ.blockRef (i,j);
1133- // std::cout << "EJ block auto " << i << "," << j << " is size " << block.rows() << " x " << block.cols() /*<< " starting at " << blockStartsEE[i] << "," << blockStartsEJ[j]*/ << std::endl;
1134-
11351140 make_auto_G_compute (fields[i].field_ ->vmesh (), block, fields[i].insideconductivity , fields[i].outsideconductivity , op_cond, triangleareas);
11361141 }
11371142 else
11381143 {
11391144 auto block = EJ.blockRef (i,j);
1140- // std::cout << "EJ block cross " << i << "," << j << " is size " << block.rows() << " x " << block.cols()/* << " starting at " << blockStartsEE[i] << "," << blockStartsEJ[j]*/ << std::endl;
1141-
1142- make_cross_G_compute (fields[i].field_ ->vmesh (), fields[sourcefieldindices[j]].field_ ->vmesh (), block, fields[i].insideconductivity , fields[i].outsideconductivity , op_cond, triangleareas);
1145+ make_cross_G_compute (fields[i].field_ ->vmesh (), fields[sourcefieldindices[j]].field_ ->vmesh (), block, fields[j].insideconductivity , fields[j].outsideconductivity , op_cond, triangleareas);
11431146 }
11441147 }
11451148 }
11461149
11471150 printInfo (EJ.matrix (), " EJ" );
11481151
1152+ // This needs to be checked. It was taken out because the deflation was producing errors
1153+ // Jeroen's matlab code, which was the basis of this code, only does a defation in test cases.
1154+
11491155 // Perform deflation on EE matrix
1150- const double deflationconstant = 1.0 /EE.matrix ().ncols ();
1151- EE.matrix () = EE.matrix ().array () + deflationconstant;
1152-
1153- printInfo (EE.matrix (), " EE after deflation" );
1156+ // const double deflationconstant = 1.0/EE.matrix().ncols();
1157+ // EE.matrix() = EE.matrix().array() + deflationconstant;
11541158
11551159 std::vector<int > measurementNodeSize (measurementfieldindices.size ());
11561160 auto measFields = fields | boost::adaptors::filtered ([](const bemfield& f) { return f.measurement ; });
0 commit comments