AMR-Solver  1.0
Block-based Octree AMR grid flow solver
field.cpp
Go to the documentation of this file.
1 #include "block.h"
2 namespace myOctree {
3 
4 //parametrized constructor with initialization fields
5 Field::Field( int N_x, int N_y, int N_z, std::string info ) : Nx(N_x), Ny(N_y), Nz(N_z), name(info) {
6  // std::cerr << "parametrized constructor of field is working" << std::endl;
7 
8  N = Nx*Ny*Nz;
9  val = new double** [Nx];
10  for(int i=0;i<Nx;i++) {
11  val[i] = new double* [Ny];
12  for(int j=0;j<Ny;j++) {
13  val[i][j] = new double [Nz];
14  }
15  }
16 
17  set_field(0.0);
18 }
19 
20 //default constructor
22  // std::cerr << "default constructor of field is working" << std::endl;
23 
24  Nx = 0;
25  Ny = 0;
26  Nz = 0;
27  N = Nx*Ny*Nz;
28  val = new double** [Nx];
29  for(int i=0;i<Nx;i++) {
30  val[i] = new double* [Ny];
31  for(int j=0;j<Ny;j++) {
32  val[i][j] = new double [Nz];
33  }
34  }
35 }
36 
37 //Copy constructor
38 Field::Field(const Field &obj) {
39 
40  // std::cerr << "copy constructor of field is working" << std::endl;
41 
42  Nx = obj.Nx;
43  Ny = obj.Ny;
44  Nz = obj.Nz;
45  N = obj.N;
46  name = obj.name;
47  // std::cerr << "field is" << name << std::endl;
48 
49  val = new double** [Nx];
50  for(int i=0;i<Nx;i++) {
51  val[i] = new double* [Ny];
52  for(int j=0;j<Ny;j++) {
53  val[i][j] = new double [Nz];
54  memcpy(val[i][j],obj.val[i][j],sizeof(double)*Nz);
55  }
56  }
57 
58  for(int i = 0; i < 3; ++ i) {
59  memcpy(&(bc[i][0]), &(obj.bc[i][0]), 2 * sizeof(FieldBc));
60  }
61 
62 }
63 
64 //Destructor
66  // std::cerr << "delete constructor of field is working" << std::endl;
67 
68  for (int i = 0; i < Nx; ++i) {
69  for (int j = 0; j < Ny; ++j)
70  delete [] val[i][j];
71 
72  delete [] val[i];
73  }
74 
75  delete [] val;
76 
77 }
78 
79 //member function
80 void Field::set_field(double value) {
81 
82  for(int i=0;i<this->Nx;i++) {
83  for(int j=0;j<this->Ny;j++) {
84  for(int k=0;k<this->Nz;k++) {
85  this->val[i][j][k] = value;
86  }
87  }
88  }
89 }
90 
91 
92 }
std::string name
Definition: field.h:21
FieldBc bc[3][2]
Definition: field.h:22
Template class for any scalar field variable in the domain.
Definition: field.h:11
double *** val
Definition: field.h:20
AMR grid stuff.
Definition: adapt.cpp:6
void set_field(double)
Definition: field.cpp:80
field_boundary_flags
Definition: boundary.h:16