Index: /issm/trunk/src/c/Bamgx/objects/Triangles.cpp
===================================================================
--- /issm/trunk/src/c/Bamgx/objects/Triangles.cpp	(revision 2852)
+++ /issm/trunk/src/c/Bamgx/objects/Triangles.cpp	(revision 2853)
@@ -95,5 +95,7 @@
 				nbv++;
 			  }
-		  assert(inbvx == nbv);
+		  if (inbvx != nbv){
+			  throw ErrorException(__FUNCT__,exprintf("inbvx != nbv"));
+		  }
 		  for (i=0;i<Tho.nbt;i++)
 			if(  reft[i] >=0 && flag[i]) 
@@ -103,14 +105,18 @@
 				int i1 = Tho.Number(t[1]);
 				int i2 = Tho.Number(t[2]);
-				assert(i0>=0 && i1 >= 0 && i2  >= 0);
-				assert(i0<Tho.nbv && i1 <Tho.nbv && i2  <Tho.nbv);
-				// cout <<i<< " F" <<  flag[i] << " T " << nbt << "   = " <<  kk[i0] << " " << kk[i1] << " " << kk[i2] ;
-				// cout << " OT  " <<  i0 << " "  << i1 << " " << i2  << " " << reft[i] << endl;
+				if (i0<0 || i1<0 || i2<0){
+					throw ErrorException(__FUNCT__,exprintf("i0<0 || i1<0 || i2< 0"));
+				}
+				if (i0>=Tho.nbv || i1>=Tho.nbv || i2>=Tho.nbv){
+					throw ErrorException(__FUNCT__,exprintf("i0>=Tho.nbv || i1>=Tho.nbv || i2>=Tho.nbv"));
+				}
 				triangles[nbt] = Triangle(this,kk[i0],kk[i1],kk[i2]);
 				triangles[nbt].color = Tho.subdomains[reft[i]].ref; 
 				nbt++;           
 			  }
-		  assert(kt==nbt);
-		  if (nbt ==0 && nbv ==0) {
+		  if (kt!=nbt){
+			  throw ErrorException(__FUNCT__,exprintf("kt!=nbt"));
+		  }
+		  if (nbt==0 && nbv==0) {
 			  throw ErrorException(__FUNCT__,exprintf("All triangles have been removed"));
 		  }
@@ -124,6 +130,10 @@
 		  FillHoleInMesh();
 
-		  assert(NbSubDomains);
-		  assert(subdomains[0].head && subdomains[0].head->link);
+		  if (!NbSubDomains){
+			  throw ErrorException(__FUNCT__,exprintf("NbSubDomains==0"));
+		  }
+		  if (!subdomains[0].head || !subdomains[0].head->link){
+			  throw ErrorException(__FUNCT__,exprintf("!subdomains[0].head || !subdomains[0].head->link"));
+		  }
 
 	  }
