1 package org.catacomb.numeric.difnet.model;
2
3 import org.catacomb.numeric.difnet.NetState;
4 import org.catacomb.numeric.difnet.NetStructure;
5 import org.catacomb.numeric.difnet.StructureLink;
6 import org.catacomb.numeric.difnet.StructureNode;
7 import org.catacomb.report.E;
8
9
10
11 public class BasicNetStructure implements NetStructure {
12
13
14 BasicStructureNode environmentNode;
15
16 int nEnvironmentLink;
17
18 public BasicStructureNode[] nodes;
19 public BasicStructureLink[] links;
20
21
22
23 public StructureNode[] getNodes() {
24 return nodes;
25 }
26
27
28 public StructureLink[] getLinks() {
29 return links;
30 }
31
32
33
34 public void setNodes(BasicStructureNode[] anp) {
35 nodes = anp;
36 }
37
38
39 public void setLinks(BasicStructureLink[] alp) {
40 links = alp;
41 }
42
43
44
45 public void setSurfaceCapacitance(double csurf) {
46 if (environmentNode != null) {
47 E.error(" - creatine new env node when already have one " + "BasicNetStructure");
48 }
49
50
51
52
53
54
55 int nn = nodes.length;
56 int nl = links.length;
57
58 BasicStructureNode[] nna = new BasicStructureNode[nn + 1];
59 BasicStructureLink[] lka = new BasicStructureLink[nl + nn];
60
61 environmentNode = new BasicStructureNode();
62 environmentNode.setFixed(true);
63
64 nEnvironmentLink = nn;
65
66 for (int i = 0; i < nn; i++) {
67 nna[i] = nodes[i];
68 }
69 nna[nn] = environmentNode;
70
71 for (int i = 0; i < nn; i++) {
72 nna[i].setArea(0.0);
73 }
74
75 for (int i = 0; i < nl; i++) {
76 links[i].calculateArea();
77 }
78
79
80 for (int i = 0; i < nn; i++) {
81 BasicStructureLink bsl = new BasicStructureLink(nna[i], environmentNode);
82 double acta = nna[i].getArea();
83 bsl.setActiveArea(acta);
84 bsl.applyAreaCapacitance(csurf);
85 lka[i] = bsl;
86 }
87
88 for (int i = 0; i < nl; i++) {
89 lka[nn + i] = links[i];
90 }
91
92
93 nodes = nna;
94 links = lka;
95
96 }
97
98
99
100 public void setEnvironmentValue(double d) {
101 if (environmentNode == null) {
102 setSurfaceCapacitance(0.);
103 }
104 environmentNode.setFixedValue(d);
105 }
106
107
108 public void setInitialValue(double d) {
109 for (int i = 0; i < nodes.length; i++) {
110 nodes[i].setInitialValue(d);
111 }
112 }
113
114
115
116
117
118 public void setSurfaceConductance(double gsurf) {
119 if (environmentNode == null) {
120 setSurfaceCapacitance(0);
121 }
122
123 for (int i = 0; i < nEnvironmentLink; i++) {
124 links[i].applyAreaConductance(gsurf);
125 }
126
127 }
128
129
130
131 public void setAxialConductance(double d) {
132
133 for (int i = nEnvironmentLink; i < links.length; i++) {
134 links[i].applyAxialConductance(d);
135
136 }
137 }
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 public NetState newState() {
161 int nn = nodes.length;
162 int nl = links.length;
163 BasicStateNode[] stateNodes = new BasicStateNode[nn];
164 BasicStateLink[] stateLinks = new BasicStateLink[nl];
165
166 for (int i = 0; i < nn; i++) {
167 nodes[i].setWork(i);
168 }
169
170 for (int i = 0; i < nn; i++) {
171 stateNodes[i] = nodes[i].newState();
172 }
173
174 for (int i = 0; i < nl; i++) {
175 BasicStructureLink lkp = links[i];
176 stateLinks[i] = lkp.newState(stateNodes[lkp.getNodeA().getWork()], stateNodes[lkp.getNodeB().getWork()]);
177 }
178 return new BasicNetState(this, stateNodes, stateLinks);
179 }
180
181
182
183 }