Skip to content

Commit

Permalink
Move remaining material_data implementation out of the header (#1622)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoenselaar authored Jun 18, 2021
1 parent 4557738 commit ff405c6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 55 deletions.
47 changes: 47 additions & 0 deletions src/material_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@

#include "material_data.hpp"

#include <algorithm>

#include "meep/mympi.hpp"

namespace meep_geom {

bool transition::operator==(const transition &other) const {
return (from_level == other.from_level && to_level == other.to_level &&
transition_rate == other.transition_rate && frequency == other.frequency &&
vector3_equal(sigma_diag, other.sigma_diag) && gamma == other.gamma &&
pumping_rate == other.pumping_rate);
}

bool transition::operator!=(const transition &other) const { return !(*this == other); }

medium_struct::medium_struct(double epsilon) :
epsilon_diag{epsilon, epsilon, epsilon},
epsilon_offdiag{},
Expand All @@ -43,4 +54,40 @@ void medium_struct::check_offdiag_im_zero_or_abort() const {
}
}

material_data::material_data()
: which_subclass(MEDIUM), medium(), user_func(NULL), user_data(NULL), do_averaging(false),
epsilon_data(NULL), epsilon_dims{}, grid_size{}, weights(NULL), medium_1(),
medium_2(), material_grid_kinds{U_DEFAULT} {}

void material_data::copy_from(const material_data &from) {
which_subclass = from.which_subclass;
medium = from.medium;

user_func = from.user_func;
// NOTE: the user_data field here opaque/void - so this is the best we can do.
user_data = from.user_data;
do_averaging = from.do_averaging;

std::copy(std::begin(from.epsilon_dims), std::end(from.epsilon_dims), std::begin(epsilon_dims));
if (from.epsilon_data) {
size_t N = from.epsilon_dims[0] * from.epsilon_dims[1] * from.epsilon_dims[2];
epsilon_data = new double[N];
std::copy_n(from.epsilon_data, N, epsilon_data);
}

grid_size = from.grid_size;
if (from.weights) {
size_t N = from.grid_size.x * from.grid_size.y * from.grid_size.z;
weights = new double[N];
std::copy_n(from.weights, N, weights);
}

medium_1 = from.medium_1;
medium_2 = from.medium_2;
beta = from.beta;
eta = from.eta;
}

material_type_list::material_type_list() : items(NULL), num_items(0) {}

} // namespace meep_geom
62 changes: 7 additions & 55 deletions src/material_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
/* the void *data field in geometric_object_struct points to */
/* a material_data structure, defined below. */
/***************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>

#include <meep.hpp>
#include <ctlgeom.h>
Expand All @@ -47,14 +43,8 @@ struct transition {
double gamma;
double pumping_rate;

bool operator==(const transition &other) const {
return (from_level == other.from_level && to_level == other.to_level &&
transition_rate == other.transition_rate && frequency == other.frequency &&
vector3_equal(sigma_diag, other.sigma_diag) && gamma == other.gamma &&
pumping_rate == other.pumping_rate);
}

bool operator!=(const transition &other) const { return !(*this == other); }
bool operator==(const transition &other) const;
bool operator!=(const transition &other) const;
};

typedef struct susceptibility_struct {
Expand Down Expand Up @@ -169,47 +159,9 @@ struct material_data {
*/
enum { U_MIN = 0, U_PROD = 1, U_MEAN = 2, U_DEFAULT = 3 } material_grid_kinds;

material_data()
: which_subclass(MEDIUM), medium(), user_func(NULL), user_data(NULL),
do_averaging(false), epsilon_data(NULL),
weights(NULL), medium_1(), medium_2() {
epsilon_dims[0] = 0;
epsilon_dims[1] = 0;
epsilon_dims[2] = 0;
grid_size.x = 0;
grid_size.y = 0;
grid_size.z = 0;
material_grid_kinds = U_DEFAULT;
}

void copy_from(const material_data& from) {
which_subclass = from.which_subclass;
medium = from.medium;

user_func = from.user_func;
// NOTE: the user_data field here opaque/void - so this is the best we can do.
user_data = from.user_data;
do_averaging = from.do_averaging;

memcpy(epsilon_dims, from.epsilon_dims, 3 * sizeof(size_t));
if (from.epsilon_data) {
size_t N = from.epsilon_dims[0] * from.epsilon_dims[1] * from.epsilon_dims[2];
epsilon_data = new double[N];
memcpy(epsilon_data, from.epsilon_data, N * sizeof(double));
}

grid_size = from.grid_size;
if (from.weights) {
size_t N = from.grid_size.x * from.grid_size.y * from.grid_size.z;
weights = new double[N];
memcpy(weights, from.weights, N * sizeof(double));
}

medium_1 = from.medium_1;
medium_2 = from.medium_2;
beta = from.beta;
eta = from.eta;
}
material_data();

void copy_from(const material_data& from);
};

typedef material_data *material_type;
Expand All @@ -218,7 +170,7 @@ struct material_type_list {
material_type *items;
int num_items;

material_type_list() : items(NULL), num_items(0) {}
material_type_list();
};

// global variables
Expand Down

0 comments on commit ff405c6

Please sign in to comment.