@@ -132,5 +142,4 @@
 	Triangles::~Triangles() {
 		long int verbosity=2;
-		//assert(NbRef<=0);
 		if (CurrentTh == this) CurrentTh=0;
 		//if(vertices)  delete [] vertices; //TEST  crash if not commented
@@ -189,6 +198,5 @@
 		  if (NbVerticesOnGeomEdge)
 			VerticesOnGeomEdge = new VertexOnGeom[NbVerticesOnGeomEdge] ;
-		  if (& BTh == & Th.BTh) // same back ground 
-			 {
+		  if (& BTh == & Th.BTh){ // same background 
 			  BTh.NbRef++;
 			  NbVertexOnBThVertex = Th.NbVertexOnBThVertex;
@@ -199,6 +207,5 @@
 				VertexOnBThEdge = new VertexOnEdge[NbVertexOnBThEdge];
 			 }
-		  else 
-			 { // no add on back ground mesh 
+		  else { // no add on background mesh 
 			  BTh.NbRef++;
 			  NbVertexOnBThVertex=0;
@@ -206,6 +213,4 @@
 			  NbVertexOnBThEdge=0;
 			  VertexOnBThEdge=0;
-			  //       assert (& BTh == this); // --- a voir 
-
 			 }
 
@@ -232,6 +237,4 @@
 		  quadtree=0;
 
-
-		  //  assert(!OutSidesTriangles);
 	  }
 	/*}}}1*/
@@ -409,8 +412,9 @@
 						j0 =  i0%2;
 						i0 =  i0/2;
-						assert( v ==  edges[i0 ].v[j0]);
+						if (v!=edges[i0 ].v[j0]){
+							throw ErrorException(__FUNCT__,exprintf("v!=edges[i0 ].v[j0]"));
+						}
 						edges[i ].adj[ j ] =edges +i0;
 						edges[i0].adj[ j0] =edges +i ;
-						assert(edges[i0].v[j0] == v);
 						v->color = -3;
 					}
@@ -777,5 +781,7 @@
 				if(st[k]==-1) st[k]=3*i+j;
 				else if(st[k]>=0) {
-					assert( ! triangles[i].TriangleAdj(j) && !triangles[st[k] / 3].TriangleAdj((int) (st[k]%3)));
+					if (triangles[i].TriangleAdj(j) || triangles[st[k]/3].TriangleAdj((int) (st[k]%3))){
+						throw ErrorException(__FUNCT__,exprintf("triangles[i].TriangleAdj(j) || triangles[st[k]/3].TriangleAdj((int) (st[k]%3))"));
+					}
 					triangles[i].SetAdj2(j,triangles + st[k] / 3,(int) (st[k]%3));
 					if (invisible)  triangles[i].SetHidden(j);
@@ -873,5 +879,7 @@
 					  }
 				  }
-				assert(k==nbe);
+				if (k!=nbe){
+					throw ErrorException(__FUNCT__,exprintf("k!=nbe"));
+				}
 				if (edgessave) delete [] edgessave;
 			  }
@@ -898,14 +906,15 @@
 					 j0 =  i0%2;
 					 i0 =  i0/2;
-					 assert( v ==  edges[i0 ].v[j0]);
+					 if (v!=edges[i0 ].v[j0]){
+						 throw ErrorException(__FUNCT__,exprintf("v!=edges[i0 ].v[j0]"));
+					 }
 					 edges[i ].adj[ j ] =edges +i0;
 					 edges[i0].adj[ j0] =edges +i ;
-					 assert(edges[i0].v[j0] == v);
-					 //	    if(verbosity>8)
-					 //  cout << " edges adj " << i0 << " "<< j0 << " <-->  "  << i << " " << j << endl;
 					 v->color = -3;}
 				}
 			// now reconstruct the sub domain info 
-			assert(!NbSubDomains);
+			if (NbSubDomains){
+				throw ErrorException(__FUNCT__,exprintf("NbSubDomains should be 0"));
+			}
 			NbSubDomains=0;
 
@@ -972,5 +981,7 @@
 						}
 					}  
-				assert(k== NbSubDomains);
+				if (k!= NbSubDomains){
+					throw ErrorException(__FUNCT__,exprintf("k!= NbSubDomains"));
+				}
 
 				delete [] colorT;
@@ -1038,5 +1049,7 @@
 
 			Gh.coefIcoor= (MaxICoor)/(Max(Gh.pmax.x-Gh.pmin.x,Gh.pmax.y-Gh.pmin.y));
-			assert(Gh.coefIcoor >0);
+			if (Gh.coefIcoor<=0){
+				throw ErrorException(__FUNCT__,exprintf("Gh.coefIcoor<=0"));
+			}
 
 			Real8 hmin = HUGE_VAL;
@@ -1068,5 +1081,4 @@
 						 Gh.edges[i].SetReverseEqui();
 						Gh.edges[i].link= & Gh.edges[j];
-						//assert(sens==0);//  meme sens pour l'instant
 					}
 
@@ -1087,10 +1099,10 @@
 				len[j1] += l12;
 				hmin = Min(hmin,l12);
-
 				Gh.edges[i].ref  = edges[i].ref;
 
 				k = edge4->addtrie(i0,i1);
-
-				assert(k == i);
+				if (k != i){
+					throw ErrorException(__FUNCT__,exprintf("k != i"));
+				}
 
 			  }
@@ -1160,10 +1172,15 @@
 		} 
 		Edge * e = &BhAB;
