S
Sean Dettrick
Hi,
I have a class which I want everything to have access to, and
which I only want to construct once.
I have a hierarchy of classes:
class ScalarField{
vector<double> f;
// constructors etc
}
class VectorField{
ScalarField x; // x component
ScalarField y; // y component
ScalarField z; // z component
// constructors etc
}
class ElectroMagneticFields{
VectorField E;
VectorField B;
// constructors etc
}
Each of the Scalar, Vector, and Electromagnetic field quantities is
defined on the same simulation domain. This domain is also described
by a class. It has various methods defined for it, giving boundaries,
domain tiling methods, and a whole bunch of MPI code for parallelism
via domain decomposition:
class Domain{
junk associated with parallelism,
definitions of subdomain boundaries, etc
int crop_domain(); //example function
}
I wish to be able to apply the same domain-related
functions to each type of Field class, e.g.
ScalarField flux();
VectorField fluid_velocity();
ElectroMagneticFields EMF();
flux.crop_domain( Nx,Ny,Nz );
fluid_velocity.crop_domain( Nx,Ny,Nz );
EMF.crop_domain( Nx,Ny,Nz );
My question is this. I only wish to construct the Domain once.
I wish to have every instance of the above fields have access to
the domain class. What's the best way to do it? Private inheritance?
Making an instance of Domain a member of every Field class?
Putting a pointer to Domain in every Field class?
I do not wish to construct 30 odd instances of Domain when they
will all be the same.
Any advice would be appreciated!
Thanks,
Sean
I have a class which I want everything to have access to, and
which I only want to construct once.
I have a hierarchy of classes:
class ScalarField{
vector<double> f;
// constructors etc
}
class VectorField{
ScalarField x; // x component
ScalarField y; // y component
ScalarField z; // z component
// constructors etc
}
class ElectroMagneticFields{
VectorField E;
VectorField B;
// constructors etc
}
Each of the Scalar, Vector, and Electromagnetic field quantities is
defined on the same simulation domain. This domain is also described
by a class. It has various methods defined for it, giving boundaries,
domain tiling methods, and a whole bunch of MPI code for parallelism
via domain decomposition:
class Domain{
junk associated with parallelism,
definitions of subdomain boundaries, etc
int crop_domain(); //example function
}
I wish to be able to apply the same domain-related
functions to each type of Field class, e.g.
ScalarField flux();
VectorField fluid_velocity();
ElectroMagneticFields EMF();
flux.crop_domain( Nx,Ny,Nz );
fluid_velocity.crop_domain( Nx,Ny,Nz );
EMF.crop_domain( Nx,Ny,Nz );
My question is this. I only wish to construct the Domain once.
I wish to have every instance of the above fields have access to
the domain class. What's the best way to do it? Private inheritance?
Making an instance of Domain a member of every Field class?
Putting a pointer to Domain in every Field class?
I do not wish to construct 30 odd instances of Domain when they
will all be the same.
Any advice would be appreciated!
Thanks,
Sean