| 1 | /* -*- mode: C++ -*- */ |
|---|
| 2 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 3 | // FILE : DesignC2.tol |
|---|
| 4 | // PURPOSE: Defines Class @DesignC2 |
|---|
| 5 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 9 | Text _.autodoc.member.DesignC2.Spheric = |
|---|
| 10 | ""; |
|---|
| 11 | Class @DesignC2.Spheric : @DesignC2 |
|---|
| 12 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 13 | { |
|---|
| 14 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 15 | //Configuration parameters |
|---|
| 16 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 17 | Real _.radius; |
|---|
| 18 | Real _.radius.margin; |
|---|
| 19 | Real _.grid.size; |
|---|
| 20 | |
|---|
| 21 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 22 | //Auxiliar members |
|---|
| 23 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 24 | VMatrix _.Y.h = Rand(0,0,0,0); |
|---|
| 25 | VMatrix _.Y.neighbourhood = Rand(0,0,0,0); |
|---|
| 26 | |
|---|
| 27 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 28 | Real build.stress.points(Real void) |
|---|
| 29 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 30 | { |
|---|
| 31 | Text _MID = "[@DesignC2.Spheric::build.stress.points] "; |
|---|
| 32 | WriteLn("TRACE "+_MID+"1"); |
|---|
| 33 | Matrix Y.neighbour.triplet = Group("ConcatRows", For(1,_.H,Matrix(Real h) |
|---|
| 34 | { |
|---|
| 35 | Set neighbours = Unique(VRow2Set(SubRow(_.Y.neighbourhood,[[h]]))); |
|---|
| 36 | Set neighbours.up = Select(neighbours,Real(Real s) { s>h }); |
|---|
| 37 | Matrix s = SetCol(Sort(neighbours.up,Compare)); |
|---|
| 38 | Rand(Rows(s),1,h,h)|s|Rand(Rows(s),1,1,1) |
|---|
| 39 | })); |
|---|
| 40 | |
|---|
| 41 | WriteLn("TRACE "+_MID+"2"); |
|---|
| 42 | VMatrix Y.neighbour.1.map = Triplet(Y.neighbour.triplet,_.H,_.H); |
|---|
| 43 | VMatrix Y.neighbour.2.map = Y.neighbour.1.map*Y.neighbour.1.map; |
|---|
| 44 | VMatrix Y.neighbour.12.map = Max(Y.neighbour.1.map,Y.neighbour.2.map); |
|---|
| 45 | Matrix Y.neighbour.12.triplet = VMat2Triplet(Y.neighbour.12.map); |
|---|
| 46 | VMatrix Z.h.a = Mat2VMat(SubCol(Y.neighbour.12.triplet,[[1]])); |
|---|
| 47 | VMatrix Z.h.b = Mat2VMat(SubCol(Y.neighbour.12.triplet,[[2]])); |
|---|
| 48 | VMatrix Y.neighbour.a = SubRow(_.Y,VCol2Set(Z.h.a)); |
|---|
| 49 | VMatrix Y.neighbour.b = SubRow(_.Y,VCol2Set(Z.h.b)); |
|---|
| 50 | VMatrix Z.all = (Y.neighbour.a + Y.neighbour.b)*0.5; |
|---|
| 51 | |
|---|
| 52 | WriteLn("TRACE "+_MID+"3"); |
|---|
| 53 | VMatrix Z.interior.a = |
|---|
| 54 | { |
|---|
| 55 | VMatrix Z.norm2 = RPow(Y.neighbour.a-Z.all,2)*Rand(_.n,1,1,1); |
|---|
| 56 | VMatrix Z.tao = RPow(Z.norm2,0.5)/_.radius; |
|---|
| 57 | LE(Z.tao,Rand(VRows(Z.tao),1,1,1)) |
|---|
| 58 | }; |
|---|
| 59 | VMatrix Z.interior.b = |
|---|
| 60 | { |
|---|
| 61 | VMatrix Z.norm2 = RPow(Y.neighbour.b-Z.all,2)*Rand(_.n,1,1,1); |
|---|
| 62 | VMatrix Z.tao = RPow(Z.norm2,0.5)/_.radius; |
|---|
| 63 | LE(Z.tao,Rand(VRows(Z.tao),1,1,1)) |
|---|
| 64 | }; |
|---|
| 65 | VMatrix match.interior = Z.interior.a $* Z.interior.b; |
|---|
| 66 | |
|---|
| 67 | Set sel.interior = MatQuery::SelectMatch(match.interior); |
|---|
| 68 | VMatrix Z.interior = SubRow(Z.all,sel.interior); |
|---|
| 69 | VMatrix Z.h.interior = SubRow(Z.h.a | Z.h.b,sel.interior); |
|---|
| 70 | Set criterium = Range(1,_.n,1); |
|---|
| 71 | Set sel.unique = Col2Set(Sort(VMat2Mat(Z.interior),criterium,True)); |
|---|
| 72 | WriteLn("TRACE "+_MID+"4"); |
|---|
| 73 | VMatrix _.Z := SubRow(Z.interior, sel.unique); |
|---|
| 74 | VMatrix _.Z.h := SubRow(Z.h.interior, sel.unique); |
|---|
| 75 | Real _.Tz := VRows(_.Z); |
|---|
| 76 | VMatrix _.Z.Y.neighbour := |
|---|
| 77 | { |
|---|
| 78 | Matrix Z.t = DifEq(1/(1-B),Rand(_.Tz,1,1,1)); |
|---|
| 79 | Matrix Z.th = (Z.t << Z.t) | |
|---|
| 80 | VMat2Mat((SubCol(_.Z.h,[[1]])<<SubCol(_.Z.h,[[2]]))); |
|---|
| 81 | Matrix Z.Y.idx = PivotByRows(Z.th,Sort(Z.th,[[2]])); |
|---|
| 82 | VMatrix Z.Y.dif = |
|---|
| 83 | SubRow(_.Z,Col2Set(SubCol(Z.Y.idx,[[1]]))) - |
|---|
| 84 | SubRow(_.Y,Col2Set(SubCol(Z.Y.idx,[[2]]))); |
|---|
| 85 | VMatrix Z.Y.norm2 = RPow(Z.Y.dif,2)*Rand(_.n,1,1,1); |
|---|
| 86 | VMatrix Z.Y.tao = RPow(Z.Y.norm2,0.5)/_.radius; |
|---|
| 87 | VMatrix Z.Y.match = LE(Z.Y.tao,Rand(VRows(Z.Y.tao),1,1,1)); |
|---|
| 88 | SubRow(Mat2VMat(Z.Y.idx),MatQuery::SelectMatch(Z.Y.match)) |
|---|
| 89 | }; |
|---|
| 90 | VMatrix aux = MatQuery::SortAndCount(SubCol(_.Z.Y.neighbour,[[2]])); |
|---|
| 91 | VMatrix _.Yt := Triplet(VMat2Mat(SubCol(aux,[[1]])) | |
|---|
| 92 | Rand(VRows(aux),1,1,1) | |
|---|
| 93 | VMat2Mat(SubCol(aux,[[2]])),_.H,1); |
|---|
| 94 | Real _.Mz := Case( |
|---|
| 95 | prior.Z.order< 0, 0, |
|---|
| 96 | prior.Z.order==0, _.Tz, |
|---|
| 97 | prior.Z.order==1, _.Tz*(1+_.n), |
|---|
| 98 | prior.Z.order==2, _.Tz*(1+_.n*3/2+(1/2)*_.n^2)); |
|---|
| 99 | _.Tz |
|---|
| 100 | }; |
|---|
| 101 | |
|---|
| 102 | /////////////////////////////////////////////////////////////////////////// |
|---|
| 103 | Set get.X.weight(Set X.dif) |
|---|
| 104 | /////////////////////////////////////////////////////////////////////////// |
|---|
| 105 | { |
|---|
| 106 | Real m = VRows(X.dif[1]); |
|---|
| 107 | Set X.tao = For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 108 | { |
|---|
| 109 | VMatrix X.norm2 = RPow(X.dif[i],2)*Rand(_.n,1,1,1); |
|---|
| 110 | RPow(X.norm2,0.5)/_.radius |
|---|
| 111 | }); |
|---|
| 112 | Set X.tao2 = For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 113 | { |
|---|
| 114 | RPow(X.tao[i],2) |
|---|
| 115 | }); |
|---|
| 116 | Set X.match = For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 117 | { |
|---|
| 118 | LE(X.tao[i],Rand(m,1,1,1)) |
|---|
| 119 | }); |
|---|
| 120 | Set X.lambda = For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 121 | { |
|---|
| 122 | RPow(X.match[i] $* (Rand(m,1,1,1)-X.tao2[i]),4) |
|---|
| 123 | }); |
|---|
| 124 | VMatrix X.lambda.sum = SetSum(X.lambda); |
|---|
| 125 | |
|---|
| 126 | For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 127 | { |
|---|
| 128 | X.lambda[i] $/ X.lambda.sum |
|---|
| 129 | }) |
|---|
| 130 | }; |
|---|
| 131 | /////////////////////////////////////////////////////////////////////////// |
|---|
| 132 | Set get.X.weight.partial.derivative.1(Set X.dif, Real s) |
|---|
| 133 | /////////////////////////////////////////////////////////////////////////// |
|---|
| 134 | { |
|---|
| 135 | Real m = VRows(X.dif[1]); |
|---|
| 136 | Set X.tao = For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 137 | { |
|---|
| 138 | VMatrix X.norm2 = RPow(X.dif[i],2)*Rand(_.n,1,1,1); |
|---|
| 139 | RPow(X.norm2,0.5)/_.radius |
|---|
| 140 | }); |
|---|
| 141 | Set X.tao2 = For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 142 | { |
|---|
| 143 | RPow(X.tao[i],2) |
|---|
| 144 | }); |
|---|
| 145 | Set X.match = For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 146 | { |
|---|
| 147 | LE(X.tao[i],Rand(m,1,1,1)) |
|---|
| 148 | }); |
|---|
| 149 | Set X.lambda = For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 150 | { |
|---|
| 151 | RPow(X.match[i] $* (Rand(m,1,1,1)-X.tao2[i]),4) |
|---|
| 152 | }); |
|---|
| 153 | Set X.lambda.der = For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 154 | { |
|---|
| 155 | RPow(X.match[i] $* (Rand(m,1,1,1)-X.tao2[i]),3)$*X.tao[i]/2 |
|---|
| 156 | }); |
|---|
| 157 | VMatrix X.lambda.sum = SetSum(X.lambda); |
|---|
| 158 | VMatrix X.lambda.sum.2 = RPow(X.lambda.sum,2); |
|---|
| 159 | VMatrix X.lambda.der.sum = SetSum(X.lambda.der); |
|---|
| 160 | For(1,_.X.maxNeighbour,VMatrix(Real i) |
|---|
| 161 | { |
|---|
| 162 | (X.lambda.der[i]$*X.lambda.sum-X.lambda[i]$*X.lambda.der.sum) |
|---|
| 163 | $/ X.lambda.sum.2 |
|---|
| 164 | }) |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | }; |
|---|