解释:target = self.survey.source.target collection = self.survey.source.collection '''Mesh''' # Conductivity in S/m (or resistivity in Ohm m) background_conductivity = 1e-6 air_conductivity = 1e-8 # Permeability in H/m background_permeability = mu_0 air_permeability = mu_0 dh = 0.1 # base cell width dom_width = 20.0 # domain width # num. base cells nbc = 2 ** int(np.round(np.log(dom_width / dh) / np.log(2.0))) # Define the base mesh h = [(dh, nbc)] mesh = TreeMesh([h, h, h], x0="CCC") # Mesh refinement near transmitters and receivers mesh = refine_tree_xyz( mesh, collection.receiver_location, octree_levels=[2, 4], method="radial", finalize=False ) # Refine core mesh region xp, yp, zp = np.meshgrid([-1.5, 1.5], [-1.5, 1.5], [-6, -4]) xyz = np.c_[mkvc(xp), mkvc(yp), mkvc(zp)] mesh = refine_tree_xyz(mesh, xyz, octree_levels=[0, 6], method="box", finalize=False) mesh.finalize() '''Maps''' # Find cells that are active in the forward modeling (cells below surface) ind_active = mesh.gridCC[:, 2] < 0 # Define mapping from model to active cells active_sigma_map = maps.InjectActiveCells(mesh, ind_active, air_conductivity) active_mu_map = maps.InjectActiveCells(mesh, ind_active, air_permeability) # Define model. Models in SimPEG are vector arrays N = int(ind_active.sum()) model = np.kron(np.ones((N, 1)), np.c_[background_conductivity, background_permeability]) ind_cylinder = self.getIndicesCylinder( [target.position[0], target.position[1], target.position[2]], target.radius, target.length, [target.pitch, target.roll], mesh.gridCC ) ind_cylinder = ind_cylinder[ind_active] model[ind_cylinder, :] = np.c_[target.conductivity, target.permeability] # Create model vector and wires model = mkvc(model) wire_map = maps.Wires(("sigma", N), ("mu", N)) # Use combo maps to map from model to mesh sigma_map = active_sigma_map * wire_map.sigma mu_map = active_mu_map * wire_map.mu '''Simulation''' simulation = fdem.simulation.Simulation3DMagneticFluxDensity( mesh, survey=self.survey.survey, sigmaMap=sigma_map, muMap=mu_map, Solver=Solver ) '''Predict''' # Compute predicted data for your model. dpred = simulation.dpred(model) dpred = dpred * 1e9 # Data are organized by frequency, transmitter location, then by receiver. # We had nFreq transmitters and each transmitter had 2 receivers (real and # imaginary component). So first we will pick out the real and imaginary # data bx_real = dpred[0: len(dpred): 6] bx_imag = dpred[1: len(dpred): 6] bx_total = np.sqrt(np.square(bx_real) + np.square(bx_imag)) by_real = dpred[2: len(dpred): 6] by_imag = dpred[3: len(dpred): 6] by_total = np.sqrt(np.square(by_real) + np.square(by_imag)) bz_real = dpred[4: len(dpred): 6] bz_imag = dpred[5: len(dpred): 6] bz_total = np.sqrt(np.square(bz_real) + np.square(bz_imag)) mag_data = np.c_[mkvc(bx_total), mkvc(by_total), mkvc(bz_total)] if collection.SNR is not None: mag_data = self.mag_data_add_noise(mag_data, collection.SNR) data = np.c_[collection.receiver_location, mag_data] # data = (data, ) return data
时间: 2024-05-04 10:18:25 浏览: 171
这段代码是一个 Python 函数,它的作用是进行三维电磁正演模拟,并返回模拟得到的数据。函数中的参数包括一个 Survey 对象和一个 Target 对象,表示要模拟的测量参数和模拟目标。函数主要分为三个部分:
1.建立网格和定义模型属性,包括电导率、磁导率和网格大小等。
2.根据接收器位置和目标位置对网格进行细化,以提高模拟精度。
3.进行电磁正演模拟,并返回模拟得到的数据。
其中,模拟的过程中还进行了噪声的添加,以模拟实际测量中的误差。
相关问题
output['Conductivity'] = {} output['Conductivity']['units'] = 'S/m' n = gc.findnumatoms(datfilename) (molcharges, atomcharges,n) = gc.getmolcharges(datfilename,n) molcharge = gc.molchargedict(molcharges, moltypel, moltype) tsjump = gt.getjump(trjfilename[0]) dt = gt.getdt(logfilename) (V, Lx, Ly, Lz) = gcn.getvolume(trjfilename[0]) (comx, comy, comz, Lx, Ly, Lz, Lx2, Ly2, Lz2) = c.calcCOM(trjfilename,datfilename, ver)解释一下代码
这段代码主要是对一些变量进行赋值和计算。具体解释如下:
1. `output['Conductivity'] = {}`:创建一个字典类型的变量 `output` ,并在其中创建一个名为 `Conductivity` 的子字典。
2. `output['Conductivity']['units'] = 'S/m'`:在 `Conductivity` 子字典中创建一个名为 `units` 的键,并将其值赋为字符串 `'S/m'`。
3. `n = gc.findnumatoms(datfilename)`:调用 `gc` 模块中的函数 `findnumatoms`,传入参数 `datfilename`,并将返回值赋给变量 `n`。
4. `(molcharges, atomcharges,n) = gc.getmolcharges(datfilename,n)`:调用 `gc` 模块中的函数 `getmolcharges`,传入参数 `datfilename` 和 `n`,并将返回值分别赋给变量 `molcharges`、`atomcharges` 和 `n`。
5. `molcharge = gc.molchargedict(molcharges, moltypel, moltype)`:调用 `gc` 模块中的函数 `molchargedict`,传入参数 `molcharges`、`moltypel` 和 `moltype`,并将返回值赋给变量 `molcharge`。
6. `tsjump = gt.getjump(trjfilename[0])`:调用 `gt` 模块中的函数 `getjump`,传入参数 `trjfilename[0]`,并将返回值赋给变量 `tsjump`。
7. `dt = gt.getdt(logfilename)`:调用 `gt` 模块中的函数 `getdt`,传入参数 `logfilename`,并将返回值赋给变量 `dt`。
8. `(V, Lx, Ly, Lz) = gcn.getvolume(trjfilename[0])`:调用 `gcn` 模块中的函数 `getvolume`,传入参数 `trjfilename[0]`,并将返回值分别赋给变量 `V`、`Lx`、`Ly` 和 `Lz`。
9. `(comx, comy, comz, Lx, Ly, Lz, Lx2, Ly2, Lz2) = c.calcCOM(trjfilename,datfilename, ver)`:调用 `c` 模块中的函数 `calcCOM`,传入参数 `trjfilename`、`datfilename` 和 `ver`,并将返回值分别赋给变量 `comx`、`comy`、`comz`、`Lx`、`Ly`、`Lz`、`Lx2`、`Ly2` 和 `Lz2`。
openfoam中适合interphasechangefoam的ZuberGoda.C和ZuberGoda.H的代码
以下是OpenFOAM中适用于InterPhaseChangeFoam求解器的ZuberGoda.C和ZuberGoda.H的代码:
ZuberGoda.C:
```
#include "thermoPhysicalModels/basic/lnInclude/ZuberGoda.H"
#include "fluidThermophysicalModels/specie/lnInclude/constThermo.H"
#include "basicThermophysicalModels/lnInclude/twoPhaseMixture.H"
#include "lnInclude.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
ZuberGoda::ZuberGoda
(
const twoPhaseMixture& tpm,
const word& prop,
const word& phase1,
const word& phase2
) :
thermoPhysicalModel(tpm),
property(prop),
phase1_(phase1),
phase2_(phase2)
{
// Get the species thermophysical properties
const volScalarField& rAU = tpm.rAU();
const volScalarField& rAL = tpm.rAL();
const volScalarField& rMU = tpm.rMU();
const volScalarField& rML = tpm.rML();
const volScalarField& hU = tpm.hU();
const volScalarField& hL = tpm.hL();
const volScalarField& sMU = tpm.sMU();
const volScalarField& sML = tpm.sML();
// Get the species fraction fields
const volScalarField& alpha1 = tpm.alpha1();
const volScalarField& alpha2 = tpm.alpha2();
// Calculate the mixture density and specific heat capacity
rho_ = alpha1*rAU + alpha2*rAL;
Cp_ = (alpha1*hU + alpha2*hL)/(alpha1*rAU + alpha2*rAL);
// Calculate the thermal conductivity and dynamic viscosity
const volScalarField lambda = alpha1*tpm.lambdaU() + alpha2*tpm.lambdaL();
const volScalarField mu = alpha1*rMU + alpha2*rML;
// Calculate the Prandtl number
const volScalarField Pr = Cp_*mu/lambda;
// Calculate the saturation temperature
const volScalarField& Tsat = tpm.Tsat();
// Calculate the boiling temperature
const volScalarField Tboil = Tsat*(1.0 + 0.00196*sqrt(rho_));
// Calculate the difference between the boiling and saturation temperatures
const volScalarField dT = Tboil - Tsat;
// Calculate the heat of vaporization
const volScalarField hVapor = (alpha1*hU - alpha2*hL)/(alpha1 - alpha2);
// Calculate the thermal conductivity ratio
const volScalarField lambdaRatio = tpm.lambdaL()/tpm.lambdaU();
// Calculate the heat transfer coefficient ratio
const volScalarField alphaRatio =
0.023*pow(lambdaRatio, 0.8)*pow(Pr, 0.4)*pow(rho_/dT, 0.5);
// Calculate the Zuber-Goda parameter
zg_ = alphaRatio*mu*Cp_/hVapor;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
ZuberGoda::~ZuberGoda()
{
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
volScalarField ZuberGoda::value() const
{
if (property == "ZuberGoda")
{
return zg_;
}
else if (property == "rho")
{
return rho_;
}
else if (property == "Cp")
{
return Cp_;
}
else
{
FatalErrorIn("ZuberGoda::value()")
<< "Unknown property requested: " << property << nl
<< "Valid properties are: ZuberGoda, rho, Cp" << nl
<< abort(FatalError);
}
}
} // End namespace Foam
```
ZuberGoda.H:
```
#ifndef ZuberGoda_H
#define ZuberGoda_H
#include "lnInclude.h"
#include "thermoPhysicalModels/lnInclude/thermoPhysicalModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class ZuberGoda : public thermoPhysicalModel
{
// Private data
//- Property name
const word property;
//- Phase names
const word phase1_;
const word phase2_;
//- Mixture properties
volScalarField rho_;
volScalarField Cp_;
volScalarField zg_;
public:
// Constructors
explicit ZuberGoda
(
const twoPhaseMixture&,
const word& prop,
const word& phase1,
const word& phase2
);
// Destructor
virtual ~ZuberGoda();
// Member functions
virtual volScalarField value() const;
// Static member functions
static const word& typeName();
};
} // End namespace Foam
#endif // ZuberGoda_H
```
这些代码是OpenFOAM中ZuberGoda模型的实现。这个模型计算多相流模型中相变的热物理性质,适用于InterPhaseChangeFoam求解器,提供了更精确的相变模型,能够更好地模拟多相流体系。
阅读全文