FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
FEMFields.hpp
1
2//
3// $Id: hpp,v 1.0 2000/01/01 00:00:01 werner Exp $
4//
5// $Log: hpp,v $
6// Created 2012/05/21 12:57:24 marcel
7// Initial version
8//
9//
11#ifndef __FEMFIELDS_HPP
12#define __FEMFIELDS_HPP
13
14#include "FEM.hpp"
15#include <eagle/PhysicalSpace.hpp>
16#include "gridtypesDllApi.h"
17#include <grid/Grid.hpp>
18
19//#include <ocean/plankton/VInput.hpp>
20
21namespace Fiber
22{
23
25{
26 WeakPtr<Grid> m_vgrid;
27 WeakPtr<Grid> m_igrid;
28
29 string m_field_name;
30 size_t m_size;
31
32 FEMOperatorData( WeakPtr<Grid> vgrid, WeakPtr<Grid> igrid, string field_name, size_t size = 0 )
33 : m_vgrid( vgrid )
34 , m_igrid( igrid )
35 , m_field_name( field_name )
36 , m_size( size )
37 {}
38};
39
40
53
54// stress related fields:
70
71
87
103
119
121{
124
126
131 ~Mises() {}
132
133 RefPtr<ResultArray_t> result() const;
134};
135
151
167
168template<class T> void initValues( T& foo);
169template<> void initValues<float>( float& foo);
170template<> void initValues<double>( double& foo);
171template<> void initValues<Eagle::PhysicalSpace::tvector>( Eagle::PhysicalSpace::tvector& foo);
172template<> void initValues<Eagle::metric33>( Eagle::metric33& foo);
173
174
175template<class T>
177{
180
182
187 {
188 std::cout << "AverageStress::AverageStress()" << std::endl;
189 std::cout.flush();
190
191 RefPtr<Skeleton> v_cells = (*FEMData.m_vgrid)( FEM::cellID3D() );
192 RefPtr<Skeleton> v_vertices = FEMData.m_vgrid->findVertices();
193 assert(v_cells);
194 assert(v_vertices);
195
196 RefPtr<Representation> v_cells_as_vertices = (*v_cells)(v_vertices);
197 assert(v_cells_as_vertices);
198
199//RefPtr<Representation> v_vertices_as_cells = (*v_vertices)(v_cells);
200// assert(v_vertices_as_cells);
201
202 RefPtr<Field> v_c_v_pos = v_cells_as_vertices->Positions();
204
205//RefPtr<Field> v_v_c_pos = v_vertices_as_cells->Positions();
206// assert(v_v_c_pos);
207
208 RefPtr<MemArray<1, Eagle::PhysicalSpace::point> > vert_arr = FEMData.m_vgrid->getCartesianPositions()->getData();
210
211 RefPtr<Field> i_field = (*FEMData.m_igrid)( FEMData.m_field_name );
212 assert(i_field);
213
217
218 m_data = new MemArray<1, T>(vert_arr->Size() );
219 MultiArray<1, T>& av_values = *m_data;
221 mi = 0;
222 do
223 {
224 //Wizt::VInputValueTrait<T>::init( av_values[mi] );
226
227 }while( mi.inc( vert_arr->Size() ) );
228
229 RefPtr<Skeleton> i_vertices = FEMData.m_igrid->findVertices();
230 RefPtr<Skeleton> i_cells = (*FEMData.m_igrid)( FEM::cellID3D() );
231 assert(i_vertices);
232 assert(i_cells);
233 RefPtr<Representation> i_cells_as_vertices = (*i_cells)(i_vertices);
234 assert(i_cells_as_vertices);
235 RefPtr<Field> i_c_v_pos = i_cells_as_vertices->Positions();
237
238 {
241
242 if( cell_v_arr && cell_i_arr )
243 {
246
247// iterate over cells
248 mi = 0;
249 do
250 {
253
254 // sum up:
255 if( one_icell.size() == 1 ) // reduced integrated cells
256 {
257 // for vertices of cells compute contribution of reduced stress value
258 // to each vertex equally
259 for( size_t i = 0; i < one_vcell.size(); i++ )
260 {
261 const unsigned& mv = one_vcell[i];
262 const unsigned& mj = one_icell[0];
263
264 av_values[mv] += i_av_values[mj] / one_vcell.size();
265 }
266 }
267// else
268 if( one_icell.size() == 27 && one_vcell.size() == 20 ) // c3d20 element
269 {
270 for( size_t i = 0; i < one_vcell.size(); i++ )
271 {
272 const unsigned& mv = one_vcell[i];
273 double weight_sum = 0;
274
275 T tmp;
277
278 for( size_t j = 0; j < one_icell.size(); j++ )
279 {
280 const unsigned& mj = one_icell[j];
281
282 double weight = FEMFunc::getC3D20GaussWeight(j, i);
283
284 tmp += T(i_av_values[mj] * weight);
285
286 weight_sum += weight;
287 }
289 }
290 }
291 if( one_icell.size() == 8 && one_vcell.size() == 8 ) // c3d8 element
292 {
293 for( size_t i = 0; i < one_vcell.size(); i++ )
294 {
295 const unsigned& mv = one_vcell[i];
296
297 double weight_sum = 0;
298
299 T tmp;
301
302 for( size_t j = 0; j < one_icell.size(); j++ )
303 {
304 const unsigned& mj = one_icell[j];
305
306 double weight = FEMFunc::getC3D8GaussWeight(j, i);
307 tmp += T(i_av_values[mj] * weight);
308 weight_sum += weight;
309 }
311
312 }
313 }
314
315 }while( mi.inc( cell_v_arr->Size() ) );
316
317 std::cout << "AverageStress::AverageStress()END" << std::endl;
318 std::cout.flush();
319 }
320 }
321 // fixed sizes?
322 {
325 if( cell_v_arr && cell_i_arr )
326 {
329
331 mi = 0, 0;
332 mv = 0, 0;
333
334 std::vector<double> weight_sum( vert_arr->Size()[0], 0.0 );
335
336 // weighted sum:
337 // for cells
338 for( index_t c = 0; c < cell_v_arr->Size()[1]; c++)
339 {
340 // for vertices (of cell)
341 for( index_t v = 0; v < cell_v_arr->Size()[0]; v++ )
342 {
343 mv = v, c;
344
345 // for int Eagle::points
346 for( index_t i = 0; i < cell_i_arr->Size()[0]; i++ )
347 {
348 mi = i, c;
349 double weight = 0;
350
351 if( cell_v_arr->Size()[0] == 20 && cell_i_arr->Size()[0] == 27 )
352 weight = FEMFunc::getC3D20GaussWeight(i, v);
353 else if( cell_v_arr->Size()[0] == 8 && cell_i_arr->Size()[0] == 8 )
354 weight = FEMFunc::getC3D8GaussWeight(i, v);
355 else if( cell_v_arr->Size()[0] == 8 && cell_i_arr->Size()[0] == 1 )
356 weight = 1;
357 else if( cell_v_arr->Size()[0] == 20 && cell_i_arr->Size()[0] == 8 )
358 weight = FEMFunc::getC3D20RGaussWeight(i, v);
359 else if( cell_v_arr->Size()[0] == 4 && cell_i_arr->Size()[0] == 1 )
360 weight = 1;
361 else
362 assert( 0 && "unsupported element type" );
363
364 av_values[ coords_cell[mv] ] += T(i_av_values[ int_points_cell[mi] ] * weight);
365 weight_sum[ coords_cell[mv] ] += weight;
366 }
367 }
368 }
369
370 // normalize:
371 for( index_t i = 0; i < vert_arr->Size()[0]; i++ )
372 av_values[ i ] /= weight_sum[ i ];
373
374 }
375 }
376 }
377
378
379 ~AverageField() {}
380
381 RefPtr<ResultArray_t> result() const
382 {
383 return m_data;
384 }
385};
386
387
388template<class T>
390{
393
395
400 {
401#ifdef VERBOSE
402 std::cout << "ComputeCellField::ComputeCellField()" << std::endl;
403 std::cout.flush();
404#endif
405// std::cin.ignore();
406
407 RefPtr<Skeleton> v_cells = (*FEMData.m_vgrid)( FEM::cellID3D() );
408 RefPtr<Skeleton> v_vertices = FEMData.m_vgrid->findVertices();
409 assert(v_cells);
410 assert(v_vertices);
411
412 RefPtr<Representation> v_cells_as_vertices = (*v_cells)(v_vertices);
413 assert(v_cells_as_vertices);
414
415//RefPtr<Representation> v_vertices_as_cells = (*v_vertices)(v_cells);
416// assert(v_vertices_as_cells);
417
418 RefPtr<Field> v_c_v_pos = v_cells_as_vertices->Positions();
420
421//RefPtr<Field> v_v_c_pos = v_vertices_as_cells->Positions();
422// assert(v_v_c_pos);
423
424 RefPtr<MemArray<1, Eagle::PhysicalSpace::point> > vert_arr = FEMData.m_vgrid->getCartesianPositions()->getData();
426
427 RefPtr<Field> i_field = (*FEMData.m_igrid)( FEMData.m_field_name );
428 assert(i_field);
429
433
436
437 m_data = new MemArray<2, T>( cell_v_arr->Size() );
438 MultiArray<2, T>& new_values = *m_data;
440 mi = 0,0;
441 do
442 {
443 //Wizt::VInputValueTrait<T>::init( av_values[mi] );
445
446 }while( mi.inc( cell_v_arr->Size() ) );
447
448 RefPtr<Skeleton> i_vertices = FEMData.m_igrid->findVertices();
449 RefPtr<Skeleton> i_cells = (*FEMData.m_igrid)( FEM::cellID3D() );
450 assert(i_vertices);
451 assert(i_cells);
452 RefPtr<Representation> i_cells_as_vertices = (*i_cells)(i_vertices);
453 assert(i_cells_as_vertices);
454 RefPtr<Field> i_c_v_pos = i_cells_as_vertices->Positions();
456
457// fixed size support only (nor now)
458 {
459// RefPtr<MemArray<2, uint32_t> > cell_v_arr = v_c_v_pos->getData();
461 if( cell_v_arr && cell_i_arr )
462 {
463// MultiArray<2, uint32_t>& coords_cell = *cell_v_arr;
465
467 mi = 0, 0;
468 mv = 0, 0;
469
470// vector<double> weight_sum( vert_arr->Size()[0], 0.0 );
473
474 // weighted sum:
475 // for cells
476 for( index_t c = 0; c < cell_v_arr->Size()[1]; c++)
477 {
478 // for vertices (of cell)
479 for( index_t v = 0; v < cell_v_arr->Size()[0]; v++ )
480 {
481 mv = v, c;
482
483 // for int Eagle::points
484 for( index_t i = 0; i < cell_i_arr->Size()[0]; i++ )
485 {
486 mi = i, c;
487 double weight = 0;
488
489 if( cell_v_arr->Size()[0] == 20 && cell_i_arr->Size()[0] == 27 )
490 weight = FEMFunc::getC3D20GaussWeight(i, v);
491 else if( cell_v_arr->Size()[0] == 8 && cell_i_arr->Size()[0] == 8 )
492 weight = FEMFunc::getC3D8GaussWeight(i, v);
493 else if( cell_v_arr->Size()[0] == 8 && cell_i_arr->Size()[0] == 1 )
494 weight = 1;
495 else if( cell_v_arr->Size()[0] == 20 && cell_i_arr->Size()[0] == 8 )
496 weight = FEMFunc::getC3D20RGaussWeight(i, v);
497 else if( cell_v_arr->Size()[0] == 4 && cell_i_arr->Size()[0] == 1 )
498 weight = 1;
499 else
500 assert( 0 && "unsupported element type" );
501
502 new_values[ mv ] += T(i_av_values[ int_points_cell[mi] ] * weight);
503 weight_sum[ mv ] += weight;
504 }
505 }
506 }
507
508 std::cout << "ComputeCellField:: normalize" << std::endl;
509 // normalize
510 mv = 0,0;
511 do
512 {
513 std::cout << mv << std::endl;
514 new_values[ mv ] /= weight_sum[mv];
515 }while( mv.inc( cell_v_arr->Size() ) );
516
517 }
518 }
519 }
520
521
523
524 RefPtr<ResultArray_t> result() const
525 {
526 return m_data;
527 }
528};
529
531{
534
536
541// ~CellNeighborhood() {}
542
543RefPtr<ResultArray_t> result() const;
544};
545
546
552{
555
557
562// ~CellNeighborhood() {}
563
564RefPtr<ResultArray_t> result() const;
565};
566
571{
574
576
581// ~CellNeighborhood() {}
582
583RefPtr<ResultArray_t> result() const;
584};
585
586
595{
598
600
605// ~CellNeighborhood() {}
606
607RefPtr<ResultArray_t> result() const;
608};
609
629
630}
631
632#endif
valarray< size_t > size() const
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ostream cout
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
std::nullptr_t NullPtr
Definition FEMFields.hpp:177
AverageField(const FEMOperatorData &FEMData, const MemBase::Creator_t &C=MemCore::NullPtr())
Definition FEMFields.hpp:186
Creator for a vector field pointing from the cell centers of the strong neighbors to the center of th...
Definition FEMFields.hpp:615
CellDirectionsFixed(const FEMOperatorData &FEMData, const MemBase::Creator_t &C=MemCore::NullPtr())
Creator for a vector field pointing from the cell centers of the weak neighbors to the center of the ...
Definition FEMFields.hpp:571
Creator for computing strong neighbors and stores them as a fixed array of cell indices per cells in ...
Definition FEMFields.hpp:595
Creator for computing weak neighbors and stores them as a std::vector of cell indices per cells in a ...
Definition FEMFields.hpp:552
Definition FEMFields.hpp:390
ComputeCellField(const FEMOperatorData &FEMData, const MemBase::Creator_t &C=MemCore::NullPtr())
Definition FEMFields.hpp:399
Definition FEMFields.hpp:153
Definition FEMFields.hpp:137
Definition FEMFields.hpp:25
Definition FEMFields.hpp:42
Definition FEMFields.hpp:73
Definition FEMFields.hpp:89
Definition FEMFields.hpp:105
Definition FEMFields.hpp:56
Definition FEMFields.hpp:121
Definition FEMFields.hpp:531