File: mfmops.h

package info (click to toggle)
gwyddion 2.52-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 46,588 kB
  • sloc: ansic: 367,740; python: 7,788; sh: 5,245; makefile: 4,317; xml: 3,631; cpp: 2,550; pascal: 418; perl: 154; ruby: 130
file content (178 lines) | stat: -rw-r--r-- 6,523 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 *  $Id: mfmops.h 21471 2018-09-26 19:47:48Z klapetek $
 *  Copyright (C) 2017-2018 David Necas (Yeti), Petr Klapetek.
 *  E-mail: yeti@gwyddion.net, klapetek@gwyddion.net.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */

#ifndef __GWY_MFMOPS_H__
#define __GWY_MFMOPS_H__

#include <libgwyddion/gwymath.h>
#include <libprocess/gwyprocesstypes.h>
#include <libprocess/arithmetic.h>
#include <libprocess/inttrans.h>
#include <libprocess/filters.h>
#include <libprocess/stats.h>
#include <libprocess/mfm.h>

#define MU_0 1.256637061435917295e-6

#define MFM_DIMENSION_ARGS_INIT \
    { 256, 256, 5.0, (gpointer)"m", NULL, -9, 0, FALSE, FALSE }



G_GNUC_UNUSED
static void
set_transfer_function_units(GwyDataField *source, GwyDataField *image,
                            GwyDataField *transferfunc)
{
    GwySIUnit *sunit, *iunit, *tunit, *xyunit;

    xyunit = gwy_data_field_get_si_unit_xy(image);
    sunit = gwy_data_field_get_si_unit_z(source);
    iunit = gwy_data_field_get_si_unit_z(image);
    tunit = gwy_data_field_get_si_unit_z(transferfunc);
    gwy_si_unit_divide(iunit, sunit, tunit);
    gwy_si_unit_power_multiply(tunit, 1, xyunit, -2, tunit);
}

G_GNUC_UNUSED
static gdouble
mfm_factor(GwyMFMGradientType type, gdouble dx, gdouble dy)
{
    if (type == GWY_MFM_GRADIENT_MFM) 
        return 1.0/MU_0;

    if (type == GWY_MFM_GRADIENT_MFM_AREA)
        return 1.0/(MU_0*dx*dy);

    return 1.0;
}

G_GNUC_UNUSED
static gchar*
mfm_unit(GwyMFMGradientType type)
{
    if (type == GWY_MFM_GRADIENT_MFM) 
        return g_strdup("A^2/m");

    if (type == GWY_MFM_GRADIENT_MFM_AREA)
        return g_strdup("A^2/m^3");

    return g_strdup("N/m");
}


G_GNUC_UNUSED
static void
gwy_data_field_mfm_phase_to_force_gradient(GwyDataField *dfield,
                                           gdouble spring_constant,
                                           gdouble quality,
                                           GwyMFMGradientType type)
{
    gdouble dx = gwy_data_field_get_dx(dfield);
    gdouble dy = gwy_data_field_get_dy(dfield);
    gdouble factor = spring_constant/(quality);

    gwy_data_field_multiply(dfield, factor*mfm_factor(type, dx, dy));
    gwy_si_unit_set_from_string(gwy_data_field_get_si_unit_z(dfield), mfm_unit(type));
}

G_GNUC_UNUSED
static void
gwy_data_field_mfm_frequency_shift_to_force_gradient(GwyDataField *dfield,
                                                     gdouble spring_constant,
                                                     gdouble base_frequency,
                                                     GwyMFMGradientType type)
{
    gdouble dx = gwy_data_field_get_dx(dfield);
    gdouble dy = gwy_data_field_get_dy(dfield);
    gdouble factor = 2*spring_constant/(base_frequency);

    gwy_data_field_multiply(dfield, factor*mfm_factor(type, dx, dy));
    gwy_si_unit_set_from_string(gwy_data_field_get_si_unit_z(dfield), mfm_unit(type));
}

G_GNUC_UNUSED
static void
gwy_data_field_mfm_amplitude_shift_to_force_gradient(GwyDataField *dfield,
                                                     gdouble spring_constant,
                                                     gdouble quality,
                                                     gdouble base_amplitude,
                                                     GwyMFMGradientType type)
{
    gdouble dx = gwy_data_field_get_dx(dfield);
    gdouble dy = gwy_data_field_get_dy(dfield);
    gdouble factor = 3*sqrt(3)*spring_constant/(2*base_amplitude*quality);

    gwy_data_field_multiply(dfield, factor*mfm_factor(type, dx, dy));
    gwy_si_unit_set_from_string(gwy_data_field_get_si_unit_z(dfield), mfm_unit(type));
}

// the same code for volume data, this should not be here repeated twice !!!

G_GNUC_UNUSED
static void
gwy_brick_mfm_phase_to_force_gradient(GwyBrick *brick,
                                      gdouble spring_constant,
                                      gdouble quality,
                                      GwyMFMGradientType type)
{
    gdouble dx = gwy_brick_get_xreal(brick)/gwy_brick_get_xres(brick);
    gdouble dy = gwy_brick_get_yreal(brick)/gwy_brick_get_yres(brick);
    gdouble factor = spring_constant/(quality);

    gwy_brick_multiply(brick, factor*mfm_factor(type, dx, dy));
    gwy_si_unit_set_from_string(gwy_brick_get_si_unit_w(brick), mfm_unit(type));
}

G_GNUC_UNUSED
static void
gwy_brick_mfm_frequency_shift_to_force_gradient(GwyBrick *brick,
                                                gdouble spring_constant,
                                                gdouble base_frequency,
                                                GwyMFMGradientType type)
{
    gdouble dx = gwy_brick_get_xreal(brick)/gwy_brick_get_xres(brick);
    gdouble dy = gwy_brick_get_yreal(brick)/gwy_brick_get_yres(brick);
    gdouble factor = 2*spring_constant/(base_frequency);

    gwy_brick_multiply(brick, factor*mfm_factor(type, dx, dy));
    gwy_si_unit_set_from_string(gwy_brick_get_si_unit_w(brick), mfm_unit(type));
}

G_GNUC_UNUSED
static void
gwy_brick_mfm_amplitude_shift_to_force_gradient(GwyBrick *brick,
                                                gdouble spring_constant,
                                                gdouble quality,
                                                gdouble base_amplitude,
                                                GwyMFMGradientType type)
{
    gdouble dx = gwy_brick_get_xreal(brick)/gwy_brick_get_xres(brick);
    gdouble dy = gwy_brick_get_yreal(brick)/gwy_brick_get_yres(brick);
    gdouble factor = 3*sqrt(3)*spring_constant/(2*base_amplitude*quality);

    gwy_brick_multiply(brick, factor*mfm_factor(type, dx, dy));
    gwy_si_unit_set_from_string(gwy_brick_get_si_unit_w(brick), mfm_unit(type));
}

#endif

/* vim: set cin et ts=4 sw=4 cino=>1s,e0,n0,f0,{0,}0,^0,\:1s,=0,g1s,h0,t0,+1s,c3,(0,u0 : */