-		assert( pA && pB && e);
+		if (!pA || !pB || !e){
+			throw ErrorException(__FUNCT__,exprintf("!pA || !pB || !e"));
+		}
 		// be carefull the back ground edge e is on same geom edge 
 		// of the initiale edge def by the 2 vertex A B;
-		assert(e>=BTh.edges && e<BTh.edges+BTh.nbe);// Is a background Mesh;   
+		//check Is a background Mesh;   
+		if (e<BTh.edges || e>=BTh.edges+BTh.nbe){
+			throw ErrorException(__FUNCT__,exprintf("e<BTh.edges || e>=BTh.edges+BTh.nbe"));
+		}
 		// walk on BTh edge 
-		//assert(0 /* not finish ProjectOnCurve with BackGround Mesh*/);
+		//not finish ProjectOnCurve with BackGround Mesh);
 		// 1 first find a back ground edge contening the vertex A
 		// 2 walk n back gound boundary to find the final vertex B
@@ -1185,7 +1202,6 @@
 			// cout << " EXCHANGE  A et B) " << endl;
 		  } 
-		else
-		  { // do the search by walking 
-			assert(0 /* A FAIRE */);
+		else{ // do the search by walking 
+			throw ErrorException(__FUNCT__,exprintf("case not supported yet"));
 		  }
 
@@ -1214,36 +1230,37 @@
 			for ( eee=e,iii=sens,te0=tA;
 						eee && ((( void*) eee) != pB) && (( void*) (v1=&((*eee)[iii]))) != pB ;
-						neee = eee->adj[iii],iii = 1-neee->Intersection(*eee),eee = neee,v0=v1,te0=1-iii )   
-			  { 
+						neee = eee->adj[iii],iii = 1-neee->Intersection(*eee),eee = neee,v0=v1,te0=1-iii ) { 
 				//	cout << kkk << " eee = " << BTh.Number(eee) << "  v0=  " 
 				//     << BTh.Number(v0) << " v1 = " << BTh.Number(v1) << endl;
 
-				assert(kkk++<100);
-				assert(eee);
+				kkk=kkk+1;
+				if (kkk>=100){
+					throw ErrorException(__FUNCT__,exprintf("kkk>=100"));
+				}
+				if (!eee){
+					throw ErrorException(__FUNCT__,exprintf("!eee"));
+				}
 				Real8 lg0 = lg;
 				Real8 dp = LengthInterpole(v0->m,v1->m,(R2) *v1 - (R2) *v0);
 				lg += dp;
-				if (cas && abscisse <= lg)
-				  { // ok we find the geom edge 
+				if (cas && abscisse <= lg) { // ok we find the geom edge 
 					Real8 sss  =   (abscisse-lg0)/dp;
 					Real8 thetab = te0*(1-sss)+ sss*iii;
-					assert(thetab>=0 && thetab<=1);
+					if (thetab<0 || thetab>1){
+						throw ErrorException(__FUNCT__,exprintf("thetab<0 || thetab>1"));
+					}
 					BR = VertexOnEdge(&R,eee,thetab);
-
-					// cout << Number(R) << " = " <<  thetab << " on  " <<  BTh.Number(eee)
-					//	 << " = " << R << endl;
-
 					return  Gh.ProjectOnCurve(*eee,thetab,R,GR);
-
 				  }
 			  }
 			// we find the end 
-			if (v1 != pvB) 
-			  {
+			if (v1 != pvB){
 				if (( void*) v1 == pB)
 				 tB = iii;
 
 				Real8 lg0 = lg;
-				assert(eee);
+				if (!eee){
+					throw ErrorException(__FUNCT__,exprintf("!eee"));
+				}
 				v1 = pvB;
 				Real8 dp = LengthInterpole(v0->m,v1->m,(R2) *v1 - (R2) *v0);
@@ -1254,5 +1271,7 @@
 					Real8 sss  =   (abscisse-lg0)/dp;
 					Real8 thetab = te0*(1-sss)+ sss*tB;
-					assert(thetab>=0 && thetab<=1);
+					if (thetab<0 || thetab>1){
+						throw ErrorException(__FUNCT__,exprintf("thetab<0 || thetab>1"));
+					}
 					BR = VertexOnEdge(&R,eee,thetab);
 					return  Gh.ProjectOnCurve(*eee,thetab,R,GR);
@@ -1404,11 +1423,12 @@
 			if (ong) // a geometrical edges 
 			  { 
-				if (withBackground)
-				  {
+				if (withBackground){
 					// walk on back ground mesh 
 					//  newVertexOnBThEdge[ibe++] = VertexOnEdge(vertices[k],bedge,absicsseonBedge); 
 					// a faire -- difficile 
 					// the first PB is to now a background edge between the 2 vertices
-					assert(edgesGtoB); 
+					if (!edgesGtoB){
+						throw ErrorException(__FUNCT__,exprintf("!edgesGtoB"));
+					}
 					// cout << " ie = " << ie <<"  v0 = " <<  Number(newedges[ie][0]) << endl;
 					ong= ProjectOnCurve(*edgesGtoB[Gh.Number(edges[i].on)],
@@ -1488,5 +1508,7 @@
 		for (i=0;i<nbt;i++) {
 			Triangle & t = triangles[i];
-			assert(t.link);
+			if (!t.link){
+				throw ErrorException(__FUNCT__,exprintf("!t.link"));
+			}
 			for(int j=0;j<3;j++)
 			  {
@@ -1586,5 +1608,7 @@
 
 			  } 
-			assert (nbinvisible<2);
+			if (nbinvisible>=2){
+				throw ErrorException(__FUNCT__,exprintf("nbinvisible>=2"));
+			}
 			// cout << " " <<  nbinvisible << " " <<  nbsplitedge << endl;
 			switch (nbsplitedge) {
@@ -1597,5 +1621,7 @@
 						  break;
 			} 
-			assert(ksplit[i]>=40);
+			if (ksplit[i]<40){
+				throw ErrorException(__FUNCT__,exprintf("ksplit[i]<40"));
+			}
 		  }
 		//  now do the element split
@@ -1617,5 +1643,7 @@
 			Int4 kk=ksplit[i]/10;
 			int  ke=(int) (ksplit[i]%10);
-			assert(kk<7 && kk >0);
+			if (kk>=7 || kk<=0){
+				throw ErrorException(__FUNCT__,exprintf("kk>=7 || kk<=0"));
+			}
 
 			// def the numbering   k (edge) i vertex 
@@ -1632,6 +1660,7 @@
 			Vertex * v2=t0(i2);
 
-			// cout << "nbmkadj " << nbmkadj << " it=" << i <<endl;
-			assert(nbmkadj< 10);
+			if (nbmkadj>=10){
+				throw ErrorException(__FUNCT__,exprintf("nbmkadj>=10"));
+			}
 			// --------------------------
 			TriangleAdjacent ta0(t0.Adj(i0)),ta1(t0.Adj(i1)),ta2(t0.Adj(i2));
@@ -1649,5 +1678,7 @@
 							Triangle &t1=triangles[kkk++];
 							t1=t0;
-							assert (kedge[3*i+i0]>=0);
+							if (kedge[3*i+i0]<0){
+								throw ErrorException(__FUNCT__,exprintf("kedge[3*i+i0]<0"));
+							}
 							Vertex * v3 = vertices + kedge[3*i+k0];
 
@@ -1663,6 +1694,10 @@
 							Triangle &t2=triangles[kkk++];
 							t2=t1=t0;
-							assert (kedge[3*i+k1]>=0);
-							assert (kedge[3*i+k2]>=0);
+							if (kedge[3*i+k1]<0){
+								throw ErrorException(__FUNCT__,exprintf("kedge[3*i+k1]<0"));
+							}
+							if (kedge[3*i+k2]<0){
+								throw ErrorException(__FUNCT__,exprintf("kedge[3*i+k2]<0"));
+							}
 
 							Vertex * v01 = vertices + kedge[3*i+k2];
@@ -1686,5 +1721,7 @@
 							Triangle &t3=triangles[kkk++];
 							t3=t2=t1=t0;
-							assert(kedge[3*i+k0] >=0 && kedge[3*i+k1] >=0 && kedge[3*i+k2] >=0);
+							if (kedge[3*i+k0] <0 || kedge[3*i+k1]<0 || kedge[3*i+k2]<0){
+								throw ErrorException(__FUNCT__,exprintf("kedge[3*i+k0] <0 || kedge[3*i+k1]<0 || kedge[3*i+k2]<0"));
+							}
 							Vertex * v12 = vertices + kedge[3*i+k0];
 							Vertex * v02 = vertices + kedge[3*i+k1]; 
@@ -1767,5 +1804,7 @@
 				}
 			// cout << "  -- " << i << " " << nbmkadj << endl;
-			assert(nbmkadj<=13);// 13 = 6 + 4 + 3
+			if (nbmkadj>13){// 13 = 6 + 4 +
+				throw ErrorException(__FUNCT__,exprintf("nbmkadj>13"));
+			}
 
 			if (kk==6)  newNbOfQuad+=3;
@@ -2103,9 +2142,7 @@
 					int rswap =tt[izerodet]->swap(iedge);
 
-					if (!rswap) 
-					  {
-						cout << " Pb swap the point s is on a edge =>swap " << iedge << " "  << *tt[izerodet] << endl;
-					  }
-					assert(rswap);
+					if (!rswap) {
+						throw ErrorException(__FUNCT__,exprintf("swap the point s is on a edge"));
+					}
 				}
 	}
@@ -2166,5 +2203,7 @@
 
 				quadtree->Add(vi);
-				assert (tcvi && tcvi->det >= 0) ;// internal 
+				if (!tcvi || tcvi->det<0){// internal
+					throw ErrorException(__FUNCT__,exprintf("!tcvi || tcvi->det < 0"));
+				}
 				Add(vi,tcvi,dete);
 				NbSwap += vi.Optim(1);          
@@ -2224,5 +2263,7 @@
 					Vertex & vj = vertices[iv];
 					Int4 j = vj.ReferenceNumber; 
-					assert( &vj== ordre[j]);
+					if ( &vj!= ordre[j]){
+						throw ErrorException(__FUNCT__,exprintf("&vj!= ordre[j]"));
+					}
 					if(i!=j)
 					  { //  for valgring 
@@ -2231,6 +2272,4 @@
 					  }
 					vj.ReferenceNumber=0; 
-					//	cout << " Add " << Number(vj) << " " << vj 
-					// << "   " <<  Number(vi) << " <--> " << Number(vj) <<endl;
 					Triangle *tcvj = FindTriangleContening(vj.i,dete);
 					if (tcvj && !tcvj->link){
@@ -2238,5 +2277,4 @@
 					}
 					quadtree->Add(vj);
-					assert (tcvj && tcvj->det >= 0) ;// internal 
 					Add(vj,tcvj,dete);
 					NbSwap += vj.Optim(1);          
@@ -2317,5 +2355,7 @@
 				// we can change first_np_or_next_t[i]
 				//      cout << " Do the triangle " << i << " Next_t=" << next_t << endl;
-				assert(i>=0 && i < nbt );
+				if (i<0 || i>=nbt ){
+					throw ErrorException(__FUNCT__,exprintf("i<0 || i>=nbt"));
+				}
 				first_np_or_next_t[i] = iter; 
 				for(j=0;j<3;j++)
@@ -2366,5 +2406,7 @@
 					if (first_np_or_next_t[kt]>0) 
 					 first_np_or_next_t[kt]=-Headt,Headt=kt;
-					assert( ta.EdgeVertex(0) == s);
+					if (ta.EdgeVertex(0)!=s){
+						throw ErrorException(__FUNCT__,exprintf("ta.EdgeVertex(0)!=s"));
+					}
 					ta = Next(Adj(ta));
 				} while ( (tbegin != (Triangle*) ta)); 
@@ -2444,5 +2486,4 @@
 				trace =  TRACETRIANGLE <0 ? 1 : i == TRACETRIANGLE;
 #endif
-				//      cout << " Do the triangle " << i << " Next_t=" << next_t << endl;
 				assert(i>=0 && i < nbt );
 				first_np_or_next_t[i] = nbv; // to save the fist new point of triangle
