OOFEM 3.0
Loading...
Searching...
No Matches
voxelvoffield.h
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35#ifndef fvoxelvoffield_h
36#define fvoxelvoffield_h
37
38#include "field.h"
39#include "element.h"
40#include "node.h"
41#include "VoxelGrid.h"
42#include "timestep.h"
43#include "floatarray.h"
44
45
46namespace oofem {
48{
49 protected:
51 public:
52 VoxelVOFField(VoxelGrid *vg = nullptr) : Field (oofem::FieldType::FT_VOF), voxelGrid(vg) {}
53 void setGrid(VoxelGrid *vg) { voxelGrid = vg; }
54 int evaluateAt(FloatArray &answer, const FloatArray &coords, ValueModeType mode, TimeStep *tStep) override {
55 answer.resize(1);
56 auto indices = voxelGrid->get_indices_from_point({coords[0], coords[1], coords[2]});
57 int indx = voxelGrid->get_index( std::get<0>(indices),
58 std::get<1>(indices),
59 std::get<2>(indices) );
60 if (voxelGrid->is_active(indx)) {
61 answer[0]=voxelGrid->get_voxel(indx).getVofAt(tStep->giveIntrinsicTime());
62 } else {
63 answer[0] = 0.0; // empty voxel
64 }
65 return 0;
66 }
67
68 int evaluateAt(FloatArray &answer, DofManager *dman,
69 ValueModeType mode, TimeStep *tStep) override {
70 answer.resize(1);
71 answer[0]=0.0;
72 return 0;
73 }
74
75 int evaluateAt(FloatArray &answer, Element *el,
76 ValueModeType mode, TimeStep *tStep) override {
77 // there is no mapping from element number to voxel idx, so compute element center and get voxel from that
78 FloatArray coords(3);
79 int nnodes = el->giveNumberOfNodes();
80 for (int i=1; i<=nnodes; i++) {
81 auto c = el->giveNode(i)->giveCoordinates();
82 coords.add(c);
83 }
84 coords *= 1000./nnodes; // convert from m to mm
85 auto indices = voxelGrid->get_indices_from_point({coords[0], coords[1], coords[2]});
86 int indx = voxelGrid->get_index( std::get<0>(indices),
87 std::get<1>(indices),
88 std::get<2>(indices) );
89 if (voxelGrid->is_active(indx)) {
90 answer[0]=voxelGrid->get_voxel(indx).getVofAt(tStep->giveIntrinsicTime());
91 } else {
92 answer[0] = 0.0; // empty voxel
93 }
94 return 0;
95 }
96
97 void saveContext(DataStream &stream) override {};
98 void restoreContext(DataStream &stream) override {};
99
100
102 virtual const char *giveClassName() const override {
103 return "VoxelVOFField";
104 }
105
106 // for Field classes supporting instantiation from input record
107 virtual void initializeFrom(InputRecord &ir) override { };
108};
109} // end namespace oofem
110#endif // fvoxelvoffield_h
A class to represent a 3D grid of voxels.
Definition VoxelGrid.h:65
const FloatArray & giveCoordinates() const
Definition dofmanager.h:390
Node * giveNode(int i) const
Definition element.h:629
virtual int giveNumberOfNodes() const
Definition element.h:703
Field(FieldType b=FieldType::FT_Unknown)
Definition field.h:95
void resize(Index s)
Definition floatarray.C:94
void add(const FloatArray &src)
Definition floatarray.C:218
double giveIntrinsicTime()
Returns intrinsic time, e.g. time in which constitutive model is evaluated.
Definition timestep.h:166
void saveContext(DataStream &stream) override
int evaluateAt(FloatArray &answer, Element *el, ValueModeType mode, TimeStep *tStep) override
virtual void initializeFrom(InputRecord &ir) override
int evaluateAt(FloatArray &answer, const FloatArray &coords, ValueModeType mode, TimeStep *tStep) override
virtual const char * giveClassName() const override
VoxelVOFField(VoxelGrid *vg=nullptr)
void setGrid(VoxelGrid *vg)
void restoreContext(DataStream &stream) override
int evaluateAt(FloatArray &answer, DofManager *dman, ValueModeType mode, TimeStep *tStep) override
FieldType
Physical type of field.
Definition field.h:64

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011